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