blob: e9a8fc9100512b870c095a8f19493ea5d59df3c8 [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"
Patrice Arruda96850362020-08-11 20:41:11 +000027 "github.com/golang/protobuf/proto"
28
29 smpb "android/soong/ui/metrics/metrics_proto"
Dan Willemsen1e704462016-08-21 15:17:17 -070030)
31
32type Config struct{ *configImpl }
33
34type configImpl struct {
35 // From the environment
Colin Cross28f527c2019-11-26 16:19:04 -080036 arguments []string
37 goma bool
38 environ *Environment
39 distDir string
40 buildDateTime string
Dan Willemsen1e704462016-08-21 15:17:17 -070041
42 // From the arguments
Colin Cross37193492017-11-16 17:55:00 -080043 parallel int
44 keepGoing int
45 verbose bool
46 checkbuild bool
47 dist bool
48 skipMake bool
Dan Willemsen1e704462016-08-21 15:17:17 -070049
50 // From the product config
Dan Willemsen6ab79db2018-05-02 00:06:28 -070051 katiArgs []string
52 ninjaArgs []string
53 katiSuffix string
54 targetDevice string
55 targetDeviceDir string
Dan Willemsen3d60b112018-04-04 22:25:56 -070056
Dan Willemsen2bb82d02019-12-27 09:35:42 -080057 // Autodetected
58 totalRAM uint64
59
Dan Willemsene3336352020-01-02 19:10:38 -080060 brokenDupRules bool
61 brokenUsesNetwork bool
62 brokenNinjaEnvVars []string
Dan Willemsen18490112018-05-25 16:30:04 -070063
64 pathReplaced bool
Dan Willemsen1e704462016-08-21 15:17:17 -070065}
66
Dan Willemsenc2af0be2017-01-20 14:10:01 -080067const srcDirFileCheck = "build/soong/root.bp"
68
Patrice Arruda9450d0b2019-07-08 11:06:46 -070069var buildFiles = []string{"Android.mk", "Android.bp"}
70
Patrice Arruda13848222019-04-22 17:12:02 -070071type BuildAction uint
72
73const (
74 // Builds all of the modules and their dependencies of a specified directory, relative to the root
75 // directory of the source tree.
76 BUILD_MODULES_IN_A_DIRECTORY BuildAction = iota
77
78 // Builds all of the modules and their dependencies of a list of specified directories. All specified
79 // directories are relative to the root directory of the source tree.
80 BUILD_MODULES_IN_DIRECTORIES
Patrice Arruda39282062019-06-20 16:35:12 -070081
82 // Build a list of specified modules. If none was specified, simply build the whole source tree.
83 BUILD_MODULES
Patrice Arruda13848222019-04-22 17:12:02 -070084)
85
86// checkTopDir validates that the current directory is at the root directory of the source tree.
87func checkTopDir(ctx Context) {
88 if _, err := os.Stat(srcDirFileCheck); err != nil {
89 if os.IsNotExist(err) {
90 ctx.Fatalf("Current working directory must be the source tree. %q not found.", srcDirFileCheck)
91 }
92 ctx.Fatalln("Error verifying tree state:", err)
93 }
94}
95
Dan Willemsen1e704462016-08-21 15:17:17 -070096func NewConfig(ctx Context, args ...string) Config {
97 ret := &configImpl{
98 environ: OsEnvironment(),
99 }
100
Patrice Arruda90109172020-07-28 18:07:27 +0000101 // Default matching ninja
Dan Willemsen9b587492017-07-10 22:13:00 -0700102 ret.parallel = runtime.NumCPU() + 2
103 ret.keepGoing = 1
104
Dan Willemsen2bb82d02019-12-27 09:35:42 -0800105 ret.totalRAM = detectTotalRAM(ctx)
106
Dan Willemsen9b587492017-07-10 22:13:00 -0700107 ret.parseArgs(ctx, args)
108
Dan Willemsen0c3919e2017-03-02 15:49:10 -0800109 // Make sure OUT_DIR is set appropriately
Dan Willemsen02f3add2017-05-12 13:50:19 -0700110 if outDir, ok := ret.environ.Get("OUT_DIR"); ok {
111 ret.environ.Set("OUT_DIR", filepath.Clean(outDir))
112 } else {
Dan Willemsen0c3919e2017-03-02 15:49:10 -0800113 outDir := "out"
114 if baseDir, ok := ret.environ.Get("OUT_DIR_COMMON_BASE"); ok {
115 if wd, err := os.Getwd(); err != nil {
116 ctx.Fatalln("Failed to get working directory:", err)
117 } else {
118 outDir = filepath.Join(baseDir, filepath.Base(wd))
119 }
120 }
121 ret.environ.Set("OUT_DIR", outDir)
122 }
123
Dan Willemsen2d31a442018-10-20 21:33:41 -0700124 if distDir, ok := ret.environ.Get("DIST_DIR"); ok {
125 ret.distDir = filepath.Clean(distDir)
126 } else {
127 ret.distDir = filepath.Join(ret.OutDir(), "dist")
128 }
Dan Willemsend50e89f2018-10-16 17:49:25 -0700129
Dan Willemsen1e704462016-08-21 15:17:17 -0700130 ret.environ.Unset(
131 // We're already using it
132 "USE_SOONG_UI",
133
134 // We should never use GOROOT/GOPATH from the shell environment
135 "GOROOT",
136 "GOPATH",
137
138 // These should only come from Soong, not the environment.
139 "CLANG",
140 "CLANG_CXX",
141 "CCC_CC",
142 "CCC_CXX",
143
144 // Used by the goma compiler wrapper, but should only be set by
145 // gomacc
146 "GOMACC_PATH",
Dan Willemsen0c3919e2017-03-02 15:49:10 -0800147
148 // We handle this above
149 "OUT_DIR_COMMON_BASE",
Dan Willemsen68a09852017-04-18 13:56:57 -0700150
Dan Willemsen2d31a442018-10-20 21:33:41 -0700151 // This is handled above too, and set for individual commands later
152 "DIST_DIR",
153
Dan Willemsen68a09852017-04-18 13:56:57 -0700154 // Variables that have caused problems in the past
Dan Willemsen1c504d92019-11-18 19:13:53 +0000155 "BASH_ENV",
Dan Willemsenebfe33a2018-05-01 10:07:50 -0700156 "CDPATH",
Dan Willemsen68a09852017-04-18 13:56:57 -0700157 "DISPLAY",
158 "GREP_OPTIONS",
Dan Willemsenebfe33a2018-05-01 10:07:50 -0700159 "NDK_ROOT",
Dan Willemsen00fcb262018-08-15 15:35:38 -0700160 "POSIXLY_CORRECT",
Dan Willemsenc40e10b2017-07-11 14:30:00 -0700161
162 // Drop make flags
163 "MAKEFLAGS",
164 "MAKELEVEL",
165 "MFLAGS",
Dan Willemsend9e8f0a2017-10-30 13:42:06 -0700166
167 // Set in envsetup.sh, reset in makefiles
168 "ANDROID_JAVA_TOOLCHAIN",
Colin Cross7f09c402018-07-11 14:49:31 -0700169
170 // Set by envsetup.sh, but shouldn't be used inside the build because envsetup.sh is optional
171 "ANDROID_BUILD_TOP",
172 "ANDROID_HOST_OUT",
173 "ANDROID_PRODUCT_OUT",
174 "ANDROID_HOST_OUT_TESTCASES",
175 "ANDROID_TARGET_OUT_TESTCASES",
176 "ANDROID_TOOLCHAIN",
177 "ANDROID_TOOLCHAIN_2ND_ARCH",
178 "ANDROID_DEV_SCRIPTS",
179 "ANDROID_EMULATOR_PREBUILTS",
180 "ANDROID_PRE_BUILD_PATHS",
Dan Willemsenf99915f2018-10-25 22:04:42 -0700181
182 // Only set in multiproduct_kati after config generation
183 "EMPTY_NINJA_FILE",
Dan Willemsen1e704462016-08-21 15:17:17 -0700184 )
185
186 // Tell python not to spam the source tree with .pyc files.
187 ret.environ.Set("PYTHONDONTWRITEBYTECODE", "1")
188
Ramy Medhatca1e44c2020-07-16 12:18:37 -0400189 tmpDir := absPath(ctx, ret.TempDir())
190 ret.environ.Set("TMPDIR", tmpDir)
Dan Willemsen32a669b2018-03-08 19:42:00 -0800191
Dan Willemsen70c1ff82019-08-21 14:56:13 -0700192 // Always set ASAN_SYMBOLIZER_PATH so that ASAN-based tools can symbolize any crashes
193 symbolizerPath := filepath.Join("prebuilts/clang/host", ret.HostPrebuiltTag(),
194 "llvm-binutils-stable/llvm-symbolizer")
195 ret.environ.Set("ASAN_SYMBOLIZER_PATH", absPath(ctx, symbolizerPath))
196
Dan Willemsenc2af0be2017-01-20 14:10:01 -0800197 // Precondition: the current directory is the top of the source tree
Patrice Arruda13848222019-04-22 17:12:02 -0700198 checkTopDir(ctx)
Dan Willemsenc2af0be2017-01-20 14:10:01 -0800199
Dan Willemsend9e8f0a2017-10-30 13:42:06 -0700200 if srcDir := absPath(ctx, "."); strings.ContainsRune(srcDir, ' ') {
Colin Cross1f6faeb2019-09-23 15:52:40 -0700201 ctx.Println("You are building in a directory whose absolute path contains a space character:")
202 ctx.Println()
203 ctx.Printf("%q\n", srcDir)
204 ctx.Println()
205 ctx.Fatalln("Directory names containing spaces are not supported")
Dan Willemsendb8457c2017-05-12 16:38:17 -0700206 }
207
208 if outDir := ret.OutDir(); strings.ContainsRune(outDir, ' ') {
Colin Cross1f6faeb2019-09-23 15:52:40 -0700209 ctx.Println("The absolute path of your output directory ($OUT_DIR) contains a space character:")
210 ctx.Println()
211 ctx.Printf("%q\n", outDir)
212 ctx.Println()
213 ctx.Fatalln("Directory names containing spaces are not supported")
Dan Willemsendb8457c2017-05-12 16:38:17 -0700214 }
215
216 if distDir := ret.DistDir(); strings.ContainsRune(distDir, ' ') {
Colin Cross1f6faeb2019-09-23 15:52:40 -0700217 ctx.Println("The absolute path of your dist directory ($DIST_DIR) contains a space character:")
218 ctx.Println()
219 ctx.Printf("%q\n", distDir)
220 ctx.Println()
221 ctx.Fatalln("Directory names containing spaces are not supported")
Dan Willemsendb8457c2017-05-12 16:38:17 -0700222 }
223
Dan Willemsend9e8f0a2017-10-30 13:42:06 -0700224 // Configure Java-related variables, including adding it to $PATH
Tobias Thierere59aeff2017-12-20 22:40:39 +0000225 java8Home := filepath.Join("prebuilts/jdk/jdk8", ret.HostPrebuiltTag())
226 java9Home := filepath.Join("prebuilts/jdk/jdk9", ret.HostPrebuiltTag())
Pete Gillin1f52e932019-10-09 17:10:08 +0100227 java11Home := filepath.Join("prebuilts/jdk/jdk11", ret.HostPrebuiltTag())
Dan Willemsend9e8f0a2017-10-30 13:42:06 -0700228 javaHome := func() string {
229 if override, ok := ret.environ.Get("OVERRIDE_ANDROID_JAVA_HOME"); ok {
230 return override
231 }
Pete Gillina7a3d642019-11-07 18:58:42 +0000232 if toolchain11, ok := ret.environ.Get("EXPERIMENTAL_USE_OPENJDK11_TOOLCHAIN"); ok && toolchain11 != "true" {
233 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 +0100234 }
Pete Gillinabbcdda2019-10-28 16:15:33 +0000235 return java11Home
Dan Willemsend9e8f0a2017-10-30 13:42:06 -0700236 }()
237 absJavaHome := absPath(ctx, javaHome)
238
Dan Willemsened869522018-01-08 14:58:46 -0800239 ret.configureLocale(ctx)
240
Dan Willemsend9e8f0a2017-10-30 13:42:06 -0700241 newPath := []string{filepath.Join(absJavaHome, "bin")}
242 if path, ok := ret.environ.Get("PATH"); ok && path != "" {
243 newPath = append(newPath, path)
244 }
Pete Gillin1f52e932019-10-09 17:10:08 +0100245
Dan Willemsend9e8f0a2017-10-30 13:42:06 -0700246 ret.environ.Unset("OVERRIDE_ANDROID_JAVA_HOME")
247 ret.environ.Set("JAVA_HOME", absJavaHome)
248 ret.environ.Set("ANDROID_JAVA_HOME", javaHome)
Tobias Thierere59aeff2017-12-20 22:40:39 +0000249 ret.environ.Set("ANDROID_JAVA8_HOME", java8Home)
250 ret.environ.Set("ANDROID_JAVA9_HOME", java9Home)
Pete Gillin1f52e932019-10-09 17:10:08 +0100251 ret.environ.Set("ANDROID_JAVA11_HOME", java11Home)
Dan Willemsend9e8f0a2017-10-30 13:42:06 -0700252 ret.environ.Set("PATH", strings.Join(newPath, string(filepath.ListSeparator)))
253
Nan Zhang2e6a4ff2018-02-14 13:27:26 -0800254 outDir := ret.OutDir()
255 buildDateTimeFile := filepath.Join(outDir, "build_date.txt")
Nan Zhang2e6a4ff2018-02-14 13:27:26 -0800256 if buildDateTime, ok := ret.environ.Get("BUILD_DATETIME"); ok && buildDateTime != "" {
Colin Cross28f527c2019-11-26 16:19:04 -0800257 ret.buildDateTime = buildDateTime
Nan Zhang2e6a4ff2018-02-14 13:27:26 -0800258 } else {
Colin Cross28f527c2019-11-26 16:19:04 -0800259 ret.buildDateTime = strconv.FormatInt(time.Now().Unix(), 10)
Nan Zhang2e6a4ff2018-02-14 13:27:26 -0800260 }
Colin Cross28f527c2019-11-26 16:19:04 -0800261
Nan Zhang2e6a4ff2018-02-14 13:27:26 -0800262 ret.environ.Set("BUILD_DATETIME_FILE", buildDateTimeFile)
263
Ramy Medhatca1e44c2020-07-16 12:18:37 -0400264 if ret.UseRBE() {
Ramy Medhat0fc67eb2020-08-12 01:26:23 -0400265 for k, v := range getRBEVars(ctx, Config{ret}) {
Ramy Medhatca1e44c2020-07-16 12:18:37 -0400266 ret.environ.Set(k, v)
267 }
268 }
269
Patrice Arruda96850362020-08-11 20:41:11 +0000270 c := Config{ret}
271 storeConfigMetrics(ctx, c)
272 return c
Dan Willemsen9b587492017-07-10 22:13:00 -0700273}
274
Patrice Arruda13848222019-04-22 17:12:02 -0700275// NewBuildActionConfig returns a build configuration based on the build action. The arguments are
276// processed based on the build action and extracts any arguments that belongs to the build action.
Dan Willemsence41e942019-07-29 23:39:30 -0700277func NewBuildActionConfig(action BuildAction, dir string, ctx Context, args ...string) Config {
278 return NewConfig(ctx, getConfigArgs(action, dir, ctx, args)...)
Patrice Arruda13848222019-04-22 17:12:02 -0700279}
280
Patrice Arruda96850362020-08-11 20:41:11 +0000281// storeConfigMetrics selects a set of configuration information and store in
282// the metrics system for further analysis.
283func storeConfigMetrics(ctx Context, config Config) {
284 if ctx.Metrics == nil {
285 return
286 }
287
288 b := &smpb.BuildConfig{
289 UseGoma: proto.Bool(config.UseGoma()),
290 UseRbe: proto.Bool(config.UseRBE()),
291 }
292 ctx.Metrics.BuildConfig(b)
293}
294
Patrice Arruda13848222019-04-22 17:12:02 -0700295// getConfigArgs processes the command arguments based on the build action and creates a set of new
296// arguments to be accepted by Config.
Dan Willemsence41e942019-07-29 23:39:30 -0700297func getConfigArgs(action BuildAction, dir string, ctx Context, args []string) []string {
Patrice Arruda13848222019-04-22 17:12:02 -0700298 // The next block of code verifies that the current directory is the root directory of the source
299 // tree. It then finds the relative path of dir based on the root directory of the source tree
300 // and verify that dir is inside of the source tree.
301 checkTopDir(ctx)
302 topDir, err := os.Getwd()
303 if err != nil {
304 ctx.Fatalf("Error retrieving top directory: %v", err)
305 }
Patrice Arrudababa9a92019-07-03 10:47:34 -0700306 dir, err = filepath.EvalSymlinks(dir)
307 if err != nil {
308 ctx.Fatalf("Unable to evaluate symlink of %s: %v", dir, err)
309 }
Patrice Arruda13848222019-04-22 17:12:02 -0700310 dir, err = filepath.Abs(dir)
311 if err != nil {
312 ctx.Fatalf("Unable to find absolute path %s: %v", dir, err)
313 }
314 relDir, err := filepath.Rel(topDir, dir)
315 if err != nil {
316 ctx.Fatalf("Unable to find relative path %s of %s: %v", relDir, topDir, err)
317 }
318 // If there are ".." in the path, it's not in the source tree.
319 if strings.Contains(relDir, "..") {
320 ctx.Fatalf("Directory %s is not under the source tree %s", dir, topDir)
321 }
322
323 configArgs := args[:]
324
325 // If the arguments contains GET-INSTALL-PATH, change the target name prefix from MODULES-IN- to
326 // GET-INSTALL-PATH-IN- to extract the installation path instead of building the modules.
327 targetNamePrefix := "MODULES-IN-"
328 if inList("GET-INSTALL-PATH", configArgs) {
329 targetNamePrefix = "GET-INSTALL-PATH-IN-"
330 configArgs = removeFromList("GET-INSTALL-PATH", configArgs)
331 }
332
Patrice Arruda13848222019-04-22 17:12:02 -0700333 var targets []string
334
335 switch action {
Patrice Arruda39282062019-06-20 16:35:12 -0700336 case BUILD_MODULES:
337 // No additional processing is required when building a list of specific modules or all modules.
Patrice Arruda13848222019-04-22 17:12:02 -0700338 case BUILD_MODULES_IN_A_DIRECTORY:
339 // If dir is the root source tree, all the modules are built of the source tree are built so
340 // no need to find the build file.
341 if topDir == dir {
342 break
343 }
Patrice Arruda0dcf27f2019-07-08 17:03:33 -0700344
Patrice Arruda13848222019-04-22 17:12:02 -0700345 buildFile := findBuildFile(ctx, relDir)
346 if buildFile == "" {
Patrice Arruda0dcf27f2019-07-08 17:03:33 -0700347 ctx.Fatalf("Build file not found for %s directory", relDir)
Patrice Arruda13848222019-04-22 17:12:02 -0700348 }
Patrice Arruda13848222019-04-22 17:12:02 -0700349 targets = []string{convertToTarget(filepath.Dir(buildFile), targetNamePrefix)}
350 case BUILD_MODULES_IN_DIRECTORIES:
351 newConfigArgs, dirs := splitArgs(configArgs)
352 configArgs = newConfigArgs
Dan Willemsence41e942019-07-29 23:39:30 -0700353 targets = getTargetsFromDirs(ctx, relDir, dirs, targetNamePrefix)
Patrice Arruda13848222019-04-22 17:12:02 -0700354 }
355
356 // Tidy only override all other specified targets.
357 tidyOnly := os.Getenv("WITH_TIDY_ONLY")
358 if tidyOnly == "true" || tidyOnly == "1" {
359 configArgs = append(configArgs, "tidy_only")
360 } else {
361 configArgs = append(configArgs, targets...)
362 }
363
364 return configArgs
365}
366
367// convertToTarget replaces "/" to "-" in dir and pre-append the targetNamePrefix to the target name.
368func convertToTarget(dir string, targetNamePrefix string) string {
369 return targetNamePrefix + strings.ReplaceAll(dir, "/", "-")
370}
371
Patrice Arruda9450d0b2019-07-08 11:06:46 -0700372// hasBuildFile returns true if dir contains an Android build file.
373func hasBuildFile(ctx Context, dir string) bool {
374 for _, buildFile := range buildFiles {
375 _, err := os.Stat(filepath.Join(dir, buildFile))
376 if err == nil {
377 return true
378 }
379 if !os.IsNotExist(err) {
380 ctx.Fatalf("Error retrieving the build file stats: %v", err)
381 }
382 }
383 return false
384}
385
Patrice Arruda0dcf27f2019-07-08 17:03:33 -0700386// findBuildFile finds a build file (makefile or blueprint file) by looking if there is a build file
387// in the current and any sub directory of dir. If a build file is not found, traverse the path
388// up by one directory and repeat again until either a build file is found or reached to the root
389// source tree. The returned filename of build file is "Android.mk". If one was not found, a blank
390// string is returned.
Patrice Arruda13848222019-04-22 17:12:02 -0700391func findBuildFile(ctx Context, dir string) string {
Patrice Arruda0dcf27f2019-07-08 17:03:33 -0700392 // If the string is empty or ".", assume it is top directory of the source tree.
393 if dir == "" || dir == "." {
Patrice Arruda13848222019-04-22 17:12:02 -0700394 return ""
395 }
396
Patrice Arruda0dcf27f2019-07-08 17:03:33 -0700397 found := false
398 for buildDir := dir; buildDir != "."; buildDir = filepath.Dir(buildDir) {
399 err := filepath.Walk(buildDir, func(path string, info os.FileInfo, err error) error {
400 if err != nil {
401 return err
402 }
403 if found {
404 return filepath.SkipDir
405 }
406 if info.IsDir() {
407 return nil
408 }
409 for _, buildFile := range buildFiles {
410 if info.Name() == buildFile {
411 found = true
412 return filepath.SkipDir
413 }
414 }
415 return nil
416 })
417 if err != nil {
418 ctx.Fatalf("Error finding Android build file: %v", err)
419 }
420
421 if found {
422 return filepath.Join(buildDir, "Android.mk")
Patrice Arruda13848222019-04-22 17:12:02 -0700423 }
424 }
425
426 return ""
427}
428
429// splitArgs iterates over the arguments list and splits into two lists: arguments and directories.
430func splitArgs(args []string) (newArgs []string, dirs []string) {
431 specialArgs := map[string]bool{
432 "showcommands": true,
433 "snod": true,
434 "dist": true,
435 "checkbuild": true,
436 }
437
438 newArgs = []string{}
439 dirs = []string{}
440
441 for _, arg := range args {
442 // It's a dash argument if it starts with "-" or it's a key=value pair, it's not a directory.
443 if strings.IndexRune(arg, '-') == 0 || strings.IndexRune(arg, '=') != -1 {
444 newArgs = append(newArgs, arg)
445 continue
446 }
447
448 if _, ok := specialArgs[arg]; ok {
449 newArgs = append(newArgs, arg)
450 continue
451 }
452
453 dirs = append(dirs, arg)
454 }
455
456 return newArgs, dirs
457}
458
459// getTargetsFromDirs iterates over the dirs list and creates a list of targets to build. If a
460// directory from the dirs list does not exist, a fatal error is raised. relDir is related to the
461// source root tree where the build action command was invoked. Each directory is validated if the
462// build file can be found and follows the format "dir1:target1,target2,...". Target is optional.
Dan Willemsence41e942019-07-29 23:39:30 -0700463func getTargetsFromDirs(ctx Context, relDir string, dirs []string, targetNamePrefix string) (targets []string) {
Patrice Arruda13848222019-04-22 17:12:02 -0700464 for _, dir := range dirs {
465 // The directory may have specified specific modules to build. ":" is the separator to separate
466 // the directory and the list of modules.
467 s := strings.Split(dir, ":")
468 l := len(s)
469 if l > 2 { // more than one ":" was specified.
470 ctx.Fatalf("%s not in proper directory:target1,target2,... format (\":\" was specified more than once)", dir)
471 }
472
473 dir = filepath.Join(relDir, s[0])
474 if _, err := os.Stat(dir); err != nil {
475 ctx.Fatalf("couldn't find directory %s", dir)
476 }
477
478 // Verify that if there are any targets specified after ":". Each target is separated by ",".
479 var newTargets []string
480 if l == 2 && s[1] != "" {
481 newTargets = strings.Split(s[1], ",")
482 if inList("", newTargets) {
483 ctx.Fatalf("%s not in proper directory:target1,target2,... format", dir)
484 }
485 }
486
Patrice Arruda9450d0b2019-07-08 11:06:46 -0700487 // If there are specified targets to build in dir, an android build file must exist for the one
488 // shot build. For the non-targets case, find the appropriate build file and build all the
489 // modules in dir (or the closest one in the dir path).
Patrice Arruda13848222019-04-22 17:12:02 -0700490 if len(newTargets) > 0 {
Patrice Arruda9450d0b2019-07-08 11:06:46 -0700491 if !hasBuildFile(ctx, dir) {
Patrice Arruda13848222019-04-22 17:12:02 -0700492 ctx.Fatalf("Couldn't locate a build file from %s directory", dir)
493 }
494 } else {
Patrice Arruda9450d0b2019-07-08 11:06:46 -0700495 buildFile := findBuildFile(ctx, dir)
496 if buildFile == "" {
497 ctx.Fatalf("Build file not found for %s directory", dir)
498 }
499 newTargets = []string{convertToTarget(filepath.Dir(buildFile), targetNamePrefix)}
Patrice Arruda13848222019-04-22 17:12:02 -0700500 }
501
Patrice Arruda13848222019-04-22 17:12:02 -0700502 targets = append(targets, newTargets...)
503 }
504
Dan Willemsence41e942019-07-29 23:39:30 -0700505 return targets
Patrice Arruda13848222019-04-22 17:12:02 -0700506}
507
Dan Willemsen9b587492017-07-10 22:13:00 -0700508func (c *configImpl) parseArgs(ctx Context, args []string) {
509 for i := 0; i < len(args); i++ {
510 arg := strings.TrimSpace(args[i])
Dan Willemsen1e704462016-08-21 15:17:17 -0700511 if arg == "--make-mode" {
Dan Willemsen1e704462016-08-21 15:17:17 -0700512 } else if arg == "showcommands" {
Dan Willemsen9b587492017-07-10 22:13:00 -0700513 c.verbose = true
Dan Willemsene0879fc2017-08-04 15:06:27 -0700514 } else if arg == "--skip-make" {
515 c.skipMake = true
Dan Willemsen6ac63ef2017-10-17 20:35:34 -0700516 } else if len(arg) > 0 && arg[0] == '-' {
Dan Willemsen9b587492017-07-10 22:13:00 -0700517 parseArgNum := func(def int) int {
518 if len(arg) > 2 {
519 p, err := strconv.ParseUint(arg[2:], 10, 31)
520 if err != nil {
521 ctx.Fatalf("Failed to parse %q: %v", arg, err)
522 }
523 return int(p)
524 } else if i+1 < len(args) {
525 p, err := strconv.ParseUint(args[i+1], 10, 31)
526 if err == nil {
527 i++
528 return int(p)
529 }
530 }
531 return def
532 }
533
Dan Willemsen6ac63ef2017-10-17 20:35:34 -0700534 if len(arg) > 1 && arg[1] == 'j' {
Dan Willemsen9b587492017-07-10 22:13:00 -0700535 c.parallel = parseArgNum(c.parallel)
Dan Willemsen6ac63ef2017-10-17 20:35:34 -0700536 } else if len(arg) > 1 && arg[1] == 'k' {
Dan Willemsen9b587492017-07-10 22:13:00 -0700537 c.keepGoing = parseArgNum(0)
Dan Willemsen1e704462016-08-21 15:17:17 -0700538 } else {
539 ctx.Fatalln("Unknown option:", arg)
540 }
Dan Willemsen091525e2017-07-11 14:17:50 -0700541 } else if k, v, ok := decodeKeyValue(arg); ok && len(k) > 0 {
Dan Willemsen6dfe30a2018-09-10 12:41:10 -0700542 if k == "OUT_DIR" {
543 ctx.Fatalln("OUT_DIR may only be set in the environment, not as a command line option.")
544 }
Dan Willemsen091525e2017-07-11 14:17:50 -0700545 c.environ.Set(k, v)
Dan Willemsen2d31a442018-10-20 21:33:41 -0700546 } else if arg == "dist" {
547 c.dist = true
Dan Willemsen1e704462016-08-21 15:17:17 -0700548 } else {
Dan Willemsen2d31a442018-10-20 21:33:41 -0700549 if arg == "checkbuild" {
Colin Cross37193492017-11-16 17:55:00 -0800550 c.checkbuild = true
Dan Willemsene0879fc2017-08-04 15:06:27 -0700551 }
Dan Willemsen9b587492017-07-10 22:13:00 -0700552 c.arguments = append(c.arguments, arg)
Dan Willemsen1e704462016-08-21 15:17:17 -0700553 }
554 }
Dan Willemsen1e704462016-08-21 15:17:17 -0700555}
556
Dan Willemsened869522018-01-08 14:58:46 -0800557func (c *configImpl) configureLocale(ctx Context) {
558 cmd := Command(ctx, Config{c}, "locale", "locale", "-a")
559 output, err := cmd.Output()
560
561 var locales []string
562 if err == nil {
563 locales = strings.Split(string(output), "\n")
564 } else {
565 // If we're unable to list the locales, let's assume en_US.UTF-8
566 locales = []string{"en_US.UTF-8"}
567 ctx.Verbosef("Failed to list locales (%q), falling back to %q", err, locales)
568 }
569
570 // gettext uses LANGUAGE, which is passed directly through
571
572 // For LANG and LC_*, only preserve the evaluated version of
573 // LC_MESSAGES
574 user_lang := ""
575 if lc_all, ok := c.environ.Get("LC_ALL"); ok {
576 user_lang = lc_all
577 } else if lc_messages, ok := c.environ.Get("LC_MESSAGES"); ok {
578 user_lang = lc_messages
579 } else if lang, ok := c.environ.Get("LANG"); ok {
580 user_lang = lang
581 }
582
583 c.environ.UnsetWithPrefix("LC_")
584
585 if user_lang != "" {
586 c.environ.Set("LC_MESSAGES", user_lang)
587 }
588
589 // The for LANG, use C.UTF-8 if it exists (Debian currently, proposed
590 // for others)
591 if inList("C.UTF-8", locales) {
592 c.environ.Set("LANG", "C.UTF-8")
Aaron Klingd236e0e2018-08-07 19:21:36 -0500593 } else if inList("C.utf8", locales) {
594 // These normalize to the same thing
595 c.environ.Set("LANG", "C.UTF-8")
Dan Willemsened869522018-01-08 14:58:46 -0800596 } else if inList("en_US.UTF-8", locales) {
597 c.environ.Set("LANG", "en_US.UTF-8")
598 } else if inList("en_US.utf8", locales) {
599 // These normalize to the same thing
600 c.environ.Set("LANG", "en_US.UTF-8")
601 } else {
602 ctx.Fatalln("System doesn't support either C.UTF-8 or en_US.UTF-8")
603 }
604}
605
Dan Willemsen1e704462016-08-21 15:17:17 -0700606// Lunch configures the environment for a specific product similarly to the
607// `lunch` bash function.
608func (c *configImpl) Lunch(ctx Context, product, variant string) {
609 if variant != "eng" && variant != "userdebug" && variant != "user" {
610 ctx.Fatalf("Invalid variant %q. Must be one of 'user', 'userdebug' or 'eng'", variant)
611 }
612
613 c.environ.Set("TARGET_PRODUCT", product)
614 c.environ.Set("TARGET_BUILD_VARIANT", variant)
615 c.environ.Set("TARGET_BUILD_TYPE", "release")
616 c.environ.Unset("TARGET_BUILD_APPS")
Martin Stjernholm08802332020-06-04 17:00:01 +0100617 c.environ.Unset("TARGET_BUILD_UNBUNDLED")
Dan Willemsen1e704462016-08-21 15:17:17 -0700618}
619
620// Tapas configures the environment to build one or more unbundled apps,
621// similarly to the `tapas` bash function.
622func (c *configImpl) Tapas(ctx Context, apps []string, arch, variant string) {
623 if len(apps) == 0 {
624 apps = []string{"all"}
625 }
626 if variant == "" {
627 variant = "eng"
628 }
629
630 if variant != "eng" && variant != "userdebug" && variant != "user" {
631 ctx.Fatalf("Invalid variant %q. Must be one of 'user', 'userdebug' or 'eng'", variant)
632 }
633
634 var product string
635 switch arch {
Dan Willemsen1e704462016-08-21 15:17:17 -0700636 case "arm", "":
637 product = "aosp_arm"
638 case "arm64":
639 product = "aosm_arm64"
Dan Willemsen1e704462016-08-21 15:17:17 -0700640 case "x86":
641 product = "aosp_x86"
642 case "x86_64":
643 product = "aosp_x86_64"
644 default:
645 ctx.Fatalf("Invalid architecture: %q", arch)
646 }
647
648 c.environ.Set("TARGET_PRODUCT", product)
649 c.environ.Set("TARGET_BUILD_VARIANT", variant)
650 c.environ.Set("TARGET_BUILD_TYPE", "release")
651 c.environ.Set("TARGET_BUILD_APPS", strings.Join(apps, " "))
652}
653
654func (c *configImpl) Environment() *Environment {
655 return c.environ
656}
657
658func (c *configImpl) Arguments() []string {
659 return c.arguments
660}
661
662func (c *configImpl) OutDir() string {
663 if outDir, ok := c.environ.Get("OUT_DIR"); ok {
Patrice Arruda19bd53e2019-07-08 17:26:47 -0700664 return outDir
Dan Willemsen1e704462016-08-21 15:17:17 -0700665 }
666 return "out"
667}
668
Dan Willemsen8a073a82017-02-04 17:30:44 -0800669func (c *configImpl) DistDir() string {
Dan Willemsen2d31a442018-10-20 21:33:41 -0700670 return c.distDir
Dan Willemsen8a073a82017-02-04 17:30:44 -0800671}
672
Dan Willemsen1e704462016-08-21 15:17:17 -0700673func (c *configImpl) NinjaArgs() []string {
Dan Willemsene0879fc2017-08-04 15:06:27 -0700674 if c.skipMake {
675 return c.arguments
676 }
Dan Willemsen1e704462016-08-21 15:17:17 -0700677 return c.ninjaArgs
678}
679
680func (c *configImpl) SoongOutDir() string {
681 return filepath.Join(c.OutDir(), "soong")
682}
683
Jeff Gastonefc1b412017-03-29 17:29:06 -0700684func (c *configImpl) TempDir() string {
685 return shared.TempDirForOutDir(c.SoongOutDir())
686}
687
Jeff Gastonb64fc1c2017-08-04 12:30:12 -0700688func (c *configImpl) FileListDir() string {
689 return filepath.Join(c.OutDir(), ".module_paths")
690}
691
Dan Willemsen1e704462016-08-21 15:17:17 -0700692func (c *configImpl) KatiSuffix() string {
693 if c.katiSuffix != "" {
694 return c.katiSuffix
695 }
696 panic("SetKatiSuffix has not been called")
697}
698
Colin Cross37193492017-11-16 17:55:00 -0800699// Checkbuild returns true if "checkbuild" was one of the build goals, which means that the
700// user is interested in additional checks at the expense of build time.
701func (c *configImpl) Checkbuild() bool {
702 return c.checkbuild
703}
704
Dan Willemsen8a073a82017-02-04 17:30:44 -0800705func (c *configImpl) Dist() bool {
706 return c.dist
707}
708
Dan Willemsen1e704462016-08-21 15:17:17 -0700709func (c *configImpl) IsVerbose() bool {
710 return c.verbose
711}
712
Dan Willemsene0879fc2017-08-04 15:06:27 -0700713func (c *configImpl) SkipMake() bool {
714 return c.skipMake
715}
716
Dan Willemsen1e704462016-08-21 15:17:17 -0700717func (c *configImpl) TargetProduct() string {
718 if v, ok := c.environ.Get("TARGET_PRODUCT"); ok {
719 return v
720 }
721 panic("TARGET_PRODUCT is not defined")
722}
723
Dan Willemsen02781d52017-05-12 19:28:13 -0700724func (c *configImpl) TargetDevice() string {
725 return c.targetDevice
726}
727
728func (c *configImpl) SetTargetDevice(device string) {
729 c.targetDevice = device
730}
731
732func (c *configImpl) TargetBuildVariant() string {
733 if v, ok := c.environ.Get("TARGET_BUILD_VARIANT"); ok {
734 return v
735 }
736 panic("TARGET_BUILD_VARIANT is not defined")
737}
738
Dan Willemsen1e704462016-08-21 15:17:17 -0700739func (c *configImpl) KatiArgs() []string {
740 return c.katiArgs
741}
742
743func (c *configImpl) Parallel() int {
744 return c.parallel
745}
746
Colin Cross8b8bec32019-11-15 13:18:43 -0800747func (c *configImpl) HighmemParallel() int {
748 if i, ok := c.environ.GetInt("NINJA_HIGHMEM_NUM_JOBS"); ok {
749 return i
750 }
751
752 const minMemPerHighmemProcess = 8 * 1024 * 1024 * 1024
753 parallel := c.Parallel()
754 if c.UseRemoteBuild() {
755 // Ninja doesn't support nested pools, and when remote builds are enabled the total ninja parallelism
756 // is set very high (i.e. 500). Using a large value here would cause the total number of running jobs
757 // to be the sum of the sizes of the local and highmem pools, which will cause extra CPU contention.
758 // Return 1/16th of the size of the local pool, rounding up.
759 return (parallel + 15) / 16
760 } else if c.totalRAM == 0 {
761 // Couldn't detect the total RAM, don't restrict highmem processes.
762 return parallel
Dan Willemsen570a2922020-05-26 23:02:29 -0700763 } else if c.totalRAM <= 16*1024*1024*1024 {
764 // Less than 16GB of ram, restrict to 1 highmem processes
765 return 1
Colin Cross8b8bec32019-11-15 13:18:43 -0800766 } else if c.totalRAM <= 32*1024*1024*1024 {
767 // Less than 32GB of ram, restrict to 2 highmem processes
768 return 2
769 } else if p := int(c.totalRAM / minMemPerHighmemProcess); p < parallel {
770 // If less than 8GB total RAM per process, reduce the number of highmem processes
771 return p
772 }
773 // No restriction on highmem processes
774 return parallel
775}
776
Dan Willemsen2bb82d02019-12-27 09:35:42 -0800777func (c *configImpl) TotalRAM() uint64 {
778 return c.totalRAM
779}
780
Dan Willemsen1e704462016-08-21 15:17:17 -0700781func (c *configImpl) UseGoma() bool {
782 if v, ok := c.environ.Get("USE_GOMA"); ok {
783 v = strings.TrimSpace(v)
784 if v != "" && v != "false" {
785 return true
786 }
787 }
788 return false
789}
790
Yoshisato Yanagisawa2cb0e5d2019-01-10 10:14:16 +0900791func (c *configImpl) StartGoma() bool {
792 if !c.UseGoma() {
793 return false
794 }
795
796 if v, ok := c.environ.Get("NOSTART_GOMA"); ok {
797 v = strings.TrimSpace(v)
798 if v != "" && v != "false" {
799 return false
800 }
801 }
802 return true
803}
804
Ramy Medhatbbf25672019-07-17 12:30:04 +0000805func (c *configImpl) UseRBE() bool {
806 if v, ok := c.environ.Get("USE_RBE"); ok {
807 v = strings.TrimSpace(v)
808 if v != "" && v != "false" {
809 return true
810 }
811 }
812 return false
813}
814
815func (c *configImpl) StartRBE() bool {
816 if !c.UseRBE() {
817 return false
818 }
819
820 if v, ok := c.environ.Get("NOSTART_RBE"); ok {
821 v = strings.TrimSpace(v)
822 if v != "" && v != "false" {
823 return false
824 }
825 }
826 return true
827}
828
Ramy Medhat0fc67eb2020-08-12 01:26:23 -0400829func (c *configImpl) logDir() string {
830 if c.Dist() {
831 return filepath.Join(c.DistDir(), "logs")
832 }
833 return c.OutDir()
834}
835
836func (c *configImpl) rbeStatsOutputDir() string {
Patrice Arruda62f1bf22020-07-07 12:48:26 +0000837 for _, f := range []string{"RBE_output_dir", "FLAG_output_dir"} {
838 if v, ok := c.environ.Get(f); ok {
839 return v
840 }
841 }
Ramy Medhat0fc67eb2020-08-12 01:26:23 -0400842 return c.logDir()
843}
844
845func (c *configImpl) rbeLogPath() string {
846 for _, f := range []string{"RBE_log_path", "FLAG_log_path"} {
847 if v, ok := c.environ.Get(f); ok {
848 return v
849 }
850 }
851 return fmt.Sprintf("text://%v/reproxy_log.txt", c.logDir())
852}
853
854func (c *configImpl) rbeExecRoot() string {
855 for _, f := range []string{"RBE_exec_root", "FLAG_exec_root"} {
856 if v, ok := c.environ.Get(f); ok {
857 return v
858 }
859 }
860 wd, err := os.Getwd()
861 if err != nil {
862 return ""
863 }
864 return wd
865}
866
867func (c *configImpl) rbeDir() string {
868 if v, ok := c.environ.Get("RBE_DIR"); ok {
869 return v
870 }
871 return "prebuilts/remoteexecution-client/live/"
872}
873
874func (c *configImpl) rbeReproxy() string {
875 for _, f := range []string{"RBE_re_proxy", "FLAG_re_proxy"} {
876 if v, ok := c.environ.Get(f); ok {
877 return v
878 }
879 }
880 return filepath.Join(c.rbeDir(), "reproxy")
881}
882
883func (c *configImpl) rbeAuth() (string, string) {
884 credFlags := []string{"use_application_default_credentials", "use_gce_credentials", "credential_file"}
885 for _, cf := range credFlags {
886 for _, f := range []string{"RBE_" + cf, "FLAG_" + cf} {
887 if v, ok := c.environ.Get(f); ok {
888 v = strings.TrimSpace(v)
889 if v != "" && v != "false" && v != "0" {
890 return "RBE_" + cf, v
891 }
892 }
893 }
894 }
895 return "RBE_use_application_default_credentials", "true"
Patrice Arruda62f1bf22020-07-07 12:48:26 +0000896}
897
Colin Cross9016b912019-11-11 14:57:42 -0800898func (c *configImpl) UseRemoteBuild() bool {
899 return c.UseGoma() || c.UseRBE()
900}
901
Dan Willemsen1e704462016-08-21 15:17:17 -0700902// RemoteParallel controls how many remote jobs (i.e., commands which contain
Jeff Gastonefc1b412017-03-29 17:29:06 -0700903// gomacc) are run in parallel. Note the parallelism of all other jobs is
Dan Willemsen1e704462016-08-21 15:17:17 -0700904// still limited by Parallel()
905func (c *configImpl) RemoteParallel() int {
Colin Cross8b8bec32019-11-15 13:18:43 -0800906 if !c.UseRemoteBuild() {
907 return 0
908 }
909 if i, ok := c.environ.GetInt("NINJA_REMOTE_NUM_JOBS"); ok {
910 return i
Dan Willemsen1e704462016-08-21 15:17:17 -0700911 }
912 return 500
913}
914
915func (c *configImpl) SetKatiArgs(args []string) {
916 c.katiArgs = args
917}
918
919func (c *configImpl) SetNinjaArgs(args []string) {
920 c.ninjaArgs = args
921}
922
923func (c *configImpl) SetKatiSuffix(suffix string) {
924 c.katiSuffix = suffix
925}
926
Dan Willemsene0879fc2017-08-04 15:06:27 -0700927func (c *configImpl) LastKatiSuffixFile() string {
928 return filepath.Join(c.OutDir(), "last_kati_suffix")
929}
930
931func (c *configImpl) HasKatiSuffix() bool {
932 return c.katiSuffix != ""
933}
934
Dan Willemsen1e704462016-08-21 15:17:17 -0700935func (c *configImpl) KatiEnvFile() string {
936 return filepath.Join(c.OutDir(), "env"+c.KatiSuffix()+".sh")
937}
938
Dan Willemsen29971232018-09-26 14:58:30 -0700939func (c *configImpl) KatiBuildNinjaFile() string {
940 return filepath.Join(c.OutDir(), "build"+c.KatiSuffix()+katiBuildSuffix+".ninja")
Dan Willemsen1e704462016-08-21 15:17:17 -0700941}
942
Dan Willemsenfb1271a2018-09-26 15:00:42 -0700943func (c *configImpl) KatiPackageNinjaFile() string {
944 return filepath.Join(c.OutDir(), "build"+c.KatiSuffix()+katiPackageSuffix+".ninja")
945}
946
Dan Willemsen1e704462016-08-21 15:17:17 -0700947func (c *configImpl) SoongNinjaFile() string {
948 return filepath.Join(c.SoongOutDir(), "build.ninja")
949}
950
951func (c *configImpl) CombinedNinjaFile() string {
Dan Willemsene0879fc2017-08-04 15:06:27 -0700952 if c.katiSuffix == "" {
953 return filepath.Join(c.OutDir(), "combined.ninja")
954 }
Dan Willemsen1e704462016-08-21 15:17:17 -0700955 return filepath.Join(c.OutDir(), "combined"+c.KatiSuffix()+".ninja")
956}
957
958func (c *configImpl) SoongAndroidMk() string {
959 return filepath.Join(c.SoongOutDir(), "Android-"+c.TargetProduct()+".mk")
960}
961
962func (c *configImpl) SoongMakeVarsMk() string {
963 return filepath.Join(c.SoongOutDir(), "make_vars-"+c.TargetProduct()+".mk")
964}
965
Dan Willemsenf052f782017-05-18 15:29:04 -0700966func (c *configImpl) ProductOut() string {
Dan Willemsen4dc4e142017-09-08 14:35:43 -0700967 return filepath.Join(c.OutDir(), "target", "product", c.TargetDevice())
Dan Willemsenf052f782017-05-18 15:29:04 -0700968}
969
Dan Willemsen02781d52017-05-12 19:28:13 -0700970func (c *configImpl) DevicePreviousProductConfig() string {
Dan Willemsenf052f782017-05-18 15:29:04 -0700971 return filepath.Join(c.ProductOut(), "previous_build_config.mk")
972}
973
Dan Willemsenfb1271a2018-09-26 15:00:42 -0700974func (c *configImpl) KatiPackageMkDir() string {
975 return filepath.Join(c.ProductOut(), "obj", "CONFIG", "kati_packaging")
976}
977
Dan Willemsenf052f782017-05-18 15:29:04 -0700978func (c *configImpl) hostOutRoot() string {
Dan Willemsen4dc4e142017-09-08 14:35:43 -0700979 return filepath.Join(c.OutDir(), "host")
Dan Willemsenf052f782017-05-18 15:29:04 -0700980}
981
982func (c *configImpl) HostOut() string {
983 return filepath.Join(c.hostOutRoot(), c.HostPrebuiltTag())
984}
985
986// This probably needs to be multi-valued, so not exporting it for now
987func (c *configImpl) hostCrossOut() string {
988 if runtime.GOOS == "linux" {
989 return filepath.Join(c.hostOutRoot(), "windows-x86")
990 } else {
991 return ""
992 }
Dan Willemsen02781d52017-05-12 19:28:13 -0700993}
994
Dan Willemsen1e704462016-08-21 15:17:17 -0700995func (c *configImpl) HostPrebuiltTag() string {
996 if runtime.GOOS == "linux" {
997 return "linux-x86"
998 } else if runtime.GOOS == "darwin" {
999 return "darwin-x86"
1000 } else {
1001 panic("Unsupported OS")
1002 }
1003}
Dan Willemsenf173d592017-04-27 14:28:00 -07001004
Dan Willemsen8122bd52017-10-12 20:20:41 -07001005func (c *configImpl) PrebuiltBuildTool(name string) string {
Dan Willemsenf173d592017-04-27 14:28:00 -07001006 if v, ok := c.environ.Get("SANITIZE_HOST"); ok {
1007 if sanitize := strings.Fields(v); inList("address", sanitize) {
Dan Willemsen8122bd52017-10-12 20:20:41 -07001008 asan := filepath.Join("prebuilts/build-tools", c.HostPrebuiltTag(), "asan/bin", name)
1009 if _, err := os.Stat(asan); err == nil {
1010 return asan
1011 }
Dan Willemsenf173d592017-04-27 14:28:00 -07001012 }
1013 }
1014 return filepath.Join("prebuilts/build-tools", c.HostPrebuiltTag(), "bin", name)
1015}
Dan Willemsen3d60b112018-04-04 22:25:56 -07001016
1017func (c *configImpl) SetBuildBrokenDupRules(val bool) {
1018 c.brokenDupRules = val
1019}
1020
1021func (c *configImpl) BuildBrokenDupRules() bool {
1022 return c.brokenDupRules
1023}
Dan Willemsen6ab79db2018-05-02 00:06:28 -07001024
Dan Willemsen25e6f092019-04-09 10:22:43 -07001025func (c *configImpl) SetBuildBrokenUsesNetwork(val bool) {
1026 c.brokenUsesNetwork = val
1027}
1028
1029func (c *configImpl) BuildBrokenUsesNetwork() bool {
1030 return c.brokenUsesNetwork
1031}
1032
Dan Willemsene3336352020-01-02 19:10:38 -08001033func (c *configImpl) SetBuildBrokenNinjaUsesEnvVars(val []string) {
1034 c.brokenNinjaEnvVars = val
1035}
1036
1037func (c *configImpl) BuildBrokenNinjaUsesEnvVars() []string {
1038 return c.brokenNinjaEnvVars
1039}
1040
Dan Willemsen6ab79db2018-05-02 00:06:28 -07001041func (c *configImpl) SetTargetDeviceDir(dir string) {
1042 c.targetDeviceDir = dir
1043}
1044
1045func (c *configImpl) TargetDeviceDir() string {
1046 return c.targetDeviceDir
1047}
Dan Willemsenfa42f3c2018-06-15 21:54:47 -07001048
Patrice Arruda219eef32020-06-01 17:29:30 +00001049func (c *configImpl) BuildDateTime() string {
1050 return c.buildDateTime
1051}
1052
1053func (c *configImpl) MetricsUploaderApp() string {
1054 if p, ok := c.environ.Get("ANDROID_ENABLE_METRICS_UPLOAD"); ok {
1055 return p
1056 }
1057 return ""
1058}