Jeff Gaston | 79a43f2 | 2019-04-09 16:19:12 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Aurimas Liutikas | 7fceeb6 | 2022-04-04 13:59:05 -0700 | [diff] [blame] | 17 | import groovy.lang.Tuple; |
| 18 | |
Jeff Gaston | 79a43f2 | 2019-04-09 16:19:12 -0400 | [diff] [blame] | 19 | def init = new Properties() |
| 20 | ext.init = init |
| 21 | |
Aurimas Liutikas | 7fceeb6 | 2022-04-04 13:59:05 -0700 | [diff] [blame] | 22 | def getOutDir(subdir = "") { |
Jeff Gaston | 79a43f2 | 2019-04-09 16:19:12 -0400 | [diff] [blame] | 23 | /* |
| 24 | * The OUT_DIR is a temporary directory you can use to put things during the build. |
| 25 | */ |
| 26 | def outDir = System.env.OUT_DIR |
Aurimas Liutikas | 7fceeb6 | 2022-04-04 13:59:05 -0700 | [diff] [blame] | 27 | def buildSrcOut |
Jeff Gaston | 79a43f2 | 2019-04-09 16:19:12 -0400 | [diff] [blame] | 28 | if (outDir == null) { |
Jeff Gaston | 5633a81 | 2021-08-13 11:34:58 -0400 | [diff] [blame] | 29 | def checkoutRoot = System.getProperty("CHECKOUT_ROOT") |
| 30 | if (checkoutRoot == null) { |
| 31 | checkoutRoot = new File("${buildscript.sourceFile.parent}/../../..") |
| 32 | } |
| 33 | outDir = new File("${checkoutRoot}/out${subdir}") |
Aurimas Liutikas | 7fceeb6 | 2022-04-04 13:59:05 -0700 | [diff] [blame] | 34 | buildSrcOut = new File("${checkoutRoot}/out/buildSrc") |
Jeff Gaston | 8fd9fc8 | 2019-07-26 14:26:10 -0400 | [diff] [blame] | 35 | } else { |
| 36 | outDir = new File(outDir) |
Aurimas Liutikas | 7fceeb6 | 2022-04-04 13:59:05 -0700 | [diff] [blame] | 37 | buildSrcOut = new File("${outDir}/buildSrc") |
Jeff Gaston | 79a43f2 | 2019-04-09 16:19:12 -0400 | [diff] [blame] | 38 | } |
Aurimas Liutikas | 7fceeb6 | 2022-04-04 13:59:05 -0700 | [diff] [blame] | 39 | return new Tuple(outDir, buildSrcOut) |
| 40 | } |
| 41 | |
Jeff Gaston | d82bdcd | 2023-08-08 12:17:33 -0400 | [diff] [blame] | 42 | // Ideally this function would just be chooseBuildDir, but Gradle doesn't include the text ":buildSrc" in the project path |
| 43 | def chooseBuildSrcBuildDir(subdir = "") { |
Aurimas Liutikas | 7fceeb6 | 2022-04-04 13:59:05 -0700 | [diff] [blame] | 44 | def (outDir, buildSrcOut) = getOutDir(subdir) |
| 45 | project.ext.buildSrcOut = buildSrcOut |
Jeff Gaston | 8fd9fc8 | 2019-07-26 14:26:10 -0400 | [diff] [blame] | 46 | project.ext.outDir = outDir |
Jeff Gaston | 0915419 | 2023-09-18 14:28:45 -0400 | [diff] [blame] | 47 | def pathAsFilepath = project.path.replaceFirst(":", "").replaceAll(":", "/") |
Jeff Gaston | d82bdcd | 2023-08-08 12:17:33 -0400 | [diff] [blame] | 48 | project.layout.buildDirectory.set(new File(buildSrcOut, "$pathAsFilepath/build").getCanonicalFile()) |
| 49 | } |
| 50 | |
| 51 | def chooseOutDir(subdir = "") { |
| 52 | chooseBuildSrcBuildDir() |
Aurimas | 10f65f0 | 2024-01-24 17:29:15 +0000 | [diff] [blame] | 53 | project.layout.buildDirectory.set(new File(project.ext.outDir, subdir)) |
Jeff Gaston | 79a43f2 | 2019-04-09 16:19:12 -0400 | [diff] [blame] | 54 | subprojects { |
Aurimas | 10f65f0 | 2024-01-24 17:29:15 +0000 | [diff] [blame] | 55 | // Expected out directory structure for :foo:bar is out/androidx/foo/bar |
| 56 | it.buildDir = new File(outDir, "${subdir}/androidx/${it.path.replace(":", "/")}/build") |
Jeff Gaston | 79a43f2 | 2019-04-09 16:19:12 -0400 | [diff] [blame] | 57 | } |
Jeff Gaston | 79a43f2 | 2019-04-09 16:19:12 -0400 | [diff] [blame] | 58 | } |
| 59 | |
Aurimas Liutikas | 7fceeb6 | 2022-04-04 13:59:05 -0700 | [diff] [blame] | 60 | ext.init.getOutDir = this.&getOutDir |
Jeff Gaston | 79a43f2 | 2019-04-09 16:19:12 -0400 | [diff] [blame] | 61 | ext.init.chooseOutDir = this.&chooseOutDir |
Jeff Gaston | d82bdcd | 2023-08-08 12:17:33 -0400 | [diff] [blame] | 62 | ext.init.chooseBuildSrcBuildDir = this.&chooseBuildSrcBuildDir |