blob: df98124aa41177bdce7e43dc2435ab596298611e [file] [log] [blame]
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -08001buildscript {
2 repositories {
3 maven { url '../../prebuilts/gradle-plugin' }
4 maven { url '../../prebuilts/tools/common/m2/repository' }
5 maven { url '../../prebuilts/tools/common/m2/internal' }
Yigit Boyarc9750a12016-01-06 17:28:55 -08006 maven { url "../../prebuilts/maven_repo/android" }
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -08007 }
8 dependencies {
Yigit Boyarc9750a12016-01-06 17:28:55 -08009 classpath 'com.android.tools.build:gradle:1.5.0'
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -080010 }
11}
12
Chris Flatt86e7e292015-11-02 13:12:37 -080013ext.supportVersion = '23.2.0-SNAPSHOT'
Chris Flatt5a948ff2015-10-27 08:00:57 -070014ext.extraVersion = 25
Xavier Ducrohet020e4322014-03-18 16:41:30 -070015ext.supportRepoOut = ''
Yigit Boyarc9750a12016-01-06 17:28:55 -080016ext.buildToolsVersion = '23.0.2'
Xavier Ducrohetfa385272014-11-14 13:12:09 -080017ext.buildNumber = Integer.toString(ext.extraVersion)
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -080018
Xavier Ducrohet020e4322014-03-18 16:41:30 -070019/*
20 * With the build server you are given two env variables.
21 * The OUT_DIR is a temporary directory you can use to put things during the build.
22 * The DIST_DIR is where you want to save things from the build.
23 *
24 * The build server will copy the contents of DIST_DIR to somewhere and make it available.
25 */
26if (System.env.DIST_DIR != null && System.env.OUT_DIR != null) {
Xavier Ducrohet4e04b7a2014-10-17 18:02:33 -070027 buildDir = new File(System.env.OUT_DIR + '/gradle/frameworks/support/build').getCanonicalFile()
28 project.ext.distDir = new File(System.env.DIST_DIR).getCanonicalFile()
Xavier Ducrohetfa385272014-11-14 13:12:09 -080029
30 // the build server does not pass the build number so we infer it from the last folder of the dist path.
31 ext.buildNumber = project.ext.distDir.getName()
Xavier Ducrohet020e4322014-03-18 16:41:30 -070032} else {
33 buildDir = file('../../out/host/gradle/frameworks/support/build')
34 project.ext.distDir = file('../../out/dist')
35}
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -080036
Xavier Ducrohet020e4322014-03-18 16:41:30 -070037ext.supportRepoOut = new File(buildDir, 'support_repo')
Yigit Boyarf18d9752015-12-01 13:45:28 -080038ext.testApkDistOut = ext.distDir
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -080039
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -070040// Main task called by the build server.
41task(createArchive) << {
Xavier Ducrohet020e4322014-03-18 16:41:30 -070042}
43
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -070044
45// upload anchor for subprojects to upload their artifacts
46// to the local repo.
47task(mainUpload) << {
48}
49
50// repository creation task
51task createRepository(type: Zip, dependsOn: mainUpload) {
Xavier Ducrohet020e4322014-03-18 16:41:30 -070052 from project.ext.supportRepoOut
53 destinationDir project.ext.distDir
Xavier Ducrohet9dc44802014-03-20 14:15:16 -070054 into 'm2repository'
Xavier Ducrohetfa385272014-11-14 13:12:09 -080055 baseName = String.format("sdk-repo-linux-m2repository-%s", project.ext.buildNumber)
Xavier Ducrohet020e4322014-03-18 16:41:30 -070056}
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -070057createArchive.dependsOn createRepository
Xavier Ducrohet020e4322014-03-18 16:41:30 -070058
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -070059// prepare repository with older versions
Xavier Ducrohet64fe2322014-06-16 17:59:34 -070060task unzipRepo(type: Copy) {
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -080061 from "$rootDir/../../prebuilts/maven_repo/android"
Xavier Ducrohet855a9222014-01-02 19:00:43 -080062 into project.ext.supportRepoOut
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -080063}
64
Xavier Ducrohet64fe2322014-06-16 17:59:34 -070065unzipRepo.doFirst {
Xavier Ducrohet020e4322014-03-18 16:41:30 -070066 project.ext.supportRepoOut.deleteDir()
67 project.ext.supportRepoOut.mkdirs()
68}
69
Xavier Ducrohet64fe2322014-06-16 17:59:34 -070070// anchor for prepare repo. This is post unzip + sourceProp.
71task(prepareRepo) << {
72}
73
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -070074import com.google.common.io.Files
75import com.google.common.base.Charsets
76
77task(createXml) << {
78 def repoArchive = createRepository.archivePath
79 def repoArchiveName = createRepository.archiveName
80 def size = repoArchive.length()
81 def sha1 = getSha1(repoArchive)
82
83 def xml =
84"<sdk:sdk-addon xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:sdk=\"http://schemas.android.com/sdk/android/addon/6\">\n\
85 <sdk:extra>\n\
86 <sdk:revision>\n\
87 <sdk:major>${project.ext.extraVersion}</sdk:major>\n\
88 </sdk:revision>\n\
89 <sdk:vendor-display>Android</sdk:vendor-display>\n\
90 <sdk:vendor-id>android</sdk:vendor-id>\n\
91 <sdk:name-display>Local Maven repository for Support Libraries</sdk:name-display>\n\
92 <sdk:path>m2repository</sdk:path>\n\
93 <sdk:archives>\n\
Xavier Ducrohetc16b62d2014-12-09 12:37:45 -080094 <sdk:archive>\n\
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -070095 <sdk:size>${size}</sdk:size>\n\
96 <sdk:checksum type=\"sha1\">${sha1}</sdk:checksum>\n\
97 <sdk:url>${repoArchiveName}</sdk:url>\n\
98 </sdk:archive>\n\
99 </sdk:archives>\n\
100 </sdk:extra>\n\
101</sdk:sdk-addon>"
102
103 Files.write(xml, new File(project.ext.distDir, 'repo-extras.xml'), Charsets.UTF_8)
104}
105createArchive.dependsOn createXml
106
Xavier Ducrohet64fe2322014-06-16 17:59:34 -0700107task(createSourceProp) << {
108 def sourceProp =
109"Extra.VendorDisplay=Android\n\
110Extra.Path=m2repository\n\
111Archive.Arch=ANY\n\
112Extra.NameDisplay=Android Support Repository\n\
113Archive.Os=ANY\n\
114Pkg.Revision=${project.ext.extraVersion}.0.0\n\
115Extra.VendorId=android"
116
117 Files.write(sourceProp, new File(project.ext.supportRepoOut, 'source.properties'), Charsets.UTF_8)
118}
119createSourceProp.dependsOn unzipRepo
120prepareRepo.dependsOn createSourceProp
121
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -0700122import com.google.common.hash.HashCode
123import com.google.common.hash.HashFunction
124import com.google.common.hash.Hashing
Chris Banes96f1e912015-03-05 20:04:05 +0000125import java.nio.charset.Charset
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -0700126
127def getSha1(File inputFile) {
128 HashFunction hashFunction = Hashing.sha1()
Chris Banes96f1e912015-03-05 20:04:05 +0000129 HashCode hashCode = hashFunction.hashString(inputFile.getAbsolutePath(), Charset.forName("UTF-8"))
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -0700130 return hashCode.toString()
131}
132
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -0800133subprojects {
134 // Change buildDir first so that all plugins pick up the new value.
Xavier Ducrohet616b95d2014-02-12 09:09:43 -0800135 project.buildDir = project.file("$project.parent.buildDir/../$project.name/build")
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -0800136
137 apply plugin: 'maven'
138
Xavier Ducrohet855a9222014-01-02 19:00:43 -0800139 version = rootProject.ext.supportVersion
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -0800140 group = 'com.android.support'
141
Yigit Boyarbe7a54a2015-04-07 13:23:50 -0700142 repositories {
143 maven { url "${project.parent.projectDir}/../../prebuilts/tools/common/m2/repository" }
144 maven { url "${project.parent.projectDir}/../../prebuilts/tools/common/m2/internal" }
145 maven { url "${project.parent.projectDir}/../../prebuilts/maven_repo/android" }
146 }
147
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -0800148 task release(type: Upload) {
149 configuration = configurations.archives
150 repositories {
151 mavenDeployer {
Xavier Ducrohet855a9222014-01-02 19:00:43 -0800152 repository(url: uri("$rootProject.ext.supportRepoOut"))
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -0800153 }
154 }
155 }
Xavier Ducrohet020e4322014-03-18 16:41:30 -0700156
Xavier Ducrohete4cf5a92015-03-06 17:17:30 -0800157 def deployer = release.repositories.mavenDeployer
158 deployer.pom*.whenConfigured { pom ->
159 pom.dependencies.findAll {dep -> dep.groupId == 'com.android.support' && dep.artifactId != 'support-annotations' }*.type = 'aar'
160 }
161
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -0700162 // before the upload, make sure the repo is ready.
Xavier Ducrohet020e4322014-03-18 16:41:30 -0700163 release.dependsOn rootProject.tasks.prepareRepo
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -0700164 // make the mainupload depend on this one.
Xavier Ducrohet020e4322014-03-18 16:41:30 -0700165 mainUpload.dependsOn release
Jeff Davidson84faec52014-06-18 09:10:36 -0700166
167 project.plugins.whenPluginAdded { plugin ->
168 if ("com.android.build.gradle.LibraryPlugin".equals(plugin.class.name)) {
169 project.android.buildToolsVersion = rootProject.buildToolsVersion
170 }
171 }
Chris Banesdaea0692015-12-29 12:48:24 +0000172
173 // Copy instrumentation test APK into the dist dir
174 project.afterEvaluate {
175 def assembleTestTask = project.tasks.findByPath('assembleAndroidTest')
176 if (assembleTestTask != null) {
177 assembleTestTask.doLast {
178 // If the project actually has some instrumentation tests, copy its APK
179 if (!project.android.sourceSets.androidTest.java.sourceFiles.isEmpty()) {
180 def pkgTask = project.tasks.findByPath('packageDebugAndroidTest')
181 copy {
182 from(pkgTask.outputFile)
183 into(rootProject.ext.testApkDistOut)
184 }
185 }
186 }
187 }
188 }
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -0800189}
190
Chris Banes9ae4ee82015-09-11 10:32:15 +1000191project.gradle.buildFinished { buildResult ->
192 if (buildResult.getFailure() != null) {
193 println()
194 println 'Build failed. Possible causes include:'
195 println ' 1) Bad codes'
196 println ' 2) Out of date prebuilts in prebuilts/sdk'
Chris Banes9e2e8032015-09-16 10:15:37 +0100197 println ' 3) Need to update the compileSdkVersion in a library\'s build.gradle'
Chris Banes9ae4ee82015-09-11 10:32:15 +1000198 println()
199 }
200}
201
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -0800202FileCollection getAndroidPrebuilt(String apiLevel) {
203 files("$rootDir/../../prebuilts/sdk/$apiLevel/android.jar")
Tor Norbye47c59fb2015-04-08 14:42:16 -0700204}