105f668cdd54faba1e63a817b5a5541187323ce97Alan Viverette/*
205f668cdd54faba1e63a817b5a5541187323ce97Alan Viverette * Copyright (C) 2017 The Android Open Source Project
305f668cdd54faba1e63a817b5a5541187323ce97Alan Viverette *
405f668cdd54faba1e63a817b5a5541187323ce97Alan Viverette * Licensed under the Apache License, Version 2.0 (the "License");
505f668cdd54faba1e63a817b5a5541187323ce97Alan Viverette * you may not use this file except in compliance with the License.
605f668cdd54faba1e63a817b5a5541187323ce97Alan Viverette * You may obtain a copy of the License at
705f668cdd54faba1e63a817b5a5541187323ce97Alan Viverette *
805f668cdd54faba1e63a817b5a5541187323ce97Alan Viverette *      http://www.apache.org/licenses/LICENSE-2.0
905f668cdd54faba1e63a817b5a5541187323ce97Alan Viverette *
1005f668cdd54faba1e63a817b5a5541187323ce97Alan Viverette * Unless required by applicable law or agreed to in writing, software
1105f668cdd54faba1e63a817b5a5541187323ce97Alan Viverette * distributed under the License is distributed on an "AS IS" BASIS,
1205f668cdd54faba1e63a817b5a5541187323ce97Alan Viverette * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1305f668cdd54faba1e63a817b5a5541187323ce97Alan Viverette * See the License for the specific language governing permissions and
1405f668cdd54faba1e63a817b5a5541187323ce97Alan Viverette * limitations under the License.
1505f668cdd54faba1e63a817b5a5541187323ce97Alan Viverette */
1605f668cdd54faba1e63a817b5a5541187323ce97Alan Viverette
1705f668cdd54faba1e63a817b5a5541187323ce97Alan Viveretteimport org.gradle.internal.os.OperatingSystem
1805f668cdd54faba1e63a817b5a5541187323ce97Alan Viverette
19b98bb46334f2cead330588b9bc7c92361c54bb5bXavier Ducrohetbuildscript {
20b98bb46334f2cead330588b9bc7c92361c54bb5bXavier Ducrohet    repositories {
21b98bb46334f2cead330588b9bc7c92361c54bb5bXavier Ducrohet        maven { url '../../prebuilts/gradle-plugin' }
22b98bb46334f2cead330588b9bc7c92361c54bb5bXavier Ducrohet        maven { url '../../prebuilts/tools/common/m2/repository' }
23b98bb46334f2cead330588b9bc7c92361c54bb5bXavier Ducrohet        maven { url '../../prebuilts/tools/common/m2/internal' }
24b98bb46334f2cead330588b9bc7c92361c54bb5bXavier Ducrohet    }
25b98bb46334f2cead330588b9bc7c92361c54bb5bXavier Ducrohet    dependencies {
2605f668cdd54faba1e63a817b5a5541187323ce97Alan Viverette        classpath 'com.android.tools.build:gradle:2.3.0'
27b98bb46334f2cead330588b9bc7c92361c54bb5bXavier Ducrohet    }
28b98bb46334f2cead330588b9bc7c92361c54bb5bXavier Ducrohet}
29b98bb46334f2cead330588b9bc7c92361c54bb5bXavier Ducrohet
3005f668cdd54faba1e63a817b5a5541187323ce97Alan Viveretteapply from: 'version.gradle'
3105f668cdd54faba1e63a817b5a5541187323ce97Alan Viverette
3205f668cdd54faba1e63a817b5a5541187323ce97Alan Viverettefinal String platform = OperatingSystem.current().isMacOsX() ? 'darwin' : 'linux'
3305f668cdd54faba1e63a817b5a5541187323ce97Alan ViveretteSystem.setProperty('android.dir', "${rootDir}/../../")
3405f668cdd54faba1e63a817b5a5541187323ce97Alan Viverettefinal String fullSdkPath = "${rootDir}/../../prebuilts/fullsdk-${platform}"
3505f668cdd54faba1e63a817b5a5541187323ce97Alan Viveretteif (file(fullSdkPath).exists()) {
3605f668cdd54faba1e63a817b5a5541187323ce97Alan Viverette    gradle.ext.currentSdk = 26
3705f668cdd54faba1e63a817b5a5541187323ce97Alan Viverette    ext.buildToolsVersion = '26.0.0'
3805f668cdd54faba1e63a817b5a5541187323ce97Alan Viverette    project.ext.androidJar = files("${fullSdkPath}/platforms/android-${gradle.currentSdk}/android.jar")
3905f668cdd54faba1e63a817b5a5541187323ce97Alan Viverette    System.setProperty('android.home', "${rootDir}/../../prebuilts/fullsdk-${platform}")
4005f668cdd54faba1e63a817b5a5541187323ce97Alan Viverette    File props = file("local.properties")
4105f668cdd54faba1e63a817b5a5541187323ce97Alan Viverette    props.write "sdk.dir=${fullSdkPath}"
4205f668cdd54faba1e63a817b5a5541187323ce97Alan Viverette} else {
4305f668cdd54faba1e63a817b5a5541187323ce97Alan Viverette    gradle.ext.currentSdk = 'current'
4405f668cdd54faba1e63a817b5a5541187323ce97Alan Viverette    ext.buildToolsVersion = '26.0.0'
4505f668cdd54faba1e63a817b5a5541187323ce97Alan Viverette    project.ext.androidJar = files("${project.rootDir}/../../prebuilts/sdk/current/android.jar")
4605f668cdd54faba1e63a817b5a5541187323ce97Alan Viverette    File props = file("local.properties")
4705f668cdd54faba1e63a817b5a5541187323ce97Alan Viverette    props.write "android.dir=../../"
4805f668cdd54faba1e63a817b5a5541187323ce97Alan Viverette}
49b98bb46334f2cead330588b9bc7c92361c54bb5bXavier Ducrohet
50b98bb46334f2cead330588b9bc7c92361c54bb5bXavier Ducrohet/*
51b98bb46334f2cead330588b9bc7c92361c54bb5bXavier Ducrohet * With the build server you are given two env variables.
52b98bb46334f2cead330588b9bc7c92361c54bb5bXavier Ducrohet * The OUT_DIR is a temporary directory you can use to put things during the build.
53b98bb46334f2cead330588b9bc7c92361c54bb5bXavier Ducrohet * The DIST_DIR is where you want to save things from the build.
54b98bb46334f2cead330588b9bc7c92361c54bb5bXavier Ducrohet *
55b98bb46334f2cead330588b9bc7c92361c54bb5bXavier Ducrohet * The build server will copy the contents of DIST_DIR to somewhere and make it available.
56b98bb46334f2cead330588b9bc7c92361c54bb5bXavier Ducrohet */
57b98bb46334f2cead330588b9bc7c92361c54bb5bXavier Ducrohetif (System.env.DIST_DIR != null && System.env.OUT_DIR != null) {
58b98bb46334f2cead330588b9bc7c92361c54bb5bXavier Ducrohet    buildDir = new File(System.env.OUT_DIR + '/gradle/frameworks/support/build').getCanonicalFile()
59b98bb46334f2cead330588b9bc7c92361c54bb5bXavier Ducrohet    project.ext.distDir = new File(System.env.DIST_DIR).getCanonicalFile()
60b98bb46334f2cead330588b9bc7c92361c54bb5bXavier Ducrohet} else {
61b98bb46334f2cead330588b9bc7c92361c54bb5bXavier Ducrohet    buildDir = file('../../out/host/gradle/frameworks/support/build')
62b98bb46334f2cead330588b9bc7c92361c54bb5bXavier Ducrohet    project.ext.distDir = file('../../out/dist')
63b98bb46334f2cead330588b9bc7c92361c54bb5bXavier Ducrohet}
64b98bb46334f2cead330588b9bc7c92361c54bb5bXavier Ducrohet
65b98bb46334f2cead330588b9bc7c92361c54bb5bXavier Ducrohetext.supportRepoOut = new File(buildDir, 'support_repo')
66b98bb46334f2cead330588b9bc7c92361c54bb5bXavier Ducrohet
67b98bb46334f2cead330588b9bc7c92361c54bb5bXavier Ducrohet// upload anchor for subprojects to upload their artifacts
68b98bb46334f2cead330588b9bc7c92361c54bb5bXavier Ducrohet// to the local repo.
69fd97bb8f04182220658b39cce4601aa9bada0b6fAurimas Liutikastask dist(type: Zip)  {
7005f668cdd54faba1e63a817b5a5541187323ce97Alan Viverette    group = BasePlugin.BUILD_GROUP
7105f668cdd54faba1e63a817b5a5541187323ce97Alan Viverette    description 'Builds distribution artifacts.'
72fd97bb8f04182220658b39cce4601aa9bada0b6fAurimas Liutikas
73fd97bb8f04182220658b39cce4601aa9bada0b6fAurimas Liutikas    from project.ext.supportRepoOut
74fd97bb8f04182220658b39cce4601aa9bada0b6fAurimas Liutikas    into 'm2repository'
75fd97bb8f04182220658b39cce4601aa9bada0b6fAurimas Liutikas    destinationDir project.ext.distDir
76fd97bb8f04182220658b39cce4601aa9bada0b6fAurimas Liutikas    baseName = String.format("top-of-tree-m2repository-%s", project.multidexVersion)
77fd97bb8f04182220658b39cce4601aa9bada0b6fAurimas Liutikas
78fd97bb8f04182220658b39cce4601aa9bada0b6fAurimas Liutikas    doLast {
79fd97bb8f04182220658b39cce4601aa9bada0b6fAurimas Liutikas        logger.warn "Compressed maven artifacts to ${archivePath}"
80fd97bb8f04182220658b39cce4601aa9bada0b6fAurimas Liutikas    }
81b98bb46334f2cead330588b9bc7c92361c54bb5bXavier Ducrohet}
82b98bb46334f2cead330588b9bc7c92361c54bb5bXavier Ducrohet
83b98bb46334f2cead330588b9bc7c92361c54bb5bXavier Ducrohetsubprojects {
84b98bb46334f2cead330588b9bc7c92361c54bb5bXavier Ducrohet    // Change buildDir first so that all plugins pick up the new value.
8505f668cdd54faba1e63a817b5a5541187323ce97Alan Viverette    project.buildDir = project.file("${project.parent.buildDir}/../${project.name}/build")
86b98bb46334f2cead330588b9bc7c92361c54bb5bXavier Ducrohet
87b98bb46334f2cead330588b9bc7c92361c54bb5bXavier Ducrohet    apply plugin: 'maven'
88b98bb46334f2cead330588b9bc7c92361c54bb5bXavier Ducrohet
8905f668cdd54faba1e63a817b5a5541187323ce97Alan Viverette    version = rootProject.multidexVersion
90475db106115d4f25f0e41612a2a71a0cfe83ab38Alan Viverette    group = 'androidx.multidex'
91b98bb46334f2cead330588b9bc7c92361c54bb5bXavier Ducrohet
92a5272c3d40c2b81c266454b600d4d763b2adc009Aurimas Liutikas    dist.dependsOn project.tasks.uploadArchives
93b98bb46334f2cead330588b9bc7c92361c54bb5bXavier Ducrohet
94b98bb46334f2cead330588b9bc7c92361c54bb5bXavier Ducrohet    project.plugins.whenPluginAdded { plugin ->
95b98bb46334f2cead330588b9bc7c92361c54bb5bXavier Ducrohet        if ("com.android.build.gradle.LibraryPlugin".equals(plugin.class.name)) {
96b98bb46334f2cead330588b9bc7c92361c54bb5bXavier Ducrohet            project.android.buildToolsVersion = rootProject.buildToolsVersion
97b98bb46334f2cead330588b9bc7c92361c54bb5bXavier Ducrohet        }
98b98bb46334f2cead330588b9bc7c92361c54bb5bXavier Ducrohet    }
99b98bb46334f2cead330588b9bc7c92361c54bb5bXavier Ducrohet}
100