Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 1 | // Copyright 2017 Google Inc. All rights reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package build |
| 16 | |
| 17 | import ( |
Ramy Medhat | 0fc67eb | 2020-08-12 01:26:23 -0400 | [diff] [blame] | 18 | "fmt" |
Dan Willemsen | c2af0be | 2017-01-20 14:10:01 -0800 | [diff] [blame] | 19 | "os" |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 20 | "path/filepath" |
| 21 | "runtime" |
| 22 | "strconv" |
| 23 | "strings" |
Nan Zhang | 2e6a4ff | 2018-02-14 13:27:26 -0800 | [diff] [blame] | 24 | "time" |
Jeff Gaston | efc1b41 | 2017-03-29 17:29:06 -0700 | [diff] [blame] | 25 | |
| 26 | "android/soong/shared" |
Kousik Kumar | ec47864 | 2020-09-21 13:39:24 -0400 | [diff] [blame] | 27 | |
Patrice Arruda | 9685036 | 2020-08-11 20:41:11 +0000 | [diff] [blame] | 28 | "github.com/golang/protobuf/proto" |
| 29 | |
| 30 | smpb "android/soong/ui/metrics/metrics_proto" |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 31 | ) |
| 32 | |
| 33 | type Config struct{ *configImpl } |
| 34 | |
| 35 | type configImpl struct { |
| 36 | // From the environment |
Colin Cross | 28f527c | 2019-11-26 16:19:04 -0800 | [diff] [blame] | 37 | arguments []string |
| 38 | goma bool |
| 39 | environ *Environment |
| 40 | distDir string |
| 41 | buildDateTime string |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 42 | |
| 43 | // From the arguments |
Colin Cross | 00a8a3f | 2020-10-29 14:08:31 -0700 | [diff] [blame] | 44 | parallel int |
| 45 | keepGoing int |
| 46 | verbose bool |
| 47 | checkbuild bool |
| 48 | dist bool |
Anton Hansson | 5e5c48b | 2020-11-27 12:35:20 +0000 | [diff] [blame^] | 49 | skipConfig bool |
| 50 | skipKati bool |
Colin Cross | 00a8a3f | 2020-10-29 14:08:31 -0700 | [diff] [blame] | 51 | skipSoongTests bool |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 52 | |
| 53 | // From the product config |
Dan Willemsen | 6ab79db | 2018-05-02 00:06:28 -0700 | [diff] [blame] | 54 | katiArgs []string |
| 55 | ninjaArgs []string |
| 56 | katiSuffix string |
| 57 | targetDevice string |
| 58 | targetDeviceDir string |
Dan Willemsen | 3d60b11 | 2018-04-04 22:25:56 -0700 | [diff] [blame] | 59 | |
Dan Willemsen | 2bb82d0 | 2019-12-27 09:35:42 -0800 | [diff] [blame] | 60 | // Autodetected |
| 61 | totalRAM uint64 |
| 62 | |
Dan Willemsen | e333635 | 2020-01-02 19:10:38 -0800 | [diff] [blame] | 63 | brokenDupRules bool |
| 64 | brokenUsesNetwork bool |
| 65 | brokenNinjaEnvVars []string |
Dan Willemsen | 1849011 | 2018-05-25 16:30:04 -0700 | [diff] [blame] | 66 | |
| 67 | pathReplaced bool |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 68 | } |
| 69 | |
Dan Willemsen | c2af0be | 2017-01-20 14:10:01 -0800 | [diff] [blame] | 70 | const srcDirFileCheck = "build/soong/root.bp" |
| 71 | |
Patrice Arruda | 9450d0b | 2019-07-08 11:06:46 -0700 | [diff] [blame] | 72 | var buildFiles = []string{"Android.mk", "Android.bp"} |
| 73 | |
Patrice Arruda | 1384822 | 2019-04-22 17:12:02 -0700 | [diff] [blame] | 74 | type BuildAction uint |
| 75 | |
| 76 | const ( |
| 77 | // Builds all of the modules and their dependencies of a specified directory, relative to the root |
| 78 | // directory of the source tree. |
| 79 | BUILD_MODULES_IN_A_DIRECTORY BuildAction = iota |
| 80 | |
| 81 | // Builds all of the modules and their dependencies of a list of specified directories. All specified |
| 82 | // directories are relative to the root directory of the source tree. |
| 83 | BUILD_MODULES_IN_DIRECTORIES |
Patrice Arruda | 3928206 | 2019-06-20 16:35:12 -0700 | [diff] [blame] | 84 | |
| 85 | // Build a list of specified modules. If none was specified, simply build the whole source tree. |
| 86 | BUILD_MODULES |
Patrice Arruda | 1384822 | 2019-04-22 17:12:02 -0700 | [diff] [blame] | 87 | ) |
| 88 | |
| 89 | // checkTopDir validates that the current directory is at the root directory of the source tree. |
| 90 | func checkTopDir(ctx Context) { |
| 91 | if _, err := os.Stat(srcDirFileCheck); err != nil { |
| 92 | if os.IsNotExist(err) { |
| 93 | ctx.Fatalf("Current working directory must be the source tree. %q not found.", srcDirFileCheck) |
| 94 | } |
| 95 | ctx.Fatalln("Error verifying tree state:", err) |
| 96 | } |
| 97 | } |
| 98 | |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 99 | func NewConfig(ctx Context, args ...string) Config { |
| 100 | ret := &configImpl{ |
| 101 | environ: OsEnvironment(), |
| 102 | } |
| 103 | |
Patrice Arruda | 9010917 | 2020-07-28 18:07:27 +0000 | [diff] [blame] | 104 | // Default matching ninja |
Dan Willemsen | 9b58749 | 2017-07-10 22:13:00 -0700 | [diff] [blame] | 105 | ret.parallel = runtime.NumCPU() + 2 |
| 106 | ret.keepGoing = 1 |
| 107 | |
Dan Willemsen | 2bb82d0 | 2019-12-27 09:35:42 -0800 | [diff] [blame] | 108 | ret.totalRAM = detectTotalRAM(ctx) |
| 109 | |
Dan Willemsen | 9b58749 | 2017-07-10 22:13:00 -0700 | [diff] [blame] | 110 | ret.parseArgs(ctx, args) |
| 111 | |
Dan Willemsen | 0c3919e | 2017-03-02 15:49:10 -0800 | [diff] [blame] | 112 | // Make sure OUT_DIR is set appropriately |
Dan Willemsen | 02f3add | 2017-05-12 13:50:19 -0700 | [diff] [blame] | 113 | if outDir, ok := ret.environ.Get("OUT_DIR"); ok { |
| 114 | ret.environ.Set("OUT_DIR", filepath.Clean(outDir)) |
| 115 | } else { |
Dan Willemsen | 0c3919e | 2017-03-02 15:49:10 -0800 | [diff] [blame] | 116 | outDir := "out" |
| 117 | if baseDir, ok := ret.environ.Get("OUT_DIR_COMMON_BASE"); ok { |
| 118 | if wd, err := os.Getwd(); err != nil { |
| 119 | ctx.Fatalln("Failed to get working directory:", err) |
| 120 | } else { |
| 121 | outDir = filepath.Join(baseDir, filepath.Base(wd)) |
| 122 | } |
| 123 | } |
| 124 | ret.environ.Set("OUT_DIR", outDir) |
| 125 | } |
| 126 | |
Dan Willemsen | 2d31a44 | 2018-10-20 21:33:41 -0700 | [diff] [blame] | 127 | if distDir, ok := ret.environ.Get("DIST_DIR"); ok { |
| 128 | ret.distDir = filepath.Clean(distDir) |
| 129 | } else { |
| 130 | ret.distDir = filepath.Join(ret.OutDir(), "dist") |
| 131 | } |
Dan Willemsen | d50e89f | 2018-10-16 17:49:25 -0700 | [diff] [blame] | 132 | |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 133 | ret.environ.Unset( |
| 134 | // We're already using it |
| 135 | "USE_SOONG_UI", |
| 136 | |
| 137 | // We should never use GOROOT/GOPATH from the shell environment |
| 138 | "GOROOT", |
| 139 | "GOPATH", |
| 140 | |
| 141 | // These should only come from Soong, not the environment. |
| 142 | "CLANG", |
| 143 | "CLANG_CXX", |
| 144 | "CCC_CC", |
| 145 | "CCC_CXX", |
| 146 | |
| 147 | // Used by the goma compiler wrapper, but should only be set by |
| 148 | // gomacc |
| 149 | "GOMACC_PATH", |
Dan Willemsen | 0c3919e | 2017-03-02 15:49:10 -0800 | [diff] [blame] | 150 | |
| 151 | // We handle this above |
| 152 | "OUT_DIR_COMMON_BASE", |
Dan Willemsen | 68a0985 | 2017-04-18 13:56:57 -0700 | [diff] [blame] | 153 | |
Dan Willemsen | 2d31a44 | 2018-10-20 21:33:41 -0700 | [diff] [blame] | 154 | // This is handled above too, and set for individual commands later |
| 155 | "DIST_DIR", |
| 156 | |
Dan Willemsen | 68a0985 | 2017-04-18 13:56:57 -0700 | [diff] [blame] | 157 | // Variables that have caused problems in the past |
Dan Willemsen | 1c504d9 | 2019-11-18 19:13:53 +0000 | [diff] [blame] | 158 | "BASH_ENV", |
Dan Willemsen | ebfe33a | 2018-05-01 10:07:50 -0700 | [diff] [blame] | 159 | "CDPATH", |
Dan Willemsen | 68a0985 | 2017-04-18 13:56:57 -0700 | [diff] [blame] | 160 | "DISPLAY", |
| 161 | "GREP_OPTIONS", |
Dan Willemsen | ebfe33a | 2018-05-01 10:07:50 -0700 | [diff] [blame] | 162 | "NDK_ROOT", |
Dan Willemsen | 00fcb26 | 2018-08-15 15:35:38 -0700 | [diff] [blame] | 163 | "POSIXLY_CORRECT", |
Dan Willemsen | c40e10b | 2017-07-11 14:30:00 -0700 | [diff] [blame] | 164 | |
| 165 | // Drop make flags |
| 166 | "MAKEFLAGS", |
| 167 | "MAKELEVEL", |
| 168 | "MFLAGS", |
Dan Willemsen | d9e8f0a | 2017-10-30 13:42:06 -0700 | [diff] [blame] | 169 | |
| 170 | // Set in envsetup.sh, reset in makefiles |
| 171 | "ANDROID_JAVA_TOOLCHAIN", |
Colin Cross | 7f09c40 | 2018-07-11 14:49:31 -0700 | [diff] [blame] | 172 | |
| 173 | // Set by envsetup.sh, but shouldn't be used inside the build because envsetup.sh is optional |
| 174 | "ANDROID_BUILD_TOP", |
| 175 | "ANDROID_HOST_OUT", |
| 176 | "ANDROID_PRODUCT_OUT", |
| 177 | "ANDROID_HOST_OUT_TESTCASES", |
| 178 | "ANDROID_TARGET_OUT_TESTCASES", |
| 179 | "ANDROID_TOOLCHAIN", |
| 180 | "ANDROID_TOOLCHAIN_2ND_ARCH", |
| 181 | "ANDROID_DEV_SCRIPTS", |
| 182 | "ANDROID_EMULATOR_PREBUILTS", |
| 183 | "ANDROID_PRE_BUILD_PATHS", |
Dan Willemsen | f99915f | 2018-10-25 22:04:42 -0700 | [diff] [blame] | 184 | |
| 185 | // Only set in multiproduct_kati after config generation |
| 186 | "EMPTY_NINJA_FILE", |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 187 | ) |
| 188 | |
Kousik Kumar | b328f6d | 2020-10-19 01:45:46 -0400 | [diff] [blame] | 189 | if ret.UseGoma() || ret.ForceUseGoma() { |
| 190 | ctx.Println("Goma for Android has been deprecated and replaced with RBE. See go/rbe_for_android for instructions on how to use RBE.") |
| 191 | ctx.Fatalln("USE_GOMA / FORCE_USE_GOMA flag is no longer supported.") |
Kousik Kumar | ec47864 | 2020-09-21 13:39:24 -0400 | [diff] [blame] | 192 | } |
| 193 | |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 194 | // Tell python not to spam the source tree with .pyc files. |
| 195 | ret.environ.Set("PYTHONDONTWRITEBYTECODE", "1") |
| 196 | |
Ramy Medhat | ca1e44c | 2020-07-16 12:18:37 -0400 | [diff] [blame] | 197 | tmpDir := absPath(ctx, ret.TempDir()) |
| 198 | ret.environ.Set("TMPDIR", tmpDir) |
Dan Willemsen | 32a669b | 2018-03-08 19:42:00 -0800 | [diff] [blame] | 199 | |
Dan Willemsen | 70c1ff8 | 2019-08-21 14:56:13 -0700 | [diff] [blame] | 200 | // Always set ASAN_SYMBOLIZER_PATH so that ASAN-based tools can symbolize any crashes |
| 201 | symbolizerPath := filepath.Join("prebuilts/clang/host", ret.HostPrebuiltTag(), |
| 202 | "llvm-binutils-stable/llvm-symbolizer") |
| 203 | ret.environ.Set("ASAN_SYMBOLIZER_PATH", absPath(ctx, symbolizerPath)) |
| 204 | |
Dan Willemsen | c2af0be | 2017-01-20 14:10:01 -0800 | [diff] [blame] | 205 | // Precondition: the current directory is the top of the source tree |
Patrice Arruda | 1384822 | 2019-04-22 17:12:02 -0700 | [diff] [blame] | 206 | checkTopDir(ctx) |
Dan Willemsen | c2af0be | 2017-01-20 14:10:01 -0800 | [diff] [blame] | 207 | |
Dan Willemsen | d9e8f0a | 2017-10-30 13:42:06 -0700 | [diff] [blame] | 208 | if srcDir := absPath(ctx, "."); strings.ContainsRune(srcDir, ' ') { |
Colin Cross | 1f6faeb | 2019-09-23 15:52:40 -0700 | [diff] [blame] | 209 | ctx.Println("You are building in a directory whose absolute path contains a space character:") |
| 210 | ctx.Println() |
| 211 | ctx.Printf("%q\n", srcDir) |
| 212 | ctx.Println() |
| 213 | ctx.Fatalln("Directory names containing spaces are not supported") |
Dan Willemsen | db8457c | 2017-05-12 16:38:17 -0700 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | if outDir := ret.OutDir(); strings.ContainsRune(outDir, ' ') { |
Colin Cross | 1f6faeb | 2019-09-23 15:52:40 -0700 | [diff] [blame] | 217 | ctx.Println("The absolute path of your output directory ($OUT_DIR) contains a space character:") |
| 218 | ctx.Println() |
| 219 | ctx.Printf("%q\n", outDir) |
| 220 | ctx.Println() |
| 221 | ctx.Fatalln("Directory names containing spaces are not supported") |
Dan Willemsen | db8457c | 2017-05-12 16:38:17 -0700 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | if distDir := ret.DistDir(); strings.ContainsRune(distDir, ' ') { |
Colin Cross | 1f6faeb | 2019-09-23 15:52:40 -0700 | [diff] [blame] | 225 | ctx.Println("The absolute path of your dist directory ($DIST_DIR) contains a space character:") |
| 226 | ctx.Println() |
| 227 | ctx.Printf("%q\n", distDir) |
| 228 | ctx.Println() |
| 229 | ctx.Fatalln("Directory names containing spaces are not supported") |
Dan Willemsen | db8457c | 2017-05-12 16:38:17 -0700 | [diff] [blame] | 230 | } |
| 231 | |
Dan Willemsen | d9e8f0a | 2017-10-30 13:42:06 -0700 | [diff] [blame] | 232 | // Configure Java-related variables, including adding it to $PATH |
Tobias Thierer | e59aeff | 2017-12-20 22:40:39 +0000 | [diff] [blame] | 233 | java8Home := filepath.Join("prebuilts/jdk/jdk8", ret.HostPrebuiltTag()) |
| 234 | java9Home := filepath.Join("prebuilts/jdk/jdk9", ret.HostPrebuiltTag()) |
Pete Gillin | 1f52e93 | 2019-10-09 17:10:08 +0100 | [diff] [blame] | 235 | java11Home := filepath.Join("prebuilts/jdk/jdk11", ret.HostPrebuiltTag()) |
Dan Willemsen | d9e8f0a | 2017-10-30 13:42:06 -0700 | [diff] [blame] | 236 | javaHome := func() string { |
| 237 | if override, ok := ret.environ.Get("OVERRIDE_ANDROID_JAVA_HOME"); ok { |
| 238 | return override |
| 239 | } |
Pete Gillin | a7a3d64 | 2019-11-07 18:58:42 +0000 | [diff] [blame] | 240 | if toolchain11, ok := ret.environ.Get("EXPERIMENTAL_USE_OPENJDK11_TOOLCHAIN"); ok && toolchain11 != "true" { |
| 241 | ctx.Fatalln("The environment variable EXPERIMENTAL_USE_OPENJDK11_TOOLCHAIN is no longer supported. An OpenJDK 11 toolchain is now the global default.") |
Pete Gillin | 1f52e93 | 2019-10-09 17:10:08 +0100 | [diff] [blame] | 242 | } |
Pete Gillin | abbcdda | 2019-10-28 16:15:33 +0000 | [diff] [blame] | 243 | return java11Home |
Dan Willemsen | d9e8f0a | 2017-10-30 13:42:06 -0700 | [diff] [blame] | 244 | }() |
| 245 | absJavaHome := absPath(ctx, javaHome) |
| 246 | |
Dan Willemsen | ed86952 | 2018-01-08 14:58:46 -0800 | [diff] [blame] | 247 | ret.configureLocale(ctx) |
| 248 | |
Dan Willemsen | d9e8f0a | 2017-10-30 13:42:06 -0700 | [diff] [blame] | 249 | newPath := []string{filepath.Join(absJavaHome, "bin")} |
| 250 | if path, ok := ret.environ.Get("PATH"); ok && path != "" { |
| 251 | newPath = append(newPath, path) |
| 252 | } |
Pete Gillin | 1f52e93 | 2019-10-09 17:10:08 +0100 | [diff] [blame] | 253 | |
Dan Willemsen | d9e8f0a | 2017-10-30 13:42:06 -0700 | [diff] [blame] | 254 | ret.environ.Unset("OVERRIDE_ANDROID_JAVA_HOME") |
| 255 | ret.environ.Set("JAVA_HOME", absJavaHome) |
| 256 | ret.environ.Set("ANDROID_JAVA_HOME", javaHome) |
Tobias Thierer | e59aeff | 2017-12-20 22:40:39 +0000 | [diff] [blame] | 257 | ret.environ.Set("ANDROID_JAVA8_HOME", java8Home) |
| 258 | ret.environ.Set("ANDROID_JAVA9_HOME", java9Home) |
Pete Gillin | 1f52e93 | 2019-10-09 17:10:08 +0100 | [diff] [blame] | 259 | ret.environ.Set("ANDROID_JAVA11_HOME", java11Home) |
Dan Willemsen | d9e8f0a | 2017-10-30 13:42:06 -0700 | [diff] [blame] | 260 | ret.environ.Set("PATH", strings.Join(newPath, string(filepath.ListSeparator))) |
| 261 | |
Nan Zhang | 2e6a4ff | 2018-02-14 13:27:26 -0800 | [diff] [blame] | 262 | outDir := ret.OutDir() |
| 263 | buildDateTimeFile := filepath.Join(outDir, "build_date.txt") |
Nan Zhang | 2e6a4ff | 2018-02-14 13:27:26 -0800 | [diff] [blame] | 264 | if buildDateTime, ok := ret.environ.Get("BUILD_DATETIME"); ok && buildDateTime != "" { |
Colin Cross | 28f527c | 2019-11-26 16:19:04 -0800 | [diff] [blame] | 265 | ret.buildDateTime = buildDateTime |
Nan Zhang | 2e6a4ff | 2018-02-14 13:27:26 -0800 | [diff] [blame] | 266 | } else { |
Colin Cross | 28f527c | 2019-11-26 16:19:04 -0800 | [diff] [blame] | 267 | ret.buildDateTime = strconv.FormatInt(time.Now().Unix(), 10) |
Nan Zhang | 2e6a4ff | 2018-02-14 13:27:26 -0800 | [diff] [blame] | 268 | } |
Colin Cross | 28f527c | 2019-11-26 16:19:04 -0800 | [diff] [blame] | 269 | |
Nan Zhang | 2e6a4ff | 2018-02-14 13:27:26 -0800 | [diff] [blame] | 270 | ret.environ.Set("BUILD_DATETIME_FILE", buildDateTimeFile) |
| 271 | |
Ramy Medhat | ca1e44c | 2020-07-16 12:18:37 -0400 | [diff] [blame] | 272 | if ret.UseRBE() { |
Ramy Medhat | 0fc67eb | 2020-08-12 01:26:23 -0400 | [diff] [blame] | 273 | for k, v := range getRBEVars(ctx, Config{ret}) { |
Ramy Medhat | ca1e44c | 2020-07-16 12:18:37 -0400 | [diff] [blame] | 274 | ret.environ.Set(k, v) |
| 275 | } |
| 276 | } |
| 277 | |
Patrice Arruda | af880da | 2020-11-13 08:41:26 -0800 | [diff] [blame] | 278 | bpd := shared.BazelMetricsDir(ret.OutDir()) |
| 279 | if err := os.RemoveAll(bpd); err != nil { |
| 280 | ctx.Fatalf("Unable to remove bazel profile directory %q: %v", bpd, err) |
| 281 | } |
| 282 | if ret.UseBazel() { |
| 283 | if err := os.MkdirAll(bpd, 0777); err != nil { |
| 284 | ctx.Fatalf("Failed to create bazel profile directory %q: %v", bpd, err) |
| 285 | } |
| 286 | } |
| 287 | |
Patrice Arruda | 9685036 | 2020-08-11 20:41:11 +0000 | [diff] [blame] | 288 | c := Config{ret} |
| 289 | storeConfigMetrics(ctx, c) |
| 290 | return c |
Dan Willemsen | 9b58749 | 2017-07-10 22:13:00 -0700 | [diff] [blame] | 291 | } |
| 292 | |
Patrice Arruda | 1384822 | 2019-04-22 17:12:02 -0700 | [diff] [blame] | 293 | // NewBuildActionConfig returns a build configuration based on the build action. The arguments are |
| 294 | // processed based on the build action and extracts any arguments that belongs to the build action. |
Dan Willemsen | ce41e94 | 2019-07-29 23:39:30 -0700 | [diff] [blame] | 295 | func NewBuildActionConfig(action BuildAction, dir string, ctx Context, args ...string) Config { |
| 296 | return NewConfig(ctx, getConfigArgs(action, dir, ctx, args)...) |
Patrice Arruda | 1384822 | 2019-04-22 17:12:02 -0700 | [diff] [blame] | 297 | } |
| 298 | |
Patrice Arruda | 9685036 | 2020-08-11 20:41:11 +0000 | [diff] [blame] | 299 | // storeConfigMetrics selects a set of configuration information and store in |
| 300 | // the metrics system for further analysis. |
| 301 | func storeConfigMetrics(ctx Context, config Config) { |
| 302 | if ctx.Metrics == nil { |
| 303 | return |
| 304 | } |
| 305 | |
| 306 | b := &smpb.BuildConfig{ |
Patrice Arruda | c97d6dc | 2020-09-28 18:22:07 +0000 | [diff] [blame] | 307 | ForceUseGoma: proto.Bool(config.ForceUseGoma()), |
| 308 | UseGoma: proto.Bool(config.UseGoma()), |
| 309 | UseRbe: proto.Bool(config.UseRBE()), |
Patrice Arruda | 9685036 | 2020-08-11 20:41:11 +0000 | [diff] [blame] | 310 | } |
| 311 | ctx.Metrics.BuildConfig(b) |
Patrice Arruda | 3edfd48 | 2020-10-13 23:58:41 +0000 | [diff] [blame] | 312 | |
| 313 | s := &smpb.SystemResourceInfo{ |
| 314 | TotalPhysicalMemory: proto.Uint64(config.TotalRAM()), |
| 315 | AvailableCpus: proto.Int32(int32(runtime.NumCPU())), |
| 316 | } |
| 317 | ctx.Metrics.SystemResourceInfo(s) |
Patrice Arruda | 9685036 | 2020-08-11 20:41:11 +0000 | [diff] [blame] | 318 | } |
| 319 | |
Patrice Arruda | 1384822 | 2019-04-22 17:12:02 -0700 | [diff] [blame] | 320 | // getConfigArgs processes the command arguments based on the build action and creates a set of new |
| 321 | // arguments to be accepted by Config. |
Dan Willemsen | ce41e94 | 2019-07-29 23:39:30 -0700 | [diff] [blame] | 322 | func getConfigArgs(action BuildAction, dir string, ctx Context, args []string) []string { |
Patrice Arruda | 1384822 | 2019-04-22 17:12:02 -0700 | [diff] [blame] | 323 | // The next block of code verifies that the current directory is the root directory of the source |
| 324 | // tree. It then finds the relative path of dir based on the root directory of the source tree |
| 325 | // and verify that dir is inside of the source tree. |
| 326 | checkTopDir(ctx) |
| 327 | topDir, err := os.Getwd() |
| 328 | if err != nil { |
| 329 | ctx.Fatalf("Error retrieving top directory: %v", err) |
| 330 | } |
Patrice Arruda | baba9a9 | 2019-07-03 10:47:34 -0700 | [diff] [blame] | 331 | dir, err = filepath.EvalSymlinks(dir) |
| 332 | if err != nil { |
| 333 | ctx.Fatalf("Unable to evaluate symlink of %s: %v", dir, err) |
| 334 | } |
Patrice Arruda | 1384822 | 2019-04-22 17:12:02 -0700 | [diff] [blame] | 335 | dir, err = filepath.Abs(dir) |
| 336 | if err != nil { |
| 337 | ctx.Fatalf("Unable to find absolute path %s: %v", dir, err) |
| 338 | } |
| 339 | relDir, err := filepath.Rel(topDir, dir) |
| 340 | if err != nil { |
| 341 | ctx.Fatalf("Unable to find relative path %s of %s: %v", relDir, topDir, err) |
| 342 | } |
| 343 | // If there are ".." in the path, it's not in the source tree. |
| 344 | if strings.Contains(relDir, "..") { |
| 345 | ctx.Fatalf("Directory %s is not under the source tree %s", dir, topDir) |
| 346 | } |
| 347 | |
| 348 | configArgs := args[:] |
| 349 | |
| 350 | // If the arguments contains GET-INSTALL-PATH, change the target name prefix from MODULES-IN- to |
| 351 | // GET-INSTALL-PATH-IN- to extract the installation path instead of building the modules. |
| 352 | targetNamePrefix := "MODULES-IN-" |
| 353 | if inList("GET-INSTALL-PATH", configArgs) { |
| 354 | targetNamePrefix = "GET-INSTALL-PATH-IN-" |
| 355 | configArgs = removeFromList("GET-INSTALL-PATH", configArgs) |
| 356 | } |
| 357 | |
Patrice Arruda | 1384822 | 2019-04-22 17:12:02 -0700 | [diff] [blame] | 358 | var targets []string |
| 359 | |
| 360 | switch action { |
Patrice Arruda | 3928206 | 2019-06-20 16:35:12 -0700 | [diff] [blame] | 361 | case BUILD_MODULES: |
| 362 | // No additional processing is required when building a list of specific modules or all modules. |
Patrice Arruda | 1384822 | 2019-04-22 17:12:02 -0700 | [diff] [blame] | 363 | case BUILD_MODULES_IN_A_DIRECTORY: |
| 364 | // If dir is the root source tree, all the modules are built of the source tree are built so |
| 365 | // no need to find the build file. |
| 366 | if topDir == dir { |
| 367 | break |
| 368 | } |
Patrice Arruda | 0dcf27f | 2019-07-08 17:03:33 -0700 | [diff] [blame] | 369 | |
Patrice Arruda | 1384822 | 2019-04-22 17:12:02 -0700 | [diff] [blame] | 370 | buildFile := findBuildFile(ctx, relDir) |
| 371 | if buildFile == "" { |
Patrice Arruda | 0dcf27f | 2019-07-08 17:03:33 -0700 | [diff] [blame] | 372 | ctx.Fatalf("Build file not found for %s directory", relDir) |
Patrice Arruda | 1384822 | 2019-04-22 17:12:02 -0700 | [diff] [blame] | 373 | } |
Patrice Arruda | 1384822 | 2019-04-22 17:12:02 -0700 | [diff] [blame] | 374 | targets = []string{convertToTarget(filepath.Dir(buildFile), targetNamePrefix)} |
| 375 | case BUILD_MODULES_IN_DIRECTORIES: |
| 376 | newConfigArgs, dirs := splitArgs(configArgs) |
| 377 | configArgs = newConfigArgs |
Dan Willemsen | ce41e94 | 2019-07-29 23:39:30 -0700 | [diff] [blame] | 378 | targets = getTargetsFromDirs(ctx, relDir, dirs, targetNamePrefix) |
Patrice Arruda | 1384822 | 2019-04-22 17:12:02 -0700 | [diff] [blame] | 379 | } |
| 380 | |
| 381 | // Tidy only override all other specified targets. |
| 382 | tidyOnly := os.Getenv("WITH_TIDY_ONLY") |
| 383 | if tidyOnly == "true" || tidyOnly == "1" { |
| 384 | configArgs = append(configArgs, "tidy_only") |
| 385 | } else { |
| 386 | configArgs = append(configArgs, targets...) |
| 387 | } |
| 388 | |
| 389 | return configArgs |
| 390 | } |
| 391 | |
| 392 | // convertToTarget replaces "/" to "-" in dir and pre-append the targetNamePrefix to the target name. |
| 393 | func convertToTarget(dir string, targetNamePrefix string) string { |
| 394 | return targetNamePrefix + strings.ReplaceAll(dir, "/", "-") |
| 395 | } |
| 396 | |
Patrice Arruda | 9450d0b | 2019-07-08 11:06:46 -0700 | [diff] [blame] | 397 | // hasBuildFile returns true if dir contains an Android build file. |
| 398 | func hasBuildFile(ctx Context, dir string) bool { |
| 399 | for _, buildFile := range buildFiles { |
| 400 | _, err := os.Stat(filepath.Join(dir, buildFile)) |
| 401 | if err == nil { |
| 402 | return true |
| 403 | } |
| 404 | if !os.IsNotExist(err) { |
| 405 | ctx.Fatalf("Error retrieving the build file stats: %v", err) |
| 406 | } |
| 407 | } |
| 408 | return false |
| 409 | } |
| 410 | |
Patrice Arruda | 0dcf27f | 2019-07-08 17:03:33 -0700 | [diff] [blame] | 411 | // findBuildFile finds a build file (makefile or blueprint file) by looking if there is a build file |
| 412 | // in the current and any sub directory of dir. If a build file is not found, traverse the path |
| 413 | // up by one directory and repeat again until either a build file is found or reached to the root |
| 414 | // source tree. The returned filename of build file is "Android.mk". If one was not found, a blank |
| 415 | // string is returned. |
Patrice Arruda | 1384822 | 2019-04-22 17:12:02 -0700 | [diff] [blame] | 416 | func findBuildFile(ctx Context, dir string) string { |
Patrice Arruda | 0dcf27f | 2019-07-08 17:03:33 -0700 | [diff] [blame] | 417 | // If the string is empty or ".", assume it is top directory of the source tree. |
| 418 | if dir == "" || dir == "." { |
Patrice Arruda | 1384822 | 2019-04-22 17:12:02 -0700 | [diff] [blame] | 419 | return "" |
| 420 | } |
| 421 | |
Patrice Arruda | 0dcf27f | 2019-07-08 17:03:33 -0700 | [diff] [blame] | 422 | found := false |
| 423 | for buildDir := dir; buildDir != "."; buildDir = filepath.Dir(buildDir) { |
| 424 | err := filepath.Walk(buildDir, func(path string, info os.FileInfo, err error) error { |
| 425 | if err != nil { |
| 426 | return err |
| 427 | } |
| 428 | if found { |
| 429 | return filepath.SkipDir |
| 430 | } |
| 431 | if info.IsDir() { |
| 432 | return nil |
| 433 | } |
| 434 | for _, buildFile := range buildFiles { |
| 435 | if info.Name() == buildFile { |
| 436 | found = true |
| 437 | return filepath.SkipDir |
| 438 | } |
| 439 | } |
| 440 | return nil |
| 441 | }) |
| 442 | if err != nil { |
| 443 | ctx.Fatalf("Error finding Android build file: %v", err) |
| 444 | } |
| 445 | |
| 446 | if found { |
| 447 | return filepath.Join(buildDir, "Android.mk") |
Patrice Arruda | 1384822 | 2019-04-22 17:12:02 -0700 | [diff] [blame] | 448 | } |
| 449 | } |
| 450 | |
| 451 | return "" |
| 452 | } |
| 453 | |
| 454 | // splitArgs iterates over the arguments list and splits into two lists: arguments and directories. |
| 455 | func splitArgs(args []string) (newArgs []string, dirs []string) { |
| 456 | specialArgs := map[string]bool{ |
| 457 | "showcommands": true, |
| 458 | "snod": true, |
| 459 | "dist": true, |
| 460 | "checkbuild": true, |
| 461 | } |
| 462 | |
| 463 | newArgs = []string{} |
| 464 | dirs = []string{} |
| 465 | |
| 466 | for _, arg := range args { |
| 467 | // It's a dash argument if it starts with "-" or it's a key=value pair, it's not a directory. |
| 468 | if strings.IndexRune(arg, '-') == 0 || strings.IndexRune(arg, '=') != -1 { |
| 469 | newArgs = append(newArgs, arg) |
| 470 | continue |
| 471 | } |
| 472 | |
| 473 | if _, ok := specialArgs[arg]; ok { |
| 474 | newArgs = append(newArgs, arg) |
| 475 | continue |
| 476 | } |
| 477 | |
| 478 | dirs = append(dirs, arg) |
| 479 | } |
| 480 | |
| 481 | return newArgs, dirs |
| 482 | } |
| 483 | |
| 484 | // getTargetsFromDirs iterates over the dirs list and creates a list of targets to build. If a |
| 485 | // directory from the dirs list does not exist, a fatal error is raised. relDir is related to the |
| 486 | // source root tree where the build action command was invoked. Each directory is validated if the |
| 487 | // build file can be found and follows the format "dir1:target1,target2,...". Target is optional. |
Dan Willemsen | ce41e94 | 2019-07-29 23:39:30 -0700 | [diff] [blame] | 488 | func getTargetsFromDirs(ctx Context, relDir string, dirs []string, targetNamePrefix string) (targets []string) { |
Patrice Arruda | 1384822 | 2019-04-22 17:12:02 -0700 | [diff] [blame] | 489 | for _, dir := range dirs { |
| 490 | // The directory may have specified specific modules to build. ":" is the separator to separate |
| 491 | // the directory and the list of modules. |
| 492 | s := strings.Split(dir, ":") |
| 493 | l := len(s) |
| 494 | if l > 2 { // more than one ":" was specified. |
| 495 | ctx.Fatalf("%s not in proper directory:target1,target2,... format (\":\" was specified more than once)", dir) |
| 496 | } |
| 497 | |
| 498 | dir = filepath.Join(relDir, s[0]) |
| 499 | if _, err := os.Stat(dir); err != nil { |
| 500 | ctx.Fatalf("couldn't find directory %s", dir) |
| 501 | } |
| 502 | |
| 503 | // Verify that if there are any targets specified after ":". Each target is separated by ",". |
| 504 | var newTargets []string |
| 505 | if l == 2 && s[1] != "" { |
| 506 | newTargets = strings.Split(s[1], ",") |
| 507 | if inList("", newTargets) { |
| 508 | ctx.Fatalf("%s not in proper directory:target1,target2,... format", dir) |
| 509 | } |
| 510 | } |
| 511 | |
Patrice Arruda | 9450d0b | 2019-07-08 11:06:46 -0700 | [diff] [blame] | 512 | // If there are specified targets to build in dir, an android build file must exist for the one |
| 513 | // shot build. For the non-targets case, find the appropriate build file and build all the |
| 514 | // modules in dir (or the closest one in the dir path). |
Patrice Arruda | 1384822 | 2019-04-22 17:12:02 -0700 | [diff] [blame] | 515 | if len(newTargets) > 0 { |
Patrice Arruda | 9450d0b | 2019-07-08 11:06:46 -0700 | [diff] [blame] | 516 | if !hasBuildFile(ctx, dir) { |
Patrice Arruda | 1384822 | 2019-04-22 17:12:02 -0700 | [diff] [blame] | 517 | ctx.Fatalf("Couldn't locate a build file from %s directory", dir) |
| 518 | } |
| 519 | } else { |
Patrice Arruda | 9450d0b | 2019-07-08 11:06:46 -0700 | [diff] [blame] | 520 | buildFile := findBuildFile(ctx, dir) |
| 521 | if buildFile == "" { |
| 522 | ctx.Fatalf("Build file not found for %s directory", dir) |
| 523 | } |
| 524 | newTargets = []string{convertToTarget(filepath.Dir(buildFile), targetNamePrefix)} |
Patrice Arruda | 1384822 | 2019-04-22 17:12:02 -0700 | [diff] [blame] | 525 | } |
| 526 | |
Patrice Arruda | 1384822 | 2019-04-22 17:12:02 -0700 | [diff] [blame] | 527 | targets = append(targets, newTargets...) |
| 528 | } |
| 529 | |
Dan Willemsen | ce41e94 | 2019-07-29 23:39:30 -0700 | [diff] [blame] | 530 | return targets |
Patrice Arruda | 1384822 | 2019-04-22 17:12:02 -0700 | [diff] [blame] | 531 | } |
| 532 | |
Dan Willemsen | 9b58749 | 2017-07-10 22:13:00 -0700 | [diff] [blame] | 533 | func (c *configImpl) parseArgs(ctx Context, args []string) { |
| 534 | for i := 0; i < len(args); i++ { |
| 535 | arg := strings.TrimSpace(args[i]) |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 536 | if arg == "--make-mode" { |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 537 | } else if arg == "showcommands" { |
Dan Willemsen | 9b58749 | 2017-07-10 22:13:00 -0700 | [diff] [blame] | 538 | c.verbose = true |
Dan Willemsen | e0879fc | 2017-08-04 15:06:27 -0700 | [diff] [blame] | 539 | } else if arg == "--skip-make" { |
Anton Hansson | 5e5c48b | 2020-11-27 12:35:20 +0000 | [diff] [blame^] | 540 | c.skipConfig = true |
| 541 | c.skipKati = true |
| 542 | } else if arg == "--skip-kati" { |
| 543 | c.skipKati = true |
Colin Cross | 00a8a3f | 2020-10-29 14:08:31 -0700 | [diff] [blame] | 544 | } else if arg == "--skip-soong-tests" { |
| 545 | c.skipSoongTests = true |
Dan Willemsen | 6ac63ef | 2017-10-17 20:35:34 -0700 | [diff] [blame] | 546 | } else if len(arg) > 0 && arg[0] == '-' { |
Dan Willemsen | 9b58749 | 2017-07-10 22:13:00 -0700 | [diff] [blame] | 547 | parseArgNum := func(def int) int { |
| 548 | if len(arg) > 2 { |
| 549 | p, err := strconv.ParseUint(arg[2:], 10, 31) |
| 550 | if err != nil { |
| 551 | ctx.Fatalf("Failed to parse %q: %v", arg, err) |
| 552 | } |
| 553 | return int(p) |
| 554 | } else if i+1 < len(args) { |
| 555 | p, err := strconv.ParseUint(args[i+1], 10, 31) |
| 556 | if err == nil { |
| 557 | i++ |
| 558 | return int(p) |
| 559 | } |
| 560 | } |
| 561 | return def |
| 562 | } |
| 563 | |
Dan Willemsen | 6ac63ef | 2017-10-17 20:35:34 -0700 | [diff] [blame] | 564 | if len(arg) > 1 && arg[1] == 'j' { |
Dan Willemsen | 9b58749 | 2017-07-10 22:13:00 -0700 | [diff] [blame] | 565 | c.parallel = parseArgNum(c.parallel) |
Dan Willemsen | 6ac63ef | 2017-10-17 20:35:34 -0700 | [diff] [blame] | 566 | } else if len(arg) > 1 && arg[1] == 'k' { |
Dan Willemsen | 9b58749 | 2017-07-10 22:13:00 -0700 | [diff] [blame] | 567 | c.keepGoing = parseArgNum(0) |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 568 | } else { |
| 569 | ctx.Fatalln("Unknown option:", arg) |
| 570 | } |
Dan Willemsen | 091525e | 2017-07-11 14:17:50 -0700 | [diff] [blame] | 571 | } else if k, v, ok := decodeKeyValue(arg); ok && len(k) > 0 { |
Dan Willemsen | 6dfe30a | 2018-09-10 12:41:10 -0700 | [diff] [blame] | 572 | if k == "OUT_DIR" { |
| 573 | ctx.Fatalln("OUT_DIR may only be set in the environment, not as a command line option.") |
| 574 | } |
Dan Willemsen | 091525e | 2017-07-11 14:17:50 -0700 | [diff] [blame] | 575 | c.environ.Set(k, v) |
Dan Willemsen | 2d31a44 | 2018-10-20 21:33:41 -0700 | [diff] [blame] | 576 | } else if arg == "dist" { |
| 577 | c.dist = true |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 578 | } else { |
Dan Willemsen | 2d31a44 | 2018-10-20 21:33:41 -0700 | [diff] [blame] | 579 | if arg == "checkbuild" { |
Colin Cross | 3719349 | 2017-11-16 17:55:00 -0800 | [diff] [blame] | 580 | c.checkbuild = true |
Dan Willemsen | e0879fc | 2017-08-04 15:06:27 -0700 | [diff] [blame] | 581 | } |
Dan Willemsen | 9b58749 | 2017-07-10 22:13:00 -0700 | [diff] [blame] | 582 | c.arguments = append(c.arguments, arg) |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 583 | } |
| 584 | } |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 585 | } |
| 586 | |
Dan Willemsen | ed86952 | 2018-01-08 14:58:46 -0800 | [diff] [blame] | 587 | func (c *configImpl) configureLocale(ctx Context) { |
| 588 | cmd := Command(ctx, Config{c}, "locale", "locale", "-a") |
| 589 | output, err := cmd.Output() |
| 590 | |
| 591 | var locales []string |
| 592 | if err == nil { |
| 593 | locales = strings.Split(string(output), "\n") |
| 594 | } else { |
| 595 | // If we're unable to list the locales, let's assume en_US.UTF-8 |
| 596 | locales = []string{"en_US.UTF-8"} |
| 597 | ctx.Verbosef("Failed to list locales (%q), falling back to %q", err, locales) |
| 598 | } |
| 599 | |
| 600 | // gettext uses LANGUAGE, which is passed directly through |
| 601 | |
| 602 | // For LANG and LC_*, only preserve the evaluated version of |
| 603 | // LC_MESSAGES |
| 604 | user_lang := "" |
| 605 | if lc_all, ok := c.environ.Get("LC_ALL"); ok { |
| 606 | user_lang = lc_all |
| 607 | } else if lc_messages, ok := c.environ.Get("LC_MESSAGES"); ok { |
| 608 | user_lang = lc_messages |
| 609 | } else if lang, ok := c.environ.Get("LANG"); ok { |
| 610 | user_lang = lang |
| 611 | } |
| 612 | |
| 613 | c.environ.UnsetWithPrefix("LC_") |
| 614 | |
| 615 | if user_lang != "" { |
| 616 | c.environ.Set("LC_MESSAGES", user_lang) |
| 617 | } |
| 618 | |
| 619 | // The for LANG, use C.UTF-8 if it exists (Debian currently, proposed |
| 620 | // for others) |
| 621 | if inList("C.UTF-8", locales) { |
| 622 | c.environ.Set("LANG", "C.UTF-8") |
Aaron Kling | d236e0e | 2018-08-07 19:21:36 -0500 | [diff] [blame] | 623 | } else if inList("C.utf8", locales) { |
| 624 | // These normalize to the same thing |
| 625 | c.environ.Set("LANG", "C.UTF-8") |
Dan Willemsen | ed86952 | 2018-01-08 14:58:46 -0800 | [diff] [blame] | 626 | } else if inList("en_US.UTF-8", locales) { |
| 627 | c.environ.Set("LANG", "en_US.UTF-8") |
| 628 | } else if inList("en_US.utf8", locales) { |
| 629 | // These normalize to the same thing |
| 630 | c.environ.Set("LANG", "en_US.UTF-8") |
| 631 | } else { |
| 632 | ctx.Fatalln("System doesn't support either C.UTF-8 or en_US.UTF-8") |
| 633 | } |
| 634 | } |
| 635 | |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 636 | // Lunch configures the environment for a specific product similarly to the |
| 637 | // `lunch` bash function. |
| 638 | func (c *configImpl) Lunch(ctx Context, product, variant string) { |
| 639 | if variant != "eng" && variant != "userdebug" && variant != "user" { |
| 640 | ctx.Fatalf("Invalid variant %q. Must be one of 'user', 'userdebug' or 'eng'", variant) |
| 641 | } |
| 642 | |
| 643 | c.environ.Set("TARGET_PRODUCT", product) |
| 644 | c.environ.Set("TARGET_BUILD_VARIANT", variant) |
| 645 | c.environ.Set("TARGET_BUILD_TYPE", "release") |
| 646 | c.environ.Unset("TARGET_BUILD_APPS") |
Martin Stjernholm | 0880233 | 2020-06-04 17:00:01 +0100 | [diff] [blame] | 647 | c.environ.Unset("TARGET_BUILD_UNBUNDLED") |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 648 | } |
| 649 | |
| 650 | // Tapas configures the environment to build one or more unbundled apps, |
| 651 | // similarly to the `tapas` bash function. |
| 652 | func (c *configImpl) Tapas(ctx Context, apps []string, arch, variant string) { |
| 653 | if len(apps) == 0 { |
| 654 | apps = []string{"all"} |
| 655 | } |
| 656 | if variant == "" { |
| 657 | variant = "eng" |
| 658 | } |
| 659 | |
| 660 | if variant != "eng" && variant != "userdebug" && variant != "user" { |
| 661 | ctx.Fatalf("Invalid variant %q. Must be one of 'user', 'userdebug' or 'eng'", variant) |
| 662 | } |
| 663 | |
| 664 | var product string |
| 665 | switch arch { |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 666 | case "arm", "": |
| 667 | product = "aosp_arm" |
| 668 | case "arm64": |
| 669 | product = "aosm_arm64" |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 670 | case "x86": |
| 671 | product = "aosp_x86" |
| 672 | case "x86_64": |
| 673 | product = "aosp_x86_64" |
| 674 | default: |
| 675 | ctx.Fatalf("Invalid architecture: %q", arch) |
| 676 | } |
| 677 | |
| 678 | c.environ.Set("TARGET_PRODUCT", product) |
| 679 | c.environ.Set("TARGET_BUILD_VARIANT", variant) |
| 680 | c.environ.Set("TARGET_BUILD_TYPE", "release") |
| 681 | c.environ.Set("TARGET_BUILD_APPS", strings.Join(apps, " ")) |
| 682 | } |
| 683 | |
| 684 | func (c *configImpl) Environment() *Environment { |
| 685 | return c.environ |
| 686 | } |
| 687 | |
| 688 | func (c *configImpl) Arguments() []string { |
| 689 | return c.arguments |
| 690 | } |
| 691 | |
| 692 | func (c *configImpl) OutDir() string { |
| 693 | if outDir, ok := c.environ.Get("OUT_DIR"); ok { |
Patrice Arruda | 19bd53e | 2019-07-08 17:26:47 -0700 | [diff] [blame] | 694 | return outDir |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 695 | } |
| 696 | return "out" |
| 697 | } |
| 698 | |
Dan Willemsen | 8a073a8 | 2017-02-04 17:30:44 -0800 | [diff] [blame] | 699 | func (c *configImpl) DistDir() string { |
Dan Willemsen | 2d31a44 | 2018-10-20 21:33:41 -0700 | [diff] [blame] | 700 | return c.distDir |
Dan Willemsen | 8a073a8 | 2017-02-04 17:30:44 -0800 | [diff] [blame] | 701 | } |
| 702 | |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 703 | func (c *configImpl) NinjaArgs() []string { |
Anton Hansson | 5e5c48b | 2020-11-27 12:35:20 +0000 | [diff] [blame^] | 704 | if c.skipKati { |
Dan Willemsen | e0879fc | 2017-08-04 15:06:27 -0700 | [diff] [blame] | 705 | return c.arguments |
| 706 | } |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 707 | return c.ninjaArgs |
| 708 | } |
| 709 | |
Jingwen Chen | 7c6089a | 2020-11-02 02:56:20 -0500 | [diff] [blame] | 710 | func (c *configImpl) BazelOutDir() string { |
| 711 | return filepath.Join(c.OutDir(), "bazel") |
| 712 | } |
| 713 | |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 714 | func (c *configImpl) SoongOutDir() string { |
| 715 | return filepath.Join(c.OutDir(), "soong") |
| 716 | } |
| 717 | |
Jeff Gaston | efc1b41 | 2017-03-29 17:29:06 -0700 | [diff] [blame] | 718 | func (c *configImpl) TempDir() string { |
| 719 | return shared.TempDirForOutDir(c.SoongOutDir()) |
| 720 | } |
| 721 | |
Jeff Gaston | b64fc1c | 2017-08-04 12:30:12 -0700 | [diff] [blame] | 722 | func (c *configImpl) FileListDir() string { |
| 723 | return filepath.Join(c.OutDir(), ".module_paths") |
| 724 | } |
| 725 | |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 726 | func (c *configImpl) KatiSuffix() string { |
| 727 | if c.katiSuffix != "" { |
| 728 | return c.katiSuffix |
| 729 | } |
| 730 | panic("SetKatiSuffix has not been called") |
| 731 | } |
| 732 | |
Colin Cross | 3719349 | 2017-11-16 17:55:00 -0800 | [diff] [blame] | 733 | // Checkbuild returns true if "checkbuild" was one of the build goals, which means that the |
| 734 | // user is interested in additional checks at the expense of build time. |
| 735 | func (c *configImpl) Checkbuild() bool { |
| 736 | return c.checkbuild |
| 737 | } |
| 738 | |
Dan Willemsen | 8a073a8 | 2017-02-04 17:30:44 -0800 | [diff] [blame] | 739 | func (c *configImpl) Dist() bool { |
| 740 | return c.dist |
| 741 | } |
| 742 | |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 743 | func (c *configImpl) IsVerbose() bool { |
| 744 | return c.verbose |
| 745 | } |
| 746 | |
Anton Hansson | 5e5c48b | 2020-11-27 12:35:20 +0000 | [diff] [blame^] | 747 | func (c *configImpl) SkipKati() bool { |
| 748 | return c.skipKati |
| 749 | } |
| 750 | |
| 751 | func (c *configImpl) SkipConfig() bool { |
| 752 | return c.skipConfig |
Dan Willemsen | e0879fc | 2017-08-04 15:06:27 -0700 | [diff] [blame] | 753 | } |
| 754 | |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 755 | func (c *configImpl) TargetProduct() string { |
| 756 | if v, ok := c.environ.Get("TARGET_PRODUCT"); ok { |
| 757 | return v |
| 758 | } |
| 759 | panic("TARGET_PRODUCT is not defined") |
| 760 | } |
| 761 | |
Dan Willemsen | 02781d5 | 2017-05-12 19:28:13 -0700 | [diff] [blame] | 762 | func (c *configImpl) TargetDevice() string { |
| 763 | return c.targetDevice |
| 764 | } |
| 765 | |
| 766 | func (c *configImpl) SetTargetDevice(device string) { |
| 767 | c.targetDevice = device |
| 768 | } |
| 769 | |
| 770 | func (c *configImpl) TargetBuildVariant() string { |
| 771 | if v, ok := c.environ.Get("TARGET_BUILD_VARIANT"); ok { |
| 772 | return v |
| 773 | } |
| 774 | panic("TARGET_BUILD_VARIANT is not defined") |
| 775 | } |
| 776 | |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 777 | func (c *configImpl) KatiArgs() []string { |
| 778 | return c.katiArgs |
| 779 | } |
| 780 | |
| 781 | func (c *configImpl) Parallel() int { |
| 782 | return c.parallel |
| 783 | } |
| 784 | |
Colin Cross | 8b8bec3 | 2019-11-15 13:18:43 -0800 | [diff] [blame] | 785 | func (c *configImpl) HighmemParallel() int { |
| 786 | if i, ok := c.environ.GetInt("NINJA_HIGHMEM_NUM_JOBS"); ok { |
| 787 | return i |
| 788 | } |
| 789 | |
| 790 | const minMemPerHighmemProcess = 8 * 1024 * 1024 * 1024 |
| 791 | parallel := c.Parallel() |
| 792 | if c.UseRemoteBuild() { |
| 793 | // Ninja doesn't support nested pools, and when remote builds are enabled the total ninja parallelism |
| 794 | // is set very high (i.e. 500). Using a large value here would cause the total number of running jobs |
| 795 | // to be the sum of the sizes of the local and highmem pools, which will cause extra CPU contention. |
| 796 | // Return 1/16th of the size of the local pool, rounding up. |
| 797 | return (parallel + 15) / 16 |
| 798 | } else if c.totalRAM == 0 { |
| 799 | // Couldn't detect the total RAM, don't restrict highmem processes. |
| 800 | return parallel |
Dan Willemsen | 570a292 | 2020-05-26 23:02:29 -0700 | [diff] [blame] | 801 | } else if c.totalRAM <= 16*1024*1024*1024 { |
| 802 | // Less than 16GB of ram, restrict to 1 highmem processes |
| 803 | return 1 |
Colin Cross | 8b8bec3 | 2019-11-15 13:18:43 -0800 | [diff] [blame] | 804 | } else if c.totalRAM <= 32*1024*1024*1024 { |
| 805 | // Less than 32GB of ram, restrict to 2 highmem processes |
| 806 | return 2 |
| 807 | } else if p := int(c.totalRAM / minMemPerHighmemProcess); p < parallel { |
| 808 | // If less than 8GB total RAM per process, reduce the number of highmem processes |
| 809 | return p |
| 810 | } |
| 811 | // No restriction on highmem processes |
| 812 | return parallel |
| 813 | } |
| 814 | |
Dan Willemsen | 2bb82d0 | 2019-12-27 09:35:42 -0800 | [diff] [blame] | 815 | func (c *configImpl) TotalRAM() uint64 { |
| 816 | return c.totalRAM |
| 817 | } |
| 818 | |
Kousik Kumar | ec47864 | 2020-09-21 13:39:24 -0400 | [diff] [blame] | 819 | // ForceUseGoma determines whether we should override Goma deprecation |
| 820 | // and use Goma for the current build or not. |
| 821 | func (c *configImpl) ForceUseGoma() bool { |
| 822 | if v, ok := c.environ.Get("FORCE_USE_GOMA"); ok { |
| 823 | v = strings.TrimSpace(v) |
| 824 | if v != "" && v != "false" { |
| 825 | return true |
| 826 | } |
| 827 | } |
| 828 | return false |
| 829 | } |
| 830 | |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 831 | func (c *configImpl) UseGoma() bool { |
| 832 | if v, ok := c.environ.Get("USE_GOMA"); ok { |
| 833 | v = strings.TrimSpace(v) |
| 834 | if v != "" && v != "false" { |
| 835 | return true |
| 836 | } |
| 837 | } |
| 838 | return false |
| 839 | } |
| 840 | |
Yoshisato Yanagisawa | 2cb0e5d | 2019-01-10 10:14:16 +0900 | [diff] [blame] | 841 | func (c *configImpl) StartGoma() bool { |
| 842 | if !c.UseGoma() { |
| 843 | return false |
| 844 | } |
| 845 | |
| 846 | if v, ok := c.environ.Get("NOSTART_GOMA"); ok { |
| 847 | v = strings.TrimSpace(v) |
| 848 | if v != "" && v != "false" { |
| 849 | return false |
| 850 | } |
| 851 | } |
| 852 | return true |
| 853 | } |
| 854 | |
Ramy Medhat | bbf2567 | 2019-07-17 12:30:04 +0000 | [diff] [blame] | 855 | func (c *configImpl) UseRBE() bool { |
| 856 | if v, ok := c.environ.Get("USE_RBE"); ok { |
| 857 | v = strings.TrimSpace(v) |
| 858 | if v != "" && v != "false" { |
| 859 | return true |
| 860 | } |
| 861 | } |
| 862 | return false |
| 863 | } |
| 864 | |
Patrice Arruda | 0c1c456 | 2020-11-11 13:01:25 -0800 | [diff] [blame] | 865 | func (c *configImpl) UseBazel() bool { |
| 866 | if v, ok := c.environ.Get("USE_BAZEL"); ok { |
| 867 | v = strings.TrimSpace(v) |
| 868 | if v != "" && v != "false" { |
| 869 | return true |
| 870 | } |
| 871 | } |
| 872 | return false |
| 873 | } |
| 874 | |
Ramy Medhat | bbf2567 | 2019-07-17 12:30:04 +0000 | [diff] [blame] | 875 | func (c *configImpl) StartRBE() bool { |
| 876 | if !c.UseRBE() { |
| 877 | return false |
| 878 | } |
| 879 | |
| 880 | if v, ok := c.environ.Get("NOSTART_RBE"); ok { |
| 881 | v = strings.TrimSpace(v) |
| 882 | if v != "" && v != "false" { |
| 883 | return false |
| 884 | } |
| 885 | } |
| 886 | return true |
| 887 | } |
| 888 | |
Ramy Medhat | 0fc67eb | 2020-08-12 01:26:23 -0400 | [diff] [blame] | 889 | func (c *configImpl) logDir() string { |
Kousik Kumar | 0d15a72 | 2020-09-23 02:54:11 -0400 | [diff] [blame] | 890 | for _, f := range []string{"RBE_log_dir", "FLAG_log_dir"} { |
| 891 | if v, ok := c.environ.Get(f); ok { |
| 892 | return v |
| 893 | } |
| 894 | } |
Ramy Medhat | 0fc67eb | 2020-08-12 01:26:23 -0400 | [diff] [blame] | 895 | if c.Dist() { |
| 896 | return filepath.Join(c.DistDir(), "logs") |
| 897 | } |
| 898 | return c.OutDir() |
| 899 | } |
| 900 | |
| 901 | func (c *configImpl) rbeStatsOutputDir() string { |
Patrice Arruda | 62f1bf2 | 2020-07-07 12:48:26 +0000 | [diff] [blame] | 902 | for _, f := range []string{"RBE_output_dir", "FLAG_output_dir"} { |
| 903 | if v, ok := c.environ.Get(f); ok { |
| 904 | return v |
| 905 | } |
| 906 | } |
Ramy Medhat | 0fc67eb | 2020-08-12 01:26:23 -0400 | [diff] [blame] | 907 | return c.logDir() |
| 908 | } |
| 909 | |
| 910 | func (c *configImpl) rbeLogPath() string { |
| 911 | for _, f := range []string{"RBE_log_path", "FLAG_log_path"} { |
| 912 | if v, ok := c.environ.Get(f); ok { |
| 913 | return v |
| 914 | } |
| 915 | } |
| 916 | return fmt.Sprintf("text://%v/reproxy_log.txt", c.logDir()) |
| 917 | } |
| 918 | |
| 919 | func (c *configImpl) rbeExecRoot() string { |
| 920 | for _, f := range []string{"RBE_exec_root", "FLAG_exec_root"} { |
| 921 | if v, ok := c.environ.Get(f); ok { |
| 922 | return v |
| 923 | } |
| 924 | } |
| 925 | wd, err := os.Getwd() |
| 926 | if err != nil { |
| 927 | return "" |
| 928 | } |
| 929 | return wd |
| 930 | } |
| 931 | |
| 932 | func (c *configImpl) rbeDir() string { |
| 933 | if v, ok := c.environ.Get("RBE_DIR"); ok { |
| 934 | return v |
| 935 | } |
| 936 | return "prebuilts/remoteexecution-client/live/" |
| 937 | } |
| 938 | |
| 939 | func (c *configImpl) rbeReproxy() string { |
| 940 | for _, f := range []string{"RBE_re_proxy", "FLAG_re_proxy"} { |
| 941 | if v, ok := c.environ.Get(f); ok { |
| 942 | return v |
| 943 | } |
| 944 | } |
| 945 | return filepath.Join(c.rbeDir(), "reproxy") |
| 946 | } |
| 947 | |
| 948 | func (c *configImpl) rbeAuth() (string, string) { |
| 949 | credFlags := []string{"use_application_default_credentials", "use_gce_credentials", "credential_file"} |
| 950 | for _, cf := range credFlags { |
| 951 | for _, f := range []string{"RBE_" + cf, "FLAG_" + cf} { |
| 952 | if v, ok := c.environ.Get(f); ok { |
| 953 | v = strings.TrimSpace(v) |
| 954 | if v != "" && v != "false" && v != "0" { |
| 955 | return "RBE_" + cf, v |
| 956 | } |
| 957 | } |
| 958 | } |
| 959 | } |
| 960 | return "RBE_use_application_default_credentials", "true" |
Patrice Arruda | 62f1bf2 | 2020-07-07 12:48:26 +0000 | [diff] [blame] | 961 | } |
| 962 | |
Colin Cross | 9016b91 | 2019-11-11 14:57:42 -0800 | [diff] [blame] | 963 | func (c *configImpl) UseRemoteBuild() bool { |
| 964 | return c.UseGoma() || c.UseRBE() |
| 965 | } |
| 966 | |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 967 | // RemoteParallel controls how many remote jobs (i.e., commands which contain |
Jeff Gaston | efc1b41 | 2017-03-29 17:29:06 -0700 | [diff] [blame] | 968 | // gomacc) are run in parallel. Note the parallelism of all other jobs is |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 969 | // still limited by Parallel() |
| 970 | func (c *configImpl) RemoteParallel() int { |
Colin Cross | 8b8bec3 | 2019-11-15 13:18:43 -0800 | [diff] [blame] | 971 | if !c.UseRemoteBuild() { |
| 972 | return 0 |
| 973 | } |
| 974 | if i, ok := c.environ.GetInt("NINJA_REMOTE_NUM_JOBS"); ok { |
| 975 | return i |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 976 | } |
| 977 | return 500 |
| 978 | } |
| 979 | |
| 980 | func (c *configImpl) SetKatiArgs(args []string) { |
| 981 | c.katiArgs = args |
| 982 | } |
| 983 | |
| 984 | func (c *configImpl) SetNinjaArgs(args []string) { |
| 985 | c.ninjaArgs = args |
| 986 | } |
| 987 | |
| 988 | func (c *configImpl) SetKatiSuffix(suffix string) { |
| 989 | c.katiSuffix = suffix |
| 990 | } |
| 991 | |
Dan Willemsen | e0879fc | 2017-08-04 15:06:27 -0700 | [diff] [blame] | 992 | func (c *configImpl) LastKatiSuffixFile() string { |
| 993 | return filepath.Join(c.OutDir(), "last_kati_suffix") |
| 994 | } |
| 995 | |
| 996 | func (c *configImpl) HasKatiSuffix() bool { |
| 997 | return c.katiSuffix != "" |
| 998 | } |
| 999 | |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 1000 | func (c *configImpl) KatiEnvFile() string { |
| 1001 | return filepath.Join(c.OutDir(), "env"+c.KatiSuffix()+".sh") |
| 1002 | } |
| 1003 | |
Dan Willemsen | 2997123 | 2018-09-26 14:58:30 -0700 | [diff] [blame] | 1004 | func (c *configImpl) KatiBuildNinjaFile() string { |
| 1005 | return filepath.Join(c.OutDir(), "build"+c.KatiSuffix()+katiBuildSuffix+".ninja") |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 1006 | } |
| 1007 | |
Dan Willemsen | fb1271a | 2018-09-26 15:00:42 -0700 | [diff] [blame] | 1008 | func (c *configImpl) KatiPackageNinjaFile() string { |
| 1009 | return filepath.Join(c.OutDir(), "build"+c.KatiSuffix()+katiPackageSuffix+".ninja") |
| 1010 | } |
| 1011 | |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 1012 | func (c *configImpl) SoongNinjaFile() string { |
| 1013 | return filepath.Join(c.SoongOutDir(), "build.ninja") |
| 1014 | } |
| 1015 | |
| 1016 | func (c *configImpl) CombinedNinjaFile() string { |
Dan Willemsen | e0879fc | 2017-08-04 15:06:27 -0700 | [diff] [blame] | 1017 | if c.katiSuffix == "" { |
| 1018 | return filepath.Join(c.OutDir(), "combined.ninja") |
| 1019 | } |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 1020 | return filepath.Join(c.OutDir(), "combined"+c.KatiSuffix()+".ninja") |
| 1021 | } |
| 1022 | |
| 1023 | func (c *configImpl) SoongAndroidMk() string { |
| 1024 | return filepath.Join(c.SoongOutDir(), "Android-"+c.TargetProduct()+".mk") |
| 1025 | } |
| 1026 | |
| 1027 | func (c *configImpl) SoongMakeVarsMk() string { |
| 1028 | return filepath.Join(c.SoongOutDir(), "make_vars-"+c.TargetProduct()+".mk") |
| 1029 | } |
| 1030 | |
Dan Willemsen | f052f78 | 2017-05-18 15:29:04 -0700 | [diff] [blame] | 1031 | func (c *configImpl) ProductOut() string { |
Dan Willemsen | 4dc4e14 | 2017-09-08 14:35:43 -0700 | [diff] [blame] | 1032 | return filepath.Join(c.OutDir(), "target", "product", c.TargetDevice()) |
Dan Willemsen | f052f78 | 2017-05-18 15:29:04 -0700 | [diff] [blame] | 1033 | } |
| 1034 | |
Dan Willemsen | 02781d5 | 2017-05-12 19:28:13 -0700 | [diff] [blame] | 1035 | func (c *configImpl) DevicePreviousProductConfig() string { |
Dan Willemsen | f052f78 | 2017-05-18 15:29:04 -0700 | [diff] [blame] | 1036 | return filepath.Join(c.ProductOut(), "previous_build_config.mk") |
| 1037 | } |
| 1038 | |
Dan Willemsen | fb1271a | 2018-09-26 15:00:42 -0700 | [diff] [blame] | 1039 | func (c *configImpl) KatiPackageMkDir() string { |
| 1040 | return filepath.Join(c.ProductOut(), "obj", "CONFIG", "kati_packaging") |
| 1041 | } |
| 1042 | |
Dan Willemsen | f052f78 | 2017-05-18 15:29:04 -0700 | [diff] [blame] | 1043 | func (c *configImpl) hostOutRoot() string { |
Dan Willemsen | 4dc4e14 | 2017-09-08 14:35:43 -0700 | [diff] [blame] | 1044 | return filepath.Join(c.OutDir(), "host") |
Dan Willemsen | f052f78 | 2017-05-18 15:29:04 -0700 | [diff] [blame] | 1045 | } |
| 1046 | |
| 1047 | func (c *configImpl) HostOut() string { |
| 1048 | return filepath.Join(c.hostOutRoot(), c.HostPrebuiltTag()) |
| 1049 | } |
| 1050 | |
| 1051 | // This probably needs to be multi-valued, so not exporting it for now |
| 1052 | func (c *configImpl) hostCrossOut() string { |
| 1053 | if runtime.GOOS == "linux" { |
| 1054 | return filepath.Join(c.hostOutRoot(), "windows-x86") |
| 1055 | } else { |
| 1056 | return "" |
| 1057 | } |
Dan Willemsen | 02781d5 | 2017-05-12 19:28:13 -0700 | [diff] [blame] | 1058 | } |
| 1059 | |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 1060 | func (c *configImpl) HostPrebuiltTag() string { |
| 1061 | if runtime.GOOS == "linux" { |
| 1062 | return "linux-x86" |
| 1063 | } else if runtime.GOOS == "darwin" { |
| 1064 | return "darwin-x86" |
| 1065 | } else { |
| 1066 | panic("Unsupported OS") |
| 1067 | } |
| 1068 | } |
Dan Willemsen | f173d59 | 2017-04-27 14:28:00 -0700 | [diff] [blame] | 1069 | |
Dan Willemsen | 8122bd5 | 2017-10-12 20:20:41 -0700 | [diff] [blame] | 1070 | func (c *configImpl) PrebuiltBuildTool(name string) string { |
Dan Willemsen | f173d59 | 2017-04-27 14:28:00 -0700 | [diff] [blame] | 1071 | if v, ok := c.environ.Get("SANITIZE_HOST"); ok { |
| 1072 | if sanitize := strings.Fields(v); inList("address", sanitize) { |
Dan Willemsen | 8122bd5 | 2017-10-12 20:20:41 -0700 | [diff] [blame] | 1073 | asan := filepath.Join("prebuilts/build-tools", c.HostPrebuiltTag(), "asan/bin", name) |
| 1074 | if _, err := os.Stat(asan); err == nil { |
| 1075 | return asan |
| 1076 | } |
Dan Willemsen | f173d59 | 2017-04-27 14:28:00 -0700 | [diff] [blame] | 1077 | } |
| 1078 | } |
| 1079 | return filepath.Join("prebuilts/build-tools", c.HostPrebuiltTag(), "bin", name) |
| 1080 | } |
Dan Willemsen | 3d60b11 | 2018-04-04 22:25:56 -0700 | [diff] [blame] | 1081 | |
| 1082 | func (c *configImpl) SetBuildBrokenDupRules(val bool) { |
| 1083 | c.brokenDupRules = val |
| 1084 | } |
| 1085 | |
| 1086 | func (c *configImpl) BuildBrokenDupRules() bool { |
| 1087 | return c.brokenDupRules |
| 1088 | } |
Dan Willemsen | 6ab79db | 2018-05-02 00:06:28 -0700 | [diff] [blame] | 1089 | |
Dan Willemsen | 25e6f09 | 2019-04-09 10:22:43 -0700 | [diff] [blame] | 1090 | func (c *configImpl) SetBuildBrokenUsesNetwork(val bool) { |
| 1091 | c.brokenUsesNetwork = val |
| 1092 | } |
| 1093 | |
| 1094 | func (c *configImpl) BuildBrokenUsesNetwork() bool { |
| 1095 | return c.brokenUsesNetwork |
| 1096 | } |
| 1097 | |
Dan Willemsen | e333635 | 2020-01-02 19:10:38 -0800 | [diff] [blame] | 1098 | func (c *configImpl) SetBuildBrokenNinjaUsesEnvVars(val []string) { |
| 1099 | c.brokenNinjaEnvVars = val |
| 1100 | } |
| 1101 | |
| 1102 | func (c *configImpl) BuildBrokenNinjaUsesEnvVars() []string { |
| 1103 | return c.brokenNinjaEnvVars |
| 1104 | } |
| 1105 | |
Dan Willemsen | 6ab79db | 2018-05-02 00:06:28 -0700 | [diff] [blame] | 1106 | func (c *configImpl) SetTargetDeviceDir(dir string) { |
| 1107 | c.targetDeviceDir = dir |
| 1108 | } |
| 1109 | |
| 1110 | func (c *configImpl) TargetDeviceDir() string { |
| 1111 | return c.targetDeviceDir |
| 1112 | } |
Dan Willemsen | fa42f3c | 2018-06-15 21:54:47 -0700 | [diff] [blame] | 1113 | |
Patrice Arruda | 219eef3 | 2020-06-01 17:29:30 +0000 | [diff] [blame] | 1114 | func (c *configImpl) BuildDateTime() string { |
| 1115 | return c.buildDateTime |
| 1116 | } |
| 1117 | |
| 1118 | func (c *configImpl) MetricsUploaderApp() string { |
| 1119 | if p, ok := c.environ.Get("ANDROID_ENABLE_METRICS_UPLOAD"); ok { |
| 1120 | return p |
| 1121 | } |
| 1122 | return "" |
| 1123 | } |