blob: 8fd588f98574298f88e00d769e43fe98d6fd21c4 [file] [log] [blame]
Jeff Gaston79a43f22019-04-09 16:19:12 -04001/*
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 Liutikas7fceeb62022-04-04 13:59:05 -070017import groovy.lang.Tuple;
18
Jeff Gaston79a43f22019-04-09 16:19:12 -040019def init = new Properties()
20ext.init = init
21
Aurimas Liutikas7fceeb62022-04-04 13:59:05 -070022def getOutDir(subdir = "") {
Jeff Gaston79a43f22019-04-09 16:19:12 -040023 /*
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 Liutikas7fceeb62022-04-04 13:59:05 -070027 def buildSrcOut
Jeff Gaston79a43f22019-04-09 16:19:12 -040028 if (outDir == null) {
Jeff Gaston5633a812021-08-13 11:34:58 -040029 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 Liutikas7fceeb62022-04-04 13:59:05 -070034 buildSrcOut = new File("${checkoutRoot}/out/buildSrc")
Jeff Gaston8fd9fc82019-07-26 14:26:10 -040035 } else {
36 outDir = new File(outDir)
Aurimas Liutikas7fceeb62022-04-04 13:59:05 -070037 buildSrcOut = new File("${outDir}/buildSrc")
Jeff Gaston79a43f22019-04-09 16:19:12 -040038 }
Aurimas Liutikas7fceeb62022-04-04 13:59:05 -070039 return new Tuple(outDir, buildSrcOut)
40}
41
Jeff Gastond82bdcd2023-08-08 12:17:33 -040042// Ideally this function would just be chooseBuildDir, but Gradle doesn't include the text ":buildSrc" in the project path
43def chooseBuildSrcBuildDir(subdir = "") {
Aurimas Liutikas7fceeb62022-04-04 13:59:05 -070044 def (outDir, buildSrcOut) = getOutDir(subdir)
45 project.ext.buildSrcOut = buildSrcOut
Jeff Gaston8fd9fc82019-07-26 14:26:10 -040046 project.ext.outDir = outDir
Jeff Gaston09154192023-09-18 14:28:45 -040047 def pathAsFilepath = project.path.replaceFirst(":", "").replaceAll(":", "/")
Jeff Gastond82bdcd2023-08-08 12:17:33 -040048 project.layout.buildDirectory.set(new File(buildSrcOut, "$pathAsFilepath/build").getCanonicalFile())
49}
50
51def chooseOutDir(subdir = "") {
52 chooseBuildSrcBuildDir()
Jeff Gaston79a43f22019-04-09 16:19:12 -040053 subprojects {
54 // Change buildDir first so that all plugins pick up the new value.
Jeff Gastond82bdcd2023-08-08 12:17:33 -040055 project.layout.buildDirectory.set(new File("$project.parent.buildDir/../$project.name/build"))
Jeff Gaston79a43f22019-04-09 16:19:12 -040056 }
Jeff Gaston79a43f22019-04-09 16:19:12 -040057}
58
Aurimas Liutikas7fceeb62022-04-04 13:59:05 -070059ext.init.getOutDir = this.&getOutDir
Jeff Gaston79a43f22019-04-09 16:19:12 -040060ext.init.chooseOutDir = this.&chooseOutDir
Jeff Gastond82bdcd2023-08-08 12:17:33 -040061ext.init.chooseBuildSrcBuildDir = this.&chooseBuildSrcBuildDir