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