blob: 0ca906984d99bc4e410bce6343c0307dc4066b85 [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
42def chooseOutDir(subdir = "") {
43 def (outDir, buildSrcOut) = getOutDir(subdir)
44 project.ext.buildSrcOut = buildSrcOut
Jeff Gaston8fd9fc82019-07-26 14:26:10 -040045 project.ext.outDir = outDir
Jeff Gaston79a43f22019-04-09 16:19:12 -040046 buildDir = new File(outDir, "$project.name/build")
47 .getCanonicalFile()
48 subprojects {
49 // Change buildDir first so that all plugins pick up the new value.
50 project.buildDir = new File("$project.parent.buildDir/../$project.name/build")
51 }
Jeff Gaston79a43f22019-04-09 16:19:12 -040052}
53
Aurimas Liutikas7fceeb62022-04-04 13:59:05 -070054ext.init.getOutDir = this.&getOutDir
Jeff Gaston79a43f22019-04-09 16:19:12 -040055ext.init.chooseOutDir = this.&chooseOutDir