blob: 79896f52c400c025e13bf48a537aa9e719351d1b [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 {
Xavier Ducrohet21648b32014-04-10 17:09:18 -07008 classpath 'com.android.tools.build:gradle:0.10.0'
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -08009 }
10}
11
Xavier Ducrohet4407f3f2014-10-14 10:18:51 -070012ext.supportVersion = '21.0.0'
13ext.extraVersion = 7
Xavier Ducrohet020e4322014-03-18 16:41:30 -070014ext.supportRepoOut = ''
Jeff Davidson84faec52014-06-18 09:10:36 -070015ext.buildToolsVersion = '19.0.3'
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -080016
Xavier Ducrohet020e4322014-03-18 16:41:30 -070017/*
18 * With the build server you are given two env variables.
19 * The OUT_DIR is a temporary directory you can use to put things during the build.
20 * The DIST_DIR is where you want to save things from the build.
21 *
22 * The build server will copy the contents of DIST_DIR to somewhere and make it available.
23 */
24if (System.env.DIST_DIR != null && System.env.OUT_DIR != null) {
Xavier Ducrohet4e04b7a2014-10-17 18:02:33 -070025 buildDir = new File(System.env.OUT_DIR + '/gradle/frameworks/support/build').getCanonicalFile()
26 project.ext.distDir = new File(System.env.DIST_DIR).getCanonicalFile()
Xavier Ducrohet020e4322014-03-18 16:41:30 -070027} else {
28 buildDir = file('../../out/host/gradle/frameworks/support/build')
29 project.ext.distDir = file('../../out/dist')
30}
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -080031
Xavier Ducrohet020e4322014-03-18 16:41:30 -070032ext.supportRepoOut = new File(buildDir, 'support_repo')
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -080033
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -070034// Main task called by the build server.
35task(createArchive) << {
Xavier Ducrohet020e4322014-03-18 16:41:30 -070036}
37
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -070038
39// upload anchor for subprojects to upload their artifacts
40// to the local repo.
41task(mainUpload) << {
42}
43
44// repository creation task
45task createRepository(type: Zip, dependsOn: mainUpload) {
Xavier Ducrohet020e4322014-03-18 16:41:30 -070046 from project.ext.supportRepoOut
47 destinationDir project.ext.distDir
Xavier Ducrohet9dc44802014-03-20 14:15:16 -070048 into 'm2repository'
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -070049 baseName = String.format("android_m2repository_r%02d", project.ext.extraVersion)
Xavier Ducrohet020e4322014-03-18 16:41:30 -070050}
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -070051createArchive.dependsOn createRepository
Xavier Ducrohet020e4322014-03-18 16:41:30 -070052
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -070053// prepare repository with older versions
Xavier Ducrohet64fe2322014-06-16 17:59:34 -070054task unzipRepo(type: Copy) {
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -080055 from "$rootDir/../../prebuilts/maven_repo/android"
Xavier Ducrohet855a9222014-01-02 19:00:43 -080056 into project.ext.supportRepoOut
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -080057}
58
Xavier Ducrohet64fe2322014-06-16 17:59:34 -070059unzipRepo.doFirst {
Xavier Ducrohet020e4322014-03-18 16:41:30 -070060 project.ext.supportRepoOut.deleteDir()
61 project.ext.supportRepoOut.mkdirs()
62}
63
Xavier Ducrohet64fe2322014-06-16 17:59:34 -070064// anchor for prepare repo. This is post unzip + sourceProp.
65task(prepareRepo) << {
66}
67
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -070068import com.google.common.io.Files
69import com.google.common.base.Charsets
70
71task(createXml) << {
72 def repoArchive = createRepository.archivePath
73 def repoArchiveName = createRepository.archiveName
74 def size = repoArchive.length()
75 def sha1 = getSha1(repoArchive)
76
77 def xml =
78"<sdk:sdk-addon xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:sdk=\"http://schemas.android.com/sdk/android/addon/6\">\n\
79 <sdk:extra>\n\
80 <sdk:revision>\n\
81 <sdk:major>${project.ext.extraVersion}</sdk:major>\n\
82 </sdk:revision>\n\
83 <sdk:vendor-display>Android</sdk:vendor-display>\n\
84 <sdk:vendor-id>android</sdk:vendor-id>\n\
85 <sdk:name-display>Local Maven repository for Support Libraries</sdk:name-display>\n\
86 <sdk:path>m2repository</sdk:path>\n\
87 <sdk:archives>\n\
88 <sdk:archive os=\"any\" arch=\"any\">\n\
89 <sdk:size>${size}</sdk:size>\n\
90 <sdk:checksum type=\"sha1\">${sha1}</sdk:checksum>\n\
91 <sdk:url>${repoArchiveName}</sdk:url>\n\
92 </sdk:archive>\n\
93 </sdk:archives>\n\
94 </sdk:extra>\n\
95</sdk:sdk-addon>"
96
97 Files.write(xml, new File(project.ext.distDir, 'repo-extras.xml'), Charsets.UTF_8)
98}
99createArchive.dependsOn createXml
100
Xavier Ducrohet64fe2322014-06-16 17:59:34 -0700101task(createSourceProp) << {
102 def sourceProp =
103"Extra.VendorDisplay=Android\n\
104Extra.Path=m2repository\n\
105Archive.Arch=ANY\n\
106Extra.NameDisplay=Android Support Repository\n\
107Archive.Os=ANY\n\
108Pkg.Revision=${project.ext.extraVersion}.0.0\n\
109Extra.VendorId=android"
110
111 Files.write(sourceProp, new File(project.ext.supportRepoOut, 'source.properties'), Charsets.UTF_8)
112}
113createSourceProp.dependsOn unzipRepo
114prepareRepo.dependsOn createSourceProp
115
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -0700116
117import com.google.common.hash.HashCode
118import com.google.common.hash.HashFunction
119import com.google.common.hash.Hashing
120
121def getSha1(File inputFile) {
122 HashFunction hashFunction = Hashing.sha1()
123 HashCode hashCode = hashFunction.hashString(inputFile.getAbsolutePath())
124 return hashCode.toString()
125}
126
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -0800127subprojects {
128 // Change buildDir first so that all plugins pick up the new value.
Xavier Ducrohet616b95d2014-02-12 09:09:43 -0800129 project.buildDir = project.file("$project.parent.buildDir/../$project.name/build")
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -0800130
131 apply plugin: 'maven'
132
Xavier Ducrohet855a9222014-01-02 19:00:43 -0800133 version = rootProject.ext.supportVersion
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -0800134 group = 'com.android.support'
135
136 task release(type: Upload) {
137 configuration = configurations.archives
138 repositories {
139 mavenDeployer {
Xavier Ducrohet855a9222014-01-02 19:00:43 -0800140 repository(url: uri("$rootProject.ext.supportRepoOut"))
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -0800141 }
142 }
143 }
Xavier Ducrohet020e4322014-03-18 16:41:30 -0700144
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -0700145 // before the upload, make sure the repo is ready.
Xavier Ducrohet020e4322014-03-18 16:41:30 -0700146 release.dependsOn rootProject.tasks.prepareRepo
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -0700147 // make the mainupload depend on this one.
Xavier Ducrohet020e4322014-03-18 16:41:30 -0700148 mainUpload.dependsOn release
Jeff Davidson84faec52014-06-18 09:10:36 -0700149
150 project.plugins.whenPluginAdded { plugin ->
151 if ("com.android.build.gradle.LibraryPlugin".equals(plugin.class.name)) {
152 project.android.buildToolsVersion = rootProject.buildToolsVersion
153 }
154 }
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -0800155}
156
157FileCollection getAndroidPrebuilt(String apiLevel) {
158 files("$rootDir/../../prebuilts/sdk/$apiLevel/android.jar")
159}
Xavier Ducrohet855a9222014-01-02 19:00:43 -0800160