blob: 45d99010fbdcd5fe3add3fce8a774d60698ceb5a [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' }
6 }
7 dependencies {
Chris Banes490bf522015-08-07 11:13:34 +01008 classpath 'com.android.tools.build:gradle:1.3.1'
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -08009 }
10}
11
Chris Flatt86e7e292015-11-02 13:12:37 -080012ext.supportVersion = '23.2.0-SNAPSHOT'
Chris Flatt5a948ff2015-10-27 08:00:57 -070013ext.extraVersion = 25
Xavier Ducrohet020e4322014-03-18 16:41:30 -070014ext.supportRepoOut = ''
Chris Banesf9190ca2015-05-11 16:04:09 +010015ext.buildToolsVersion = '22.1.0'
Xavier Ducrohetfa385272014-11-14 13:12:09 -080016ext.buildNumber = Integer.toString(ext.extraVersion)
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -080017
Xavier Ducrohet020e4322014-03-18 16:41:30 -070018/*
19 * With the build server you are given two env variables.
20 * The OUT_DIR is a temporary directory you can use to put things during the build.
21 * The DIST_DIR is where you want to save things from the build.
22 *
23 * The build server will copy the contents of DIST_DIR to somewhere and make it available.
24 */
25if (System.env.DIST_DIR != null && System.env.OUT_DIR != null) {
Xavier Ducrohet4e04b7a2014-10-17 18:02:33 -070026 buildDir = new File(System.env.OUT_DIR + '/gradle/frameworks/support/build').getCanonicalFile()
27 project.ext.distDir = new File(System.env.DIST_DIR).getCanonicalFile()
Xavier Ducrohetfa385272014-11-14 13:12:09 -080028
29 // the build server does not pass the build number so we infer it from the last folder of the dist path.
30 ext.buildNumber = project.ext.distDir.getName()
Xavier Ducrohet020e4322014-03-18 16:41:30 -070031} else {
32 buildDir = file('../../out/host/gradle/frameworks/support/build')
33 project.ext.distDir = file('../../out/dist')
34}
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -080035
Xavier Ducrohet020e4322014-03-18 16:41:30 -070036ext.supportRepoOut = new File(buildDir, 'support_repo')
Yigit Boyarf18d9752015-12-01 13:45:28 -080037ext.testApkDistOut = ext.distDir
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -080038
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -070039// Main task called by the build server.
40task(createArchive) << {
Xavier Ducrohet020e4322014-03-18 16:41:30 -070041}
42
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -070043
44// upload anchor for subprojects to upload their artifacts
45// to the local repo.
46task(mainUpload) << {
47}
48
49// repository creation task
50task createRepository(type: Zip, dependsOn: mainUpload) {
Xavier Ducrohet020e4322014-03-18 16:41:30 -070051 from project.ext.supportRepoOut
52 destinationDir project.ext.distDir
Xavier Ducrohet9dc44802014-03-20 14:15:16 -070053 into 'm2repository'
Xavier Ducrohetfa385272014-11-14 13:12:09 -080054 baseName = String.format("sdk-repo-linux-m2repository-%s", project.ext.buildNumber)
Xavier Ducrohet020e4322014-03-18 16:41:30 -070055}
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -070056createArchive.dependsOn createRepository
Xavier Ducrohet020e4322014-03-18 16:41:30 -070057
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -070058// prepare repository with older versions
Xavier Ducrohet64fe2322014-06-16 17:59:34 -070059task unzipRepo(type: Copy) {
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -080060 from "$rootDir/../../prebuilts/maven_repo/android"
Xavier Ducrohet855a9222014-01-02 19:00:43 -080061 into project.ext.supportRepoOut
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -080062}
63
Xavier Ducrohet64fe2322014-06-16 17:59:34 -070064unzipRepo.doFirst {
Xavier Ducrohet020e4322014-03-18 16:41:30 -070065 project.ext.supportRepoOut.deleteDir()
66 project.ext.supportRepoOut.mkdirs()
67}
68
Xavier Ducrohet64fe2322014-06-16 17:59:34 -070069// anchor for prepare repo. This is post unzip + sourceProp.
70task(prepareRepo) << {
71}
72
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -070073import com.google.common.io.Files
74import com.google.common.base.Charsets
75
76task(createXml) << {
77 def repoArchive = createRepository.archivePath
78 def repoArchiveName = createRepository.archiveName
79 def size = repoArchive.length()
80 def sha1 = getSha1(repoArchive)
81
82 def xml =
83"<sdk:sdk-addon xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:sdk=\"http://schemas.android.com/sdk/android/addon/6\">\n\
84 <sdk:extra>\n\
85 <sdk:revision>\n\
86 <sdk:major>${project.ext.extraVersion}</sdk:major>\n\
87 </sdk:revision>\n\
88 <sdk:vendor-display>Android</sdk:vendor-display>\n\
89 <sdk:vendor-id>android</sdk:vendor-id>\n\
90 <sdk:name-display>Local Maven repository for Support Libraries</sdk:name-display>\n\
91 <sdk:path>m2repository</sdk:path>\n\
92 <sdk:archives>\n\
Xavier Ducrohetc16b62d2014-12-09 12:37:45 -080093 <sdk:archive>\n\
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -070094 <sdk:size>${size}</sdk:size>\n\
95 <sdk:checksum type=\"sha1\">${sha1}</sdk:checksum>\n\
96 <sdk:url>${repoArchiveName}</sdk:url>\n\
97 </sdk:archive>\n\
98 </sdk:archives>\n\
99 </sdk:extra>\n\
100</sdk:sdk-addon>"
101
102 Files.write(xml, new File(project.ext.distDir, 'repo-extras.xml'), Charsets.UTF_8)
103}
104createArchive.dependsOn createXml
105
Xavier Ducrohet64fe2322014-06-16 17:59:34 -0700106task(createSourceProp) << {
107 def sourceProp =
108"Extra.VendorDisplay=Android\n\
109Extra.Path=m2repository\n\
110Archive.Arch=ANY\n\
111Extra.NameDisplay=Android Support Repository\n\
112Archive.Os=ANY\n\
113Pkg.Revision=${project.ext.extraVersion}.0.0\n\
114Extra.VendorId=android"
115
116 Files.write(sourceProp, new File(project.ext.supportRepoOut, 'source.properties'), Charsets.UTF_8)
117}
118createSourceProp.dependsOn unzipRepo
119prepareRepo.dependsOn createSourceProp
120
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -0700121import com.google.common.hash.HashCode
122import com.google.common.hash.HashFunction
123import com.google.common.hash.Hashing
Chris Banes96f1e912015-03-05 20:04:05 +0000124import java.nio.charset.Charset
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -0700125
126def getSha1(File inputFile) {
127 HashFunction hashFunction = Hashing.sha1()
Chris Banes96f1e912015-03-05 20:04:05 +0000128 HashCode hashCode = hashFunction.hashString(inputFile.getAbsolutePath(), Charset.forName("UTF-8"))
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -0700129 return hashCode.toString()
130}
131
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -0800132subprojects {
133 // Change buildDir first so that all plugins pick up the new value.
Xavier Ducrohet616b95d2014-02-12 09:09:43 -0800134 project.buildDir = project.file("$project.parent.buildDir/../$project.name/build")
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -0800135
136 apply plugin: 'maven'
137
Xavier Ducrohet855a9222014-01-02 19:00:43 -0800138 version = rootProject.ext.supportVersion
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -0800139 group = 'com.android.support'
140
Yigit Boyarbe7a54a2015-04-07 13:23:50 -0700141 repositories {
142 maven { url "${project.parent.projectDir}/../../prebuilts/tools/common/m2/repository" }
143 maven { url "${project.parent.projectDir}/../../prebuilts/tools/common/m2/internal" }
144 maven { url "${project.parent.projectDir}/../../prebuilts/maven_repo/android" }
145 }
146
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -0800147 task release(type: Upload) {
148 configuration = configurations.archives
149 repositories {
150 mavenDeployer {
Xavier Ducrohet855a9222014-01-02 19:00:43 -0800151 repository(url: uri("$rootProject.ext.supportRepoOut"))
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -0800152 }
153 }
154 }
Xavier Ducrohet020e4322014-03-18 16:41:30 -0700155
Xavier Ducrohete4cf5a92015-03-06 17:17:30 -0800156 def deployer = release.repositories.mavenDeployer
157 deployer.pom*.whenConfigured { pom ->
158 pom.dependencies.findAll {dep -> dep.groupId == 'com.android.support' && dep.artifactId != 'support-annotations' }*.type = 'aar'
159 }
160
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -0700161 // before the upload, make sure the repo is ready.
Xavier Ducrohet020e4322014-03-18 16:41:30 -0700162 release.dependsOn rootProject.tasks.prepareRepo
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -0700163 // make the mainupload depend on this one.
Xavier Ducrohet020e4322014-03-18 16:41:30 -0700164 mainUpload.dependsOn release
Jeff Davidson84faec52014-06-18 09:10:36 -0700165
166 project.plugins.whenPluginAdded { plugin ->
167 if ("com.android.build.gradle.LibraryPlugin".equals(plugin.class.name)) {
168 project.android.buildToolsVersion = rootProject.buildToolsVersion
169 }
170 }
Chris Banesdaea0692015-12-29 12:48:24 +0000171
172 // Copy instrumentation test APK into the dist dir
173 project.afterEvaluate {
174 def assembleTestTask = project.tasks.findByPath('assembleAndroidTest')
175 if (assembleTestTask != null) {
176 assembleTestTask.doLast {
177 // If the project actually has some instrumentation tests, copy its APK
178 if (!project.android.sourceSets.androidTest.java.sourceFiles.isEmpty()) {
179 def pkgTask = project.tasks.findByPath('packageDebugAndroidTest')
180 copy {
181 from(pkgTask.outputFile)
182 into(rootProject.ext.testApkDistOut)
183 }
184 }
185 }
186 }
187 }
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -0800188}
189
Chris Banes9ae4ee82015-09-11 10:32:15 +1000190project.gradle.buildFinished { buildResult ->
191 if (buildResult.getFailure() != null) {
192 println()
193 println 'Build failed. Possible causes include:'
194 println ' 1) Bad codes'
195 println ' 2) Out of date prebuilts in prebuilts/sdk'
Chris Banes9e2e8032015-09-16 10:15:37 +0100196 println ' 3) Need to update the compileSdkVersion in a library\'s build.gradle'
Chris Banes9ae4ee82015-09-11 10:32:15 +1000197 println()
198 }
199}
200
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -0800201FileCollection getAndroidPrebuilt(String apiLevel) {
202 files("$rootDir/../../prebuilts/sdk/$apiLevel/android.jar")
Tor Norbye47c59fb2015-04-08 14:42:16 -0700203}