blob: 840f505b5f9397aa7be9718495bd2e7d91b0b035 [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 Willemsen18490112018-05-25 16:30:04 -070058
59 pathReplaced bool
Dan Willemsen1e704462016-08-21 15:17:17 -070060}
61
Dan Willemsenc2af0be2017-01-20 14:10:01 -080062const srcDirFileCheck = "build/soong/root.bp"
63
Dan Willemsen1e704462016-08-21 15:17:17 -070064func NewConfig(ctx Context, args ...string) Config {
65 ret := &configImpl{
66 environ: OsEnvironment(),
67 }
68
Dan Willemsen9b587492017-07-10 22:13:00 -070069 // Sane default matching ninja
70 ret.parallel = runtime.NumCPU() + 2
71 ret.keepGoing = 1
72
73 ret.parseArgs(ctx, args)
74
Dan Willemsen0c3919e2017-03-02 15:49:10 -080075 // Make sure OUT_DIR is set appropriately
Dan Willemsen02f3add2017-05-12 13:50:19 -070076 if outDir, ok := ret.environ.Get("OUT_DIR"); ok {
77 ret.environ.Set("OUT_DIR", filepath.Clean(outDir))
78 } else {
Dan Willemsen0c3919e2017-03-02 15:49:10 -080079 outDir := "out"
80 if baseDir, ok := ret.environ.Get("OUT_DIR_COMMON_BASE"); ok {
81 if wd, err := os.Getwd(); err != nil {
82 ctx.Fatalln("Failed to get working directory:", err)
83 } else {
84 outDir = filepath.Join(baseDir, filepath.Base(wd))
85 }
86 }
87 ret.environ.Set("OUT_DIR", outDir)
88 }
89
Dan Willemsen2d31a442018-10-20 21:33:41 -070090 if distDir, ok := ret.environ.Get("DIST_DIR"); ok {
91 ret.distDir = filepath.Clean(distDir)
92 } else {
93 ret.distDir = filepath.Join(ret.OutDir(), "dist")
94 }
Dan Willemsend50e89f2018-10-16 17:49:25 -070095
Dan Willemsen1e704462016-08-21 15:17:17 -070096 ret.environ.Unset(
97 // We're already using it
98 "USE_SOONG_UI",
99
100 // We should never use GOROOT/GOPATH from the shell environment
101 "GOROOT",
102 "GOPATH",
103
104 // These should only come from Soong, not the environment.
105 "CLANG",
106 "CLANG_CXX",
107 "CCC_CC",
108 "CCC_CXX",
109
110 // Used by the goma compiler wrapper, but should only be set by
111 // gomacc
112 "GOMACC_PATH",
Dan Willemsen0c3919e2017-03-02 15:49:10 -0800113
114 // We handle this above
115 "OUT_DIR_COMMON_BASE",
Dan Willemsen68a09852017-04-18 13:56:57 -0700116
Dan Willemsen2d31a442018-10-20 21:33:41 -0700117 // This is handled above too, and set for individual commands later
118 "DIST_DIR",
119
Dan Willemsen68a09852017-04-18 13:56:57 -0700120 // Variables that have caused problems in the past
Dan Willemsenebfe33a2018-05-01 10:07:50 -0700121 "CDPATH",
Dan Willemsen68a09852017-04-18 13:56:57 -0700122 "DISPLAY",
123 "GREP_OPTIONS",
Dan Willemsenebfe33a2018-05-01 10:07:50 -0700124 "NDK_ROOT",
Dan Willemsen00fcb262018-08-15 15:35:38 -0700125 "POSIXLY_CORRECT",
Dan Willemsenc40e10b2017-07-11 14:30:00 -0700126
127 // Drop make flags
128 "MAKEFLAGS",
129 "MAKELEVEL",
130 "MFLAGS",
Dan Willemsend9e8f0a2017-10-30 13:42:06 -0700131
132 // Set in envsetup.sh, reset in makefiles
133 "ANDROID_JAVA_TOOLCHAIN",
Colin Cross7f09c402018-07-11 14:49:31 -0700134
135 // Set by envsetup.sh, but shouldn't be used inside the build because envsetup.sh is optional
136 "ANDROID_BUILD_TOP",
137 "ANDROID_HOST_OUT",
138 "ANDROID_PRODUCT_OUT",
139 "ANDROID_HOST_OUT_TESTCASES",
140 "ANDROID_TARGET_OUT_TESTCASES",
141 "ANDROID_TOOLCHAIN",
142 "ANDROID_TOOLCHAIN_2ND_ARCH",
143 "ANDROID_DEV_SCRIPTS",
144 "ANDROID_EMULATOR_PREBUILTS",
145 "ANDROID_PRE_BUILD_PATHS",
Dan Willemsen1e704462016-08-21 15:17:17 -0700146 )
147
148 // Tell python not to spam the source tree with .pyc files.
149 ret.environ.Set("PYTHONDONTWRITEBYTECODE", "1")
150
Dan Willemsen32a669b2018-03-08 19:42:00 -0800151 ret.environ.Set("TMPDIR", absPath(ctx, ret.TempDir()))
152
Dan Willemsenc2af0be2017-01-20 14:10:01 -0800153 // Precondition: the current directory is the top of the source tree
154 if _, err := os.Stat(srcDirFileCheck); err != nil {
155 if os.IsNotExist(err) {
156 log.Fatalf("Current working directory must be the source tree. %q not found", srcDirFileCheck)
157 }
158 log.Fatalln("Error verifying tree state:", err)
159 }
160
Dan Willemsend9e8f0a2017-10-30 13:42:06 -0700161 if srcDir := absPath(ctx, "."); strings.ContainsRune(srcDir, ' ') {
162 log.Println("You are building in a directory whose absolute path contains a space character:")
163 log.Println()
164 log.Printf("%q\n", srcDir)
165 log.Println()
166 log.Fatalln("Directory names containing spaces are not supported")
Dan Willemsendb8457c2017-05-12 16:38:17 -0700167 }
168
169 if outDir := ret.OutDir(); strings.ContainsRune(outDir, ' ') {
170 log.Println("The absolute path of your output directory ($OUT_DIR) contains a space character:")
171 log.Println()
172 log.Printf("%q\n", outDir)
173 log.Println()
174 log.Fatalln("Directory names containing spaces are not supported")
175 }
176
177 if distDir := ret.DistDir(); strings.ContainsRune(distDir, ' ') {
178 log.Println("The absolute path of your dist directory ($DIST_DIR) contains a space character:")
179 log.Println()
180 log.Printf("%q\n", distDir)
181 log.Println()
182 log.Fatalln("Directory names containing spaces are not supported")
183 }
184
Dan Willemsend9e8f0a2017-10-30 13:42:06 -0700185 // Configure Java-related variables, including adding it to $PATH
Tobias Thierere59aeff2017-12-20 22:40:39 +0000186 java8Home := filepath.Join("prebuilts/jdk/jdk8", ret.HostPrebuiltTag())
187 java9Home := filepath.Join("prebuilts/jdk/jdk9", ret.HostPrebuiltTag())
Dan Willemsend9e8f0a2017-10-30 13:42:06 -0700188 javaHome := func() string {
189 if override, ok := ret.environ.Get("OVERRIDE_ANDROID_JAVA_HOME"); ok {
190 return override
191 }
Colin Cross997262f2018-06-19 22:49:39 -0700192 return java9Home
Dan Willemsend9e8f0a2017-10-30 13:42:06 -0700193 }()
194 absJavaHome := absPath(ctx, javaHome)
195
Dan Willemsened869522018-01-08 14:58:46 -0800196 ret.configureLocale(ctx)
197
Dan Willemsend9e8f0a2017-10-30 13:42:06 -0700198 newPath := []string{filepath.Join(absJavaHome, "bin")}
199 if path, ok := ret.environ.Get("PATH"); ok && path != "" {
200 newPath = append(newPath, path)
201 }
202 ret.environ.Unset("OVERRIDE_ANDROID_JAVA_HOME")
203 ret.environ.Set("JAVA_HOME", absJavaHome)
204 ret.environ.Set("ANDROID_JAVA_HOME", javaHome)
Tobias Thierere59aeff2017-12-20 22:40:39 +0000205 ret.environ.Set("ANDROID_JAVA8_HOME", java8Home)
206 ret.environ.Set("ANDROID_JAVA9_HOME", java9Home)
Dan Willemsend9e8f0a2017-10-30 13:42:06 -0700207 ret.environ.Set("PATH", strings.Join(newPath, string(filepath.ListSeparator)))
208
Nan Zhang2e6a4ff2018-02-14 13:27:26 -0800209 outDir := ret.OutDir()
210 buildDateTimeFile := filepath.Join(outDir, "build_date.txt")
211 var content string
212 if buildDateTime, ok := ret.environ.Get("BUILD_DATETIME"); ok && buildDateTime != "" {
213 content = buildDateTime
214 } else {
215 content = strconv.FormatInt(time.Now().Unix(), 10)
216 }
217 err := ioutil.WriteFile(buildDateTimeFile, []byte(content), 0777)
218 if err != nil {
219 ctx.Fatalln("Failed to write BUILD_DATETIME to file:", err)
220 }
221 ret.environ.Set("BUILD_DATETIME_FILE", buildDateTimeFile)
222
Dan Willemsen9b587492017-07-10 22:13:00 -0700223 return Config{ret}
224}
225
226func (c *configImpl) parseArgs(ctx Context, args []string) {
227 for i := 0; i < len(args); i++ {
228 arg := strings.TrimSpace(args[i])
Dan Willemsen1e704462016-08-21 15:17:17 -0700229 if arg == "--make-mode" {
Dan Willemsen1e704462016-08-21 15:17:17 -0700230 } else if arg == "showcommands" {
Dan Willemsen9b587492017-07-10 22:13:00 -0700231 c.verbose = true
Dan Willemsene0879fc2017-08-04 15:06:27 -0700232 } else if arg == "--skip-make" {
233 c.skipMake = true
Dan Willemsen6ac63ef2017-10-17 20:35:34 -0700234 } else if len(arg) > 0 && arg[0] == '-' {
Dan Willemsen9b587492017-07-10 22:13:00 -0700235 parseArgNum := func(def int) int {
236 if len(arg) > 2 {
237 p, err := strconv.ParseUint(arg[2:], 10, 31)
238 if err != nil {
239 ctx.Fatalf("Failed to parse %q: %v", arg, err)
240 }
241 return int(p)
242 } else if i+1 < len(args) {
243 p, err := strconv.ParseUint(args[i+1], 10, 31)
244 if err == nil {
245 i++
246 return int(p)
247 }
248 }
249 return def
250 }
251
Dan Willemsen6ac63ef2017-10-17 20:35:34 -0700252 if len(arg) > 1 && arg[1] == 'j' {
Dan Willemsen9b587492017-07-10 22:13:00 -0700253 c.parallel = parseArgNum(c.parallel)
Dan Willemsen6ac63ef2017-10-17 20:35:34 -0700254 } else if len(arg) > 1 && arg[1] == 'k' {
Dan Willemsen9b587492017-07-10 22:13:00 -0700255 c.keepGoing = parseArgNum(0)
Dan Willemsen1e704462016-08-21 15:17:17 -0700256 } else {
257 ctx.Fatalln("Unknown option:", arg)
258 }
Dan Willemsen091525e2017-07-11 14:17:50 -0700259 } else if k, v, ok := decodeKeyValue(arg); ok && len(k) > 0 {
260 c.environ.Set(k, v)
Dan Willemsen2d31a442018-10-20 21:33:41 -0700261 } else if arg == "dist" {
262 c.dist = true
Dan Willemsen1e704462016-08-21 15:17:17 -0700263 } else {
Dan Willemsen2d31a442018-10-20 21:33:41 -0700264 if arg == "checkbuild" {
Colin Cross37193492017-11-16 17:55:00 -0800265 c.checkbuild = true
Dan Willemsene0879fc2017-08-04 15:06:27 -0700266 }
Dan Willemsen9b587492017-07-10 22:13:00 -0700267 c.arguments = append(c.arguments, arg)
Dan Willemsen1e704462016-08-21 15:17:17 -0700268 }
269 }
Dan Willemsen1e704462016-08-21 15:17:17 -0700270}
271
Dan Willemsened869522018-01-08 14:58:46 -0800272func (c *configImpl) configureLocale(ctx Context) {
273 cmd := Command(ctx, Config{c}, "locale", "locale", "-a")
274 output, err := cmd.Output()
275
276 var locales []string
277 if err == nil {
278 locales = strings.Split(string(output), "\n")
279 } else {
280 // If we're unable to list the locales, let's assume en_US.UTF-8
281 locales = []string{"en_US.UTF-8"}
282 ctx.Verbosef("Failed to list locales (%q), falling back to %q", err, locales)
283 }
284
285 // gettext uses LANGUAGE, which is passed directly through
286
287 // For LANG and LC_*, only preserve the evaluated version of
288 // LC_MESSAGES
289 user_lang := ""
290 if lc_all, ok := c.environ.Get("LC_ALL"); ok {
291 user_lang = lc_all
292 } else if lc_messages, ok := c.environ.Get("LC_MESSAGES"); ok {
293 user_lang = lc_messages
294 } else if lang, ok := c.environ.Get("LANG"); ok {
295 user_lang = lang
296 }
297
298 c.environ.UnsetWithPrefix("LC_")
299
300 if user_lang != "" {
301 c.environ.Set("LC_MESSAGES", user_lang)
302 }
303
304 // The for LANG, use C.UTF-8 if it exists (Debian currently, proposed
305 // for others)
306 if inList("C.UTF-8", locales) {
307 c.environ.Set("LANG", "C.UTF-8")
Aaron Klingd236e0e2018-08-07 19:21:36 -0500308 } else if inList("C.utf8", locales) {
309 // These normalize to the same thing
310 c.environ.Set("LANG", "C.UTF-8")
Dan Willemsened869522018-01-08 14:58:46 -0800311 } else if inList("en_US.UTF-8", locales) {
312 c.environ.Set("LANG", "en_US.UTF-8")
313 } else if inList("en_US.utf8", locales) {
314 // These normalize to the same thing
315 c.environ.Set("LANG", "en_US.UTF-8")
316 } else {
317 ctx.Fatalln("System doesn't support either C.UTF-8 or en_US.UTF-8")
318 }
319}
320
Dan Willemsen1e704462016-08-21 15:17:17 -0700321// Lunch configures the environment for a specific product similarly to the
322// `lunch` bash function.
323func (c *configImpl) Lunch(ctx Context, product, variant string) {
324 if variant != "eng" && variant != "userdebug" && variant != "user" {
325 ctx.Fatalf("Invalid variant %q. Must be one of 'user', 'userdebug' or 'eng'", variant)
326 }
327
328 c.environ.Set("TARGET_PRODUCT", product)
329 c.environ.Set("TARGET_BUILD_VARIANT", variant)
330 c.environ.Set("TARGET_BUILD_TYPE", "release")
331 c.environ.Unset("TARGET_BUILD_APPS")
332}
333
334// Tapas configures the environment to build one or more unbundled apps,
335// similarly to the `tapas` bash function.
336func (c *configImpl) Tapas(ctx Context, apps []string, arch, variant string) {
337 if len(apps) == 0 {
338 apps = []string{"all"}
339 }
340 if variant == "" {
341 variant = "eng"
342 }
343
344 if variant != "eng" && variant != "userdebug" && variant != "user" {
345 ctx.Fatalf("Invalid variant %q. Must be one of 'user', 'userdebug' or 'eng'", variant)
346 }
347
348 var product string
349 switch arch {
Dan Willemsen1e704462016-08-21 15:17:17 -0700350 case "arm", "":
351 product = "aosp_arm"
352 case "arm64":
353 product = "aosm_arm64"
354 case "mips":
355 product = "aosp_mips"
356 case "mips64":
357 product = "aosp_mips64"
358 case "x86":
359 product = "aosp_x86"
360 case "x86_64":
361 product = "aosp_x86_64"
362 default:
363 ctx.Fatalf("Invalid architecture: %q", arch)
364 }
365
366 c.environ.Set("TARGET_PRODUCT", product)
367 c.environ.Set("TARGET_BUILD_VARIANT", variant)
368 c.environ.Set("TARGET_BUILD_TYPE", "release")
369 c.environ.Set("TARGET_BUILD_APPS", strings.Join(apps, " "))
370}
371
372func (c *configImpl) Environment() *Environment {
373 return c.environ
374}
375
376func (c *configImpl) Arguments() []string {
377 return c.arguments
378}
379
380func (c *configImpl) OutDir() string {
381 if outDir, ok := c.environ.Get("OUT_DIR"); ok {
Dan Willemsen25a56182018-08-31 20:25:32 -0700382 return filepath.Clean(outDir)
Dan Willemsen1e704462016-08-21 15:17:17 -0700383 }
384 return "out"
385}
386
Dan Willemsen8a073a82017-02-04 17:30:44 -0800387func (c *configImpl) DistDir() string {
Dan Willemsen2d31a442018-10-20 21:33:41 -0700388 return c.distDir
Dan Willemsen8a073a82017-02-04 17:30:44 -0800389}
390
Dan Willemsen1e704462016-08-21 15:17:17 -0700391func (c *configImpl) NinjaArgs() []string {
Dan Willemsene0879fc2017-08-04 15:06:27 -0700392 if c.skipMake {
393 return c.arguments
394 }
Dan Willemsen1e704462016-08-21 15:17:17 -0700395 return c.ninjaArgs
396}
397
398func (c *configImpl) SoongOutDir() string {
399 return filepath.Join(c.OutDir(), "soong")
400}
401
Jeff Gastonefc1b412017-03-29 17:29:06 -0700402func (c *configImpl) TempDir() string {
403 return shared.TempDirForOutDir(c.SoongOutDir())
404}
405
Jeff Gastonb64fc1c2017-08-04 12:30:12 -0700406func (c *configImpl) FileListDir() string {
407 return filepath.Join(c.OutDir(), ".module_paths")
408}
409
Dan Willemsen1e704462016-08-21 15:17:17 -0700410func (c *configImpl) KatiSuffix() string {
411 if c.katiSuffix != "" {
412 return c.katiSuffix
413 }
414 panic("SetKatiSuffix has not been called")
415}
416
Colin Cross37193492017-11-16 17:55:00 -0800417// Checkbuild returns true if "checkbuild" was one of the build goals, which means that the
418// user is interested in additional checks at the expense of build time.
419func (c *configImpl) Checkbuild() bool {
420 return c.checkbuild
421}
422
Dan Willemsen8a073a82017-02-04 17:30:44 -0800423func (c *configImpl) Dist() bool {
424 return c.dist
425}
426
Dan Willemsen1e704462016-08-21 15:17:17 -0700427func (c *configImpl) IsVerbose() bool {
428 return c.verbose
429}
430
Dan Willemsene0879fc2017-08-04 15:06:27 -0700431func (c *configImpl) SkipMake() bool {
432 return c.skipMake
433}
434
Dan Willemsen1e704462016-08-21 15:17:17 -0700435func (c *configImpl) TargetProduct() string {
436 if v, ok := c.environ.Get("TARGET_PRODUCT"); ok {
437 return v
438 }
439 panic("TARGET_PRODUCT is not defined")
440}
441
Dan Willemsen02781d52017-05-12 19:28:13 -0700442func (c *configImpl) TargetDevice() string {
443 return c.targetDevice
444}
445
446func (c *configImpl) SetTargetDevice(device string) {
447 c.targetDevice = device
448}
449
450func (c *configImpl) TargetBuildVariant() string {
451 if v, ok := c.environ.Get("TARGET_BUILD_VARIANT"); ok {
452 return v
453 }
454 panic("TARGET_BUILD_VARIANT is not defined")
455}
456
Dan Willemsen1e704462016-08-21 15:17:17 -0700457func (c *configImpl) KatiArgs() []string {
458 return c.katiArgs
459}
460
461func (c *configImpl) Parallel() int {
462 return c.parallel
463}
464
465func (c *configImpl) UseGoma() bool {
466 if v, ok := c.environ.Get("USE_GOMA"); ok {
467 v = strings.TrimSpace(v)
468 if v != "" && v != "false" {
469 return true
470 }
471 }
472 return false
473}
474
475// RemoteParallel controls how many remote jobs (i.e., commands which contain
Jeff Gastonefc1b412017-03-29 17:29:06 -0700476// gomacc) are run in parallel. Note the parallelism of all other jobs is
Dan Willemsen1e704462016-08-21 15:17:17 -0700477// still limited by Parallel()
478func (c *configImpl) RemoteParallel() int {
479 if v, ok := c.environ.Get("NINJA_REMOTE_NUM_JOBS"); ok {
480 if i, err := strconv.Atoi(v); err == nil {
481 return i
482 }
483 }
484 return 500
485}
486
487func (c *configImpl) SetKatiArgs(args []string) {
488 c.katiArgs = args
489}
490
491func (c *configImpl) SetNinjaArgs(args []string) {
492 c.ninjaArgs = args
493}
494
495func (c *configImpl) SetKatiSuffix(suffix string) {
496 c.katiSuffix = suffix
497}
498
Dan Willemsene0879fc2017-08-04 15:06:27 -0700499func (c *configImpl) LastKatiSuffixFile() string {
500 return filepath.Join(c.OutDir(), "last_kati_suffix")
501}
502
503func (c *configImpl) HasKatiSuffix() bool {
504 return c.katiSuffix != ""
505}
506
Dan Willemsen1e704462016-08-21 15:17:17 -0700507func (c *configImpl) KatiEnvFile() string {
508 return filepath.Join(c.OutDir(), "env"+c.KatiSuffix()+".sh")
509}
510
Dan Willemsen29971232018-09-26 14:58:30 -0700511func (c *configImpl) KatiBuildNinjaFile() string {
512 return filepath.Join(c.OutDir(), "build"+c.KatiSuffix()+katiBuildSuffix+".ninja")
Dan Willemsen1e704462016-08-21 15:17:17 -0700513}
514
Dan Willemsenfb1271a2018-09-26 15:00:42 -0700515func (c *configImpl) KatiPackageNinjaFile() string {
516 return filepath.Join(c.OutDir(), "build"+c.KatiSuffix()+katiPackageSuffix+".ninja")
517}
518
Dan Willemsen1e704462016-08-21 15:17:17 -0700519func (c *configImpl) SoongNinjaFile() string {
520 return filepath.Join(c.SoongOutDir(), "build.ninja")
521}
522
523func (c *configImpl) CombinedNinjaFile() string {
Dan Willemsene0879fc2017-08-04 15:06:27 -0700524 if c.katiSuffix == "" {
525 return filepath.Join(c.OutDir(), "combined.ninja")
526 }
Dan Willemsen1e704462016-08-21 15:17:17 -0700527 return filepath.Join(c.OutDir(), "combined"+c.KatiSuffix()+".ninja")
528}
529
530func (c *configImpl) SoongAndroidMk() string {
531 return filepath.Join(c.SoongOutDir(), "Android-"+c.TargetProduct()+".mk")
532}
533
534func (c *configImpl) SoongMakeVarsMk() string {
535 return filepath.Join(c.SoongOutDir(), "make_vars-"+c.TargetProduct()+".mk")
536}
537
Dan Willemsenf052f782017-05-18 15:29:04 -0700538func (c *configImpl) ProductOut() string {
Dan Willemsen4dc4e142017-09-08 14:35:43 -0700539 return filepath.Join(c.OutDir(), "target", "product", c.TargetDevice())
Dan Willemsenf052f782017-05-18 15:29:04 -0700540}
541
Dan Willemsen02781d52017-05-12 19:28:13 -0700542func (c *configImpl) DevicePreviousProductConfig() string {
Dan Willemsenf052f782017-05-18 15:29:04 -0700543 return filepath.Join(c.ProductOut(), "previous_build_config.mk")
544}
545
Dan Willemsenfb1271a2018-09-26 15:00:42 -0700546func (c *configImpl) KatiPackageMkDir() string {
547 return filepath.Join(c.ProductOut(), "obj", "CONFIG", "kati_packaging")
548}
549
Dan Willemsenf052f782017-05-18 15:29:04 -0700550func (c *configImpl) hostOutRoot() string {
Dan Willemsen4dc4e142017-09-08 14:35:43 -0700551 return filepath.Join(c.OutDir(), "host")
Dan Willemsenf052f782017-05-18 15:29:04 -0700552}
553
554func (c *configImpl) HostOut() string {
555 return filepath.Join(c.hostOutRoot(), c.HostPrebuiltTag())
556}
557
558// This probably needs to be multi-valued, so not exporting it for now
559func (c *configImpl) hostCrossOut() string {
560 if runtime.GOOS == "linux" {
561 return filepath.Join(c.hostOutRoot(), "windows-x86")
562 } else {
563 return ""
564 }
Dan Willemsen02781d52017-05-12 19:28:13 -0700565}
566
Dan Willemsen1e704462016-08-21 15:17:17 -0700567func (c *configImpl) HostPrebuiltTag() string {
568 if runtime.GOOS == "linux" {
569 return "linux-x86"
570 } else if runtime.GOOS == "darwin" {
571 return "darwin-x86"
572 } else {
573 panic("Unsupported OS")
574 }
575}
Dan Willemsenf173d592017-04-27 14:28:00 -0700576
Dan Willemsen8122bd52017-10-12 20:20:41 -0700577func (c *configImpl) PrebuiltBuildTool(name string) string {
Dan Willemsenf173d592017-04-27 14:28:00 -0700578 if v, ok := c.environ.Get("SANITIZE_HOST"); ok {
579 if sanitize := strings.Fields(v); inList("address", sanitize) {
Dan Willemsen8122bd52017-10-12 20:20:41 -0700580 asan := filepath.Join("prebuilts/build-tools", c.HostPrebuiltTag(), "asan/bin", name)
581 if _, err := os.Stat(asan); err == nil {
582 return asan
583 }
Dan Willemsenf173d592017-04-27 14:28:00 -0700584 }
585 }
586 return filepath.Join("prebuilts/build-tools", c.HostPrebuiltTag(), "bin", name)
587}
Dan Willemsen3d60b112018-04-04 22:25:56 -0700588
589func (c *configImpl) SetBuildBrokenDupRules(val bool) {
590 c.brokenDupRules = val
591}
592
593func (c *configImpl) BuildBrokenDupRules() bool {
594 return c.brokenDupRules
595}
Dan Willemsen6ab79db2018-05-02 00:06:28 -0700596
Dan Willemsend8aa39d2018-08-27 15:01:03 -0700597func (c *configImpl) SetBuildBrokenPhonyTargets(val bool) {
598 c.brokenPhonyTargets = val
599}
600
601func (c *configImpl) BuildBrokenPhonyTargets() bool {
602 return c.brokenPhonyTargets
603}
604
Dan Willemsen6ab79db2018-05-02 00:06:28 -0700605func (c *configImpl) SetTargetDeviceDir(dir string) {
606 c.targetDeviceDir = dir
607}
608
609func (c *configImpl) TargetDeviceDir() string {
610 return c.targetDeviceDir
611}
Dan Willemsenfa42f3c2018-06-15 21:54:47 -0700612
613func (c *configImpl) SetPdkBuild(pdk bool) {
614 c.pdkBuild = pdk
615}
616
617func (c *configImpl) IsPdkBuild() bool {
618 return c.pdkBuild
619}