blob: 8ba425be5ba9bb5dc53420b0a0e27b0fb3fc90a8 [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 (
Nan Zhang2e6a4ff2018-02-14 13:27:26 -080018 "io/ioutil"
Dan Willemsenc2af0be2017-01-20 14:10:01 -080019 "log"
20 "os"
Dan Willemsen1e704462016-08-21 15:17:17 -070021 "path/filepath"
22 "runtime"
23 "strconv"
24 "strings"
Nan Zhang2e6a4ff2018-02-14 13:27:26 -080025 "time"
Jeff Gastonefc1b412017-03-29 17:29:06 -070026
27 "android/soong/shared"
Dan Willemsen1e704462016-08-21 15:17:17 -070028)
29
30type Config struct{ *configImpl }
31
32type configImpl struct {
33 // From the environment
34 arguments []string
35 goma bool
36 environ *Environment
Dan Willemsen2d31a442018-10-20 21:33:41 -070037 distDir 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 Willemsend8aa39d2018-08-27 15:01:03 -070054 pdkBuild bool
55
56 brokenDupRules bool
57 brokenPhonyTargets bool
Dan Willemsen47946562019-04-09 10:22:43 -070058 brokenUsesNetwork bool
Dan Willemsen18490112018-05-25 16:30:04 -070059
60 pathReplaced bool
Dan Willemsen1e704462016-08-21 15:17:17 -070061}
62
Dan Willemsenc2af0be2017-01-20 14:10:01 -080063const srcDirFileCheck = "build/soong/root.bp"
64
Dan Willemsen1e704462016-08-21 15:17:17 -070065func NewConfig(ctx Context, args ...string) Config {
66 ret := &configImpl{
67 environ: OsEnvironment(),
68 }
69
Dan Willemsen9b587492017-07-10 22:13:00 -070070 // Sane default matching ninja
71 ret.parallel = runtime.NumCPU() + 2
72 ret.keepGoing = 1
73
74 ret.parseArgs(ctx, args)
75
Dan Willemsen0c3919e2017-03-02 15:49:10 -080076 // Make sure OUT_DIR is set appropriately
Dan Willemsen02f3add2017-05-12 13:50:19 -070077 if outDir, ok := ret.environ.Get("OUT_DIR"); ok {
78 ret.environ.Set("OUT_DIR", filepath.Clean(outDir))
79 } else {
Dan Willemsen0c3919e2017-03-02 15:49:10 -080080 outDir := "out"
81 if baseDir, ok := ret.environ.Get("OUT_DIR_COMMON_BASE"); ok {
82 if wd, err := os.Getwd(); err != nil {
83 ctx.Fatalln("Failed to get working directory:", err)
84 } else {
85 outDir = filepath.Join(baseDir, filepath.Base(wd))
86 }
87 }
88 ret.environ.Set("OUT_DIR", outDir)
89 }
90
Dan Willemsen2d31a442018-10-20 21:33:41 -070091 if distDir, ok := ret.environ.Get("DIST_DIR"); ok {
92 ret.distDir = filepath.Clean(distDir)
93 } else {
94 ret.distDir = filepath.Join(ret.OutDir(), "dist")
95 }
Dan Willemsend50e89f2018-10-16 17:49:25 -070096
Dan Willemsen1e704462016-08-21 15:17:17 -070097 ret.environ.Unset(
98 // We're already using it
99 "USE_SOONG_UI",
100
101 // We should never use GOROOT/GOPATH from the shell environment
102 "GOROOT",
103 "GOPATH",
104
105 // These should only come from Soong, not the environment.
106 "CLANG",
107 "CLANG_CXX",
108 "CCC_CC",
109 "CCC_CXX",
110
111 // Used by the goma compiler wrapper, but should only be set by
112 // gomacc
113 "GOMACC_PATH",
Dan Willemsen0c3919e2017-03-02 15:49:10 -0800114
115 // We handle this above
116 "OUT_DIR_COMMON_BASE",
Dan Willemsen68a09852017-04-18 13:56:57 -0700117
Dan Willemsen2d31a442018-10-20 21:33:41 -0700118 // This is handled above too, and set for individual commands later
119 "DIST_DIR",
120
Dan Willemsen68a09852017-04-18 13:56:57 -0700121 // Variables that have caused problems in the past
Dan Willemsenebfe33a2018-05-01 10:07:50 -0700122 "CDPATH",
Dan Willemsen68a09852017-04-18 13:56:57 -0700123 "DISPLAY",
124 "GREP_OPTIONS",
Dan Willemsenebfe33a2018-05-01 10:07:50 -0700125 "NDK_ROOT",
Dan Willemsen00fcb262018-08-15 15:35:38 -0700126 "POSIXLY_CORRECT",
Dan Willemsenc40e10b2017-07-11 14:30:00 -0700127
128 // Drop make flags
129 "MAKEFLAGS",
130 "MAKELEVEL",
131 "MFLAGS",
Dan Willemsend9e8f0a2017-10-30 13:42:06 -0700132
133 // Set in envsetup.sh, reset in makefiles
134 "ANDROID_JAVA_TOOLCHAIN",
Colin Cross7f09c402018-07-11 14:49:31 -0700135
136 // Set by envsetup.sh, but shouldn't be used inside the build because envsetup.sh is optional
137 "ANDROID_BUILD_TOP",
138 "ANDROID_HOST_OUT",
139 "ANDROID_PRODUCT_OUT",
140 "ANDROID_HOST_OUT_TESTCASES",
141 "ANDROID_TARGET_OUT_TESTCASES",
142 "ANDROID_TOOLCHAIN",
143 "ANDROID_TOOLCHAIN_2ND_ARCH",
144 "ANDROID_DEV_SCRIPTS",
145 "ANDROID_EMULATOR_PREBUILTS",
146 "ANDROID_PRE_BUILD_PATHS",
Dan Willemsenf99915f2018-10-25 22:04:42 -0700147
148 // Only set in multiproduct_kati after config generation
149 "EMPTY_NINJA_FILE",
Dan Willemsen1e704462016-08-21 15:17:17 -0700150 )
151
152 // Tell python not to spam the source tree with .pyc files.
153 ret.environ.Set("PYTHONDONTWRITEBYTECODE", "1")
154
Dan Willemsen32a669b2018-03-08 19:42:00 -0800155 ret.environ.Set("TMPDIR", absPath(ctx, ret.TempDir()))
156
Dan Willemsenc2af0be2017-01-20 14:10:01 -0800157 // Precondition: the current directory is the top of the source tree
158 if _, err := os.Stat(srcDirFileCheck); err != nil {
159 if os.IsNotExist(err) {
160 log.Fatalf("Current working directory must be the source tree. %q not found", srcDirFileCheck)
161 }
162 log.Fatalln("Error verifying tree state:", err)
163 }
164
Dan Willemsend9e8f0a2017-10-30 13:42:06 -0700165 if srcDir := absPath(ctx, "."); strings.ContainsRune(srcDir, ' ') {
166 log.Println("You are building in a directory whose absolute path contains a space character:")
167 log.Println()
168 log.Printf("%q\n", srcDir)
169 log.Println()
170 log.Fatalln("Directory names containing spaces are not supported")
Dan Willemsendb8457c2017-05-12 16:38:17 -0700171 }
172
173 if outDir := ret.OutDir(); strings.ContainsRune(outDir, ' ') {
174 log.Println("The absolute path of your output directory ($OUT_DIR) contains a space character:")
175 log.Println()
176 log.Printf("%q\n", outDir)
177 log.Println()
178 log.Fatalln("Directory names containing spaces are not supported")
179 }
180
181 if distDir := ret.DistDir(); strings.ContainsRune(distDir, ' ') {
182 log.Println("The absolute path of your dist directory ($DIST_DIR) contains a space character:")
183 log.Println()
184 log.Printf("%q\n", distDir)
185 log.Println()
186 log.Fatalln("Directory names containing spaces are not supported")
187 }
188
Dan Willemsend9e8f0a2017-10-30 13:42:06 -0700189 // Configure Java-related variables, including adding it to $PATH
Tobias Thierere59aeff2017-12-20 22:40:39 +0000190 java8Home := filepath.Join("prebuilts/jdk/jdk8", ret.HostPrebuiltTag())
191 java9Home := filepath.Join("prebuilts/jdk/jdk9", ret.HostPrebuiltTag())
Dan Willemsend9e8f0a2017-10-30 13:42:06 -0700192 javaHome := func() string {
193 if override, ok := ret.environ.Get("OVERRIDE_ANDROID_JAVA_HOME"); ok {
194 return override
195 }
Colin Cross997262f2018-06-19 22:49:39 -0700196 return java9Home
Dan Willemsend9e8f0a2017-10-30 13:42:06 -0700197 }()
198 absJavaHome := absPath(ctx, javaHome)
199
Dan Willemsened869522018-01-08 14:58:46 -0800200 ret.configureLocale(ctx)
201
Dan Willemsend9e8f0a2017-10-30 13:42:06 -0700202 newPath := []string{filepath.Join(absJavaHome, "bin")}
203 if path, ok := ret.environ.Get("PATH"); ok && path != "" {
204 newPath = append(newPath, path)
205 }
206 ret.environ.Unset("OVERRIDE_ANDROID_JAVA_HOME")
207 ret.environ.Set("JAVA_HOME", absJavaHome)
208 ret.environ.Set("ANDROID_JAVA_HOME", javaHome)
Tobias Thierere59aeff2017-12-20 22:40:39 +0000209 ret.environ.Set("ANDROID_JAVA8_HOME", java8Home)
210 ret.environ.Set("ANDROID_JAVA9_HOME", java9Home)
Dan Willemsend9e8f0a2017-10-30 13:42:06 -0700211 ret.environ.Set("PATH", strings.Join(newPath, string(filepath.ListSeparator)))
212
Nan Zhang2e6a4ff2018-02-14 13:27:26 -0800213 outDir := ret.OutDir()
214 buildDateTimeFile := filepath.Join(outDir, "build_date.txt")
215 var content string
216 if buildDateTime, ok := ret.environ.Get("BUILD_DATETIME"); ok && buildDateTime != "" {
217 content = buildDateTime
218 } else {
219 content = strconv.FormatInt(time.Now().Unix(), 10)
220 }
221 err := ioutil.WriteFile(buildDateTimeFile, []byte(content), 0777)
222 if err != nil {
223 ctx.Fatalln("Failed to write BUILD_DATETIME to file:", err)
224 }
225 ret.environ.Set("BUILD_DATETIME_FILE", buildDateTimeFile)
226
Dan Willemsen9b587492017-07-10 22:13:00 -0700227 return Config{ret}
228}
229
230func (c *configImpl) parseArgs(ctx Context, args []string) {
231 for i := 0; i < len(args); i++ {
232 arg := strings.TrimSpace(args[i])
Dan Willemsen1e704462016-08-21 15:17:17 -0700233 if arg == "--make-mode" {
Dan Willemsen1e704462016-08-21 15:17:17 -0700234 } else if arg == "showcommands" {
Dan Willemsen9b587492017-07-10 22:13:00 -0700235 c.verbose = true
Dan Willemsene0879fc2017-08-04 15:06:27 -0700236 } else if arg == "--skip-make" {
237 c.skipMake = true
Dan Willemsen6ac63ef2017-10-17 20:35:34 -0700238 } else if len(arg) > 0 && arg[0] == '-' {
Dan Willemsen9b587492017-07-10 22:13:00 -0700239 parseArgNum := func(def int) int {
240 if len(arg) > 2 {
241 p, err := strconv.ParseUint(arg[2:], 10, 31)
242 if err != nil {
243 ctx.Fatalf("Failed to parse %q: %v", arg, err)
244 }
245 return int(p)
246 } else if i+1 < len(args) {
247 p, err := strconv.ParseUint(args[i+1], 10, 31)
248 if err == nil {
249 i++
250 return int(p)
251 }
252 }
253 return def
254 }
255
Dan Willemsen6ac63ef2017-10-17 20:35:34 -0700256 if len(arg) > 1 && arg[1] == 'j' {
Dan Willemsen9b587492017-07-10 22:13:00 -0700257 c.parallel = parseArgNum(c.parallel)
Dan Willemsen6ac63ef2017-10-17 20:35:34 -0700258 } else if len(arg) > 1 && arg[1] == 'k' {
Dan Willemsen9b587492017-07-10 22:13:00 -0700259 c.keepGoing = parseArgNum(0)
Dan Willemsen1e704462016-08-21 15:17:17 -0700260 } else {
261 ctx.Fatalln("Unknown option:", arg)
262 }
Dan Willemsen091525e2017-07-11 14:17:50 -0700263 } else if k, v, ok := decodeKeyValue(arg); ok && len(k) > 0 {
264 c.environ.Set(k, v)
Dan Willemsen2d31a442018-10-20 21:33:41 -0700265 } else if arg == "dist" {
266 c.dist = true
Dan Willemsen1e704462016-08-21 15:17:17 -0700267 } else {
Dan Willemsen2d31a442018-10-20 21:33:41 -0700268 if arg == "checkbuild" {
Colin Cross37193492017-11-16 17:55:00 -0800269 c.checkbuild = true
Dan Willemsene0879fc2017-08-04 15:06:27 -0700270 }
Dan Willemsen9b587492017-07-10 22:13:00 -0700271 c.arguments = append(c.arguments, arg)
Dan Willemsen1e704462016-08-21 15:17:17 -0700272 }
273 }
Dan Willemsen1e704462016-08-21 15:17:17 -0700274}
275
Dan Willemsened869522018-01-08 14:58:46 -0800276func (c *configImpl) configureLocale(ctx Context) {
277 cmd := Command(ctx, Config{c}, "locale", "locale", "-a")
278 output, err := cmd.Output()
279
280 var locales []string
281 if err == nil {
282 locales = strings.Split(string(output), "\n")
283 } else {
284 // If we're unable to list the locales, let's assume en_US.UTF-8
285 locales = []string{"en_US.UTF-8"}
286 ctx.Verbosef("Failed to list locales (%q), falling back to %q", err, locales)
287 }
288
289 // gettext uses LANGUAGE, which is passed directly through
290
291 // For LANG and LC_*, only preserve the evaluated version of
292 // LC_MESSAGES
293 user_lang := ""
294 if lc_all, ok := c.environ.Get("LC_ALL"); ok {
295 user_lang = lc_all
296 } else if lc_messages, ok := c.environ.Get("LC_MESSAGES"); ok {
297 user_lang = lc_messages
298 } else if lang, ok := c.environ.Get("LANG"); ok {
299 user_lang = lang
300 }
301
302 c.environ.UnsetWithPrefix("LC_")
303
304 if user_lang != "" {
305 c.environ.Set("LC_MESSAGES", user_lang)
306 }
307
308 // The for LANG, use C.UTF-8 if it exists (Debian currently, proposed
309 // for others)
310 if inList("C.UTF-8", locales) {
311 c.environ.Set("LANG", "C.UTF-8")
Aaron Klingd236e0e2018-08-07 19:21:36 -0500312 } else if inList("C.utf8", locales) {
313 // These normalize to the same thing
314 c.environ.Set("LANG", "C.UTF-8")
Dan Willemsened869522018-01-08 14:58:46 -0800315 } else if inList("en_US.UTF-8", locales) {
316 c.environ.Set("LANG", "en_US.UTF-8")
317 } else if inList("en_US.utf8", locales) {
318 // These normalize to the same thing
319 c.environ.Set("LANG", "en_US.UTF-8")
320 } else {
321 ctx.Fatalln("System doesn't support either C.UTF-8 or en_US.UTF-8")
322 }
323}
324
Dan Willemsen1e704462016-08-21 15:17:17 -0700325// Lunch configures the environment for a specific product similarly to the
326// `lunch` bash function.
327func (c *configImpl) Lunch(ctx Context, product, variant string) {
328 if variant != "eng" && variant != "userdebug" && variant != "user" {
329 ctx.Fatalf("Invalid variant %q. Must be one of 'user', 'userdebug' or 'eng'", variant)
330 }
331
332 c.environ.Set("TARGET_PRODUCT", product)
333 c.environ.Set("TARGET_BUILD_VARIANT", variant)
334 c.environ.Set("TARGET_BUILD_TYPE", "release")
335 c.environ.Unset("TARGET_BUILD_APPS")
336}
337
338// Tapas configures the environment to build one or more unbundled apps,
339// similarly to the `tapas` bash function.
340func (c *configImpl) Tapas(ctx Context, apps []string, arch, variant string) {
341 if len(apps) == 0 {
342 apps = []string{"all"}
343 }
344 if variant == "" {
345 variant = "eng"
346 }
347
348 if variant != "eng" && variant != "userdebug" && variant != "user" {
349 ctx.Fatalf("Invalid variant %q. Must be one of 'user', 'userdebug' or 'eng'", variant)
350 }
351
352 var product string
353 switch arch {
Dan Willemsen1e704462016-08-21 15:17:17 -0700354 case "arm", "":
355 product = "aosp_arm"
356 case "arm64":
357 product = "aosm_arm64"
358 case "mips":
359 product = "aosp_mips"
360 case "mips64":
361 product = "aosp_mips64"
362 case "x86":
363 product = "aosp_x86"
364 case "x86_64":
365 product = "aosp_x86_64"
366 default:
367 ctx.Fatalf("Invalid architecture: %q", arch)
368 }
369
370 c.environ.Set("TARGET_PRODUCT", product)
371 c.environ.Set("TARGET_BUILD_VARIANT", variant)
372 c.environ.Set("TARGET_BUILD_TYPE", "release")
373 c.environ.Set("TARGET_BUILD_APPS", strings.Join(apps, " "))
374}
375
376func (c *configImpl) Environment() *Environment {
377 return c.environ
378}
379
380func (c *configImpl) Arguments() []string {
381 return c.arguments
382}
383
384func (c *configImpl) OutDir() string {
385 if outDir, ok := c.environ.Get("OUT_DIR"); ok {
Dan Willemsen25a56182018-08-31 20:25:32 -0700386 return filepath.Clean(outDir)
Dan Willemsen1e704462016-08-21 15:17:17 -0700387 }
388 return "out"
389}
390
Dan Willemsen8a073a82017-02-04 17:30:44 -0800391func (c *configImpl) DistDir() string {
Dan Willemsen2d31a442018-10-20 21:33:41 -0700392 return c.distDir
Dan Willemsen8a073a82017-02-04 17:30:44 -0800393}
394
Dan Willemsen1e704462016-08-21 15:17:17 -0700395func (c *configImpl) NinjaArgs() []string {
Dan Willemsene0879fc2017-08-04 15:06:27 -0700396 if c.skipMake {
397 return c.arguments
398 }
Dan Willemsen1e704462016-08-21 15:17:17 -0700399 return c.ninjaArgs
400}
401
402func (c *configImpl) SoongOutDir() string {
403 return filepath.Join(c.OutDir(), "soong")
404}
405
Jeff Gastonefc1b412017-03-29 17:29:06 -0700406func (c *configImpl) TempDir() string {
407 return shared.TempDirForOutDir(c.SoongOutDir())
408}
409
Jeff Gastonb64fc1c2017-08-04 12:30:12 -0700410func (c *configImpl) FileListDir() string {
411 return filepath.Join(c.OutDir(), ".module_paths")
412}
413
Dan Willemsen1e704462016-08-21 15:17:17 -0700414func (c *configImpl) KatiSuffix() string {
415 if c.katiSuffix != "" {
416 return c.katiSuffix
417 }
418 panic("SetKatiSuffix has not been called")
419}
420
Colin Cross37193492017-11-16 17:55:00 -0800421// Checkbuild returns true if "checkbuild" was one of the build goals, which means that the
422// user is interested in additional checks at the expense of build time.
423func (c *configImpl) Checkbuild() bool {
424 return c.checkbuild
425}
426
Dan Willemsen8a073a82017-02-04 17:30:44 -0800427func (c *configImpl) Dist() bool {
428 return c.dist
429}
430
Dan Willemsen1e704462016-08-21 15:17:17 -0700431func (c *configImpl) IsVerbose() bool {
432 return c.verbose
433}
434
Dan Willemsene0879fc2017-08-04 15:06:27 -0700435func (c *configImpl) SkipMake() bool {
436 return c.skipMake
437}
438
Dan Willemsen1e704462016-08-21 15:17:17 -0700439func (c *configImpl) TargetProduct() string {
440 if v, ok := c.environ.Get("TARGET_PRODUCT"); ok {
441 return v
442 }
443 panic("TARGET_PRODUCT is not defined")
444}
445
Dan Willemsen02781d52017-05-12 19:28:13 -0700446func (c *configImpl) TargetDevice() string {
447 return c.targetDevice
448}
449
450func (c *configImpl) SetTargetDevice(device string) {
451 c.targetDevice = device
452}
453
454func (c *configImpl) TargetBuildVariant() string {
455 if v, ok := c.environ.Get("TARGET_BUILD_VARIANT"); ok {
456 return v
457 }
458 panic("TARGET_BUILD_VARIANT is not defined")
459}
460
Dan Willemsen1e704462016-08-21 15:17:17 -0700461func (c *configImpl) KatiArgs() []string {
462 return c.katiArgs
463}
464
465func (c *configImpl) Parallel() int {
466 return c.parallel
467}
468
469func (c *configImpl) UseGoma() bool {
470 if v, ok := c.environ.Get("USE_GOMA"); ok {
471 v = strings.TrimSpace(v)
472 if v != "" && v != "false" {
473 return true
474 }
475 }
476 return false
477}
478
Yoshisato Yanagisawa2cb0e5d2019-01-10 10:14:16 +0900479func (c *configImpl) StartGoma() bool {
480 if !c.UseGoma() {
481 return false
482 }
483
484 if v, ok := c.environ.Get("NOSTART_GOMA"); ok {
485 v = strings.TrimSpace(v)
486 if v != "" && v != "false" {
487 return false
488 }
489 }
490 return true
491}
492
Ramy Medhatadf591a2019-07-17 12:30:04 +0000493func (c *configImpl) UseRBE() bool {
494 if v, ok := c.environ.Get("USE_RBE"); ok {
495 v = strings.TrimSpace(v)
496 if v != "" && v != "false" {
497 return true
498 }
499 }
500 return false
501}
502
Ramy Medhat4807a1b2020-01-27 14:19:44 -0500503func (c *configImpl) UseRBEJAVAC() bool {
504 if !c.UseRBE() {
505 return false
506 }
507
508 if v, ok := c.environ.Get("RBE_JAVAC"); ok {
509 v = strings.TrimSpace(v)
510 if v != "" && v != "false" {
511 return true
512 }
513 }
514 return false
515}
516
517func (c *configImpl) UseRBER8() bool {
518 if !c.UseRBE() {
519 return false
520 }
521
522 if v, ok := c.environ.Get("RBE_R8"); ok {
523 v = strings.TrimSpace(v)
524 if v != "" && v != "false" {
525 return true
526 }
527 }
528 return false
529}
530
531func (c *configImpl) UseRBED8() bool {
532 if !c.UseRBE() {
533 return false
534 }
535
536 if v, ok := c.environ.Get("RBE_D8"); ok {
537 v = strings.TrimSpace(v)
538 if v != "" && v != "false" {
539 return true
540 }
541 }
542 return false
543}
544
Ramy Medhatadf591a2019-07-17 12:30:04 +0000545func (c *configImpl) StartRBE() bool {
546 if !c.UseRBE() {
547 return false
548 }
549
550 if v, ok := c.environ.Get("NOSTART_RBE"); ok {
551 v = strings.TrimSpace(v)
552 if v != "" && v != "false" {
553 return false
554 }
555 }
556 return true
557}
558
Dan Willemsen1e704462016-08-21 15:17:17 -0700559// RemoteParallel controls how many remote jobs (i.e., commands which contain
Jeff Gastonefc1b412017-03-29 17:29:06 -0700560// gomacc) are run in parallel. Note the parallelism of all other jobs is
Dan Willemsen1e704462016-08-21 15:17:17 -0700561// still limited by Parallel()
562func (c *configImpl) RemoteParallel() int {
563 if v, ok := c.environ.Get("NINJA_REMOTE_NUM_JOBS"); ok {
564 if i, err := strconv.Atoi(v); err == nil {
565 return i
566 }
567 }
568 return 500
569}
570
571func (c *configImpl) SetKatiArgs(args []string) {
572 c.katiArgs = args
573}
574
575func (c *configImpl) SetNinjaArgs(args []string) {
576 c.ninjaArgs = args
577}
578
579func (c *configImpl) SetKatiSuffix(suffix string) {
580 c.katiSuffix = suffix
581}
582
Dan Willemsene0879fc2017-08-04 15:06:27 -0700583func (c *configImpl) LastKatiSuffixFile() string {
584 return filepath.Join(c.OutDir(), "last_kati_suffix")
585}
586
587func (c *configImpl) HasKatiSuffix() bool {
588 return c.katiSuffix != ""
589}
590
Dan Willemsen1e704462016-08-21 15:17:17 -0700591func (c *configImpl) KatiEnvFile() string {
592 return filepath.Join(c.OutDir(), "env"+c.KatiSuffix()+".sh")
593}
594
Dan Willemsen29971232018-09-26 14:58:30 -0700595func (c *configImpl) KatiBuildNinjaFile() string {
596 return filepath.Join(c.OutDir(), "build"+c.KatiSuffix()+katiBuildSuffix+".ninja")
Dan Willemsen1e704462016-08-21 15:17:17 -0700597}
598
Dan Willemsenfb1271a2018-09-26 15:00:42 -0700599func (c *configImpl) KatiPackageNinjaFile() string {
600 return filepath.Join(c.OutDir(), "build"+c.KatiSuffix()+katiPackageSuffix+".ninja")
601}
602
Dan Willemsen1e704462016-08-21 15:17:17 -0700603func (c *configImpl) SoongNinjaFile() string {
604 return filepath.Join(c.SoongOutDir(), "build.ninja")
605}
606
607func (c *configImpl) CombinedNinjaFile() string {
Dan Willemsene0879fc2017-08-04 15:06:27 -0700608 if c.katiSuffix == "" {
609 return filepath.Join(c.OutDir(), "combined.ninja")
610 }
Dan Willemsen1e704462016-08-21 15:17:17 -0700611 return filepath.Join(c.OutDir(), "combined"+c.KatiSuffix()+".ninja")
612}
613
614func (c *configImpl) SoongAndroidMk() string {
615 return filepath.Join(c.SoongOutDir(), "Android-"+c.TargetProduct()+".mk")
616}
617
618func (c *configImpl) SoongMakeVarsMk() string {
619 return filepath.Join(c.SoongOutDir(), "make_vars-"+c.TargetProduct()+".mk")
620}
621
Dan Willemsenf052f782017-05-18 15:29:04 -0700622func (c *configImpl) ProductOut() string {
Dan Willemsen4dc4e142017-09-08 14:35:43 -0700623 return filepath.Join(c.OutDir(), "target", "product", c.TargetDevice())
Dan Willemsenf052f782017-05-18 15:29:04 -0700624}
625
Dan Willemsen02781d52017-05-12 19:28:13 -0700626func (c *configImpl) DevicePreviousProductConfig() string {
Dan Willemsenf052f782017-05-18 15:29:04 -0700627 return filepath.Join(c.ProductOut(), "previous_build_config.mk")
628}
629
Dan Willemsenfb1271a2018-09-26 15:00:42 -0700630func (c *configImpl) KatiPackageMkDir() string {
631 return filepath.Join(c.ProductOut(), "obj", "CONFIG", "kati_packaging")
632}
633
Dan Willemsenf052f782017-05-18 15:29:04 -0700634func (c *configImpl) hostOutRoot() string {
Dan Willemsen4dc4e142017-09-08 14:35:43 -0700635 return filepath.Join(c.OutDir(), "host")
Dan Willemsenf052f782017-05-18 15:29:04 -0700636}
637
638func (c *configImpl) HostOut() string {
639 return filepath.Join(c.hostOutRoot(), c.HostPrebuiltTag())
640}
641
642// This probably needs to be multi-valued, so not exporting it for now
643func (c *configImpl) hostCrossOut() string {
644 if runtime.GOOS == "linux" {
645 return filepath.Join(c.hostOutRoot(), "windows-x86")
646 } else {
647 return ""
648 }
Dan Willemsen02781d52017-05-12 19:28:13 -0700649}
650
Dan Willemsen1e704462016-08-21 15:17:17 -0700651func (c *configImpl) HostPrebuiltTag() string {
652 if runtime.GOOS == "linux" {
653 return "linux-x86"
654 } else if runtime.GOOS == "darwin" {
655 return "darwin-x86"
656 } else {
657 panic("Unsupported OS")
658 }
659}
Dan Willemsenf173d592017-04-27 14:28:00 -0700660
Dan Willemsen8122bd52017-10-12 20:20:41 -0700661func (c *configImpl) PrebuiltBuildTool(name string) string {
Dan Willemsenf173d592017-04-27 14:28:00 -0700662 if v, ok := c.environ.Get("SANITIZE_HOST"); ok {
663 if sanitize := strings.Fields(v); inList("address", sanitize) {
Dan Willemsen8122bd52017-10-12 20:20:41 -0700664 asan := filepath.Join("prebuilts/build-tools", c.HostPrebuiltTag(), "asan/bin", name)
665 if _, err := os.Stat(asan); err == nil {
666 return asan
667 }
Dan Willemsenf173d592017-04-27 14:28:00 -0700668 }
669 }
670 return filepath.Join("prebuilts/build-tools", c.HostPrebuiltTag(), "bin", name)
671}
Dan Willemsen3d60b112018-04-04 22:25:56 -0700672
673func (c *configImpl) SetBuildBrokenDupRules(val bool) {
674 c.brokenDupRules = val
675}
676
677func (c *configImpl) BuildBrokenDupRules() bool {
678 return c.brokenDupRules
679}
Dan Willemsen6ab79db2018-05-02 00:06:28 -0700680
Dan Willemsend8aa39d2018-08-27 15:01:03 -0700681func (c *configImpl) SetBuildBrokenPhonyTargets(val bool) {
682 c.brokenPhonyTargets = val
683}
684
685func (c *configImpl) BuildBrokenPhonyTargets() bool {
686 return c.brokenPhonyTargets
687}
688
Dan Willemsen47946562019-04-09 10:22:43 -0700689func (c *configImpl) SetBuildBrokenUsesNetwork(val bool) {
690 c.brokenUsesNetwork = val
691}
692
693func (c *configImpl) BuildBrokenUsesNetwork() bool {
694 return c.brokenUsesNetwork
695}
696
Dan Willemsen6ab79db2018-05-02 00:06:28 -0700697func (c *configImpl) SetTargetDeviceDir(dir string) {
698 c.targetDeviceDir = dir
699}
700
701func (c *configImpl) TargetDeviceDir() string {
702 return c.targetDeviceDir
703}
Dan Willemsenfa42f3c2018-06-15 21:54:47 -0700704
705func (c *configImpl) SetPdkBuild(pdk bool) {
706 c.pdkBuild = pdk
707}
708
709func (c *configImpl) IsPdkBuild() bool {
710 return c.pdkBuild
711}
Patrice Arrudad519a712020-06-01 17:29:30 +0000712
713func (c *configImpl) MetricsUploaderApp() string {
714 if p, ok := c.environ.Get("ANDROID_ENABLE_METRICS_UPLOAD"); ok {
715 return p
716 }
717 return ""
718}