blob: 0414175a83cbd34003ef48c14c86ff1c86398aaa [file] [log] [blame]
Dan Willemsen1e704462016-08-21 15:17:17 -07001// 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
15package build
16
17import (
Ramy Medhat0fc67eb2020-08-12 01:26:23 -040018 "fmt"
Dan Willemsenc2af0be2017-01-20 14:10:01 -080019 "os"
Dan Willemsen1e704462016-08-21 15:17:17 -070020 "path/filepath"
21 "runtime"
22 "strconv"
23 "strings"
Nan Zhang2e6a4ff2018-02-14 13:27:26 -080024 "time"
Jeff Gastonefc1b412017-03-29 17:29:06 -070025
26 "android/soong/shared"
Dan Willemsen1e704462016-08-21 15:17:17 -070027)
28
29type Config struct{ *configImpl }
30
31type configImpl struct {
32 // From the environment
Colin Cross28f527c2019-11-26 16:19:04 -080033 arguments []string
34 goma bool
35 environ *Environment
36 distDir string
37 buildDateTime string
Dan Willemsen1e704462016-08-21 15:17:17 -070038
39 // From the arguments
Colin Cross37193492017-11-16 17:55:00 -080040 parallel int
41 keepGoing int
42 verbose bool
43 checkbuild bool
44 dist bool
45 skipMake bool
Dan Willemsen1e704462016-08-21 15:17:17 -070046
47 // From the product config
Dan Willemsen6ab79db2018-05-02 00:06:28 -070048 katiArgs []string
49 ninjaArgs []string
50 katiSuffix string
51 targetDevice string
52 targetDeviceDir string
Dan Willemsen3d60b112018-04-04 22:25:56 -070053
Dan Willemsen2bb82d02019-12-27 09:35:42 -080054 // Autodetected
55 totalRAM uint64
56
Dan Willemsene3336352020-01-02 19:10:38 -080057 brokenDupRules bool
58 brokenUsesNetwork bool
59 brokenNinjaEnvVars []string
Dan Willemsen18490112018-05-25 16:30:04 -070060
61 pathReplaced bool
Dan Willemsen1e704462016-08-21 15:17:17 -070062}
63
Dan Willemsenc2af0be2017-01-20 14:10:01 -080064const srcDirFileCheck = "build/soong/root.bp"
65
Patrice Arruda9450d0b2019-07-08 11:06:46 -070066var buildFiles = []string{"Android.mk", "Android.bp"}
67
Patrice Arruda13848222019-04-22 17:12:02 -070068type BuildAction uint
69
70const (
71 // Builds all of the modules and their dependencies of a specified directory, relative to the root
72 // directory of the source tree.
73 BUILD_MODULES_IN_A_DIRECTORY BuildAction = iota
74
75 // Builds all of the modules and their dependencies of a list of specified directories. All specified
76 // directories are relative to the root directory of the source tree.
77 BUILD_MODULES_IN_DIRECTORIES
Patrice Arruda39282062019-06-20 16:35:12 -070078
79 // Build a list of specified modules. If none was specified, simply build the whole source tree.
80 BUILD_MODULES
Patrice Arruda13848222019-04-22 17:12:02 -070081)
82
83// checkTopDir validates that the current directory is at the root directory of the source tree.
84func checkTopDir(ctx Context) {
85 if _, err := os.Stat(srcDirFileCheck); err != nil {
86 if os.IsNotExist(err) {
87 ctx.Fatalf("Current working directory must be the source tree. %q not found.", srcDirFileCheck)
88 }
89 ctx.Fatalln("Error verifying tree state:", err)
90 }
91}
92
Dan Willemsen1e704462016-08-21 15:17:17 -070093func NewConfig(ctx Context, args ...string) Config {
94 ret := &configImpl{
95 environ: OsEnvironment(),
96 }
97
Patrice Arruda90109172020-07-28 18:07:27 +000098 // Default matching ninja
Dan Willemsen9b587492017-07-10 22:13:00 -070099 ret.parallel = runtime.NumCPU() + 2
100 ret.keepGoing = 1
101
Dan Willemsen2bb82d02019-12-27 09:35:42 -0800102 ret.totalRAM = detectTotalRAM(ctx)
103
Dan Willemsen9b587492017-07-10 22:13:00 -0700104 ret.parseArgs(ctx, args)
105
Dan Willemsen0c3919e2017-03-02 15:49:10 -0800106 // Make sure OUT_DIR is set appropriately
Dan Willemsen02f3add2017-05-12 13:50:19 -0700107 if outDir, ok := ret.environ.Get("OUT_DIR"); ok {
108 ret.environ.Set("OUT_DIR", filepath.Clean(outDir))
109 } else {
Dan Willemsen0c3919e2017-03-02 15:49:10 -0800110 outDir := "out"
111 if baseDir, ok := ret.environ.Get("OUT_DIR_COMMON_BASE"); ok {
112 if wd, err := os.Getwd(); err != nil {
113 ctx.Fatalln("Failed to get working directory:", err)
114 } else {
115 outDir = filepath.Join(baseDir, filepath.Base(wd))
116 }
117 }
118 ret.environ.Set("OUT_DIR", outDir)
119 }
120
Dan Willemsen2d31a442018-10-20 21:33:41 -0700121 if distDir, ok := ret.environ.Get("DIST_DIR"); ok {
122 ret.distDir = filepath.Clean(distDir)
123 } else {
124 ret.distDir = filepath.Join(ret.OutDir(), "dist")
125 }
Dan Willemsend50e89f2018-10-16 17:49:25 -0700126
Dan Willemsen1e704462016-08-21 15:17:17 -0700127 ret.environ.Unset(
128 // We're already using it
129 "USE_SOONG_UI",
130
131 // We should never use GOROOT/GOPATH from the shell environment
132 "GOROOT",
133 "GOPATH",
134
135 // These should only come from Soong, not the environment.
136 "CLANG",
137 "CLANG_CXX",
138 "CCC_CC",
139 "CCC_CXX",
140
141 // Used by the goma compiler wrapper, but should only be set by
142 // gomacc
143 "GOMACC_PATH",
Dan Willemsen0c3919e2017-03-02 15:49:10 -0800144
145 // We handle this above
146 "OUT_DIR_COMMON_BASE",
Dan Willemsen68a09852017-04-18 13:56:57 -0700147
Dan Willemsen2d31a442018-10-20 21:33:41 -0700148 // This is handled above too, and set for individual commands later
149 "DIST_DIR",
150
Dan Willemsen68a09852017-04-18 13:56:57 -0700151 // Variables that have caused problems in the past
Dan Willemsen1c504d92019-11-18 19:13:53 +0000152 "BASH_ENV",
Dan Willemsenebfe33a2018-05-01 10:07:50 -0700153 "CDPATH",
Dan Willemsen68a09852017-04-18 13:56:57 -0700154 "DISPLAY",
155 "GREP_OPTIONS",
Dan Willemsenebfe33a2018-05-01 10:07:50 -0700156 "NDK_ROOT",
Dan Willemsen00fcb262018-08-15 15:35:38 -0700157 "POSIXLY_CORRECT",
Dan Willemsenc40e10b2017-07-11 14:30:00 -0700158
159 // Drop make flags
160 "MAKEFLAGS",
161 "MAKELEVEL",
162 "MFLAGS",
Dan Willemsend9e8f0a2017-10-30 13:42:06 -0700163
164 // Set in envsetup.sh, reset in makefiles
165 "ANDROID_JAVA_TOOLCHAIN",
Colin Cross7f09c402018-07-11 14:49:31 -0700166
167 // Set by envsetup.sh, but shouldn't be used inside the build because envsetup.sh is optional
168 "ANDROID_BUILD_TOP",
169 "ANDROID_HOST_OUT",
170 "ANDROID_PRODUCT_OUT",
171 "ANDROID_HOST_OUT_TESTCASES",
172 "ANDROID_TARGET_OUT_TESTCASES",
173 "ANDROID_TOOLCHAIN",
174 "ANDROID_TOOLCHAIN_2ND_ARCH",
175 "ANDROID_DEV_SCRIPTS",
176 "ANDROID_EMULATOR_PREBUILTS",
177 "ANDROID_PRE_BUILD_PATHS",
Dan Willemsenf99915f2018-10-25 22:04:42 -0700178
179 // Only set in multiproduct_kati after config generation
180 "EMPTY_NINJA_FILE",
Dan Willemsen1e704462016-08-21 15:17:17 -0700181 )
182
183 // Tell python not to spam the source tree with .pyc files.
184 ret.environ.Set("PYTHONDONTWRITEBYTECODE", "1")
185
Ramy Medhatca1e44c2020-07-16 12:18:37 -0400186 tmpDir := absPath(ctx, ret.TempDir())
187 ret.environ.Set("TMPDIR", tmpDir)
Dan Willemsen32a669b2018-03-08 19:42:00 -0800188
Dan Willemsen70c1ff82019-08-21 14:56:13 -0700189 // Always set ASAN_SYMBOLIZER_PATH so that ASAN-based tools can symbolize any crashes
190 symbolizerPath := filepath.Join("prebuilts/clang/host", ret.HostPrebuiltTag(),
191 "llvm-binutils-stable/llvm-symbolizer")
192 ret.environ.Set("ASAN_SYMBOLIZER_PATH", absPath(ctx, symbolizerPath))
193
Dan Willemsenc2af0be2017-01-20 14:10:01 -0800194 // Precondition: the current directory is the top of the source tree
Patrice Arruda13848222019-04-22 17:12:02 -0700195 checkTopDir(ctx)
Dan Willemsenc2af0be2017-01-20 14:10:01 -0800196
Dan Willemsend9e8f0a2017-10-30 13:42:06 -0700197 if srcDir := absPath(ctx, "."); strings.ContainsRune(srcDir, ' ') {
Colin Cross1f6faeb2019-09-23 15:52:40 -0700198 ctx.Println("You are building in a directory whose absolute path contains a space character:")
199 ctx.Println()
200 ctx.Printf("%q\n", srcDir)
201 ctx.Println()
202 ctx.Fatalln("Directory names containing spaces are not supported")
Dan Willemsendb8457c2017-05-12 16:38:17 -0700203 }
204
205 if outDir := ret.OutDir(); strings.ContainsRune(outDir, ' ') {
Colin Cross1f6faeb2019-09-23 15:52:40 -0700206 ctx.Println("The absolute path of your output directory ($OUT_DIR) contains a space character:")
207 ctx.Println()
208 ctx.Printf("%q\n", outDir)
209 ctx.Println()
210 ctx.Fatalln("Directory names containing spaces are not supported")
Dan Willemsendb8457c2017-05-12 16:38:17 -0700211 }
212
213 if distDir := ret.DistDir(); strings.ContainsRune(distDir, ' ') {
Colin Cross1f6faeb2019-09-23 15:52:40 -0700214 ctx.Println("The absolute path of your dist directory ($DIST_DIR) contains a space character:")
215 ctx.Println()
216 ctx.Printf("%q\n", distDir)
217 ctx.Println()
218 ctx.Fatalln("Directory names containing spaces are not supported")
Dan Willemsendb8457c2017-05-12 16:38:17 -0700219 }
220
Dan Willemsend9e8f0a2017-10-30 13:42:06 -0700221 // Configure Java-related variables, including adding it to $PATH
Tobias Thierere59aeff2017-12-20 22:40:39 +0000222 java8Home := filepath.Join("prebuilts/jdk/jdk8", ret.HostPrebuiltTag())
223 java9Home := filepath.Join("prebuilts/jdk/jdk9", ret.HostPrebuiltTag())
Pete Gillin1f52e932019-10-09 17:10:08 +0100224 java11Home := filepath.Join("prebuilts/jdk/jdk11", ret.HostPrebuiltTag())
Dan Willemsend9e8f0a2017-10-30 13:42:06 -0700225 javaHome := func() string {
226 if override, ok := ret.environ.Get("OVERRIDE_ANDROID_JAVA_HOME"); ok {
227 return override
228 }
Pete Gillina7a3d642019-11-07 18:58:42 +0000229 if toolchain11, ok := ret.environ.Get("EXPERIMENTAL_USE_OPENJDK11_TOOLCHAIN"); ok && toolchain11 != "true" {
230 ctx.Fatalln("The environment variable EXPERIMENTAL_USE_OPENJDK11_TOOLCHAIN is no longer supported. An OpenJDK 11 toolchain is now the global default.")
Pete Gillin1f52e932019-10-09 17:10:08 +0100231 }
Pete Gillinabbcdda2019-10-28 16:15:33 +0000232 return java11Home
Dan Willemsend9e8f0a2017-10-30 13:42:06 -0700233 }()
234 absJavaHome := absPath(ctx, javaHome)
235
Dan Willemsened869522018-01-08 14:58:46 -0800236 ret.configureLocale(ctx)
237
Dan Willemsend9e8f0a2017-10-30 13:42:06 -0700238 newPath := []string{filepath.Join(absJavaHome, "bin")}
239 if path, ok := ret.environ.Get("PATH"); ok && path != "" {
240 newPath = append(newPath, path)
241 }
Pete Gillin1f52e932019-10-09 17:10:08 +0100242
Dan Willemsend9e8f0a2017-10-30 13:42:06 -0700243 ret.environ.Unset("OVERRIDE_ANDROID_JAVA_HOME")
244 ret.environ.Set("JAVA_HOME", absJavaHome)
245 ret.environ.Set("ANDROID_JAVA_HOME", javaHome)
Tobias Thierere59aeff2017-12-20 22:40:39 +0000246 ret.environ.Set("ANDROID_JAVA8_HOME", java8Home)
247 ret.environ.Set("ANDROID_JAVA9_HOME", java9Home)
Pete Gillin1f52e932019-10-09 17:10:08 +0100248 ret.environ.Set("ANDROID_JAVA11_HOME", java11Home)
Dan Willemsend9e8f0a2017-10-30 13:42:06 -0700249 ret.environ.Set("PATH", strings.Join(newPath, string(filepath.ListSeparator)))
250
Nan Zhang2e6a4ff2018-02-14 13:27:26 -0800251 outDir := ret.OutDir()
252 buildDateTimeFile := filepath.Join(outDir, "build_date.txt")
Nan Zhang2e6a4ff2018-02-14 13:27:26 -0800253 if buildDateTime, ok := ret.environ.Get("BUILD_DATETIME"); ok && buildDateTime != "" {
Colin Cross28f527c2019-11-26 16:19:04 -0800254 ret.buildDateTime = buildDateTime
Nan Zhang2e6a4ff2018-02-14 13:27:26 -0800255 } else {
Colin Cross28f527c2019-11-26 16:19:04 -0800256 ret.buildDateTime = strconv.FormatInt(time.Now().Unix(), 10)
Nan Zhang2e6a4ff2018-02-14 13:27:26 -0800257 }
Colin Cross28f527c2019-11-26 16:19:04 -0800258
Nan Zhang2e6a4ff2018-02-14 13:27:26 -0800259 ret.environ.Set("BUILD_DATETIME_FILE", buildDateTimeFile)
260
Ramy Medhatca1e44c2020-07-16 12:18:37 -0400261 if ret.UseRBE() {
Ramy Medhat0fc67eb2020-08-12 01:26:23 -0400262 for k, v := range getRBEVars(ctx, Config{ret}) {
Ramy Medhatca1e44c2020-07-16 12:18:37 -0400263 ret.environ.Set(k, v)
264 }
265 }
266
Dan Willemsen9b587492017-07-10 22:13:00 -0700267 return Config{ret}
268}
269
Patrice Arruda13848222019-04-22 17:12:02 -0700270// NewBuildActionConfig returns a build configuration based on the build action. The arguments are
271// processed based on the build action and extracts any arguments that belongs to the build action.
Dan Willemsence41e942019-07-29 23:39:30 -0700272func NewBuildActionConfig(action BuildAction, dir string, ctx Context, args ...string) Config {
273 return NewConfig(ctx, getConfigArgs(action, dir, ctx, args)...)
Patrice Arruda13848222019-04-22 17:12:02 -0700274}
275
276// getConfigArgs processes the command arguments based on the build action and creates a set of new
277// arguments to be accepted by Config.
Dan Willemsence41e942019-07-29 23:39:30 -0700278func getConfigArgs(action BuildAction, dir string, ctx Context, args []string) []string {
Patrice Arruda13848222019-04-22 17:12:02 -0700279 // The next block of code verifies that the current directory is the root directory of the source
280 // tree. It then finds the relative path of dir based on the root directory of the source tree
281 // and verify that dir is inside of the source tree.
282 checkTopDir(ctx)
283 topDir, err := os.Getwd()
284 if err != nil {
285 ctx.Fatalf("Error retrieving top directory: %v", err)
286 }
Patrice Arrudababa9a92019-07-03 10:47:34 -0700287 dir, err = filepath.EvalSymlinks(dir)
288 if err != nil {
289 ctx.Fatalf("Unable to evaluate symlink of %s: %v", dir, err)
290 }
Patrice Arruda13848222019-04-22 17:12:02 -0700291 dir, err = filepath.Abs(dir)
292 if err != nil {
293 ctx.Fatalf("Unable to find absolute path %s: %v", dir, err)
294 }
295 relDir, err := filepath.Rel(topDir, dir)
296 if err != nil {
297 ctx.Fatalf("Unable to find relative path %s of %s: %v", relDir, topDir, err)
298 }
299 // If there are ".." in the path, it's not in the source tree.
300 if strings.Contains(relDir, "..") {
301 ctx.Fatalf("Directory %s is not under the source tree %s", dir, topDir)
302 }
303
304 configArgs := args[:]
305
306 // If the arguments contains GET-INSTALL-PATH, change the target name prefix from MODULES-IN- to
307 // GET-INSTALL-PATH-IN- to extract the installation path instead of building the modules.
308 targetNamePrefix := "MODULES-IN-"
309 if inList("GET-INSTALL-PATH", configArgs) {
310 targetNamePrefix = "GET-INSTALL-PATH-IN-"
311 configArgs = removeFromList("GET-INSTALL-PATH", configArgs)
312 }
313
Patrice Arruda13848222019-04-22 17:12:02 -0700314 var targets []string
315
316 switch action {
Patrice Arruda39282062019-06-20 16:35:12 -0700317 case BUILD_MODULES:
318 // No additional processing is required when building a list of specific modules or all modules.
Patrice Arruda13848222019-04-22 17:12:02 -0700319 case BUILD_MODULES_IN_A_DIRECTORY:
320 // If dir is the root source tree, all the modules are built of the source tree are built so
321 // no need to find the build file.
322 if topDir == dir {
323 break
324 }
Patrice Arruda0dcf27f2019-07-08 17:03:33 -0700325
Patrice Arruda13848222019-04-22 17:12:02 -0700326 buildFile := findBuildFile(ctx, relDir)
327 if buildFile == "" {
Patrice Arruda0dcf27f2019-07-08 17:03:33 -0700328 ctx.Fatalf("Build file not found for %s directory", relDir)
Patrice Arruda13848222019-04-22 17:12:02 -0700329 }
Patrice Arruda13848222019-04-22 17:12:02 -0700330 targets = []string{convertToTarget(filepath.Dir(buildFile), targetNamePrefix)}
331 case BUILD_MODULES_IN_DIRECTORIES:
332 newConfigArgs, dirs := splitArgs(configArgs)
333 configArgs = newConfigArgs
Dan Willemsence41e942019-07-29 23:39:30 -0700334 targets = getTargetsFromDirs(ctx, relDir, dirs, targetNamePrefix)
Patrice Arruda13848222019-04-22 17:12:02 -0700335 }
336
337 // Tidy only override all other specified targets.
338 tidyOnly := os.Getenv("WITH_TIDY_ONLY")
339 if tidyOnly == "true" || tidyOnly == "1" {
340 configArgs = append(configArgs, "tidy_only")
341 } else {
342 configArgs = append(configArgs, targets...)
343 }
344
345 return configArgs
346}
347
348// convertToTarget replaces "/" to "-" in dir and pre-append the targetNamePrefix to the target name.
349func convertToTarget(dir string, targetNamePrefix string) string {
350 return targetNamePrefix + strings.ReplaceAll(dir, "/", "-")
351}
352
Patrice Arruda9450d0b2019-07-08 11:06:46 -0700353// hasBuildFile returns true if dir contains an Android build file.
354func hasBuildFile(ctx Context, dir string) bool {
355 for _, buildFile := range buildFiles {
356 _, err := os.Stat(filepath.Join(dir, buildFile))
357 if err == nil {
358 return true
359 }
360 if !os.IsNotExist(err) {
361 ctx.Fatalf("Error retrieving the build file stats: %v", err)
362 }
363 }
364 return false
365}
366
Patrice Arruda0dcf27f2019-07-08 17:03:33 -0700367// findBuildFile finds a build file (makefile or blueprint file) by looking if there is a build file
368// in the current and any sub directory of dir. If a build file is not found, traverse the path
369// up by one directory and repeat again until either a build file is found or reached to the root
370// source tree. The returned filename of build file is "Android.mk". If one was not found, a blank
371// string is returned.
Patrice Arruda13848222019-04-22 17:12:02 -0700372func findBuildFile(ctx Context, dir string) string {
Patrice Arruda0dcf27f2019-07-08 17:03:33 -0700373 // If the string is empty or ".", assume it is top directory of the source tree.
374 if dir == "" || dir == "." {
Patrice Arruda13848222019-04-22 17:12:02 -0700375 return ""
376 }
377
Patrice Arruda0dcf27f2019-07-08 17:03:33 -0700378 found := false
379 for buildDir := dir; buildDir != "."; buildDir = filepath.Dir(buildDir) {
380 err := filepath.Walk(buildDir, func(path string, info os.FileInfo, err error) error {
381 if err != nil {
382 return err
383 }
384 if found {
385 return filepath.SkipDir
386 }
387 if info.IsDir() {
388 return nil
389 }
390 for _, buildFile := range buildFiles {
391 if info.Name() == buildFile {
392 found = true
393 return filepath.SkipDir
394 }
395 }
396 return nil
397 })
398 if err != nil {
399 ctx.Fatalf("Error finding Android build file: %v", err)
400 }
401
402 if found {
403 return filepath.Join(buildDir, "Android.mk")
Patrice Arruda13848222019-04-22 17:12:02 -0700404 }
405 }
406
407 return ""
408}
409
410// splitArgs iterates over the arguments list and splits into two lists: arguments and directories.
411func splitArgs(args []string) (newArgs []string, dirs []string) {
412 specialArgs := map[string]bool{
413 "showcommands": true,
414 "snod": true,
415 "dist": true,
416 "checkbuild": true,
417 }
418
419 newArgs = []string{}
420 dirs = []string{}
421
422 for _, arg := range args {
423 // It's a dash argument if it starts with "-" or it's a key=value pair, it's not a directory.
424 if strings.IndexRune(arg, '-') == 0 || strings.IndexRune(arg, '=') != -1 {
425 newArgs = append(newArgs, arg)
426 continue
427 }
428
429 if _, ok := specialArgs[arg]; ok {
430 newArgs = append(newArgs, arg)
431 continue
432 }
433
434 dirs = append(dirs, arg)
435 }
436
437 return newArgs, dirs
438}
439
440// getTargetsFromDirs iterates over the dirs list and creates a list of targets to build. If a
441// directory from the dirs list does not exist, a fatal error is raised. relDir is related to the
442// source root tree where the build action command was invoked. Each directory is validated if the
443// build file can be found and follows the format "dir1:target1,target2,...". Target is optional.
Dan Willemsence41e942019-07-29 23:39:30 -0700444func getTargetsFromDirs(ctx Context, relDir string, dirs []string, targetNamePrefix string) (targets []string) {
Patrice Arruda13848222019-04-22 17:12:02 -0700445 for _, dir := range dirs {
446 // The directory may have specified specific modules to build. ":" is the separator to separate
447 // the directory and the list of modules.
448 s := strings.Split(dir, ":")
449 l := len(s)
450 if l > 2 { // more than one ":" was specified.
451 ctx.Fatalf("%s not in proper directory:target1,target2,... format (\":\" was specified more than once)", dir)
452 }
453
454 dir = filepath.Join(relDir, s[0])
455 if _, err := os.Stat(dir); err != nil {
456 ctx.Fatalf("couldn't find directory %s", dir)
457 }
458
459 // Verify that if there are any targets specified after ":". Each target is separated by ",".
460 var newTargets []string
461 if l == 2 && s[1] != "" {
462 newTargets = strings.Split(s[1], ",")
463 if inList("", newTargets) {
464 ctx.Fatalf("%s not in proper directory:target1,target2,... format", dir)
465 }
466 }
467
Patrice Arruda9450d0b2019-07-08 11:06:46 -0700468 // If there are specified targets to build in dir, an android build file must exist for the one
469 // shot build. For the non-targets case, find the appropriate build file and build all the
470 // modules in dir (or the closest one in the dir path).
Patrice Arruda13848222019-04-22 17:12:02 -0700471 if len(newTargets) > 0 {
Patrice Arruda9450d0b2019-07-08 11:06:46 -0700472 if !hasBuildFile(ctx, dir) {
Patrice Arruda13848222019-04-22 17:12:02 -0700473 ctx.Fatalf("Couldn't locate a build file from %s directory", dir)
474 }
475 } else {
Patrice Arruda9450d0b2019-07-08 11:06:46 -0700476 buildFile := findBuildFile(ctx, dir)
477 if buildFile == "" {
478 ctx.Fatalf("Build file not found for %s directory", dir)
479 }
480 newTargets = []string{convertToTarget(filepath.Dir(buildFile), targetNamePrefix)}
Patrice Arruda13848222019-04-22 17:12:02 -0700481 }
482
Patrice Arruda13848222019-04-22 17:12:02 -0700483 targets = append(targets, newTargets...)
484 }
485
Dan Willemsence41e942019-07-29 23:39:30 -0700486 return targets
Patrice Arruda13848222019-04-22 17:12:02 -0700487}
488
Dan Willemsen9b587492017-07-10 22:13:00 -0700489func (c *configImpl) parseArgs(ctx Context, args []string) {
490 for i := 0; i < len(args); i++ {
491 arg := strings.TrimSpace(args[i])
Dan Willemsen1e704462016-08-21 15:17:17 -0700492 if arg == "--make-mode" {
Dan Willemsen1e704462016-08-21 15:17:17 -0700493 } else if arg == "showcommands" {
Dan Willemsen9b587492017-07-10 22:13:00 -0700494 c.verbose = true
Dan Willemsene0879fc2017-08-04 15:06:27 -0700495 } else if arg == "--skip-make" {
496 c.skipMake = true
Dan Willemsen6ac63ef2017-10-17 20:35:34 -0700497 } else if len(arg) > 0 && arg[0] == '-' {
Dan Willemsen9b587492017-07-10 22:13:00 -0700498 parseArgNum := func(def int) int {
499 if len(arg) > 2 {
500 p, err := strconv.ParseUint(arg[2:], 10, 31)
501 if err != nil {
502 ctx.Fatalf("Failed to parse %q: %v", arg, err)
503 }
504 return int(p)
505 } else if i+1 < len(args) {
506 p, err := strconv.ParseUint(args[i+1], 10, 31)
507 if err == nil {
508 i++
509 return int(p)
510 }
511 }
512 return def
513 }
514
Dan Willemsen6ac63ef2017-10-17 20:35:34 -0700515 if len(arg) > 1 && arg[1] == 'j' {
Dan Willemsen9b587492017-07-10 22:13:00 -0700516 c.parallel = parseArgNum(c.parallel)
Dan Willemsen6ac63ef2017-10-17 20:35:34 -0700517 } else if len(arg) > 1 && arg[1] == 'k' {
Dan Willemsen9b587492017-07-10 22:13:00 -0700518 c.keepGoing = parseArgNum(0)
Dan Willemsen1e704462016-08-21 15:17:17 -0700519 } else {
520 ctx.Fatalln("Unknown option:", arg)
521 }
Dan Willemsen091525e2017-07-11 14:17:50 -0700522 } else if k, v, ok := decodeKeyValue(arg); ok && len(k) > 0 {
Dan Willemsen6dfe30a2018-09-10 12:41:10 -0700523 if k == "OUT_DIR" {
524 ctx.Fatalln("OUT_DIR may only be set in the environment, not as a command line option.")
525 }
Dan Willemsen091525e2017-07-11 14:17:50 -0700526 c.environ.Set(k, v)
Dan Willemsen2d31a442018-10-20 21:33:41 -0700527 } else if arg == "dist" {
528 c.dist = true
Dan Willemsen1e704462016-08-21 15:17:17 -0700529 } else {
Dan Willemsen2d31a442018-10-20 21:33:41 -0700530 if arg == "checkbuild" {
Colin Cross37193492017-11-16 17:55:00 -0800531 c.checkbuild = true
Dan Willemsene0879fc2017-08-04 15:06:27 -0700532 }
Dan Willemsen9b587492017-07-10 22:13:00 -0700533 c.arguments = append(c.arguments, arg)
Dan Willemsen1e704462016-08-21 15:17:17 -0700534 }
535 }
Dan Willemsen1e704462016-08-21 15:17:17 -0700536}
537
Dan Willemsened869522018-01-08 14:58:46 -0800538func (c *configImpl) configureLocale(ctx Context) {
539 cmd := Command(ctx, Config{c}, "locale", "locale", "-a")
540 output, err := cmd.Output()
541
542 var locales []string
543 if err == nil {
544 locales = strings.Split(string(output), "\n")
545 } else {
546 // If we're unable to list the locales, let's assume en_US.UTF-8
547 locales = []string{"en_US.UTF-8"}
548 ctx.Verbosef("Failed to list locales (%q), falling back to %q", err, locales)
549 }
550
551 // gettext uses LANGUAGE, which is passed directly through
552
553 // For LANG and LC_*, only preserve the evaluated version of
554 // LC_MESSAGES
555 user_lang := ""
556 if lc_all, ok := c.environ.Get("LC_ALL"); ok {
557 user_lang = lc_all
558 } else if lc_messages, ok := c.environ.Get("LC_MESSAGES"); ok {
559 user_lang = lc_messages
560 } else if lang, ok := c.environ.Get("LANG"); ok {
561 user_lang = lang
562 }
563
564 c.environ.UnsetWithPrefix("LC_")
565
566 if user_lang != "" {
567 c.environ.Set("LC_MESSAGES", user_lang)
568 }
569
570 // The for LANG, use C.UTF-8 if it exists (Debian currently, proposed
571 // for others)
572 if inList("C.UTF-8", locales) {
573 c.environ.Set("LANG", "C.UTF-8")
Aaron Klingd236e0e2018-08-07 19:21:36 -0500574 } else if inList("C.utf8", locales) {
575 // These normalize to the same thing
576 c.environ.Set("LANG", "C.UTF-8")
Dan Willemsened869522018-01-08 14:58:46 -0800577 } else if inList("en_US.UTF-8", locales) {
578 c.environ.Set("LANG", "en_US.UTF-8")
579 } else if inList("en_US.utf8", locales) {
580 // These normalize to the same thing
581 c.environ.Set("LANG", "en_US.UTF-8")
582 } else {
583 ctx.Fatalln("System doesn't support either C.UTF-8 or en_US.UTF-8")
584 }
585}
586
Dan Willemsen1e704462016-08-21 15:17:17 -0700587// Lunch configures the environment for a specific product similarly to the
588// `lunch` bash function.
589func (c *configImpl) Lunch(ctx Context, product, variant string) {
590 if variant != "eng" && variant != "userdebug" && variant != "user" {
591 ctx.Fatalf("Invalid variant %q. Must be one of 'user', 'userdebug' or 'eng'", variant)
592 }
593
594 c.environ.Set("TARGET_PRODUCT", product)
595 c.environ.Set("TARGET_BUILD_VARIANT", variant)
596 c.environ.Set("TARGET_BUILD_TYPE", "release")
597 c.environ.Unset("TARGET_BUILD_APPS")
Martin Stjernholm08802332020-06-04 17:00:01 +0100598 c.environ.Unset("TARGET_BUILD_UNBUNDLED")
Dan Willemsen1e704462016-08-21 15:17:17 -0700599}
600
601// Tapas configures the environment to build one or more unbundled apps,
602// similarly to the `tapas` bash function.
603func (c *configImpl) Tapas(ctx Context, apps []string, arch, variant string) {
604 if len(apps) == 0 {
605 apps = []string{"all"}
606 }
607 if variant == "" {
608 variant = "eng"
609 }
610
611 if variant != "eng" && variant != "userdebug" && variant != "user" {
612 ctx.Fatalf("Invalid variant %q. Must be one of 'user', 'userdebug' or 'eng'", variant)
613 }
614
615 var product string
616 switch arch {
Dan Willemsen1e704462016-08-21 15:17:17 -0700617 case "arm", "":
618 product = "aosp_arm"
619 case "arm64":
620 product = "aosm_arm64"
Dan Willemsen1e704462016-08-21 15:17:17 -0700621 case "x86":
622 product = "aosp_x86"
623 case "x86_64":
624 product = "aosp_x86_64"
625 default:
626 ctx.Fatalf("Invalid architecture: %q", arch)
627 }
628
629 c.environ.Set("TARGET_PRODUCT", product)
630 c.environ.Set("TARGET_BUILD_VARIANT", variant)
631 c.environ.Set("TARGET_BUILD_TYPE", "release")
632 c.environ.Set("TARGET_BUILD_APPS", strings.Join(apps, " "))
633}
634
635func (c *configImpl) Environment() *Environment {
636 return c.environ
637}
638
639func (c *configImpl) Arguments() []string {
640 return c.arguments
641}
642
643func (c *configImpl) OutDir() string {
644 if outDir, ok := c.environ.Get("OUT_DIR"); ok {
Patrice Arruda19bd53e2019-07-08 17:26:47 -0700645 return outDir
Dan Willemsen1e704462016-08-21 15:17:17 -0700646 }
647 return "out"
648}
649
Dan Willemsen8a073a82017-02-04 17:30:44 -0800650func (c *configImpl) DistDir() string {
Dan Willemsen2d31a442018-10-20 21:33:41 -0700651 return c.distDir
Dan Willemsen8a073a82017-02-04 17:30:44 -0800652}
653
Dan Willemsen1e704462016-08-21 15:17:17 -0700654func (c *configImpl) NinjaArgs() []string {
Dan Willemsene0879fc2017-08-04 15:06:27 -0700655 if c.skipMake {
656 return c.arguments
657 }
Dan Willemsen1e704462016-08-21 15:17:17 -0700658 return c.ninjaArgs
659}
660
661func (c *configImpl) SoongOutDir() string {
662 return filepath.Join(c.OutDir(), "soong")
663}
664
Jeff Gastonefc1b412017-03-29 17:29:06 -0700665func (c *configImpl) TempDir() string {
666 return shared.TempDirForOutDir(c.SoongOutDir())
667}
668
Jeff Gastonb64fc1c2017-08-04 12:30:12 -0700669func (c *configImpl) FileListDir() string {
670 return filepath.Join(c.OutDir(), ".module_paths")
671}
672
Dan Willemsen1e704462016-08-21 15:17:17 -0700673func (c *configImpl) KatiSuffix() string {
674 if c.katiSuffix != "" {
675 return c.katiSuffix
676 }
677 panic("SetKatiSuffix has not been called")
678}
679
Colin Cross37193492017-11-16 17:55:00 -0800680// Checkbuild returns true if "checkbuild" was one of the build goals, which means that the
681// user is interested in additional checks at the expense of build time.
682func (c *configImpl) Checkbuild() bool {
683 return c.checkbuild
684}
685
Dan Willemsen8a073a82017-02-04 17:30:44 -0800686func (c *configImpl) Dist() bool {
687 return c.dist
688}
689
Dan Willemsen1e704462016-08-21 15:17:17 -0700690func (c *configImpl) IsVerbose() bool {
691 return c.verbose
692}
693
Dan Willemsene0879fc2017-08-04 15:06:27 -0700694func (c *configImpl) SkipMake() bool {
695 return c.skipMake
696}
697
Dan Willemsen1e704462016-08-21 15:17:17 -0700698func (c *configImpl) TargetProduct() string {
699 if v, ok := c.environ.Get("TARGET_PRODUCT"); ok {
700 return v
701 }
702 panic("TARGET_PRODUCT is not defined")
703}
704
Dan Willemsen02781d52017-05-12 19:28:13 -0700705func (c *configImpl) TargetDevice() string {
706 return c.targetDevice
707}
708
709func (c *configImpl) SetTargetDevice(device string) {
710 c.targetDevice = device
711}
712
713func (c *configImpl) TargetBuildVariant() string {
714 if v, ok := c.environ.Get("TARGET_BUILD_VARIANT"); ok {
715 return v
716 }
717 panic("TARGET_BUILD_VARIANT is not defined")
718}
719
Dan Willemsen1e704462016-08-21 15:17:17 -0700720func (c *configImpl) KatiArgs() []string {
721 return c.katiArgs
722}
723
724func (c *configImpl) Parallel() int {
725 return c.parallel
726}
727
Colin Cross8b8bec32019-11-15 13:18:43 -0800728func (c *configImpl) HighmemParallel() int {
729 if i, ok := c.environ.GetInt("NINJA_HIGHMEM_NUM_JOBS"); ok {
730 return i
731 }
732
733 const minMemPerHighmemProcess = 8 * 1024 * 1024 * 1024
734 parallel := c.Parallel()
735 if c.UseRemoteBuild() {
736 // Ninja doesn't support nested pools, and when remote builds are enabled the total ninja parallelism
737 // is set very high (i.e. 500). Using a large value here would cause the total number of running jobs
738 // to be the sum of the sizes of the local and highmem pools, which will cause extra CPU contention.
739 // Return 1/16th of the size of the local pool, rounding up.
740 return (parallel + 15) / 16
741 } else if c.totalRAM == 0 {
742 // Couldn't detect the total RAM, don't restrict highmem processes.
743 return parallel
Dan Willemsen570a2922020-05-26 23:02:29 -0700744 } else if c.totalRAM <= 16*1024*1024*1024 {
745 // Less than 16GB of ram, restrict to 1 highmem processes
746 return 1
Colin Cross8b8bec32019-11-15 13:18:43 -0800747 } else if c.totalRAM <= 32*1024*1024*1024 {
748 // Less than 32GB of ram, restrict to 2 highmem processes
749 return 2
750 } else if p := int(c.totalRAM / minMemPerHighmemProcess); p < parallel {
751 // If less than 8GB total RAM per process, reduce the number of highmem processes
752 return p
753 }
754 // No restriction on highmem processes
755 return parallel
756}
757
Dan Willemsen2bb82d02019-12-27 09:35:42 -0800758func (c *configImpl) TotalRAM() uint64 {
759 return c.totalRAM
760}
761
Dan Willemsen1e704462016-08-21 15:17:17 -0700762func (c *configImpl) UseGoma() bool {
763 if v, ok := c.environ.Get("USE_GOMA"); ok {
764 v = strings.TrimSpace(v)
765 if v != "" && v != "false" {
766 return true
767 }
768 }
769 return false
770}
771
Yoshisato Yanagisawa2cb0e5d2019-01-10 10:14:16 +0900772func (c *configImpl) StartGoma() bool {
773 if !c.UseGoma() {
774 return false
775 }
776
777 if v, ok := c.environ.Get("NOSTART_GOMA"); ok {
778 v = strings.TrimSpace(v)
779 if v != "" && v != "false" {
780 return false
781 }
782 }
783 return true
784}
785
Ramy Medhatbbf25672019-07-17 12:30:04 +0000786func (c *configImpl) UseRBE() bool {
787 if v, ok := c.environ.Get("USE_RBE"); ok {
788 v = strings.TrimSpace(v)
789 if v != "" && v != "false" {
790 return true
791 }
792 }
793 return false
794}
795
796func (c *configImpl) StartRBE() bool {
797 if !c.UseRBE() {
798 return false
799 }
800
801 if v, ok := c.environ.Get("NOSTART_RBE"); ok {
802 v = strings.TrimSpace(v)
803 if v != "" && v != "false" {
804 return false
805 }
806 }
807 return true
808}
809
Ramy Medhat0fc67eb2020-08-12 01:26:23 -0400810func (c *configImpl) logDir() string {
811 if c.Dist() {
812 return filepath.Join(c.DistDir(), "logs")
813 }
814 return c.OutDir()
815}
816
817func (c *configImpl) rbeStatsOutputDir() string {
Patrice Arruda62f1bf22020-07-07 12:48:26 +0000818 for _, f := range []string{"RBE_output_dir", "FLAG_output_dir"} {
819 if v, ok := c.environ.Get(f); ok {
820 return v
821 }
822 }
Ramy Medhat0fc67eb2020-08-12 01:26:23 -0400823 return c.logDir()
824}
825
826func (c *configImpl) rbeLogPath() string {
827 for _, f := range []string{"RBE_log_path", "FLAG_log_path"} {
828 if v, ok := c.environ.Get(f); ok {
829 return v
830 }
831 }
832 return fmt.Sprintf("text://%v/reproxy_log.txt", c.logDir())
833}
834
835func (c *configImpl) rbeExecRoot() string {
836 for _, f := range []string{"RBE_exec_root", "FLAG_exec_root"} {
837 if v, ok := c.environ.Get(f); ok {
838 return v
839 }
840 }
841 wd, err := os.Getwd()
842 if err != nil {
843 return ""
844 }
845 return wd
846}
847
848func (c *configImpl) rbeDir() string {
849 if v, ok := c.environ.Get("RBE_DIR"); ok {
850 return v
851 }
852 return "prebuilts/remoteexecution-client/live/"
853}
854
855func (c *configImpl) rbeReproxy() string {
856 for _, f := range []string{"RBE_re_proxy", "FLAG_re_proxy"} {
857 if v, ok := c.environ.Get(f); ok {
858 return v
859 }
860 }
861 return filepath.Join(c.rbeDir(), "reproxy")
862}
863
864func (c *configImpl) rbeAuth() (string, string) {
865 credFlags := []string{"use_application_default_credentials", "use_gce_credentials", "credential_file"}
866 for _, cf := range credFlags {
867 for _, f := range []string{"RBE_" + cf, "FLAG_" + cf} {
868 if v, ok := c.environ.Get(f); ok {
869 v = strings.TrimSpace(v)
870 if v != "" && v != "false" && v != "0" {
871 return "RBE_" + cf, v
872 }
873 }
874 }
875 }
876 return "RBE_use_application_default_credentials", "true"
Patrice Arruda62f1bf22020-07-07 12:48:26 +0000877}
878
Colin Cross9016b912019-11-11 14:57:42 -0800879func (c *configImpl) UseRemoteBuild() bool {
880 return c.UseGoma() || c.UseRBE()
881}
882
Dan Willemsen1e704462016-08-21 15:17:17 -0700883// RemoteParallel controls how many remote jobs (i.e., commands which contain
Jeff Gastonefc1b412017-03-29 17:29:06 -0700884// gomacc) are run in parallel. Note the parallelism of all other jobs is
Dan Willemsen1e704462016-08-21 15:17:17 -0700885// still limited by Parallel()
886func (c *configImpl) RemoteParallel() int {
Colin Cross8b8bec32019-11-15 13:18:43 -0800887 if !c.UseRemoteBuild() {
888 return 0
889 }
890 if i, ok := c.environ.GetInt("NINJA_REMOTE_NUM_JOBS"); ok {
891 return i
Dan Willemsen1e704462016-08-21 15:17:17 -0700892 }
893 return 500
894}
895
896func (c *configImpl) SetKatiArgs(args []string) {
897 c.katiArgs = args
898}
899
900func (c *configImpl) SetNinjaArgs(args []string) {
901 c.ninjaArgs = args
902}
903
904func (c *configImpl) SetKatiSuffix(suffix string) {
905 c.katiSuffix = suffix
906}
907
Dan Willemsene0879fc2017-08-04 15:06:27 -0700908func (c *configImpl) LastKatiSuffixFile() string {
909 return filepath.Join(c.OutDir(), "last_kati_suffix")
910}
911
912func (c *configImpl) HasKatiSuffix() bool {
913 return c.katiSuffix != ""
914}
915
Dan Willemsen1e704462016-08-21 15:17:17 -0700916func (c *configImpl) KatiEnvFile() string {
917 return filepath.Join(c.OutDir(), "env"+c.KatiSuffix()+".sh")
918}
919
Dan Willemsen29971232018-09-26 14:58:30 -0700920func (c *configImpl) KatiBuildNinjaFile() string {
921 return filepath.Join(c.OutDir(), "build"+c.KatiSuffix()+katiBuildSuffix+".ninja")
Dan Willemsen1e704462016-08-21 15:17:17 -0700922}
923
Dan Willemsenfb1271a2018-09-26 15:00:42 -0700924func (c *configImpl) KatiPackageNinjaFile() string {
925 return filepath.Join(c.OutDir(), "build"+c.KatiSuffix()+katiPackageSuffix+".ninja")
926}
927
Dan Willemsen1e704462016-08-21 15:17:17 -0700928func (c *configImpl) SoongNinjaFile() string {
929 return filepath.Join(c.SoongOutDir(), "build.ninja")
930}
931
932func (c *configImpl) CombinedNinjaFile() string {
Dan Willemsene0879fc2017-08-04 15:06:27 -0700933 if c.katiSuffix == "" {
934 return filepath.Join(c.OutDir(), "combined.ninja")
935 }
Dan Willemsen1e704462016-08-21 15:17:17 -0700936 return filepath.Join(c.OutDir(), "combined"+c.KatiSuffix()+".ninja")
937}
938
939func (c *configImpl) SoongAndroidMk() string {
940 return filepath.Join(c.SoongOutDir(), "Android-"+c.TargetProduct()+".mk")
941}
942
943func (c *configImpl) SoongMakeVarsMk() string {
944 return filepath.Join(c.SoongOutDir(), "make_vars-"+c.TargetProduct()+".mk")
945}
946
Dan Willemsenf052f782017-05-18 15:29:04 -0700947func (c *configImpl) ProductOut() string {
Dan Willemsen4dc4e142017-09-08 14:35:43 -0700948 return filepath.Join(c.OutDir(), "target", "product", c.TargetDevice())
Dan Willemsenf052f782017-05-18 15:29:04 -0700949}
950
Dan Willemsen02781d52017-05-12 19:28:13 -0700951func (c *configImpl) DevicePreviousProductConfig() string {
Dan Willemsenf052f782017-05-18 15:29:04 -0700952 return filepath.Join(c.ProductOut(), "previous_build_config.mk")
953}
954
Dan Willemsenfb1271a2018-09-26 15:00:42 -0700955func (c *configImpl) KatiPackageMkDir() string {
956 return filepath.Join(c.ProductOut(), "obj", "CONFIG", "kati_packaging")
957}
958
Dan Willemsenf052f782017-05-18 15:29:04 -0700959func (c *configImpl) hostOutRoot() string {
Dan Willemsen4dc4e142017-09-08 14:35:43 -0700960 return filepath.Join(c.OutDir(), "host")
Dan Willemsenf052f782017-05-18 15:29:04 -0700961}
962
963func (c *configImpl) HostOut() string {
964 return filepath.Join(c.hostOutRoot(), c.HostPrebuiltTag())
965}
966
967// This probably needs to be multi-valued, so not exporting it for now
968func (c *configImpl) hostCrossOut() string {
969 if runtime.GOOS == "linux" {
970 return filepath.Join(c.hostOutRoot(), "windows-x86")
971 } else {
972 return ""
973 }
Dan Willemsen02781d52017-05-12 19:28:13 -0700974}
975
Dan Willemsen1e704462016-08-21 15:17:17 -0700976func (c *configImpl) HostPrebuiltTag() string {
977 if runtime.GOOS == "linux" {
978 return "linux-x86"
979 } else if runtime.GOOS == "darwin" {
980 return "darwin-x86"
981 } else {
982 panic("Unsupported OS")
983 }
984}
Dan Willemsenf173d592017-04-27 14:28:00 -0700985
Dan Willemsen8122bd52017-10-12 20:20:41 -0700986func (c *configImpl) PrebuiltBuildTool(name string) string {
Dan Willemsenf173d592017-04-27 14:28:00 -0700987 if v, ok := c.environ.Get("SANITIZE_HOST"); ok {
988 if sanitize := strings.Fields(v); inList("address", sanitize) {
Dan Willemsen8122bd52017-10-12 20:20:41 -0700989 asan := filepath.Join("prebuilts/build-tools", c.HostPrebuiltTag(), "asan/bin", name)
990 if _, err := os.Stat(asan); err == nil {
991 return asan
992 }
Dan Willemsenf173d592017-04-27 14:28:00 -0700993 }
994 }
995 return filepath.Join("prebuilts/build-tools", c.HostPrebuiltTag(), "bin", name)
996}
Dan Willemsen3d60b112018-04-04 22:25:56 -0700997
998func (c *configImpl) SetBuildBrokenDupRules(val bool) {
999 c.brokenDupRules = val
1000}
1001
1002func (c *configImpl) BuildBrokenDupRules() bool {
1003 return c.brokenDupRules
1004}
Dan Willemsen6ab79db2018-05-02 00:06:28 -07001005
Dan Willemsen25e6f092019-04-09 10:22:43 -07001006func (c *configImpl) SetBuildBrokenUsesNetwork(val bool) {
1007 c.brokenUsesNetwork = val
1008}
1009
1010func (c *configImpl) BuildBrokenUsesNetwork() bool {
1011 return c.brokenUsesNetwork
1012}
1013
Dan Willemsene3336352020-01-02 19:10:38 -08001014func (c *configImpl) SetBuildBrokenNinjaUsesEnvVars(val []string) {
1015 c.brokenNinjaEnvVars = val
1016}
1017
1018func (c *configImpl) BuildBrokenNinjaUsesEnvVars() []string {
1019 return c.brokenNinjaEnvVars
1020}
1021
Dan Willemsen6ab79db2018-05-02 00:06:28 -07001022func (c *configImpl) SetTargetDeviceDir(dir string) {
1023 c.targetDeviceDir = dir
1024}
1025
1026func (c *configImpl) TargetDeviceDir() string {
1027 return c.targetDeviceDir
1028}
Dan Willemsenfa42f3c2018-06-15 21:54:47 -07001029
Patrice Arruda219eef32020-06-01 17:29:30 +00001030func (c *configImpl) BuildDateTime() string {
1031 return c.buildDateTime
1032}
1033
1034func (c *configImpl) MetricsUploaderApp() string {
1035 if p, ok := c.environ.Get("ANDROID_ENABLE_METRICS_UPLOAD"); ok {
1036 return p
1037 }
1038 return ""
1039}