Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 1 | // 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 | |
| 15 | package build |
| 16 | |
| 17 | import ( |
Dan Willemsen | c2af0be | 2017-01-20 14:10:01 -0800 | [diff] [blame] | 18 | "log" |
| 19 | "os" |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 20 | "path/filepath" |
| 21 | "runtime" |
| 22 | "strconv" |
| 23 | "strings" |
Jeff Gaston | efc1b41 | 2017-03-29 17:29:06 -0700 | [diff] [blame] | 24 | |
| 25 | "android/soong/shared" |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 26 | ) |
| 27 | |
| 28 | type Config struct{ *configImpl } |
| 29 | |
| 30 | type configImpl struct { |
| 31 | // From the environment |
| 32 | arguments []string |
| 33 | goma bool |
| 34 | environ *Environment |
| 35 | |
| 36 | // From the arguments |
| 37 | parallel int |
| 38 | keepGoing int |
| 39 | verbose bool |
Dan Willemsen | 8a073a8 | 2017-02-04 17:30:44 -0800 | [diff] [blame] | 40 | dist bool |
Dan Willemsen | e0879fc | 2017-08-04 15:06:27 -0700 | [diff] [blame] | 41 | skipMake bool |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 42 | |
| 43 | // From the product config |
Dan Willemsen | 02781d5 | 2017-05-12 19:28:13 -0700 | [diff] [blame] | 44 | katiArgs []string |
| 45 | ninjaArgs []string |
| 46 | katiSuffix string |
| 47 | targetDevice string |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 48 | } |
| 49 | |
Dan Willemsen | c2af0be | 2017-01-20 14:10:01 -0800 | [diff] [blame] | 50 | const srcDirFileCheck = "build/soong/root.bp" |
| 51 | |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 52 | func NewConfig(ctx Context, args ...string) Config { |
| 53 | ret := &configImpl{ |
| 54 | environ: OsEnvironment(), |
| 55 | } |
| 56 | |
Dan Willemsen | 9b58749 | 2017-07-10 22:13:00 -0700 | [diff] [blame] | 57 | // Sane default matching ninja |
| 58 | ret.parallel = runtime.NumCPU() + 2 |
| 59 | ret.keepGoing = 1 |
| 60 | |
| 61 | ret.parseArgs(ctx, args) |
| 62 | |
Dan Willemsen | 0c3919e | 2017-03-02 15:49:10 -0800 | [diff] [blame] | 63 | // Make sure OUT_DIR is set appropriately |
Dan Willemsen | 02f3add | 2017-05-12 13:50:19 -0700 | [diff] [blame] | 64 | if outDir, ok := ret.environ.Get("OUT_DIR"); ok { |
| 65 | ret.environ.Set("OUT_DIR", filepath.Clean(outDir)) |
| 66 | } else { |
Dan Willemsen | 0c3919e | 2017-03-02 15:49:10 -0800 | [diff] [blame] | 67 | outDir := "out" |
| 68 | if baseDir, ok := ret.environ.Get("OUT_DIR_COMMON_BASE"); ok { |
| 69 | if wd, err := os.Getwd(); err != nil { |
| 70 | ctx.Fatalln("Failed to get working directory:", err) |
| 71 | } else { |
| 72 | outDir = filepath.Join(baseDir, filepath.Base(wd)) |
| 73 | } |
| 74 | } |
| 75 | ret.environ.Set("OUT_DIR", outDir) |
| 76 | } |
| 77 | |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 78 | ret.environ.Unset( |
| 79 | // We're already using it |
| 80 | "USE_SOONG_UI", |
| 81 | |
| 82 | // We should never use GOROOT/GOPATH from the shell environment |
| 83 | "GOROOT", |
| 84 | "GOPATH", |
| 85 | |
| 86 | // These should only come from Soong, not the environment. |
| 87 | "CLANG", |
| 88 | "CLANG_CXX", |
| 89 | "CCC_CC", |
| 90 | "CCC_CXX", |
| 91 | |
| 92 | // Used by the goma compiler wrapper, but should only be set by |
| 93 | // gomacc |
| 94 | "GOMACC_PATH", |
Dan Willemsen | 0c3919e | 2017-03-02 15:49:10 -0800 | [diff] [blame] | 95 | |
| 96 | // We handle this above |
| 97 | "OUT_DIR_COMMON_BASE", |
Dan Willemsen | 68a0985 | 2017-04-18 13:56:57 -0700 | [diff] [blame] | 98 | |
| 99 | // Variables that have caused problems in the past |
| 100 | "DISPLAY", |
| 101 | "GREP_OPTIONS", |
Dan Willemsen | c40e10b | 2017-07-11 14:30:00 -0700 | [diff] [blame] | 102 | |
| 103 | // Drop make flags |
| 104 | "MAKEFLAGS", |
| 105 | "MAKELEVEL", |
| 106 | "MFLAGS", |
Dan Willemsen | d9e8f0a | 2017-10-30 13:42:06 -0700 | [diff] [blame] | 107 | |
| 108 | // Set in envsetup.sh, reset in makefiles |
| 109 | "ANDROID_JAVA_TOOLCHAIN", |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 110 | ) |
| 111 | |
| 112 | // Tell python not to spam the source tree with .pyc files. |
| 113 | ret.environ.Set("PYTHONDONTWRITEBYTECODE", "1") |
| 114 | |
Dan Willemsen | c2af0be | 2017-01-20 14:10:01 -0800 | [diff] [blame] | 115 | // Precondition: the current directory is the top of the source tree |
| 116 | if _, err := os.Stat(srcDirFileCheck); err != nil { |
| 117 | if os.IsNotExist(err) { |
| 118 | log.Fatalf("Current working directory must be the source tree. %q not found", srcDirFileCheck) |
| 119 | } |
| 120 | log.Fatalln("Error verifying tree state:", err) |
| 121 | } |
| 122 | |
Dan Willemsen | d9e8f0a | 2017-10-30 13:42:06 -0700 | [diff] [blame] | 123 | if srcDir := absPath(ctx, "."); strings.ContainsRune(srcDir, ' ') { |
| 124 | log.Println("You are building in a directory whose absolute path contains a space character:") |
| 125 | log.Println() |
| 126 | log.Printf("%q\n", srcDir) |
| 127 | log.Println() |
| 128 | log.Fatalln("Directory names containing spaces are not supported") |
Dan Willemsen | db8457c | 2017-05-12 16:38:17 -0700 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | if outDir := ret.OutDir(); strings.ContainsRune(outDir, ' ') { |
| 132 | log.Println("The absolute path of your output directory ($OUT_DIR) contains a space character:") |
| 133 | log.Println() |
| 134 | log.Printf("%q\n", outDir) |
| 135 | log.Println() |
| 136 | log.Fatalln("Directory names containing spaces are not supported") |
| 137 | } |
| 138 | |
| 139 | if distDir := ret.DistDir(); strings.ContainsRune(distDir, ' ') { |
| 140 | log.Println("The absolute path of your dist directory ($DIST_DIR) contains a space character:") |
| 141 | log.Println() |
| 142 | log.Printf("%q\n", distDir) |
| 143 | log.Println() |
| 144 | log.Fatalln("Directory names containing spaces are not supported") |
| 145 | } |
| 146 | |
Dan Willemsen | d9e8f0a | 2017-10-30 13:42:06 -0700 | [diff] [blame] | 147 | // Configure Java-related variables, including adding it to $PATH |
| 148 | javaHome := func() string { |
| 149 | if override, ok := ret.environ.Get("OVERRIDE_ANDROID_JAVA_HOME"); ok { |
| 150 | return override |
| 151 | } |
| 152 | if v, ok := ret.environ.Get("EXPERIMENTAL_USE_OPENJDK9"); ok && v != "" { |
| 153 | return filepath.Join("prebuilts/jdk/jdk9", ret.HostPrebuiltTag()) |
| 154 | } |
| 155 | return filepath.Join("prebuilts/jdk/jdk8", ret.HostPrebuiltTag()) |
| 156 | }() |
| 157 | absJavaHome := absPath(ctx, javaHome) |
| 158 | |
| 159 | newPath := []string{filepath.Join(absJavaHome, "bin")} |
| 160 | if path, ok := ret.environ.Get("PATH"); ok && path != "" { |
| 161 | newPath = append(newPath, path) |
| 162 | } |
| 163 | ret.environ.Unset("OVERRIDE_ANDROID_JAVA_HOME") |
| 164 | ret.environ.Set("JAVA_HOME", absJavaHome) |
| 165 | ret.environ.Set("ANDROID_JAVA_HOME", javaHome) |
| 166 | ret.environ.Set("PATH", strings.Join(newPath, string(filepath.ListSeparator))) |
| 167 | |
Dan Willemsen | 9b58749 | 2017-07-10 22:13:00 -0700 | [diff] [blame] | 168 | return Config{ret} |
| 169 | } |
| 170 | |
| 171 | func (c *configImpl) parseArgs(ctx Context, args []string) { |
| 172 | for i := 0; i < len(args); i++ { |
| 173 | arg := strings.TrimSpace(args[i]) |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 174 | if arg == "--make-mode" { |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 175 | } else if arg == "showcommands" { |
Dan Willemsen | 9b58749 | 2017-07-10 22:13:00 -0700 | [diff] [blame] | 176 | c.verbose = true |
Dan Willemsen | e0879fc | 2017-08-04 15:06:27 -0700 | [diff] [blame] | 177 | } else if arg == "--skip-make" { |
| 178 | c.skipMake = true |
Dan Willemsen | 6ac63ef | 2017-10-17 20:35:34 -0700 | [diff] [blame] | 179 | } else if len(arg) > 0 && arg[0] == '-' { |
Dan Willemsen | 9b58749 | 2017-07-10 22:13:00 -0700 | [diff] [blame] | 180 | parseArgNum := func(def int) int { |
| 181 | if len(arg) > 2 { |
| 182 | p, err := strconv.ParseUint(arg[2:], 10, 31) |
| 183 | if err != nil { |
| 184 | ctx.Fatalf("Failed to parse %q: %v", arg, err) |
| 185 | } |
| 186 | return int(p) |
| 187 | } else if i+1 < len(args) { |
| 188 | p, err := strconv.ParseUint(args[i+1], 10, 31) |
| 189 | if err == nil { |
| 190 | i++ |
| 191 | return int(p) |
| 192 | } |
| 193 | } |
| 194 | return def |
| 195 | } |
| 196 | |
Dan Willemsen | 6ac63ef | 2017-10-17 20:35:34 -0700 | [diff] [blame] | 197 | if len(arg) > 1 && arg[1] == 'j' { |
Dan Willemsen | 9b58749 | 2017-07-10 22:13:00 -0700 | [diff] [blame] | 198 | c.parallel = parseArgNum(c.parallel) |
Dan Willemsen | 6ac63ef | 2017-10-17 20:35:34 -0700 | [diff] [blame] | 199 | } else if len(arg) > 1 && arg[1] == 'k' { |
Dan Willemsen | 9b58749 | 2017-07-10 22:13:00 -0700 | [diff] [blame] | 200 | c.keepGoing = parseArgNum(0) |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 201 | } else { |
| 202 | ctx.Fatalln("Unknown option:", arg) |
| 203 | } |
Dan Willemsen | 091525e | 2017-07-11 14:17:50 -0700 | [diff] [blame] | 204 | } else if k, v, ok := decodeKeyValue(arg); ok && len(k) > 0 { |
| 205 | c.environ.Set(k, v) |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 206 | } else { |
Dan Willemsen | e0879fc | 2017-08-04 15:06:27 -0700 | [diff] [blame] | 207 | if arg == "dist" { |
| 208 | c.dist = true |
| 209 | } |
Dan Willemsen | 9b58749 | 2017-07-10 22:13:00 -0700 | [diff] [blame] | 210 | c.arguments = append(c.arguments, arg) |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 211 | } |
| 212 | } |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | // Lunch configures the environment for a specific product similarly to the |
| 216 | // `lunch` bash function. |
| 217 | func (c *configImpl) Lunch(ctx Context, product, variant string) { |
| 218 | if variant != "eng" && variant != "userdebug" && variant != "user" { |
| 219 | ctx.Fatalf("Invalid variant %q. Must be one of 'user', 'userdebug' or 'eng'", variant) |
| 220 | } |
| 221 | |
| 222 | c.environ.Set("TARGET_PRODUCT", product) |
| 223 | c.environ.Set("TARGET_BUILD_VARIANT", variant) |
| 224 | c.environ.Set("TARGET_BUILD_TYPE", "release") |
| 225 | c.environ.Unset("TARGET_BUILD_APPS") |
| 226 | } |
| 227 | |
| 228 | // Tapas configures the environment to build one or more unbundled apps, |
| 229 | // similarly to the `tapas` bash function. |
| 230 | func (c *configImpl) Tapas(ctx Context, apps []string, arch, variant string) { |
| 231 | if len(apps) == 0 { |
| 232 | apps = []string{"all"} |
| 233 | } |
| 234 | if variant == "" { |
| 235 | variant = "eng" |
| 236 | } |
| 237 | |
| 238 | if variant != "eng" && variant != "userdebug" && variant != "user" { |
| 239 | ctx.Fatalf("Invalid variant %q. Must be one of 'user', 'userdebug' or 'eng'", variant) |
| 240 | } |
| 241 | |
| 242 | var product string |
| 243 | switch arch { |
| 244 | case "armv5": |
| 245 | product = "generic_armv5" |
| 246 | case "arm", "": |
| 247 | product = "aosp_arm" |
| 248 | case "arm64": |
| 249 | product = "aosm_arm64" |
| 250 | case "mips": |
| 251 | product = "aosp_mips" |
| 252 | case "mips64": |
| 253 | product = "aosp_mips64" |
| 254 | case "x86": |
| 255 | product = "aosp_x86" |
| 256 | case "x86_64": |
| 257 | product = "aosp_x86_64" |
| 258 | default: |
| 259 | ctx.Fatalf("Invalid architecture: %q", arch) |
| 260 | } |
| 261 | |
| 262 | c.environ.Set("TARGET_PRODUCT", product) |
| 263 | c.environ.Set("TARGET_BUILD_VARIANT", variant) |
| 264 | c.environ.Set("TARGET_BUILD_TYPE", "release") |
| 265 | c.environ.Set("TARGET_BUILD_APPS", strings.Join(apps, " ")) |
| 266 | } |
| 267 | |
| 268 | func (c *configImpl) Environment() *Environment { |
| 269 | return c.environ |
| 270 | } |
| 271 | |
| 272 | func (c *configImpl) Arguments() []string { |
| 273 | return c.arguments |
| 274 | } |
| 275 | |
| 276 | func (c *configImpl) OutDir() string { |
| 277 | if outDir, ok := c.environ.Get("OUT_DIR"); ok { |
| 278 | return outDir |
| 279 | } |
| 280 | return "out" |
| 281 | } |
| 282 | |
Dan Willemsen | 8a073a8 | 2017-02-04 17:30:44 -0800 | [diff] [blame] | 283 | func (c *configImpl) DistDir() string { |
| 284 | if distDir, ok := c.environ.Get("DIST_DIR"); ok { |
| 285 | return distDir |
| 286 | } |
| 287 | return filepath.Join(c.OutDir(), "dist") |
| 288 | } |
| 289 | |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 290 | func (c *configImpl) NinjaArgs() []string { |
Dan Willemsen | e0879fc | 2017-08-04 15:06:27 -0700 | [diff] [blame] | 291 | if c.skipMake { |
| 292 | return c.arguments |
| 293 | } |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 294 | return c.ninjaArgs |
| 295 | } |
| 296 | |
| 297 | func (c *configImpl) SoongOutDir() string { |
| 298 | return filepath.Join(c.OutDir(), "soong") |
| 299 | } |
| 300 | |
Jeff Gaston | efc1b41 | 2017-03-29 17:29:06 -0700 | [diff] [blame] | 301 | func (c *configImpl) TempDir() string { |
| 302 | return shared.TempDirForOutDir(c.SoongOutDir()) |
| 303 | } |
| 304 | |
Jeff Gaston | b64fc1c | 2017-08-04 12:30:12 -0700 | [diff] [blame] | 305 | func (c *configImpl) FileListDir() string { |
| 306 | return filepath.Join(c.OutDir(), ".module_paths") |
| 307 | } |
| 308 | |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 309 | func (c *configImpl) KatiSuffix() string { |
| 310 | if c.katiSuffix != "" { |
| 311 | return c.katiSuffix |
| 312 | } |
| 313 | panic("SetKatiSuffix has not been called") |
| 314 | } |
| 315 | |
Dan Willemsen | 8a073a8 | 2017-02-04 17:30:44 -0800 | [diff] [blame] | 316 | func (c *configImpl) Dist() bool { |
| 317 | return c.dist |
| 318 | } |
| 319 | |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 320 | func (c *configImpl) IsVerbose() bool { |
| 321 | return c.verbose |
| 322 | } |
| 323 | |
Dan Willemsen | e0879fc | 2017-08-04 15:06:27 -0700 | [diff] [blame] | 324 | func (c *configImpl) SkipMake() bool { |
| 325 | return c.skipMake |
| 326 | } |
| 327 | |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 328 | func (c *configImpl) TargetProduct() string { |
| 329 | if v, ok := c.environ.Get("TARGET_PRODUCT"); ok { |
| 330 | return v |
| 331 | } |
| 332 | panic("TARGET_PRODUCT is not defined") |
| 333 | } |
| 334 | |
Dan Willemsen | 02781d5 | 2017-05-12 19:28:13 -0700 | [diff] [blame] | 335 | func (c *configImpl) TargetDevice() string { |
| 336 | return c.targetDevice |
| 337 | } |
| 338 | |
| 339 | func (c *configImpl) SetTargetDevice(device string) { |
| 340 | c.targetDevice = device |
| 341 | } |
| 342 | |
| 343 | func (c *configImpl) TargetBuildVariant() string { |
| 344 | if v, ok := c.environ.Get("TARGET_BUILD_VARIANT"); ok { |
| 345 | return v |
| 346 | } |
| 347 | panic("TARGET_BUILD_VARIANT is not defined") |
| 348 | } |
| 349 | |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 350 | func (c *configImpl) KatiArgs() []string { |
| 351 | return c.katiArgs |
| 352 | } |
| 353 | |
| 354 | func (c *configImpl) Parallel() int { |
| 355 | return c.parallel |
| 356 | } |
| 357 | |
| 358 | func (c *configImpl) UseGoma() bool { |
| 359 | if v, ok := c.environ.Get("USE_GOMA"); ok { |
| 360 | v = strings.TrimSpace(v) |
| 361 | if v != "" && v != "false" { |
| 362 | return true |
| 363 | } |
| 364 | } |
| 365 | return false |
| 366 | } |
| 367 | |
| 368 | // RemoteParallel controls how many remote jobs (i.e., commands which contain |
Jeff Gaston | efc1b41 | 2017-03-29 17:29:06 -0700 | [diff] [blame] | 369 | // gomacc) are run in parallel. Note the parallelism of all other jobs is |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 370 | // still limited by Parallel() |
| 371 | func (c *configImpl) RemoteParallel() int { |
| 372 | if v, ok := c.environ.Get("NINJA_REMOTE_NUM_JOBS"); ok { |
| 373 | if i, err := strconv.Atoi(v); err == nil { |
| 374 | return i |
| 375 | } |
| 376 | } |
| 377 | return 500 |
| 378 | } |
| 379 | |
| 380 | func (c *configImpl) SetKatiArgs(args []string) { |
| 381 | c.katiArgs = args |
| 382 | } |
| 383 | |
| 384 | func (c *configImpl) SetNinjaArgs(args []string) { |
| 385 | c.ninjaArgs = args |
| 386 | } |
| 387 | |
| 388 | func (c *configImpl) SetKatiSuffix(suffix string) { |
| 389 | c.katiSuffix = suffix |
| 390 | } |
| 391 | |
Dan Willemsen | e0879fc | 2017-08-04 15:06:27 -0700 | [diff] [blame] | 392 | func (c *configImpl) LastKatiSuffixFile() string { |
| 393 | return filepath.Join(c.OutDir(), "last_kati_suffix") |
| 394 | } |
| 395 | |
| 396 | func (c *configImpl) HasKatiSuffix() bool { |
| 397 | return c.katiSuffix != "" |
| 398 | } |
| 399 | |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 400 | func (c *configImpl) KatiEnvFile() string { |
| 401 | return filepath.Join(c.OutDir(), "env"+c.KatiSuffix()+".sh") |
| 402 | } |
| 403 | |
| 404 | func (c *configImpl) KatiNinjaFile() string { |
| 405 | return filepath.Join(c.OutDir(), "build"+c.KatiSuffix()+".ninja") |
| 406 | } |
| 407 | |
| 408 | func (c *configImpl) SoongNinjaFile() string { |
| 409 | return filepath.Join(c.SoongOutDir(), "build.ninja") |
| 410 | } |
| 411 | |
| 412 | func (c *configImpl) CombinedNinjaFile() string { |
Dan Willemsen | e0879fc | 2017-08-04 15:06:27 -0700 | [diff] [blame] | 413 | if c.katiSuffix == "" { |
| 414 | return filepath.Join(c.OutDir(), "combined.ninja") |
| 415 | } |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 416 | return filepath.Join(c.OutDir(), "combined"+c.KatiSuffix()+".ninja") |
| 417 | } |
| 418 | |
| 419 | func (c *configImpl) SoongAndroidMk() string { |
| 420 | return filepath.Join(c.SoongOutDir(), "Android-"+c.TargetProduct()+".mk") |
| 421 | } |
| 422 | |
| 423 | func (c *configImpl) SoongMakeVarsMk() string { |
| 424 | return filepath.Join(c.SoongOutDir(), "make_vars-"+c.TargetProduct()+".mk") |
| 425 | } |
| 426 | |
Dan Willemsen | f052f78 | 2017-05-18 15:29:04 -0700 | [diff] [blame] | 427 | func (c *configImpl) ProductOut() string { |
Dan Willemsen | 4dc4e14 | 2017-09-08 14:35:43 -0700 | [diff] [blame] | 428 | return filepath.Join(c.OutDir(), "target", "product", c.TargetDevice()) |
Dan Willemsen | f052f78 | 2017-05-18 15:29:04 -0700 | [diff] [blame] | 429 | } |
| 430 | |
Dan Willemsen | 02781d5 | 2017-05-12 19:28:13 -0700 | [diff] [blame] | 431 | func (c *configImpl) DevicePreviousProductConfig() string { |
Dan Willemsen | f052f78 | 2017-05-18 15:29:04 -0700 | [diff] [blame] | 432 | return filepath.Join(c.ProductOut(), "previous_build_config.mk") |
| 433 | } |
| 434 | |
| 435 | func (c *configImpl) hostOutRoot() string { |
Dan Willemsen | 4dc4e14 | 2017-09-08 14:35:43 -0700 | [diff] [blame] | 436 | return filepath.Join(c.OutDir(), "host") |
Dan Willemsen | f052f78 | 2017-05-18 15:29:04 -0700 | [diff] [blame] | 437 | } |
| 438 | |
| 439 | func (c *configImpl) HostOut() string { |
| 440 | return filepath.Join(c.hostOutRoot(), c.HostPrebuiltTag()) |
| 441 | } |
| 442 | |
| 443 | // This probably needs to be multi-valued, so not exporting it for now |
| 444 | func (c *configImpl) hostCrossOut() string { |
| 445 | if runtime.GOOS == "linux" { |
| 446 | return filepath.Join(c.hostOutRoot(), "windows-x86") |
| 447 | } else { |
| 448 | return "" |
| 449 | } |
Dan Willemsen | 02781d5 | 2017-05-12 19:28:13 -0700 | [diff] [blame] | 450 | } |
| 451 | |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 452 | func (c *configImpl) HostPrebuiltTag() string { |
| 453 | if runtime.GOOS == "linux" { |
| 454 | return "linux-x86" |
| 455 | } else if runtime.GOOS == "darwin" { |
| 456 | return "darwin-x86" |
| 457 | } else { |
| 458 | panic("Unsupported OS") |
| 459 | } |
| 460 | } |
Dan Willemsen | f173d59 | 2017-04-27 14:28:00 -0700 | [diff] [blame] | 461 | |
Dan Willemsen | 8122bd5 | 2017-10-12 20:20:41 -0700 | [diff] [blame] | 462 | func (c *configImpl) PrebuiltBuildTool(name string) string { |
Dan Willemsen | f173d59 | 2017-04-27 14:28:00 -0700 | [diff] [blame] | 463 | if v, ok := c.environ.Get("SANITIZE_HOST"); ok { |
| 464 | if sanitize := strings.Fields(v); inList("address", sanitize) { |
Dan Willemsen | 8122bd5 | 2017-10-12 20:20:41 -0700 | [diff] [blame] | 465 | asan := filepath.Join("prebuilts/build-tools", c.HostPrebuiltTag(), "asan/bin", name) |
| 466 | if _, err := os.Stat(asan); err == nil { |
| 467 | return asan |
| 468 | } |
Dan Willemsen | f173d59 | 2017-04-27 14:28:00 -0700 | [diff] [blame] | 469 | } |
| 470 | } |
| 471 | return filepath.Join("prebuilts/build-tools", c.HostPrebuiltTag(), "bin", name) |
| 472 | } |