blob: 1008b2e13f68df5a8a3877962de6c54d56300718 [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 Willemsend50e89f2018-10-16 17:49:25 -070089 // Make sure DIST_DIR is set appropriately
90 ret.environ.Set("DIST_DIR", ret.DistDir())
91
Dan Willemsen1e704462016-08-21 15:17:17 -070092 ret.environ.Unset(
93 // We're already using it
94 "USE_SOONG_UI",
95
96 // We should never use GOROOT/GOPATH from the shell environment
97 "GOROOT",
98 "GOPATH",
99
100 // These should only come from Soong, not the environment.
101 "CLANG",
102 "CLANG_CXX",
103 "CCC_CC",
104 "CCC_CXX",
105
106 // Used by the goma compiler wrapper, but should only be set by
107 // gomacc
108 "GOMACC_PATH",
Dan Willemsen0c3919e2017-03-02 15:49:10 -0800109
110 // We handle this above
111 "OUT_DIR_COMMON_BASE",
Dan Willemsen68a09852017-04-18 13:56:57 -0700112
113 // Variables that have caused problems in the past
Dan Willemsenebfe33a2018-05-01 10:07:50 -0700114 "CDPATH",
Dan Willemsen68a09852017-04-18 13:56:57 -0700115 "DISPLAY",
116 "GREP_OPTIONS",
Dan Willemsenebfe33a2018-05-01 10:07:50 -0700117 "NDK_ROOT",
Dan Willemsen00fcb262018-08-15 15:35:38 -0700118 "POSIXLY_CORRECT",
Dan Willemsenc40e10b2017-07-11 14:30:00 -0700119
120 // Drop make flags
121 "MAKEFLAGS",
122 "MAKELEVEL",
123 "MFLAGS",
Dan Willemsend9e8f0a2017-10-30 13:42:06 -0700124
125 // Set in envsetup.sh, reset in makefiles
126 "ANDROID_JAVA_TOOLCHAIN",
Colin Cross7f09c402018-07-11 14:49:31 -0700127
128 // Set by envsetup.sh, but shouldn't be used inside the build because envsetup.sh is optional
129 "ANDROID_BUILD_TOP",
130 "ANDROID_HOST_OUT",
131 "ANDROID_PRODUCT_OUT",
132 "ANDROID_HOST_OUT_TESTCASES",
133 "ANDROID_TARGET_OUT_TESTCASES",
134 "ANDROID_TOOLCHAIN",
135 "ANDROID_TOOLCHAIN_2ND_ARCH",
136 "ANDROID_DEV_SCRIPTS",
137 "ANDROID_EMULATOR_PREBUILTS",
138 "ANDROID_PRE_BUILD_PATHS",
Dan Willemsen1e704462016-08-21 15:17:17 -0700139 )
140
141 // Tell python not to spam the source tree with .pyc files.
142 ret.environ.Set("PYTHONDONTWRITEBYTECODE", "1")
143
Dan Willemsen32a669b2018-03-08 19:42:00 -0800144 ret.environ.Set("TMPDIR", absPath(ctx, ret.TempDir()))
145
Dan Willemsenc2af0be2017-01-20 14:10:01 -0800146 // Precondition: the current directory is the top of the source tree
147 if _, err := os.Stat(srcDirFileCheck); err != nil {
148 if os.IsNotExist(err) {
149 log.Fatalf("Current working directory must be the source tree. %q not found", srcDirFileCheck)
150 }
151 log.Fatalln("Error verifying tree state:", err)
152 }
153
Dan Willemsend9e8f0a2017-10-30 13:42:06 -0700154 if srcDir := absPath(ctx, "."); strings.ContainsRune(srcDir, ' ') {
155 log.Println("You are building in a directory whose absolute path contains a space character:")
156 log.Println()
157 log.Printf("%q\n", srcDir)
158 log.Println()
159 log.Fatalln("Directory names containing spaces are not supported")
Dan Willemsendb8457c2017-05-12 16:38:17 -0700160 }
161
162 if outDir := ret.OutDir(); strings.ContainsRune(outDir, ' ') {
163 log.Println("The absolute path of your output directory ($OUT_DIR) contains a space character:")
164 log.Println()
165 log.Printf("%q\n", outDir)
166 log.Println()
167 log.Fatalln("Directory names containing spaces are not supported")
168 }
169
170 if distDir := ret.DistDir(); strings.ContainsRune(distDir, ' ') {
171 log.Println("The absolute path of your dist directory ($DIST_DIR) contains a space character:")
172 log.Println()
173 log.Printf("%q\n", distDir)
174 log.Println()
175 log.Fatalln("Directory names containing spaces are not supported")
176 }
177
Dan Willemsend9e8f0a2017-10-30 13:42:06 -0700178 // Configure Java-related variables, including adding it to $PATH
Tobias Thierere59aeff2017-12-20 22:40:39 +0000179 java8Home := filepath.Join("prebuilts/jdk/jdk8", ret.HostPrebuiltTag())
180 java9Home := filepath.Join("prebuilts/jdk/jdk9", ret.HostPrebuiltTag())
Dan Willemsend9e8f0a2017-10-30 13:42:06 -0700181 javaHome := func() string {
182 if override, ok := ret.environ.Get("OVERRIDE_ANDROID_JAVA_HOME"); ok {
183 return override
184 }
Colin Cross997262f2018-06-19 22:49:39 -0700185 return java9Home
Dan Willemsend9e8f0a2017-10-30 13:42:06 -0700186 }()
187 absJavaHome := absPath(ctx, javaHome)
188
Dan Willemsened869522018-01-08 14:58:46 -0800189 ret.configureLocale(ctx)
190
Dan Willemsend9e8f0a2017-10-30 13:42:06 -0700191 newPath := []string{filepath.Join(absJavaHome, "bin")}
192 if path, ok := ret.environ.Get("PATH"); ok && path != "" {
193 newPath = append(newPath, path)
194 }
195 ret.environ.Unset("OVERRIDE_ANDROID_JAVA_HOME")
196 ret.environ.Set("JAVA_HOME", absJavaHome)
197 ret.environ.Set("ANDROID_JAVA_HOME", javaHome)
Tobias Thierere59aeff2017-12-20 22:40:39 +0000198 ret.environ.Set("ANDROID_JAVA8_HOME", java8Home)
199 ret.environ.Set("ANDROID_JAVA9_HOME", java9Home)
Dan Willemsend9e8f0a2017-10-30 13:42:06 -0700200 ret.environ.Set("PATH", strings.Join(newPath, string(filepath.ListSeparator)))
201
Nan Zhang2e6a4ff2018-02-14 13:27:26 -0800202 outDir := ret.OutDir()
203 buildDateTimeFile := filepath.Join(outDir, "build_date.txt")
204 var content string
205 if buildDateTime, ok := ret.environ.Get("BUILD_DATETIME"); ok && buildDateTime != "" {
206 content = buildDateTime
207 } else {
208 content = strconv.FormatInt(time.Now().Unix(), 10)
209 }
210 err := ioutil.WriteFile(buildDateTimeFile, []byte(content), 0777)
211 if err != nil {
212 ctx.Fatalln("Failed to write BUILD_DATETIME to file:", err)
213 }
214 ret.environ.Set("BUILD_DATETIME_FILE", buildDateTimeFile)
215
Dan Willemsen9b587492017-07-10 22:13:00 -0700216 return Config{ret}
217}
218
219func (c *configImpl) parseArgs(ctx Context, args []string) {
220 for i := 0; i < len(args); i++ {
221 arg := strings.TrimSpace(args[i])
Dan Willemsen1e704462016-08-21 15:17:17 -0700222 if arg == "--make-mode" {
Dan Willemsen1e704462016-08-21 15:17:17 -0700223 } else if arg == "showcommands" {
Dan Willemsen9b587492017-07-10 22:13:00 -0700224 c.verbose = true
Dan Willemsene0879fc2017-08-04 15:06:27 -0700225 } else if arg == "--skip-make" {
226 c.skipMake = true
Dan Willemsen6ac63ef2017-10-17 20:35:34 -0700227 } else if len(arg) > 0 && arg[0] == '-' {
Dan Willemsen9b587492017-07-10 22:13:00 -0700228 parseArgNum := func(def int) int {
229 if len(arg) > 2 {
230 p, err := strconv.ParseUint(arg[2:], 10, 31)
231 if err != nil {
232 ctx.Fatalf("Failed to parse %q: %v", arg, err)
233 }
234 return int(p)
235 } else if i+1 < len(args) {
236 p, err := strconv.ParseUint(args[i+1], 10, 31)
237 if err == nil {
238 i++
239 return int(p)
240 }
241 }
242 return def
243 }
244
Dan Willemsen6ac63ef2017-10-17 20:35:34 -0700245 if len(arg) > 1 && arg[1] == 'j' {
Dan Willemsen9b587492017-07-10 22:13:00 -0700246 c.parallel = parseArgNum(c.parallel)
Dan Willemsen6ac63ef2017-10-17 20:35:34 -0700247 } else if len(arg) > 1 && arg[1] == 'k' {
Dan Willemsen9b587492017-07-10 22:13:00 -0700248 c.keepGoing = parseArgNum(0)
Dan Willemsen1e704462016-08-21 15:17:17 -0700249 } else {
250 ctx.Fatalln("Unknown option:", arg)
251 }
Dan Willemsen091525e2017-07-11 14:17:50 -0700252 } else if k, v, ok := decodeKeyValue(arg); ok && len(k) > 0 {
253 c.environ.Set(k, v)
Dan Willemsen1e704462016-08-21 15:17:17 -0700254 } else {
Dan Willemsene0879fc2017-08-04 15:06:27 -0700255 if arg == "dist" {
256 c.dist = true
Colin Cross37193492017-11-16 17:55:00 -0800257 } else if arg == "checkbuild" {
258 c.checkbuild = true
Dan Willemsene0879fc2017-08-04 15:06:27 -0700259 }
Dan Willemsen9b587492017-07-10 22:13:00 -0700260 c.arguments = append(c.arguments, arg)
Dan Willemsen1e704462016-08-21 15:17:17 -0700261 }
262 }
Dan Willemsen1e704462016-08-21 15:17:17 -0700263}
264
Dan Willemsened869522018-01-08 14:58:46 -0800265func (c *configImpl) configureLocale(ctx Context) {
266 cmd := Command(ctx, Config{c}, "locale", "locale", "-a")
267 output, err := cmd.Output()
268
269 var locales []string
270 if err == nil {
271 locales = strings.Split(string(output), "\n")
272 } else {
273 // If we're unable to list the locales, let's assume en_US.UTF-8
274 locales = []string{"en_US.UTF-8"}
275 ctx.Verbosef("Failed to list locales (%q), falling back to %q", err, locales)
276 }
277
278 // gettext uses LANGUAGE, which is passed directly through
279
280 // For LANG and LC_*, only preserve the evaluated version of
281 // LC_MESSAGES
282 user_lang := ""
283 if lc_all, ok := c.environ.Get("LC_ALL"); ok {
284 user_lang = lc_all
285 } else if lc_messages, ok := c.environ.Get("LC_MESSAGES"); ok {
286 user_lang = lc_messages
287 } else if lang, ok := c.environ.Get("LANG"); ok {
288 user_lang = lang
289 }
290
291 c.environ.UnsetWithPrefix("LC_")
292
293 if user_lang != "" {
294 c.environ.Set("LC_MESSAGES", user_lang)
295 }
296
297 // The for LANG, use C.UTF-8 if it exists (Debian currently, proposed
298 // for others)
299 if inList("C.UTF-8", locales) {
300 c.environ.Set("LANG", "C.UTF-8")
Aaron Klingd236e0e2018-08-07 19:21:36 -0500301 } else if inList("C.utf8", locales) {
302 // These normalize to the same thing
303 c.environ.Set("LANG", "C.UTF-8")
Dan Willemsened869522018-01-08 14:58:46 -0800304 } else if inList("en_US.UTF-8", locales) {
305 c.environ.Set("LANG", "en_US.UTF-8")
306 } else if inList("en_US.utf8", locales) {
307 // These normalize to the same thing
308 c.environ.Set("LANG", "en_US.UTF-8")
309 } else {
310 ctx.Fatalln("System doesn't support either C.UTF-8 or en_US.UTF-8")
311 }
312}
313
Dan Willemsen1e704462016-08-21 15:17:17 -0700314// Lunch configures the environment for a specific product similarly to the
315// `lunch` bash function.
316func (c *configImpl) Lunch(ctx Context, product, variant string) {
317 if variant != "eng" && variant != "userdebug" && variant != "user" {
318 ctx.Fatalf("Invalid variant %q. Must be one of 'user', 'userdebug' or 'eng'", variant)
319 }
320
321 c.environ.Set("TARGET_PRODUCT", product)
322 c.environ.Set("TARGET_BUILD_VARIANT", variant)
323 c.environ.Set("TARGET_BUILD_TYPE", "release")
324 c.environ.Unset("TARGET_BUILD_APPS")
325}
326
327// Tapas configures the environment to build one or more unbundled apps,
328// similarly to the `tapas` bash function.
329func (c *configImpl) Tapas(ctx Context, apps []string, arch, variant string) {
330 if len(apps) == 0 {
331 apps = []string{"all"}
332 }
333 if variant == "" {
334 variant = "eng"
335 }
336
337 if variant != "eng" && variant != "userdebug" && variant != "user" {
338 ctx.Fatalf("Invalid variant %q. Must be one of 'user', 'userdebug' or 'eng'", variant)
339 }
340
341 var product string
342 switch arch {
Dan Willemsen1e704462016-08-21 15:17:17 -0700343 case "arm", "":
344 product = "aosp_arm"
345 case "arm64":
346 product = "aosm_arm64"
347 case "mips":
348 product = "aosp_mips"
349 case "mips64":
350 product = "aosp_mips64"
351 case "x86":
352 product = "aosp_x86"
353 case "x86_64":
354 product = "aosp_x86_64"
355 default:
356 ctx.Fatalf("Invalid architecture: %q", arch)
357 }
358
359 c.environ.Set("TARGET_PRODUCT", product)
360 c.environ.Set("TARGET_BUILD_VARIANT", variant)
361 c.environ.Set("TARGET_BUILD_TYPE", "release")
362 c.environ.Set("TARGET_BUILD_APPS", strings.Join(apps, " "))
363}
364
365func (c *configImpl) Environment() *Environment {
366 return c.environ
367}
368
369func (c *configImpl) Arguments() []string {
370 return c.arguments
371}
372
373func (c *configImpl) OutDir() string {
374 if outDir, ok := c.environ.Get("OUT_DIR"); ok {
Dan Willemsen25a56182018-08-31 20:25:32 -0700375 return filepath.Clean(outDir)
Dan Willemsen1e704462016-08-21 15:17:17 -0700376 }
377 return "out"
378}
379
Dan Willemsen8a073a82017-02-04 17:30:44 -0800380func (c *configImpl) DistDir() string {
381 if distDir, ok := c.environ.Get("DIST_DIR"); ok {
Dan Willemsen25a56182018-08-31 20:25:32 -0700382 return filepath.Clean(distDir)
Dan Willemsen8a073a82017-02-04 17:30:44 -0800383 }
384 return filepath.Join(c.OutDir(), "dist")
385}
386
Dan Willemsen1e704462016-08-21 15:17:17 -0700387func (c *configImpl) NinjaArgs() []string {
Dan Willemsene0879fc2017-08-04 15:06:27 -0700388 if c.skipMake {
389 return c.arguments
390 }
Dan Willemsen1e704462016-08-21 15:17:17 -0700391 return c.ninjaArgs
392}
393
394func (c *configImpl) SoongOutDir() string {
395 return filepath.Join(c.OutDir(), "soong")
396}
397
Jeff Gastonefc1b412017-03-29 17:29:06 -0700398func (c *configImpl) TempDir() string {
399 return shared.TempDirForOutDir(c.SoongOutDir())
400}
401
Jeff Gastonb64fc1c2017-08-04 12:30:12 -0700402func (c *configImpl) FileListDir() string {
403 return filepath.Join(c.OutDir(), ".module_paths")
404}
405
Dan Willemsen1e704462016-08-21 15:17:17 -0700406func (c *configImpl) KatiSuffix() string {
407 if c.katiSuffix != "" {
408 return c.katiSuffix
409 }
410 panic("SetKatiSuffix has not been called")
411}
412
Colin Cross37193492017-11-16 17:55:00 -0800413// Checkbuild returns true if "checkbuild" was one of the build goals, which means that the
414// user is interested in additional checks at the expense of build time.
415func (c *configImpl) Checkbuild() bool {
416 return c.checkbuild
417}
418
Dan Willemsen8a073a82017-02-04 17:30:44 -0800419func (c *configImpl) Dist() bool {
420 return c.dist
421}
422
Dan Willemsen1e704462016-08-21 15:17:17 -0700423func (c *configImpl) IsVerbose() bool {
424 return c.verbose
425}
426
Dan Willemsene0879fc2017-08-04 15:06:27 -0700427func (c *configImpl) SkipMake() bool {
428 return c.skipMake
429}
430
Dan Willemsen1e704462016-08-21 15:17:17 -0700431func (c *configImpl) TargetProduct() string {
432 if v, ok := c.environ.Get("TARGET_PRODUCT"); ok {
433 return v
434 }
435 panic("TARGET_PRODUCT is not defined")
436}
437
Dan Willemsen02781d52017-05-12 19:28:13 -0700438func (c *configImpl) TargetDevice() string {
439 return c.targetDevice
440}
441
442func (c *configImpl) SetTargetDevice(device string) {
443 c.targetDevice = device
444}
445
446func (c *configImpl) TargetBuildVariant() string {
447 if v, ok := c.environ.Get("TARGET_BUILD_VARIANT"); ok {
448 return v
449 }
450 panic("TARGET_BUILD_VARIANT is not defined")
451}
452
Dan Willemsen1e704462016-08-21 15:17:17 -0700453func (c *configImpl) KatiArgs() []string {
454 return c.katiArgs
455}
456
457func (c *configImpl) Parallel() int {
458 return c.parallel
459}
460
461func (c *configImpl) UseGoma() bool {
462 if v, ok := c.environ.Get("USE_GOMA"); ok {
463 v = strings.TrimSpace(v)
464 if v != "" && v != "false" {
465 return true
466 }
467 }
468 return false
469}
470
471// RemoteParallel controls how many remote jobs (i.e., commands which contain
Jeff Gastonefc1b412017-03-29 17:29:06 -0700472// gomacc) are run in parallel. Note the parallelism of all other jobs is
Dan Willemsen1e704462016-08-21 15:17:17 -0700473// still limited by Parallel()
474func (c *configImpl) RemoteParallel() int {
475 if v, ok := c.environ.Get("NINJA_REMOTE_NUM_JOBS"); ok {
476 if i, err := strconv.Atoi(v); err == nil {
477 return i
478 }
479 }
480 return 500
481}
482
483func (c *configImpl) SetKatiArgs(args []string) {
484 c.katiArgs = args
485}
486
487func (c *configImpl) SetNinjaArgs(args []string) {
488 c.ninjaArgs = args
489}
490
491func (c *configImpl) SetKatiSuffix(suffix string) {
492 c.katiSuffix = suffix
493}
494
Dan Willemsene0879fc2017-08-04 15:06:27 -0700495func (c *configImpl) LastKatiSuffixFile() string {
496 return filepath.Join(c.OutDir(), "last_kati_suffix")
497}
498
499func (c *configImpl) HasKatiSuffix() bool {
500 return c.katiSuffix != ""
501}
502
Dan Willemsen1e704462016-08-21 15:17:17 -0700503func (c *configImpl) KatiEnvFile() string {
504 return filepath.Join(c.OutDir(), "env"+c.KatiSuffix()+".sh")
505}
506
Dan Willemsen29971232018-09-26 14:58:30 -0700507func (c *configImpl) KatiBuildNinjaFile() string {
508 return filepath.Join(c.OutDir(), "build"+c.KatiSuffix()+katiBuildSuffix+".ninja")
Dan Willemsen1e704462016-08-21 15:17:17 -0700509}
510
Dan Willemsenfb1271a2018-09-26 15:00:42 -0700511func (c *configImpl) KatiPackageNinjaFile() string {
512 return filepath.Join(c.OutDir(), "build"+c.KatiSuffix()+katiPackageSuffix+".ninja")
513}
514
Dan Willemsen1e704462016-08-21 15:17:17 -0700515func (c *configImpl) SoongNinjaFile() string {
516 return filepath.Join(c.SoongOutDir(), "build.ninja")
517}
518
519func (c *configImpl) CombinedNinjaFile() string {
Dan Willemsene0879fc2017-08-04 15:06:27 -0700520 if c.katiSuffix == "" {
521 return filepath.Join(c.OutDir(), "combined.ninja")
522 }
Dan Willemsen1e704462016-08-21 15:17:17 -0700523 return filepath.Join(c.OutDir(), "combined"+c.KatiSuffix()+".ninja")
524}
525
526func (c *configImpl) SoongAndroidMk() string {
527 return filepath.Join(c.SoongOutDir(), "Android-"+c.TargetProduct()+".mk")
528}
529
530func (c *configImpl) SoongMakeVarsMk() string {
531 return filepath.Join(c.SoongOutDir(), "make_vars-"+c.TargetProduct()+".mk")
532}
533
Dan Willemsenf052f782017-05-18 15:29:04 -0700534func (c *configImpl) ProductOut() string {
Dan Willemsen4dc4e142017-09-08 14:35:43 -0700535 return filepath.Join(c.OutDir(), "target", "product", c.TargetDevice())
Dan Willemsenf052f782017-05-18 15:29:04 -0700536}
537
Dan Willemsen02781d52017-05-12 19:28:13 -0700538func (c *configImpl) DevicePreviousProductConfig() string {
Dan Willemsenf052f782017-05-18 15:29:04 -0700539 return filepath.Join(c.ProductOut(), "previous_build_config.mk")
540}
541
Dan Willemsenfb1271a2018-09-26 15:00:42 -0700542func (c *configImpl) KatiPackageMkDir() string {
543 return filepath.Join(c.ProductOut(), "obj", "CONFIG", "kati_packaging")
544}
545
Dan Willemsenf052f782017-05-18 15:29:04 -0700546func (c *configImpl) hostOutRoot() string {
Dan Willemsen4dc4e142017-09-08 14:35:43 -0700547 return filepath.Join(c.OutDir(), "host")
Dan Willemsenf052f782017-05-18 15:29:04 -0700548}
549
550func (c *configImpl) HostOut() string {
551 return filepath.Join(c.hostOutRoot(), c.HostPrebuiltTag())
552}
553
554// This probably needs to be multi-valued, so not exporting it for now
555func (c *configImpl) hostCrossOut() string {
556 if runtime.GOOS == "linux" {
557 return filepath.Join(c.hostOutRoot(), "windows-x86")
558 } else {
559 return ""
560 }
Dan Willemsen02781d52017-05-12 19:28:13 -0700561}
562
Dan Willemsen1e704462016-08-21 15:17:17 -0700563func (c *configImpl) HostPrebuiltTag() string {
564 if runtime.GOOS == "linux" {
565 return "linux-x86"
566 } else if runtime.GOOS == "darwin" {
567 return "darwin-x86"
568 } else {
569 panic("Unsupported OS")
570 }
571}
Dan Willemsenf173d592017-04-27 14:28:00 -0700572
Dan Willemsen8122bd52017-10-12 20:20:41 -0700573func (c *configImpl) PrebuiltBuildTool(name string) string {
Dan Willemsenf173d592017-04-27 14:28:00 -0700574 if v, ok := c.environ.Get("SANITIZE_HOST"); ok {
575 if sanitize := strings.Fields(v); inList("address", sanitize) {
Dan Willemsen8122bd52017-10-12 20:20:41 -0700576 asan := filepath.Join("prebuilts/build-tools", c.HostPrebuiltTag(), "asan/bin", name)
577 if _, err := os.Stat(asan); err == nil {
578 return asan
579 }
Dan Willemsenf173d592017-04-27 14:28:00 -0700580 }
581 }
582 return filepath.Join("prebuilts/build-tools", c.HostPrebuiltTag(), "bin", name)
583}
Dan Willemsen3d60b112018-04-04 22:25:56 -0700584
585func (c *configImpl) SetBuildBrokenDupRules(val bool) {
586 c.brokenDupRules = val
587}
588
589func (c *configImpl) BuildBrokenDupRules() bool {
590 return c.brokenDupRules
591}
Dan Willemsen6ab79db2018-05-02 00:06:28 -0700592
Dan Willemsend8aa39d2018-08-27 15:01:03 -0700593func (c *configImpl) SetBuildBrokenPhonyTargets(val bool) {
594 c.brokenPhonyTargets = val
595}
596
597func (c *configImpl) BuildBrokenPhonyTargets() bool {
598 return c.brokenPhonyTargets
599}
600
Dan Willemsen6ab79db2018-05-02 00:06:28 -0700601func (c *configImpl) SetTargetDeviceDir(dir string) {
602 c.targetDeviceDir = dir
603}
604
605func (c *configImpl) TargetDeviceDir() string {
606 return c.targetDeviceDir
607}
Dan Willemsenfa42f3c2018-06-15 21:54:47 -0700608
609func (c *configImpl) SetPdkBuild(pdk bool) {
610 c.pdkBuild = pdk
611}
612
613func (c *configImpl) IsPdkBuild() bool {
614 return c.pdkBuild
615}