blob: 8e8970569ce642ecf7864609b1e7c00148b9df29 [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 -0700121
122import 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 }
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -0800172}
173
Chris Banes9ae4ee82015-09-11 10:32:15 +1000174project.gradle.buildFinished { buildResult ->
175 if (buildResult.getFailure() != null) {
176 println()
177 println 'Build failed. Possible causes include:'
178 println ' 1) Bad codes'
179 println ' 2) Out of date prebuilts in prebuilts/sdk'
Chris Banes9e2e8032015-09-16 10:15:37 +0100180 println ' 3) Need to update the compileSdkVersion in a library\'s build.gradle'
Chris Banes9ae4ee82015-09-11 10:32:15 +1000181 println()
182 }
183}
184
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -0800185FileCollection getAndroidPrebuilt(String apiLevel) {
186 files("$rootDir/../../prebuilts/sdk/$apiLevel/android.jar")
Tor Norbye47c59fb2015-04-08 14:42:16 -0700187}