Xavier Ducrohet | 86fb8ef | 2013-02-22 15:04:37 -0800 | [diff] [blame] | 1 | buildscript { |
| 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 Banes | 490bf52 | 2015-08-07 11:13:34 +0100 | [diff] [blame] | 8 | classpath 'com.android.tools.build:gradle:1.3.1' |
Xavier Ducrohet | 86fb8ef | 2013-02-22 15:04:37 -0800 | [diff] [blame] | 9 | } |
| 10 | } |
| 11 | |
Chris Flatt | 86e7e29 | 2015-11-02 13:12:37 -0800 | [diff] [blame] | 12 | ext.supportVersion = '23.2.0-SNAPSHOT' |
Chris Flatt | 5a948ff | 2015-10-27 08:00:57 -0700 | [diff] [blame] | 13 | ext.extraVersion = 25 |
Xavier Ducrohet | 020e432 | 2014-03-18 16:41:30 -0700 | [diff] [blame] | 14 | ext.supportRepoOut = '' |
Chris Banes | f9190ca | 2015-05-11 16:04:09 +0100 | [diff] [blame] | 15 | ext.buildToolsVersion = '22.1.0' |
Xavier Ducrohet | fa38527 | 2014-11-14 13:12:09 -0800 | [diff] [blame] | 16 | ext.buildNumber = Integer.toString(ext.extraVersion) |
Xavier Ducrohet | 86fb8ef | 2013-02-22 15:04:37 -0800 | [diff] [blame] | 17 | |
Xavier Ducrohet | 020e432 | 2014-03-18 16:41:30 -0700 | [diff] [blame] | 18 | /* |
| 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 | */ |
| 25 | if (System.env.DIST_DIR != null && System.env.OUT_DIR != null) { |
Xavier Ducrohet | 4e04b7a | 2014-10-17 18:02:33 -0700 | [diff] [blame] | 26 | buildDir = new File(System.env.OUT_DIR + '/gradle/frameworks/support/build').getCanonicalFile() |
| 27 | project.ext.distDir = new File(System.env.DIST_DIR).getCanonicalFile() |
Xavier Ducrohet | fa38527 | 2014-11-14 13:12:09 -0800 | [diff] [blame] | 28 | |
| 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 Ducrohet | 020e432 | 2014-03-18 16:41:30 -0700 | [diff] [blame] | 31 | } else { |
| 32 | buildDir = file('../../out/host/gradle/frameworks/support/build') |
| 33 | project.ext.distDir = file('../../out/dist') |
| 34 | } |
Xavier Ducrohet | 86fb8ef | 2013-02-22 15:04:37 -0800 | [diff] [blame] | 35 | |
Xavier Ducrohet | 020e432 | 2014-03-18 16:41:30 -0700 | [diff] [blame] | 36 | ext.supportRepoOut = new File(buildDir, 'support_repo') |
Yigit Boyar | f18d975 | 2015-12-01 13:45:28 -0800 | [diff] [blame] | 37 | ext.testApkDistOut = ext.distDir |
Xavier Ducrohet | 86fb8ef | 2013-02-22 15:04:37 -0800 | [diff] [blame] | 38 | |
Xavier Ducrohet | 9220b5b | 2014-03-21 15:30:01 -0700 | [diff] [blame] | 39 | // Main task called by the build server. |
| 40 | task(createArchive) << { |
Xavier Ducrohet | 020e432 | 2014-03-18 16:41:30 -0700 | [diff] [blame] | 41 | } |
| 42 | |
Xavier Ducrohet | 9220b5b | 2014-03-21 15:30:01 -0700 | [diff] [blame] | 43 | |
| 44 | // upload anchor for subprojects to upload their artifacts |
| 45 | // to the local repo. |
| 46 | task(mainUpload) << { |
| 47 | } |
| 48 | |
| 49 | // repository creation task |
| 50 | task createRepository(type: Zip, dependsOn: mainUpload) { |
Xavier Ducrohet | 020e432 | 2014-03-18 16:41:30 -0700 | [diff] [blame] | 51 | from project.ext.supportRepoOut |
| 52 | destinationDir project.ext.distDir |
Xavier Ducrohet | 9dc4480 | 2014-03-20 14:15:16 -0700 | [diff] [blame] | 53 | into 'm2repository' |
Xavier Ducrohet | fa38527 | 2014-11-14 13:12:09 -0800 | [diff] [blame] | 54 | baseName = String.format("sdk-repo-linux-m2repository-%s", project.ext.buildNumber) |
Xavier Ducrohet | 020e432 | 2014-03-18 16:41:30 -0700 | [diff] [blame] | 55 | } |
Xavier Ducrohet | 9220b5b | 2014-03-21 15:30:01 -0700 | [diff] [blame] | 56 | createArchive.dependsOn createRepository |
Xavier Ducrohet | 020e432 | 2014-03-18 16:41:30 -0700 | [diff] [blame] | 57 | |
Xavier Ducrohet | 9220b5b | 2014-03-21 15:30:01 -0700 | [diff] [blame] | 58 | // prepare repository with older versions |
Xavier Ducrohet | 64fe232 | 2014-06-16 17:59:34 -0700 | [diff] [blame] | 59 | task unzipRepo(type: Copy) { |
Xavier Ducrohet | 86fb8ef | 2013-02-22 15:04:37 -0800 | [diff] [blame] | 60 | from "$rootDir/../../prebuilts/maven_repo/android" |
Xavier Ducrohet | 855a922 | 2014-01-02 19:00:43 -0800 | [diff] [blame] | 61 | into project.ext.supportRepoOut |
Xavier Ducrohet | 86fb8ef | 2013-02-22 15:04:37 -0800 | [diff] [blame] | 62 | } |
| 63 | |
Xavier Ducrohet | 64fe232 | 2014-06-16 17:59:34 -0700 | [diff] [blame] | 64 | unzipRepo.doFirst { |
Xavier Ducrohet | 020e432 | 2014-03-18 16:41:30 -0700 | [diff] [blame] | 65 | project.ext.supportRepoOut.deleteDir() |
| 66 | project.ext.supportRepoOut.mkdirs() |
| 67 | } |
| 68 | |
Xavier Ducrohet | 64fe232 | 2014-06-16 17:59:34 -0700 | [diff] [blame] | 69 | // anchor for prepare repo. This is post unzip + sourceProp. |
| 70 | task(prepareRepo) << { |
| 71 | } |
| 72 | |
Xavier Ducrohet | 9220b5b | 2014-03-21 15:30:01 -0700 | [diff] [blame] | 73 | import com.google.common.io.Files |
| 74 | import com.google.common.base.Charsets |
| 75 | |
| 76 | task(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 Ducrohet | c16b62d | 2014-12-09 12:37:45 -0800 | [diff] [blame] | 93 | <sdk:archive>\n\ |
Xavier Ducrohet | 9220b5b | 2014-03-21 15:30:01 -0700 | [diff] [blame] | 94 | <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 | } |
| 104 | createArchive.dependsOn createXml |
| 105 | |
Xavier Ducrohet | 64fe232 | 2014-06-16 17:59:34 -0700 | [diff] [blame] | 106 | task(createSourceProp) << { |
| 107 | def sourceProp = |
| 108 | "Extra.VendorDisplay=Android\n\ |
| 109 | Extra.Path=m2repository\n\ |
| 110 | Archive.Arch=ANY\n\ |
| 111 | Extra.NameDisplay=Android Support Repository\n\ |
| 112 | Archive.Os=ANY\n\ |
| 113 | Pkg.Revision=${project.ext.extraVersion}.0.0\n\ |
| 114 | Extra.VendorId=android" |
| 115 | |
| 116 | Files.write(sourceProp, new File(project.ext.supportRepoOut, 'source.properties'), Charsets.UTF_8) |
| 117 | } |
| 118 | createSourceProp.dependsOn unzipRepo |
| 119 | prepareRepo.dependsOn createSourceProp |
| 120 | |
Xavier Ducrohet | 9220b5b | 2014-03-21 15:30:01 -0700 | [diff] [blame] | 121 | |
| 122 | import com.google.common.hash.HashCode |
| 123 | import com.google.common.hash.HashFunction |
| 124 | import com.google.common.hash.Hashing |
Chris Banes | 96f1e91 | 2015-03-05 20:04:05 +0000 | [diff] [blame] | 125 | import java.nio.charset.Charset |
Xavier Ducrohet | 9220b5b | 2014-03-21 15:30:01 -0700 | [diff] [blame] | 126 | |
| 127 | def getSha1(File inputFile) { |
| 128 | HashFunction hashFunction = Hashing.sha1() |
Chris Banes | 96f1e91 | 2015-03-05 20:04:05 +0000 | [diff] [blame] | 129 | HashCode hashCode = hashFunction.hashString(inputFile.getAbsolutePath(), Charset.forName("UTF-8")) |
Xavier Ducrohet | 9220b5b | 2014-03-21 15:30:01 -0700 | [diff] [blame] | 130 | return hashCode.toString() |
| 131 | } |
| 132 | |
Xavier Ducrohet | 86fb8ef | 2013-02-22 15:04:37 -0800 | [diff] [blame] | 133 | subprojects { |
| 134 | // Change buildDir first so that all plugins pick up the new value. |
Xavier Ducrohet | 616b95d | 2014-02-12 09:09:43 -0800 | [diff] [blame] | 135 | project.buildDir = project.file("$project.parent.buildDir/../$project.name/build") |
Xavier Ducrohet | 86fb8ef | 2013-02-22 15:04:37 -0800 | [diff] [blame] | 136 | |
| 137 | apply plugin: 'maven' |
| 138 | |
Xavier Ducrohet | 855a922 | 2014-01-02 19:00:43 -0800 | [diff] [blame] | 139 | version = rootProject.ext.supportVersion |
Xavier Ducrohet | 86fb8ef | 2013-02-22 15:04:37 -0800 | [diff] [blame] | 140 | group = 'com.android.support' |
| 141 | |
Yigit Boyar | be7a54a | 2015-04-07 13:23:50 -0700 | [diff] [blame] | 142 | 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 Ducrohet | 86fb8ef | 2013-02-22 15:04:37 -0800 | [diff] [blame] | 148 | task release(type: Upload) { |
| 149 | configuration = configurations.archives |
| 150 | repositories { |
| 151 | mavenDeployer { |
Xavier Ducrohet | 855a922 | 2014-01-02 19:00:43 -0800 | [diff] [blame] | 152 | repository(url: uri("$rootProject.ext.supportRepoOut")) |
Xavier Ducrohet | 86fb8ef | 2013-02-22 15:04:37 -0800 | [diff] [blame] | 153 | } |
| 154 | } |
| 155 | } |
Xavier Ducrohet | 020e432 | 2014-03-18 16:41:30 -0700 | [diff] [blame] | 156 | |
Xavier Ducrohet | e4cf5a9 | 2015-03-06 17:17:30 -0800 | [diff] [blame] | 157 | 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 Ducrohet | 9220b5b | 2014-03-21 15:30:01 -0700 | [diff] [blame] | 162 | // before the upload, make sure the repo is ready. |
Xavier Ducrohet | 020e432 | 2014-03-18 16:41:30 -0700 | [diff] [blame] | 163 | release.dependsOn rootProject.tasks.prepareRepo |
Xavier Ducrohet | 9220b5b | 2014-03-21 15:30:01 -0700 | [diff] [blame] | 164 | // make the mainupload depend on this one. |
Xavier Ducrohet | 020e432 | 2014-03-18 16:41:30 -0700 | [diff] [blame] | 165 | mainUpload.dependsOn release |
Jeff Davidson | 84faec5 | 2014-06-18 09:10:36 -0700 | [diff] [blame] | 166 | |
| 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 Ducrohet | 86fb8ef | 2013-02-22 15:04:37 -0800 | [diff] [blame] | 172 | } |
| 173 | |
Chris Banes | 9ae4ee8 | 2015-09-11 10:32:15 +1000 | [diff] [blame] | 174 | project.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 Banes | 9e2e803 | 2015-09-16 10:15:37 +0100 | [diff] [blame] | 180 | println ' 3) Need to update the compileSdkVersion in a library\'s build.gradle' |
Chris Banes | 9ae4ee8 | 2015-09-11 10:32:15 +1000 | [diff] [blame] | 181 | println() |
| 182 | } |
| 183 | } |
| 184 | |
Xavier Ducrohet | 86fb8ef | 2013-02-22 15:04:37 -0800 | [diff] [blame] | 185 | FileCollection getAndroidPrebuilt(String apiLevel) { |
| 186 | files("$rootDir/../../prebuilts/sdk/$apiLevel/android.jar") |
Tor Norbye | 47c59fb | 2015-04-08 14:42:16 -0700 | [diff] [blame] | 187 | } |