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 | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 107 | ) |
| 108 | |
| 109 | // Tell python not to spam the source tree with .pyc files. |
| 110 | ret.environ.Set("PYTHONDONTWRITEBYTECODE", "1") |
| 111 | |
Dan Willemsen | c2af0be | 2017-01-20 14:10:01 -0800 | [diff] [blame] | 112 | // Precondition: the current directory is the top of the source tree |
| 113 | if _, err := os.Stat(srcDirFileCheck); err != nil { |
| 114 | if os.IsNotExist(err) { |
| 115 | log.Fatalf("Current working directory must be the source tree. %q not found", srcDirFileCheck) |
| 116 | } |
| 117 | log.Fatalln("Error verifying tree state:", err) |
| 118 | } |
| 119 | |
Dan Willemsen | db8457c | 2017-05-12 16:38:17 -0700 | [diff] [blame] | 120 | if srcDir, err := filepath.Abs("."); err == nil { |
| 121 | if strings.ContainsRune(srcDir, ' ') { |
| 122 | log.Println("You are building in a directory whose absolute path contains a space character:") |
| 123 | log.Println() |
| 124 | log.Printf("%q\n", srcDir) |
| 125 | log.Println() |
| 126 | log.Fatalln("Directory names containing spaces are not supported") |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | if outDir := ret.OutDir(); strings.ContainsRune(outDir, ' ') { |
| 131 | log.Println("The absolute path of your output directory ($OUT_DIR) contains a space character:") |
| 132 | log.Println() |
| 133 | log.Printf("%q\n", outDir) |
| 134 | log.Println() |
| 135 | log.Fatalln("Directory names containing spaces are not supported") |
| 136 | } |
| 137 | |
| 138 | if distDir := ret.DistDir(); strings.ContainsRune(distDir, ' ') { |
| 139 | log.Println("The absolute path of your dist directory ($DIST_DIR) contains a space character:") |
| 140 | log.Println() |
| 141 | log.Printf("%q\n", distDir) |
| 142 | log.Println() |
| 143 | log.Fatalln("Directory names containing spaces are not supported") |
| 144 | } |
| 145 | |
Dan Willemsen | 9b58749 | 2017-07-10 22:13:00 -0700 | [diff] [blame] | 146 | return Config{ret} |
| 147 | } |
| 148 | |
| 149 | func (c *configImpl) parseArgs(ctx Context, args []string) { |
| 150 | for i := 0; i < len(args); i++ { |
| 151 | arg := strings.TrimSpace(args[i]) |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 152 | if arg == "--make-mode" { |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 153 | } else if arg == "showcommands" { |
Dan Willemsen | 9b58749 | 2017-07-10 22:13:00 -0700 | [diff] [blame] | 154 | c.verbose = true |
Dan Willemsen | e0879fc | 2017-08-04 15:06:27 -0700 | [diff] [blame] | 155 | } else if arg == "--skip-make" { |
| 156 | c.skipMake = true |
Dan Willemsen | 6ac63ef | 2017-10-17 20:35:34 -0700 | [diff] [blame^] | 157 | } else if len(arg) > 0 && arg[0] == '-' { |
Dan Willemsen | 9b58749 | 2017-07-10 22:13:00 -0700 | [diff] [blame] | 158 | parseArgNum := func(def int) int { |
| 159 | if len(arg) > 2 { |
| 160 | p, err := strconv.ParseUint(arg[2:], 10, 31) |
| 161 | if err != nil { |
| 162 | ctx.Fatalf("Failed to parse %q: %v", arg, err) |
| 163 | } |
| 164 | return int(p) |
| 165 | } else if i+1 < len(args) { |
| 166 | p, err := strconv.ParseUint(args[i+1], 10, 31) |
| 167 | if err == nil { |
| 168 | i++ |
| 169 | return int(p) |
| 170 | } |
| 171 | } |
| 172 | return def |
| 173 | } |
| 174 | |
Dan Willemsen | 6ac63ef | 2017-10-17 20:35:34 -0700 | [diff] [blame^] | 175 | if len(arg) > 1 && arg[1] == 'j' { |
Dan Willemsen | 9b58749 | 2017-07-10 22:13:00 -0700 | [diff] [blame] | 176 | c.parallel = parseArgNum(c.parallel) |
Dan Willemsen | 6ac63ef | 2017-10-17 20:35:34 -0700 | [diff] [blame^] | 177 | } else if len(arg) > 1 && arg[1] == 'k' { |
Dan Willemsen | 9b58749 | 2017-07-10 22:13:00 -0700 | [diff] [blame] | 178 | c.keepGoing = parseArgNum(0) |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 179 | } else { |
| 180 | ctx.Fatalln("Unknown option:", arg) |
| 181 | } |
Dan Willemsen | 091525e | 2017-07-11 14:17:50 -0700 | [diff] [blame] | 182 | } else if k, v, ok := decodeKeyValue(arg); ok && len(k) > 0 { |
| 183 | c.environ.Set(k, v) |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 184 | } else { |
Dan Willemsen | e0879fc | 2017-08-04 15:06:27 -0700 | [diff] [blame] | 185 | if arg == "dist" { |
| 186 | c.dist = true |
| 187 | } |
Dan Willemsen | 9b58749 | 2017-07-10 22:13:00 -0700 | [diff] [blame] | 188 | c.arguments = append(c.arguments, arg) |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 189 | } |
| 190 | } |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | // Lunch configures the environment for a specific product similarly to the |
| 194 | // `lunch` bash function. |
| 195 | func (c *configImpl) Lunch(ctx Context, product, variant string) { |
| 196 | if variant != "eng" && variant != "userdebug" && variant != "user" { |
| 197 | ctx.Fatalf("Invalid variant %q. Must be one of 'user', 'userdebug' or 'eng'", variant) |
| 198 | } |
| 199 | |
| 200 | c.environ.Set("TARGET_PRODUCT", product) |
| 201 | c.environ.Set("TARGET_BUILD_VARIANT", variant) |
| 202 | c.environ.Set("TARGET_BUILD_TYPE", "release") |
| 203 | c.environ.Unset("TARGET_BUILD_APPS") |
| 204 | } |
| 205 | |
| 206 | // Tapas configures the environment to build one or more unbundled apps, |
| 207 | // similarly to the `tapas` bash function. |
| 208 | func (c *configImpl) Tapas(ctx Context, apps []string, arch, variant string) { |
| 209 | if len(apps) == 0 { |
| 210 | apps = []string{"all"} |
| 211 | } |
| 212 | if variant == "" { |
| 213 | variant = "eng" |
| 214 | } |
| 215 | |
| 216 | if variant != "eng" && variant != "userdebug" && variant != "user" { |
| 217 | ctx.Fatalf("Invalid variant %q. Must be one of 'user', 'userdebug' or 'eng'", variant) |
| 218 | } |
| 219 | |
| 220 | var product string |
| 221 | switch arch { |
| 222 | case "armv5": |
| 223 | product = "generic_armv5" |
| 224 | case "arm", "": |
| 225 | product = "aosp_arm" |
| 226 | case "arm64": |
| 227 | product = "aosm_arm64" |
| 228 | case "mips": |
| 229 | product = "aosp_mips" |
| 230 | case "mips64": |
| 231 | product = "aosp_mips64" |
| 232 | case "x86": |
| 233 | product = "aosp_x86" |
| 234 | case "x86_64": |
| 235 | product = "aosp_x86_64" |
| 236 | default: |
| 237 | ctx.Fatalf("Invalid architecture: %q", arch) |
| 238 | } |
| 239 | |
| 240 | c.environ.Set("TARGET_PRODUCT", product) |
| 241 | c.environ.Set("TARGET_BUILD_VARIANT", variant) |
| 242 | c.environ.Set("TARGET_BUILD_TYPE", "release") |
| 243 | c.environ.Set("TARGET_BUILD_APPS", strings.Join(apps, " ")) |
| 244 | } |
| 245 | |
| 246 | func (c *configImpl) Environment() *Environment { |
| 247 | return c.environ |
| 248 | } |
| 249 | |
| 250 | func (c *configImpl) Arguments() []string { |
| 251 | return c.arguments |
| 252 | } |
| 253 | |
| 254 | func (c *configImpl) OutDir() string { |
| 255 | if outDir, ok := c.environ.Get("OUT_DIR"); ok { |
| 256 | return outDir |
| 257 | } |
| 258 | return "out" |
| 259 | } |
| 260 | |
Dan Willemsen | 8a073a8 | 2017-02-04 17:30:44 -0800 | [diff] [blame] | 261 | func (c *configImpl) DistDir() string { |
| 262 | if distDir, ok := c.environ.Get("DIST_DIR"); ok { |
| 263 | return distDir |
| 264 | } |
| 265 | return filepath.Join(c.OutDir(), "dist") |
| 266 | } |
| 267 | |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 268 | func (c *configImpl) NinjaArgs() []string { |
Dan Willemsen | e0879fc | 2017-08-04 15:06:27 -0700 | [diff] [blame] | 269 | if c.skipMake { |
| 270 | return c.arguments |
| 271 | } |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 272 | return c.ninjaArgs |
| 273 | } |
| 274 | |
| 275 | func (c *configImpl) SoongOutDir() string { |
| 276 | return filepath.Join(c.OutDir(), "soong") |
| 277 | } |
| 278 | |
Jeff Gaston | efc1b41 | 2017-03-29 17:29:06 -0700 | [diff] [blame] | 279 | func (c *configImpl) TempDir() string { |
| 280 | return shared.TempDirForOutDir(c.SoongOutDir()) |
| 281 | } |
| 282 | |
Jeff Gaston | b64fc1c | 2017-08-04 12:30:12 -0700 | [diff] [blame] | 283 | func (c *configImpl) FileListDir() string { |
| 284 | return filepath.Join(c.OutDir(), ".module_paths") |
| 285 | } |
| 286 | |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 287 | func (c *configImpl) KatiSuffix() string { |
| 288 | if c.katiSuffix != "" { |
| 289 | return c.katiSuffix |
| 290 | } |
| 291 | panic("SetKatiSuffix has not been called") |
| 292 | } |
| 293 | |
Dan Willemsen | 8a073a8 | 2017-02-04 17:30:44 -0800 | [diff] [blame] | 294 | func (c *configImpl) Dist() bool { |
| 295 | return c.dist |
| 296 | } |
| 297 | |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 298 | func (c *configImpl) IsVerbose() bool { |
| 299 | return c.verbose |
| 300 | } |
| 301 | |
Dan Willemsen | e0879fc | 2017-08-04 15:06:27 -0700 | [diff] [blame] | 302 | func (c *configImpl) SkipMake() bool { |
| 303 | return c.skipMake |
| 304 | } |
| 305 | |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 306 | func (c *configImpl) TargetProduct() string { |
| 307 | if v, ok := c.environ.Get("TARGET_PRODUCT"); ok { |
| 308 | return v |
| 309 | } |
| 310 | panic("TARGET_PRODUCT is not defined") |
| 311 | } |
| 312 | |
Dan Willemsen | 02781d5 | 2017-05-12 19:28:13 -0700 | [diff] [blame] | 313 | func (c *configImpl) TargetDevice() string { |
| 314 | return c.targetDevice |
| 315 | } |
| 316 | |
| 317 | func (c *configImpl) SetTargetDevice(device string) { |
| 318 | c.targetDevice = device |
| 319 | } |
| 320 | |
| 321 | func (c *configImpl) TargetBuildVariant() string { |
| 322 | if v, ok := c.environ.Get("TARGET_BUILD_VARIANT"); ok { |
| 323 | return v |
| 324 | } |
| 325 | panic("TARGET_BUILD_VARIANT is not defined") |
| 326 | } |
| 327 | |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 328 | func (c *configImpl) KatiArgs() []string { |
| 329 | return c.katiArgs |
| 330 | } |
| 331 | |
| 332 | func (c *configImpl) Parallel() int { |
| 333 | return c.parallel |
| 334 | } |
| 335 | |
| 336 | func (c *configImpl) UseGoma() bool { |
| 337 | if v, ok := c.environ.Get("USE_GOMA"); ok { |
| 338 | v = strings.TrimSpace(v) |
| 339 | if v != "" && v != "false" { |
| 340 | return true |
| 341 | } |
| 342 | } |
| 343 | return false |
| 344 | } |
| 345 | |
| 346 | // RemoteParallel controls how many remote jobs (i.e., commands which contain |
Jeff Gaston | efc1b41 | 2017-03-29 17:29:06 -0700 | [diff] [blame] | 347 | // 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] | 348 | // still limited by Parallel() |
| 349 | func (c *configImpl) RemoteParallel() int { |
| 350 | if v, ok := c.environ.Get("NINJA_REMOTE_NUM_JOBS"); ok { |
| 351 | if i, err := strconv.Atoi(v); err == nil { |
| 352 | return i |
| 353 | } |
| 354 | } |
| 355 | return 500 |
| 356 | } |
| 357 | |
| 358 | func (c *configImpl) SetKatiArgs(args []string) { |
| 359 | c.katiArgs = args |
| 360 | } |
| 361 | |
| 362 | func (c *configImpl) SetNinjaArgs(args []string) { |
| 363 | c.ninjaArgs = args |
| 364 | } |
| 365 | |
| 366 | func (c *configImpl) SetKatiSuffix(suffix string) { |
| 367 | c.katiSuffix = suffix |
| 368 | } |
| 369 | |
Dan Willemsen | e0879fc | 2017-08-04 15:06:27 -0700 | [diff] [blame] | 370 | func (c *configImpl) LastKatiSuffixFile() string { |
| 371 | return filepath.Join(c.OutDir(), "last_kati_suffix") |
| 372 | } |
| 373 | |
| 374 | func (c *configImpl) HasKatiSuffix() bool { |
| 375 | return c.katiSuffix != "" |
| 376 | } |
| 377 | |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 378 | func (c *configImpl) KatiEnvFile() string { |
| 379 | return filepath.Join(c.OutDir(), "env"+c.KatiSuffix()+".sh") |
| 380 | } |
| 381 | |
| 382 | func (c *configImpl) KatiNinjaFile() string { |
| 383 | return filepath.Join(c.OutDir(), "build"+c.KatiSuffix()+".ninja") |
| 384 | } |
| 385 | |
| 386 | func (c *configImpl) SoongNinjaFile() string { |
| 387 | return filepath.Join(c.SoongOutDir(), "build.ninja") |
| 388 | } |
| 389 | |
| 390 | func (c *configImpl) CombinedNinjaFile() string { |
Dan Willemsen | e0879fc | 2017-08-04 15:06:27 -0700 | [diff] [blame] | 391 | if c.katiSuffix == "" { |
| 392 | return filepath.Join(c.OutDir(), "combined.ninja") |
| 393 | } |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 394 | return filepath.Join(c.OutDir(), "combined"+c.KatiSuffix()+".ninja") |
| 395 | } |
| 396 | |
| 397 | func (c *configImpl) SoongAndroidMk() string { |
| 398 | return filepath.Join(c.SoongOutDir(), "Android-"+c.TargetProduct()+".mk") |
| 399 | } |
| 400 | |
| 401 | func (c *configImpl) SoongMakeVarsMk() string { |
| 402 | return filepath.Join(c.SoongOutDir(), "make_vars-"+c.TargetProduct()+".mk") |
| 403 | } |
| 404 | |
Dan Willemsen | f052f78 | 2017-05-18 15:29:04 -0700 | [diff] [blame] | 405 | func (c *configImpl) ProductOut() string { |
Dan Willemsen | 4dc4e14 | 2017-09-08 14:35:43 -0700 | [diff] [blame] | 406 | return filepath.Join(c.OutDir(), "target", "product", c.TargetDevice()) |
Dan Willemsen | f052f78 | 2017-05-18 15:29:04 -0700 | [diff] [blame] | 407 | } |
| 408 | |
Dan Willemsen | 02781d5 | 2017-05-12 19:28:13 -0700 | [diff] [blame] | 409 | func (c *configImpl) DevicePreviousProductConfig() string { |
Dan Willemsen | f052f78 | 2017-05-18 15:29:04 -0700 | [diff] [blame] | 410 | return filepath.Join(c.ProductOut(), "previous_build_config.mk") |
| 411 | } |
| 412 | |
| 413 | func (c *configImpl) hostOutRoot() string { |
Dan Willemsen | 4dc4e14 | 2017-09-08 14:35:43 -0700 | [diff] [blame] | 414 | return filepath.Join(c.OutDir(), "host") |
Dan Willemsen | f052f78 | 2017-05-18 15:29:04 -0700 | [diff] [blame] | 415 | } |
| 416 | |
| 417 | func (c *configImpl) HostOut() string { |
| 418 | return filepath.Join(c.hostOutRoot(), c.HostPrebuiltTag()) |
| 419 | } |
| 420 | |
| 421 | // This probably needs to be multi-valued, so not exporting it for now |
| 422 | func (c *configImpl) hostCrossOut() string { |
| 423 | if runtime.GOOS == "linux" { |
| 424 | return filepath.Join(c.hostOutRoot(), "windows-x86") |
| 425 | } else { |
| 426 | return "" |
| 427 | } |
Dan Willemsen | 02781d5 | 2017-05-12 19:28:13 -0700 | [diff] [blame] | 428 | } |
| 429 | |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 430 | func (c *configImpl) HostPrebuiltTag() string { |
| 431 | if runtime.GOOS == "linux" { |
| 432 | return "linux-x86" |
| 433 | } else if runtime.GOOS == "darwin" { |
| 434 | return "darwin-x86" |
| 435 | } else { |
| 436 | panic("Unsupported OS") |
| 437 | } |
| 438 | } |
Dan Willemsen | f173d59 | 2017-04-27 14:28:00 -0700 | [diff] [blame] | 439 | |
Dan Willemsen | 8122bd5 | 2017-10-12 20:20:41 -0700 | [diff] [blame] | 440 | func (c *configImpl) PrebuiltBuildTool(name string) string { |
Dan Willemsen | f173d59 | 2017-04-27 14:28:00 -0700 | [diff] [blame] | 441 | if v, ok := c.environ.Get("SANITIZE_HOST"); ok { |
| 442 | if sanitize := strings.Fields(v); inList("address", sanitize) { |
Dan Willemsen | 8122bd5 | 2017-10-12 20:20:41 -0700 | [diff] [blame] | 443 | asan := filepath.Join("prebuilts/build-tools", c.HostPrebuiltTag(), "asan/bin", name) |
| 444 | if _, err := os.Stat(asan); err == nil { |
| 445 | return asan |
| 446 | } |
Dan Willemsen | f173d59 | 2017-04-27 14:28:00 -0700 | [diff] [blame] | 447 | } |
| 448 | } |
| 449 | return filepath.Join("prebuilts/build-tools", c.HostPrebuiltTag(), "bin", name) |
| 450 | } |