blob: 2605f5b5e7e1fae5a324be35887148b2324fdd39 [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
37
38 // From the arguments
Colin Cross37193492017-11-16 17:55:00 -080039 parallel int
40 keepGoing int
41 verbose bool
42 checkbuild bool
43 dist bool
44 skipMake bool
Dan Willemsen1e704462016-08-21 15:17:17 -070045
46 // From the product config
Dan Willemsen6ab79db2018-05-02 00:06:28 -070047 katiArgs []string
48 ninjaArgs []string
49 katiSuffix string
50 targetDevice string
51 targetDeviceDir string
Dan Willemsen3d60b112018-04-04 22:25:56 -070052
Dan Willemsend8aa39d2018-08-27 15:01:03 -070053 pdkBuild bool
54
55 brokenDupRules bool
56 brokenPhonyTargets bool
Dan Willemsen18490112018-05-25 16:30:04 -070057
58 pathReplaced bool
Dan Willemsen1e704462016-08-21 15:17:17 -070059}
60
Dan Willemsenc2af0be2017-01-20 14:10:01 -080061const srcDirFileCheck = "build/soong/root.bp"
62
Dan Willemsen1e704462016-08-21 15:17:17 -070063func NewConfig(ctx Context, args ...string) Config {
64 ret := &configImpl{
65 environ: OsEnvironment(),
66 }
67
Dan Willemsen9b587492017-07-10 22:13:00 -070068 // Sane default matching ninja
69 ret.parallel = runtime.NumCPU() + 2
70 ret.keepGoing = 1
71
72 ret.parseArgs(ctx, args)
73
Dan Willemsen0c3919e2017-03-02 15:49:10 -080074 // Make sure OUT_DIR is set appropriately
Dan Willemsen02f3add2017-05-12 13:50:19 -070075 if outDir, ok := ret.environ.Get("OUT_DIR"); ok {
76 ret.environ.Set("OUT_DIR", filepath.Clean(outDir))
77 } else {
Dan Willemsen0c3919e2017-03-02 15:49:10 -080078 outDir := "out"
79 if baseDir, ok := ret.environ.Get("OUT_DIR_COMMON_BASE"); ok {
80 if wd, err := os.Getwd(); err != nil {
81 ctx.Fatalln("Failed to get working directory:", err)
82 } else {
83 outDir = filepath.Join(baseDir, filepath.Base(wd))
84 }
85 }
86 ret.environ.Set("OUT_DIR", outDir)
87 }
88
Dan Willemsen1e704462016-08-21 15:17:17 -070089 ret.environ.Unset(
90 // We're already using it
91 "USE_SOONG_UI",
92
93 // We should never use GOROOT/GOPATH from the shell environment
94 "GOROOT",
95 "GOPATH",
96
97 // These should only come from Soong, not the environment.
98 "CLANG",
99 "CLANG_CXX",
100 "CCC_CC",
101 "CCC_CXX",
102
103 // Used by the goma compiler wrapper, but should only be set by
104 // gomacc
105 "GOMACC_PATH",
Dan Willemsen0c3919e2017-03-02 15:49:10 -0800106
107 // We handle this above
108 "OUT_DIR_COMMON_BASE",
Dan Willemsen68a09852017-04-18 13:56:57 -0700109
110 // Variables that have caused problems in the past
Dan Willemsenebfe33a2018-05-01 10:07:50 -0700111 "CDPATH",
Dan Willemsen68a09852017-04-18 13:56:57 -0700112 "DISPLAY",
113 "GREP_OPTIONS",
Dan Willemsenebfe33a2018-05-01 10:07:50 -0700114 "NDK_ROOT",
Dan Willemsen00fcb262018-08-15 15:35:38 -0700115 "POSIXLY_CORRECT",
Dan Willemsenc40e10b2017-07-11 14:30:00 -0700116
117 // Drop make flags
118 "MAKEFLAGS",
119 "MAKELEVEL",
120 "MFLAGS",
Dan Willemsend9e8f0a2017-10-30 13:42:06 -0700121
122 // Set in envsetup.sh, reset in makefiles
123 "ANDROID_JAVA_TOOLCHAIN",
Colin Cross7f09c402018-07-11 14:49:31 -0700124
125 // Set by envsetup.sh, but shouldn't be used inside the build because envsetup.sh is optional
126 "ANDROID_BUILD_TOP",
127 "ANDROID_HOST_OUT",
128 "ANDROID_PRODUCT_OUT",
129 "ANDROID_HOST_OUT_TESTCASES",
130 "ANDROID_TARGET_OUT_TESTCASES",
131 "ANDROID_TOOLCHAIN",
132 "ANDROID_TOOLCHAIN_2ND_ARCH",
133 "ANDROID_DEV_SCRIPTS",
134 "ANDROID_EMULATOR_PREBUILTS",
135 "ANDROID_PRE_BUILD_PATHS",
Dan Willemsen1e704462016-08-21 15:17:17 -0700136 )
137
138 // Tell python not to spam the source tree with .pyc files.
139 ret.environ.Set("PYTHONDONTWRITEBYTECODE", "1")
140
Dan Willemsen32a669b2018-03-08 19:42:00 -0800141 ret.environ.Set("TMPDIR", absPath(ctx, ret.TempDir()))
142
Dan Willemsenc2af0be2017-01-20 14:10:01 -0800143 // Precondition: the current directory is the top of the source tree
144 if _, err := os.Stat(srcDirFileCheck); err != nil {
145 if os.IsNotExist(err) {
146 log.Fatalf("Current working directory must be the source tree. %q not found", srcDirFileCheck)
147 }
148 log.Fatalln("Error verifying tree state:", err)
149 }
150
Dan Willemsend9e8f0a2017-10-30 13:42:06 -0700151 if srcDir := absPath(ctx, "."); strings.ContainsRune(srcDir, ' ') {
152 log.Println("You are building in a directory whose absolute path contains a space character:")
153 log.Println()
154 log.Printf("%q\n", srcDir)
155 log.Println()
156 log.Fatalln("Directory names containing spaces are not supported")
Dan Willemsendb8457c2017-05-12 16:38:17 -0700157 }
158
159 if outDir := ret.OutDir(); strings.ContainsRune(outDir, ' ') {
160 log.Println("The absolute path of your output directory ($OUT_DIR) contains a space character:")
161 log.Println()
162 log.Printf("%q\n", outDir)
163 log.Println()
164 log.Fatalln("Directory names containing spaces are not supported")
165 }
166
167 if distDir := ret.DistDir(); strings.ContainsRune(distDir, ' ') {
168 log.Println("The absolute path of your dist directory ($DIST_DIR) contains a space character:")
169 log.Println()
170 log.Printf("%q\n", distDir)
171 log.Println()
172 log.Fatalln("Directory names containing spaces are not supported")
173 }
174
Dan Willemsend9e8f0a2017-10-30 13:42:06 -0700175 // Configure Java-related variables, including adding it to $PATH
Tobias Thierere59aeff2017-12-20 22:40:39 +0000176 java8Home := filepath.Join("prebuilts/jdk/jdk8", ret.HostPrebuiltTag())
177 java9Home := filepath.Join("prebuilts/jdk/jdk9", ret.HostPrebuiltTag())
Dan Willemsend9e8f0a2017-10-30 13:42:06 -0700178 javaHome := func() string {
179 if override, ok := ret.environ.Get("OVERRIDE_ANDROID_JAVA_HOME"); ok {
180 return override
181 }
Colin Cross997262f2018-06-19 22:49:39 -0700182 return java9Home
Dan Willemsend9e8f0a2017-10-30 13:42:06 -0700183 }()
184 absJavaHome := absPath(ctx, javaHome)
185
Dan Willemsened869522018-01-08 14:58:46 -0800186 ret.configureLocale(ctx)
187
Dan Willemsend9e8f0a2017-10-30 13:42:06 -0700188 newPath := []string{filepath.Join(absJavaHome, "bin")}
189 if path, ok := ret.environ.Get("PATH"); ok && path != "" {
190 newPath = append(newPath, path)
191 }
192 ret.environ.Unset("OVERRIDE_ANDROID_JAVA_HOME")
193 ret.environ.Set("JAVA_HOME", absJavaHome)
194 ret.environ.Set("ANDROID_JAVA_HOME", javaHome)
Tobias Thierere59aeff2017-12-20 22:40:39 +0000195 ret.environ.Set("ANDROID_JAVA8_HOME", java8Home)
196 ret.environ.Set("ANDROID_JAVA9_HOME", java9Home)
Dan Willemsend9e8f0a2017-10-30 13:42:06 -0700197 ret.environ.Set("PATH", strings.Join(newPath, string(filepath.ListSeparator)))
198
Nan Zhang2e6a4ff2018-02-14 13:27:26 -0800199 outDir := ret.OutDir()
200 buildDateTimeFile := filepath.Join(outDir, "build_date.txt")
201 var content string
202 if buildDateTime, ok := ret.environ.Get("BUILD_DATETIME"); ok && buildDateTime != "" {
203 content = buildDateTime
204 } else {
205 content = strconv.FormatInt(time.Now().Unix(), 10)
206 }
207 err := ioutil.WriteFile(buildDateTimeFile, []byte(content), 0777)
208 if err != nil {
209 ctx.Fatalln("Failed to write BUILD_DATETIME to file:", err)
210 }
211 ret.environ.Set("BUILD_DATETIME_FILE", buildDateTimeFile)
212
Dan Willemsen9b587492017-07-10 22:13:00 -0700213 return Config{ret}
214}
215
216func (c *configImpl) parseArgs(ctx Context, args []string) {
217 for i := 0; i < len(args); i++ {
218 arg := strings.TrimSpace(args[i])
Dan Willemsen1e704462016-08-21 15:17:17 -0700219 if arg == "--make-mode" {
Dan Willemsen1e704462016-08-21 15:17:17 -0700220 } else if arg == "showcommands" {
Dan Willemsen9b587492017-07-10 22:13:00 -0700221 c.verbose = true
Dan Willemsene0879fc2017-08-04 15:06:27 -0700222 } else if arg == "--skip-make" {
223 c.skipMake = true
Dan Willemsen6ac63ef2017-10-17 20:35:34 -0700224 } else if len(arg) > 0 && arg[0] == '-' {
Dan Willemsen9b587492017-07-10 22:13:00 -0700225 parseArgNum := func(def int) int {
226 if len(arg) > 2 {
227 p, err := strconv.ParseUint(arg[2:], 10, 31)
228 if err != nil {
229 ctx.Fatalf("Failed to parse %q: %v", arg, err)
230 }
231 return int(p)
232 } else if i+1 < len(args) {
233 p, err := strconv.ParseUint(args[i+1], 10, 31)
234 if err == nil {
235 i++
236 return int(p)
237 }
238 }
239 return def
240 }
241
Dan Willemsen6ac63ef2017-10-17 20:35:34 -0700242 if len(arg) > 1 && arg[1] == 'j' {
Dan Willemsen9b587492017-07-10 22:13:00 -0700243 c.parallel = parseArgNum(c.parallel)
Dan Willemsen6ac63ef2017-10-17 20:35:34 -0700244 } else if len(arg) > 1 && arg[1] == 'k' {
Dan Willemsen9b587492017-07-10 22:13:00 -0700245 c.keepGoing = parseArgNum(0)
Dan Willemsen1e704462016-08-21 15:17:17 -0700246 } else {
247 ctx.Fatalln("Unknown option:", arg)
248 }
Dan Willemsen091525e2017-07-11 14:17:50 -0700249 } else if k, v, ok := decodeKeyValue(arg); ok && len(k) > 0 {
250 c.environ.Set(k, v)
Dan Willemsen1e704462016-08-21 15:17:17 -0700251 } else {
Dan Willemsene0879fc2017-08-04 15:06:27 -0700252 if arg == "dist" {
253 c.dist = true
Colin Cross37193492017-11-16 17:55:00 -0800254 } else if arg == "checkbuild" {
255 c.checkbuild = true
Dan Willemsene0879fc2017-08-04 15:06:27 -0700256 }
Dan Willemsen9b587492017-07-10 22:13:00 -0700257 c.arguments = append(c.arguments, arg)
Dan Willemsen1e704462016-08-21 15:17:17 -0700258 }
259 }
Dan Willemsen1e704462016-08-21 15:17:17 -0700260}
261
Dan Willemsened869522018-01-08 14:58:46 -0800262func (c *configImpl) configureLocale(ctx Context) {
263 cmd := Command(ctx, Config{c}, "locale", "locale", "-a")
264 output, err := cmd.Output()
265
266 var locales []string
267 if err == nil {
268 locales = strings.Split(string(output), "\n")
269 } else {
270 // If we're unable to list the locales, let's assume en_US.UTF-8
271 locales = []string{"en_US.UTF-8"}
272 ctx.Verbosef("Failed to list locales (%q), falling back to %q", err, locales)
273 }
274
275 // gettext uses LANGUAGE, which is passed directly through
276
277 // For LANG and LC_*, only preserve the evaluated version of
278 // LC_MESSAGES
279 user_lang := ""
280 if lc_all, ok := c.environ.Get("LC_ALL"); ok {
281 user_lang = lc_all
282 } else if lc_messages, ok := c.environ.Get("LC_MESSAGES"); ok {
283 user_lang = lc_messages
284 } else if lang, ok := c.environ.Get("LANG"); ok {
285 user_lang = lang
286 }
287
288 c.environ.UnsetWithPrefix("LC_")
289
290 if user_lang != "" {
291 c.environ.Set("LC_MESSAGES", user_lang)
292 }
293
294 // The for LANG, use C.UTF-8 if it exists (Debian currently, proposed
295 // for others)
296 if inList("C.UTF-8", locales) {
297 c.environ.Set("LANG", "C.UTF-8")
Aaron Klingd236e0e2018-08-07 19:21:36 -0500298 } else if inList("C.utf8", locales) {
299 // These normalize to the same thing
300 c.environ.Set("LANG", "C.UTF-8")
Dan Willemsened869522018-01-08 14:58:46 -0800301 } else if inList("en_US.UTF-8", locales) {
302 c.environ.Set("LANG", "en_US.UTF-8")
303 } else if inList("en_US.utf8", locales) {
304 // These normalize to the same thing
305 c.environ.Set("LANG", "en_US.UTF-8")
306 } else {
307 ctx.Fatalln("System doesn't support either C.UTF-8 or en_US.UTF-8")
308 }
309}
310
Dan Willemsen1e704462016-08-21 15:17:17 -0700311// Lunch configures the environment for a specific product similarly to the
312// `lunch` bash function.
313func (c *configImpl) Lunch(ctx Context, product, variant string) {
314 if variant != "eng" && variant != "userdebug" && variant != "user" {
315 ctx.Fatalf("Invalid variant %q. Must be one of 'user', 'userdebug' or 'eng'", variant)
316 }
317
318 c.environ.Set("TARGET_PRODUCT", product)
319 c.environ.Set("TARGET_BUILD_VARIANT", variant)
320 c.environ.Set("TARGET_BUILD_TYPE", "release")
321 c.environ.Unset("TARGET_BUILD_APPS")
322}
323
324// Tapas configures the environment to build one or more unbundled apps,
325// similarly to the `tapas` bash function.
326func (c *configImpl) Tapas(ctx Context, apps []string, arch, variant string) {
327 if len(apps) == 0 {
328 apps = []string{"all"}
329 }
330 if variant == "" {
331 variant = "eng"
332 }
333
334 if variant != "eng" && variant != "userdebug" && variant != "user" {
335 ctx.Fatalf("Invalid variant %q. Must be one of 'user', 'userdebug' or 'eng'", variant)
336 }
337
338 var product string
339 switch arch {
Dan Willemsen1e704462016-08-21 15:17:17 -0700340 case "arm", "":
341 product = "aosp_arm"
342 case "arm64":
343 product = "aosm_arm64"
344 case "mips":
345 product = "aosp_mips"
346 case "mips64":
347 product = "aosp_mips64"
348 case "x86":
349 product = "aosp_x86"
350 case "x86_64":
351 product = "aosp_x86_64"
352 default:
353 ctx.Fatalf("Invalid architecture: %q", arch)
354 }
355
356 c.environ.Set("TARGET_PRODUCT", product)
357 c.environ.Set("TARGET_BUILD_VARIANT", variant)
358 c.environ.Set("TARGET_BUILD_TYPE", "release")
359 c.environ.Set("TARGET_BUILD_APPS", strings.Join(apps, " "))
360}
361
362func (c *configImpl) Environment() *Environment {
363 return c.environ
364}
365
366func (c *configImpl) Arguments() []string {
367 return c.arguments
368}
369
370func (c *configImpl) OutDir() string {
371 if outDir, ok := c.environ.Get("OUT_DIR"); ok {
372 return outDir
373 }
374 return "out"
375}
376
Dan Willemsen8a073a82017-02-04 17:30:44 -0800377func (c *configImpl) DistDir() string {
378 if distDir, ok := c.environ.Get("DIST_DIR"); ok {
379 return distDir
380 }
381 return filepath.Join(c.OutDir(), "dist")
382}
383
Dan Willemsen1e704462016-08-21 15:17:17 -0700384func (c *configImpl) NinjaArgs() []string {
Dan Willemsene0879fc2017-08-04 15:06:27 -0700385 if c.skipMake {
386 return c.arguments
387 }
Dan Willemsen1e704462016-08-21 15:17:17 -0700388 return c.ninjaArgs
389}
390
391func (c *configImpl) SoongOutDir() string {
392 return filepath.Join(c.OutDir(), "soong")
393}
394
Jeff Gastonefc1b412017-03-29 17:29:06 -0700395func (c *configImpl) TempDir() string {
396 return shared.TempDirForOutDir(c.SoongOutDir())
397}
398
Jeff Gastonb64fc1c2017-08-04 12:30:12 -0700399func (c *configImpl) FileListDir() string {
400 return filepath.Join(c.OutDir(), ".module_paths")
401}
402
Dan Willemsen1e704462016-08-21 15:17:17 -0700403func (c *configImpl) KatiSuffix() string {
404 if c.katiSuffix != "" {
405 return c.katiSuffix
406 }
407 panic("SetKatiSuffix has not been called")
408}
409
Colin Cross37193492017-11-16 17:55:00 -0800410// Checkbuild returns true if "checkbuild" was one of the build goals, which means that the
411// user is interested in additional checks at the expense of build time.
412func (c *configImpl) Checkbuild() bool {
413 return c.checkbuild
414}
415
Dan Willemsen8a073a82017-02-04 17:30:44 -0800416func (c *configImpl) Dist() bool {
417 return c.dist
418}
419
Dan Willemsen1e704462016-08-21 15:17:17 -0700420func (c *configImpl) IsVerbose() bool {
421 return c.verbose
422}
423
Dan Willemsene0879fc2017-08-04 15:06:27 -0700424func (c *configImpl) SkipMake() bool {
425 return c.skipMake
426}
427
Dan Willemsen1e704462016-08-21 15:17:17 -0700428func (c *configImpl) TargetProduct() string {
429 if v, ok := c.environ.Get("TARGET_PRODUCT"); ok {
430 return v
431 }
432 panic("TARGET_PRODUCT is not defined")
433}
434
Dan Willemsen02781d52017-05-12 19:28:13 -0700435func (c *configImpl) TargetDevice() string {
436 return c.targetDevice
437}
438
439func (c *configImpl) SetTargetDevice(device string) {
440 c.targetDevice = device
441}
442
443func (c *configImpl) TargetBuildVariant() string {
444 if v, ok := c.environ.Get("TARGET_BUILD_VARIANT"); ok {
445 return v
446 }
447 panic("TARGET_BUILD_VARIANT is not defined")
448}
449
Dan Willemsen1e704462016-08-21 15:17:17 -0700450func (c *configImpl) KatiArgs() []string {
451 return c.katiArgs
452}
453
454func (c *configImpl) Parallel() int {
455 return c.parallel
456}
457
458func (c *configImpl) UseGoma() bool {
459 if v, ok := c.environ.Get("USE_GOMA"); ok {
460 v = strings.TrimSpace(v)
461 if v != "" && v != "false" {
462 return true
463 }
464 }
465 return false
466}
467
468// RemoteParallel controls how many remote jobs (i.e., commands which contain
Jeff Gastonefc1b412017-03-29 17:29:06 -0700469// gomacc) are run in parallel. Note the parallelism of all other jobs is
Dan Willemsen1e704462016-08-21 15:17:17 -0700470// still limited by Parallel()
471func (c *configImpl) RemoteParallel() int {
472 if v, ok := c.environ.Get("NINJA_REMOTE_NUM_JOBS"); ok {
473 if i, err := strconv.Atoi(v); err == nil {
474 return i
475 }
476 }
477 return 500
478}
479
480func (c *configImpl) SetKatiArgs(args []string) {
481 c.katiArgs = args
482}
483
484func (c *configImpl) SetNinjaArgs(args []string) {
485 c.ninjaArgs = args
486}
487
488func (c *configImpl) SetKatiSuffix(suffix string) {
489 c.katiSuffix = suffix
490}
491
Dan Willemsene0879fc2017-08-04 15:06:27 -0700492func (c *configImpl) LastKatiSuffixFile() string {
493 return filepath.Join(c.OutDir(), "last_kati_suffix")
494}
495
496func (c *configImpl) HasKatiSuffix() bool {
497 return c.katiSuffix != ""
498}
499
Dan Willemsen1e704462016-08-21 15:17:17 -0700500func (c *configImpl) KatiEnvFile() string {
501 return filepath.Join(c.OutDir(), "env"+c.KatiSuffix()+".sh")
502}
503
504func (c *configImpl) KatiNinjaFile() string {
505 return filepath.Join(c.OutDir(), "build"+c.KatiSuffix()+".ninja")
506}
507
508func (c *configImpl) SoongNinjaFile() string {
509 return filepath.Join(c.SoongOutDir(), "build.ninja")
510}
511
512func (c *configImpl) CombinedNinjaFile() string {
Dan Willemsene0879fc2017-08-04 15:06:27 -0700513 if c.katiSuffix == "" {
514 return filepath.Join(c.OutDir(), "combined.ninja")
515 }
Dan Willemsen1e704462016-08-21 15:17:17 -0700516 return filepath.Join(c.OutDir(), "combined"+c.KatiSuffix()+".ninja")
517}
518
519func (c *configImpl) SoongAndroidMk() string {
520 return filepath.Join(c.SoongOutDir(), "Android-"+c.TargetProduct()+".mk")
521}
522
523func (c *configImpl) SoongMakeVarsMk() string {
524 return filepath.Join(c.SoongOutDir(), "make_vars-"+c.TargetProduct()+".mk")
525}
526
Dan Willemsenf052f782017-05-18 15:29:04 -0700527func (c *configImpl) ProductOut() string {
Dan Willemsen4dc4e142017-09-08 14:35:43 -0700528 return filepath.Join(c.OutDir(), "target", "product", c.TargetDevice())
Dan Willemsenf052f782017-05-18 15:29:04 -0700529}
530
Dan Willemsen02781d52017-05-12 19:28:13 -0700531func (c *configImpl) DevicePreviousProductConfig() string {
Dan Willemsenf052f782017-05-18 15:29:04 -0700532 return filepath.Join(c.ProductOut(), "previous_build_config.mk")
533}
534
535func (c *configImpl) hostOutRoot() string {
Dan Willemsen4dc4e142017-09-08 14:35:43 -0700536 return filepath.Join(c.OutDir(), "host")
Dan Willemsenf052f782017-05-18 15:29:04 -0700537}
538
539func (c *configImpl) HostOut() string {
540 return filepath.Join(c.hostOutRoot(), c.HostPrebuiltTag())
541}
542
543// This probably needs to be multi-valued, so not exporting it for now
544func (c *configImpl) hostCrossOut() string {
545 if runtime.GOOS == "linux" {
546 return filepath.Join(c.hostOutRoot(), "windows-x86")
547 } else {
548 return ""
549 }
Dan Willemsen02781d52017-05-12 19:28:13 -0700550}
551
Dan Willemsen1e704462016-08-21 15:17:17 -0700552func (c *configImpl) HostPrebuiltTag() string {
553 if runtime.GOOS == "linux" {
554 return "linux-x86"
555 } else if runtime.GOOS == "darwin" {
556 return "darwin-x86"
557 } else {
558 panic("Unsupported OS")
559 }
560}
Dan Willemsenf173d592017-04-27 14:28:00 -0700561
Dan Willemsen8122bd52017-10-12 20:20:41 -0700562func (c *configImpl) PrebuiltBuildTool(name string) string {
Dan Willemsenf173d592017-04-27 14:28:00 -0700563 if v, ok := c.environ.Get("SANITIZE_HOST"); ok {
564 if sanitize := strings.Fields(v); inList("address", sanitize) {
Dan Willemsen8122bd52017-10-12 20:20:41 -0700565 asan := filepath.Join("prebuilts/build-tools", c.HostPrebuiltTag(), "asan/bin", name)
566 if _, err := os.Stat(asan); err == nil {
567 return asan
568 }
Dan Willemsenf173d592017-04-27 14:28:00 -0700569 }
570 }
571 return filepath.Join("prebuilts/build-tools", c.HostPrebuiltTag(), "bin", name)
572}
Dan Willemsen3d60b112018-04-04 22:25:56 -0700573
574func (c *configImpl) SetBuildBrokenDupRules(val bool) {
575 c.brokenDupRules = val
576}
577
578func (c *configImpl) BuildBrokenDupRules() bool {
579 return c.brokenDupRules
580}
Dan Willemsen6ab79db2018-05-02 00:06:28 -0700581
Dan Willemsend8aa39d2018-08-27 15:01:03 -0700582func (c *configImpl) SetBuildBrokenPhonyTargets(val bool) {
583 c.brokenPhonyTargets = val
584}
585
586func (c *configImpl) BuildBrokenPhonyTargets() bool {
587 return c.brokenPhonyTargets
588}
589
Dan Willemsen6ab79db2018-05-02 00:06:28 -0700590func (c *configImpl) SetTargetDeviceDir(dir string) {
591 c.targetDeviceDir = dir
592}
593
594func (c *configImpl) TargetDeviceDir() string {
595 return c.targetDeviceDir
596}
Dan Willemsenfa42f3c2018-06-15 21:54:47 -0700597
598func (c *configImpl) SetPdkBuild(pdk bool) {
599 c.pdkBuild = pdk
600}
601
602func (c *configImpl) IsPdkBuild() bool {
603 return c.pdkBuild
604}