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