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