blob: 9aa0557a7637a5244ef72aa1bcee9343290f8a69 [file] [log] [blame]
Yigit Boyarea5d9b22016-03-08 13:25:26 -08001import com.android.build.gradle.internal.coverage.JacocoReportTask
2import com.android.build.gradle.internal.tasks.DeviceProviderInstrumentTestTask
3
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -08004buildscript {
5 repositories {
6 maven { url '../../prebuilts/gradle-plugin' }
7 maven { url '../../prebuilts/tools/common/m2/repository' }
8 maven { url '../../prebuilts/tools/common/m2/internal' }
Yigit Boyarc9750a12016-01-06 17:28:55 -08009 maven { url "../../prebuilts/maven_repo/android" }
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -080010 }
11 dependencies {
Yigit Boyarc9750a12016-01-06 17:28:55 -080012 classpath 'com.android.tools.build:gradle:1.5.0'
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -080013 }
14}
15
Ian Pedowitzc0f4ca62016-02-29 16:21:03 +000016ext.supportVersion = '24.0.0-SNAPSHOT'
17ext.extraVersion = 25
Xavier Ducrohet020e4322014-03-18 16:41:30 -070018ext.supportRepoOut = ''
Yigit Boyarc9750a12016-01-06 17:28:55 -080019ext.buildToolsVersion = '23.0.2'
Xavier Ducrohetfa385272014-11-14 13:12:09 -080020ext.buildNumber = Integer.toString(ext.extraVersion)
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -080021
Xavier Ducrohet020e4322014-03-18 16:41:30 -070022/*
23 * With the build server you are given two env variables.
24 * The OUT_DIR is a temporary directory you can use to put things during the build.
25 * The DIST_DIR is where you want to save things from the build.
26 *
27 * The build server will copy the contents of DIST_DIR to somewhere and make it available.
28 */
29if (System.env.DIST_DIR != null && System.env.OUT_DIR != null) {
Xavier Ducrohet4e04b7a2014-10-17 18:02:33 -070030 buildDir = new File(System.env.OUT_DIR + '/gradle/frameworks/support/build').getCanonicalFile()
31 project.ext.distDir = new File(System.env.DIST_DIR).getCanonicalFile()
Xavier Ducrohetfa385272014-11-14 13:12:09 -080032
33 // the build server does not pass the build number so we infer it from the last folder of the dist path.
34 ext.buildNumber = project.ext.distDir.getName()
Xavier Ducrohet020e4322014-03-18 16:41:30 -070035} else {
36 buildDir = file('../../out/host/gradle/frameworks/support/build')
37 project.ext.distDir = file('../../out/dist')
38}
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -080039
Xavier Ducrohet020e4322014-03-18 16:41:30 -070040ext.supportRepoOut = new File(buildDir, 'support_repo')
Yigit Boyarf18d9752015-12-01 13:45:28 -080041ext.testApkDistOut = ext.distDir
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -080042
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -070043// Main task called by the build server.
44task(createArchive) << {
Xavier Ducrohet020e4322014-03-18 16:41:30 -070045}
46
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -070047
48// upload anchor for subprojects to upload their artifacts
49// to the local repo.
50task(mainUpload) << {
51}
52
53// repository creation task
54task createRepository(type: Zip, dependsOn: mainUpload) {
Xavier Ducrohet020e4322014-03-18 16:41:30 -070055 from project.ext.supportRepoOut
56 destinationDir project.ext.distDir
Xavier Ducrohet9dc44802014-03-20 14:15:16 -070057 into 'm2repository'
Xavier Ducrohetfa385272014-11-14 13:12:09 -080058 baseName = String.format("sdk-repo-linux-m2repository-%s", project.ext.buildNumber)
Xavier Ducrohet020e4322014-03-18 16:41:30 -070059}
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -070060createArchive.dependsOn createRepository
Xavier Ducrohet020e4322014-03-18 16:41:30 -070061
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -070062// prepare repository with older versions
Xavier Ducrohet64fe2322014-06-16 17:59:34 -070063task unzipRepo(type: Copy) {
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -080064 from "$rootDir/../../prebuilts/maven_repo/android"
Xavier Ducrohet855a9222014-01-02 19:00:43 -080065 into project.ext.supportRepoOut
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -080066}
67
Xavier Ducrohet64fe2322014-06-16 17:59:34 -070068unzipRepo.doFirst {
Xavier Ducrohet020e4322014-03-18 16:41:30 -070069 project.ext.supportRepoOut.deleteDir()
70 project.ext.supportRepoOut.mkdirs()
71}
72
Xavier Ducrohet64fe2322014-06-16 17:59:34 -070073// anchor for prepare repo. This is post unzip + sourceProp.
74task(prepareRepo) << {
75}
76
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -070077import com.google.common.io.Files
78import com.google.common.base.Charsets
79
80task(createXml) << {
81 def repoArchive = createRepository.archivePath
82 def repoArchiveName = createRepository.archiveName
83 def size = repoArchive.length()
84 def sha1 = getSha1(repoArchive)
85
86 def xml =
87"<sdk:sdk-addon xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:sdk=\"http://schemas.android.com/sdk/android/addon/6\">\n\
88 <sdk:extra>\n\
89 <sdk:revision>\n\
90 <sdk:major>${project.ext.extraVersion}</sdk:major>\n\
91 </sdk:revision>\n\
92 <sdk:vendor-display>Android</sdk:vendor-display>\n\
93 <sdk:vendor-id>android</sdk:vendor-id>\n\
94 <sdk:name-display>Local Maven repository for Support Libraries</sdk:name-display>\n\
95 <sdk:path>m2repository</sdk:path>\n\
96 <sdk:archives>\n\
Xavier Ducrohetc16b62d2014-12-09 12:37:45 -080097 <sdk:archive>\n\
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -070098 <sdk:size>${size}</sdk:size>\n\
99 <sdk:checksum type=\"sha1\">${sha1}</sdk:checksum>\n\
100 <sdk:url>${repoArchiveName}</sdk:url>\n\
101 </sdk:archive>\n\
102 </sdk:archives>\n\
103 </sdk:extra>\n\
104</sdk:sdk-addon>"
105
106 Files.write(xml, new File(project.ext.distDir, 'repo-extras.xml'), Charsets.UTF_8)
107}
108createArchive.dependsOn createXml
109
Xavier Ducrohet64fe2322014-06-16 17:59:34 -0700110task(createSourceProp) << {
111 def sourceProp =
112"Extra.VendorDisplay=Android\n\
113Extra.Path=m2repository\n\
114Archive.Arch=ANY\n\
115Extra.NameDisplay=Android Support Repository\n\
116Archive.Os=ANY\n\
117Pkg.Revision=${project.ext.extraVersion}.0.0\n\
118Extra.VendorId=android"
119
120 Files.write(sourceProp, new File(project.ext.supportRepoOut, 'source.properties'), Charsets.UTF_8)
121}
122createSourceProp.dependsOn unzipRepo
123prepareRepo.dependsOn createSourceProp
124
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -0700125import com.google.common.hash.HashCode
126import com.google.common.hash.HashFunction
127import com.google.common.hash.Hashing
Chris Banes96f1e912015-03-05 20:04:05 +0000128import java.nio.charset.Charset
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -0700129
130def getSha1(File inputFile) {
131 HashFunction hashFunction = Hashing.sha1()
Chris Banes96f1e912015-03-05 20:04:05 +0000132 HashCode hashCode = hashFunction.hashString(inputFile.getAbsolutePath(), Charset.forName("UTF-8"))
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -0700133 return hashCode.toString()
134}
135
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -0800136subprojects {
137 // Change buildDir first so that all plugins pick up the new value.
Xavier Ducrohet616b95d2014-02-12 09:09:43 -0800138 project.buildDir = project.file("$project.parent.buildDir/../$project.name/build")
Yigit Boyar02a9e8c2016-01-26 20:41:00 -0800139 project.ext.currentSdk = 'current'
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -0800140 apply plugin: 'maven'
141
Xavier Ducrohet855a9222014-01-02 19:00:43 -0800142 version = rootProject.ext.supportVersion
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -0800143 group = 'com.android.support'
144
Yigit Boyarbe7a54a2015-04-07 13:23:50 -0700145 repositories {
146 maven { url "${project.parent.projectDir}/../../prebuilts/tools/common/m2/repository" }
147 maven { url "${project.parent.projectDir}/../../prebuilts/tools/common/m2/internal" }
148 maven { url "${project.parent.projectDir}/../../prebuilts/maven_repo/android" }
149 }
150
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -0800151 task release(type: Upload) {
152 configuration = configurations.archives
153 repositories {
154 mavenDeployer {
Xavier Ducrohet855a9222014-01-02 19:00:43 -0800155 repository(url: uri("$rootProject.ext.supportRepoOut"))
Justin Klaassen533239e2016-01-09 09:16:23 -0800156
157 // Disable unique names for SNAPSHOTS so they can be updated in place.
158 setUniqueVersion(false)
Justin Klaassend99d7742016-01-21 15:33:57 -0800159 doLast {
160 // Remove any invalid maven-metadata.xml files that may have been created
161 // for SNAPSHOT versions that are *not* uniquely versioned.
162 pom*.each { pom ->
163 if (pom.version.endsWith('-SNAPSHOT')) {
164 final File artifactDir = new File(rootProject.ext.supportRepoOut,
165 pom.groupId.replace('.', '/')
166 + '/' + pom.artifactId
167 + '/' + pom.version)
168 delete fileTree(dir: artifactDir, include: 'maven-metadata.xml*')
169 }
170 }
171 }
Justin Klaassen533239e2016-01-09 09:16:23 -0800172 }
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -0800173 }
174 }
Xavier Ducrohet020e4322014-03-18 16:41:30 -0700175
Xavier Ducrohete4cf5a92015-03-06 17:17:30 -0800176 def deployer = release.repositories.mavenDeployer
177 deployer.pom*.whenConfigured { pom ->
178 pom.dependencies.findAll {dep -> dep.groupId == 'com.android.support' && dep.artifactId != 'support-annotations' }*.type = 'aar'
179 }
180
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -0700181 // before the upload, make sure the repo is ready.
Xavier Ducrohet020e4322014-03-18 16:41:30 -0700182 release.dependsOn rootProject.tasks.prepareRepo
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -0700183 // make the mainupload depend on this one.
Xavier Ducrohet020e4322014-03-18 16:41:30 -0700184 mainUpload.dependsOn release
Jeff Davidson84faec52014-06-18 09:10:36 -0700185
186 project.plugins.whenPluginAdded { plugin ->
187 if ("com.android.build.gradle.LibraryPlugin".equals(plugin.class.name)) {
188 project.android.buildToolsVersion = rootProject.buildToolsVersion
Yigit Boyarea5d9b22016-03-08 13:25:26 -0800189 // enable code coverage for debug builds
190 // run createDebugCoverageReport to get the coverage
191 project.android.buildTypes.debug.testCoverageEnabled = true
Jeff Davidson84faec52014-06-18 09:10:36 -0700192 }
193 }
Chris Banesdaea0692015-12-29 12:48:24 +0000194
195 // Copy instrumentation test APK into the dist dir
196 project.afterEvaluate {
197 def assembleTestTask = project.tasks.findByPath('assembleAndroidTest')
198 if (assembleTestTask != null) {
199 assembleTestTask.doLast {
200 // If the project actually has some instrumentation tests, copy its APK
201 if (!project.android.sourceSets.androidTest.java.sourceFiles.isEmpty()) {
202 def pkgTask = project.tasks.findByPath('packageDebugAndroidTest')
203 copy {
204 from(pkgTask.outputFile)
205 into(rootProject.ext.testApkDistOut)
206 }
207 }
208 }
209 }
210 }
Yigit Boyarea5d9b22016-03-08 13:25:26 -0800211
212 project.afterEvaluate { p ->
213 // remove dependency on the test so that we still get coverage even if some tests fail
214 p.tasks.findAll { it instanceof JacocoReportTask}.each { task ->
215 def toBeRemoved = new ArrayList()
216 def dependencyList = task.taskDependencies.values
217 dependencyList.each { dep ->
218 if (dep instanceof String) {
219 def t = tasks.findByName(dep)
220 if (t instanceof DeviceProviderInstrumentTestTask) {
221 toBeRemoved.add(dep)
222 task.mustRunAfter(t)
223 }
224 }
225 }
226 toBeRemoved.each { dep ->
227 dependencyList.remove(dep)
228 }
229 }
230 }
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -0800231}
232
Chris Banes9ae4ee82015-09-11 10:32:15 +1000233project.gradle.buildFinished { buildResult ->
234 if (buildResult.getFailure() != null) {
235 println()
236 println 'Build failed. Possible causes include:'
237 println ' 1) Bad codes'
238 println ' 2) Out of date prebuilts in prebuilts/sdk'
Chris Banes9e2e8032015-09-16 10:15:37 +0100239 println ' 3) Need to update the compileSdkVersion in a library\'s build.gradle'
Chris Banes9ae4ee82015-09-11 10:32:15 +1000240 println()
241 }
242}
243
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -0800244FileCollection getAndroidPrebuilt(String apiLevel) {
245 files("$rootDir/../../prebuilts/sdk/$apiLevel/android.jar")
Tor Norbye47c59fb2015-04-08 14:42:16 -0700246}