1/* 2 * Copyright 2024 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 17import org.gradle.api.Project 18 19class BuildDirectoryHelper { 20 private static File getOutDirectory(File checkoutRoot) { 21 def outDir = System.env.OUT_DIR 22 if (outDir == null) { 23 outDir = new File("${checkoutRoot}/out") 24 } else { 25 outDir = new File(outDir) 26 } 27 return outDir 28 } 29 30 static void chooseBuildDirectory(File checkoutRoot, String rootProjectName, Project project) { 31 File outDir = getOutDirectory(checkoutRoot) 32 project.ext.outDir = outDir 33 // Expected out directory structure for :foo:bar is out/androidx/foo/bar 34 project.layout.buildDirectory.set( 35 new File(outDir, "$rootProjectName/${project.path.replace(":", "/")}/build").canonicalFile 36 ) 37 } 38} 39 40def init = new Properties() 41ext.init = init 42ext.init.chooseBuildDirectory = (new BuildDirectoryHelper()).&chooseBuildDirectory 43