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 |
Dan Willemsen | 2d31a44 | 2018-10-20 21:33:41 -0700 | [diff] [blame] | 37 | distDir string |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 38 | |
| 39 | // From the arguments |
Colin Cross | 3719349 | 2017-11-16 17:55:00 -0800 | [diff] [blame] | 40 | parallel int |
| 41 | keepGoing int |
| 42 | verbose bool |
| 43 | checkbuild bool |
| 44 | dist bool |
| 45 | skipMake bool |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 46 | |
| 47 | // From the product config |
Dan Willemsen | 6ab79db | 2018-05-02 00:06:28 -0700 | [diff] [blame] | 48 | katiArgs []string |
| 49 | ninjaArgs []string |
| 50 | katiSuffix string |
| 51 | targetDevice string |
| 52 | targetDeviceDir string |
Dan Willemsen | 3d60b11 | 2018-04-04 22:25:56 -0700 | [diff] [blame] | 53 | |
Dan Willemsen | d8aa39d | 2018-08-27 15:01:03 -0700 | [diff] [blame] | 54 | pdkBuild bool |
| 55 | |
Dan Willemsen | 6097746 | 2019-04-18 09:40:15 -0700 | [diff] [blame] | 56 | brokenDupRules bool |
| 57 | brokenUsesNetwork bool |
Dan Willemsen | 1849011 | 2018-05-25 16:30:04 -0700 | [diff] [blame] | 58 | |
| 59 | pathReplaced bool |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 60 | } |
| 61 | |
Dan Willemsen | c2af0be | 2017-01-20 14:10:01 -0800 | [diff] [blame] | 62 | const srcDirFileCheck = "build/soong/root.bp" |
| 63 | |
Patrice Arruda | 1384822 | 2019-04-22 17:12:02 -0700 | [diff] [blame] | 64 | type BuildAction uint |
| 65 | |
| 66 | const ( |
| 67 | // Builds all of the modules and their dependencies of a specified directory, relative to the root |
| 68 | // directory of the source tree. |
| 69 | BUILD_MODULES_IN_A_DIRECTORY BuildAction = iota |
| 70 | |
| 71 | // Builds all of the modules and their dependencies of a list of specified directories. All specified |
| 72 | // directories are relative to the root directory of the source tree. |
| 73 | BUILD_MODULES_IN_DIRECTORIES |
Patrice Arruda | 3928206 | 2019-06-20 16:35:12 -0700 | [diff] [blame^] | 74 | |
| 75 | // Build a list of specified modules. If none was specified, simply build the whole source tree. |
| 76 | BUILD_MODULES |
Patrice Arruda | 1384822 | 2019-04-22 17:12:02 -0700 | [diff] [blame] | 77 | ) |
| 78 | |
| 79 | // checkTopDir validates that the current directory is at the root directory of the source tree. |
| 80 | func checkTopDir(ctx Context) { |
| 81 | if _, err := os.Stat(srcDirFileCheck); err != nil { |
| 82 | if os.IsNotExist(err) { |
| 83 | ctx.Fatalf("Current working directory must be the source tree. %q not found.", srcDirFileCheck) |
| 84 | } |
| 85 | ctx.Fatalln("Error verifying tree state:", err) |
| 86 | } |
| 87 | } |
| 88 | |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 89 | func NewConfig(ctx Context, args ...string) Config { |
| 90 | ret := &configImpl{ |
| 91 | environ: OsEnvironment(), |
| 92 | } |
| 93 | |
Dan Willemsen | 9b58749 | 2017-07-10 22:13:00 -0700 | [diff] [blame] | 94 | // Sane default matching ninja |
| 95 | ret.parallel = runtime.NumCPU() + 2 |
| 96 | ret.keepGoing = 1 |
| 97 | |
| 98 | ret.parseArgs(ctx, args) |
| 99 | |
Dan Willemsen | 0c3919e | 2017-03-02 15:49:10 -0800 | [diff] [blame] | 100 | // Make sure OUT_DIR is set appropriately |
Dan Willemsen | 02f3add | 2017-05-12 13:50:19 -0700 | [diff] [blame] | 101 | if outDir, ok := ret.environ.Get("OUT_DIR"); ok { |
| 102 | ret.environ.Set("OUT_DIR", filepath.Clean(outDir)) |
| 103 | } else { |
Dan Willemsen | 0c3919e | 2017-03-02 15:49:10 -0800 | [diff] [blame] | 104 | outDir := "out" |
| 105 | if baseDir, ok := ret.environ.Get("OUT_DIR_COMMON_BASE"); ok { |
| 106 | if wd, err := os.Getwd(); err != nil { |
| 107 | ctx.Fatalln("Failed to get working directory:", err) |
| 108 | } else { |
| 109 | outDir = filepath.Join(baseDir, filepath.Base(wd)) |
| 110 | } |
| 111 | } |
| 112 | ret.environ.Set("OUT_DIR", outDir) |
| 113 | } |
| 114 | |
Dan Willemsen | 2d31a44 | 2018-10-20 21:33:41 -0700 | [diff] [blame] | 115 | if distDir, ok := ret.environ.Get("DIST_DIR"); ok { |
| 116 | ret.distDir = filepath.Clean(distDir) |
| 117 | } else { |
| 118 | ret.distDir = filepath.Join(ret.OutDir(), "dist") |
| 119 | } |
Dan Willemsen | d50e89f | 2018-10-16 17:49:25 -0700 | [diff] [blame] | 120 | |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 121 | ret.environ.Unset( |
| 122 | // We're already using it |
| 123 | "USE_SOONG_UI", |
| 124 | |
| 125 | // We should never use GOROOT/GOPATH from the shell environment |
| 126 | "GOROOT", |
| 127 | "GOPATH", |
| 128 | |
| 129 | // These should only come from Soong, not the environment. |
| 130 | "CLANG", |
| 131 | "CLANG_CXX", |
| 132 | "CCC_CC", |
| 133 | "CCC_CXX", |
| 134 | |
| 135 | // Used by the goma compiler wrapper, but should only be set by |
| 136 | // gomacc |
| 137 | "GOMACC_PATH", |
Dan Willemsen | 0c3919e | 2017-03-02 15:49:10 -0800 | [diff] [blame] | 138 | |
| 139 | // We handle this above |
| 140 | "OUT_DIR_COMMON_BASE", |
Dan Willemsen | 68a0985 | 2017-04-18 13:56:57 -0700 | [diff] [blame] | 141 | |
Dan Willemsen | 2d31a44 | 2018-10-20 21:33:41 -0700 | [diff] [blame] | 142 | // This is handled above too, and set for individual commands later |
| 143 | "DIST_DIR", |
| 144 | |
Dan Willemsen | 68a0985 | 2017-04-18 13:56:57 -0700 | [diff] [blame] | 145 | // Variables that have caused problems in the past |
Dan Willemsen | ebfe33a | 2018-05-01 10:07:50 -0700 | [diff] [blame] | 146 | "CDPATH", |
Dan Willemsen | 68a0985 | 2017-04-18 13:56:57 -0700 | [diff] [blame] | 147 | "DISPLAY", |
| 148 | "GREP_OPTIONS", |
Dan Willemsen | ebfe33a | 2018-05-01 10:07:50 -0700 | [diff] [blame] | 149 | "NDK_ROOT", |
Dan Willemsen | 00fcb26 | 2018-08-15 15:35:38 -0700 | [diff] [blame] | 150 | "POSIXLY_CORRECT", |
Dan Willemsen | c40e10b | 2017-07-11 14:30:00 -0700 | [diff] [blame] | 151 | |
| 152 | // Drop make flags |
| 153 | "MAKEFLAGS", |
| 154 | "MAKELEVEL", |
| 155 | "MFLAGS", |
Dan Willemsen | d9e8f0a | 2017-10-30 13:42:06 -0700 | [diff] [blame] | 156 | |
| 157 | // Set in envsetup.sh, reset in makefiles |
| 158 | "ANDROID_JAVA_TOOLCHAIN", |
Colin Cross | 7f09c40 | 2018-07-11 14:49:31 -0700 | [diff] [blame] | 159 | |
| 160 | // Set by envsetup.sh, but shouldn't be used inside the build because envsetup.sh is optional |
| 161 | "ANDROID_BUILD_TOP", |
| 162 | "ANDROID_HOST_OUT", |
| 163 | "ANDROID_PRODUCT_OUT", |
| 164 | "ANDROID_HOST_OUT_TESTCASES", |
| 165 | "ANDROID_TARGET_OUT_TESTCASES", |
| 166 | "ANDROID_TOOLCHAIN", |
| 167 | "ANDROID_TOOLCHAIN_2ND_ARCH", |
| 168 | "ANDROID_DEV_SCRIPTS", |
| 169 | "ANDROID_EMULATOR_PREBUILTS", |
| 170 | "ANDROID_PRE_BUILD_PATHS", |
Dan Willemsen | f99915f | 2018-10-25 22:04:42 -0700 | [diff] [blame] | 171 | |
| 172 | // Only set in multiproduct_kati after config generation |
| 173 | "EMPTY_NINJA_FILE", |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 174 | ) |
| 175 | |
| 176 | // Tell python not to spam the source tree with .pyc files. |
| 177 | ret.environ.Set("PYTHONDONTWRITEBYTECODE", "1") |
| 178 | |
Dan Willemsen | 32a669b | 2018-03-08 19:42:00 -0800 | [diff] [blame] | 179 | ret.environ.Set("TMPDIR", absPath(ctx, ret.TempDir())) |
| 180 | |
Dan Willemsen | c2af0be | 2017-01-20 14:10:01 -0800 | [diff] [blame] | 181 | // Precondition: the current directory is the top of the source tree |
Patrice Arruda | 1384822 | 2019-04-22 17:12:02 -0700 | [diff] [blame] | 182 | checkTopDir(ctx) |
Dan Willemsen | c2af0be | 2017-01-20 14:10:01 -0800 | [diff] [blame] | 183 | |
Dan Willemsen | d9e8f0a | 2017-10-30 13:42:06 -0700 | [diff] [blame] | 184 | if srcDir := absPath(ctx, "."); strings.ContainsRune(srcDir, ' ') { |
| 185 | log.Println("You are building in a directory whose absolute path contains a space character:") |
| 186 | log.Println() |
| 187 | log.Printf("%q\n", srcDir) |
| 188 | log.Println() |
| 189 | log.Fatalln("Directory names containing spaces are not supported") |
Dan Willemsen | db8457c | 2017-05-12 16:38:17 -0700 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | if outDir := ret.OutDir(); strings.ContainsRune(outDir, ' ') { |
| 193 | log.Println("The absolute path of your output directory ($OUT_DIR) contains a space character:") |
| 194 | log.Println() |
| 195 | log.Printf("%q\n", outDir) |
| 196 | log.Println() |
| 197 | log.Fatalln("Directory names containing spaces are not supported") |
| 198 | } |
| 199 | |
| 200 | if distDir := ret.DistDir(); strings.ContainsRune(distDir, ' ') { |
| 201 | log.Println("The absolute path of your dist directory ($DIST_DIR) contains a space character:") |
| 202 | log.Println() |
| 203 | log.Printf("%q\n", distDir) |
| 204 | log.Println() |
| 205 | log.Fatalln("Directory names containing spaces are not supported") |
| 206 | } |
| 207 | |
Dan Willemsen | d9e8f0a | 2017-10-30 13:42:06 -0700 | [diff] [blame] | 208 | // Configure Java-related variables, including adding it to $PATH |
Tobias Thierer | e59aeff | 2017-12-20 22:40:39 +0000 | [diff] [blame] | 209 | java8Home := filepath.Join("prebuilts/jdk/jdk8", ret.HostPrebuiltTag()) |
| 210 | java9Home := filepath.Join("prebuilts/jdk/jdk9", ret.HostPrebuiltTag()) |
Dan Willemsen | d9e8f0a | 2017-10-30 13:42:06 -0700 | [diff] [blame] | 211 | javaHome := func() string { |
| 212 | if override, ok := ret.environ.Get("OVERRIDE_ANDROID_JAVA_HOME"); ok { |
| 213 | return override |
| 214 | } |
Colin Cross | 997262f | 2018-06-19 22:49:39 -0700 | [diff] [blame] | 215 | return java9Home |
Dan Willemsen | d9e8f0a | 2017-10-30 13:42:06 -0700 | [diff] [blame] | 216 | }() |
| 217 | absJavaHome := absPath(ctx, javaHome) |
| 218 | |
Dan Willemsen | ed86952 | 2018-01-08 14:58:46 -0800 | [diff] [blame] | 219 | ret.configureLocale(ctx) |
| 220 | |
Dan Willemsen | d9e8f0a | 2017-10-30 13:42:06 -0700 | [diff] [blame] | 221 | newPath := []string{filepath.Join(absJavaHome, "bin")} |
| 222 | if path, ok := ret.environ.Get("PATH"); ok && path != "" { |
| 223 | newPath = append(newPath, path) |
| 224 | } |
| 225 | ret.environ.Unset("OVERRIDE_ANDROID_JAVA_HOME") |
| 226 | ret.environ.Set("JAVA_HOME", absJavaHome) |
| 227 | ret.environ.Set("ANDROID_JAVA_HOME", javaHome) |
Tobias Thierer | e59aeff | 2017-12-20 22:40:39 +0000 | [diff] [blame] | 228 | ret.environ.Set("ANDROID_JAVA8_HOME", java8Home) |
| 229 | ret.environ.Set("ANDROID_JAVA9_HOME", java9Home) |
Dan Willemsen | d9e8f0a | 2017-10-30 13:42:06 -0700 | [diff] [blame] | 230 | ret.environ.Set("PATH", strings.Join(newPath, string(filepath.ListSeparator))) |
| 231 | |
Nan Zhang | 2e6a4ff | 2018-02-14 13:27:26 -0800 | [diff] [blame] | 232 | outDir := ret.OutDir() |
| 233 | buildDateTimeFile := filepath.Join(outDir, "build_date.txt") |
| 234 | var content string |
| 235 | if buildDateTime, ok := ret.environ.Get("BUILD_DATETIME"); ok && buildDateTime != "" { |
| 236 | content = buildDateTime |
| 237 | } else { |
| 238 | content = strconv.FormatInt(time.Now().Unix(), 10) |
| 239 | } |
Nan Zhang | 17f2767 | 2018-12-12 16:01:49 -0800 | [diff] [blame] | 240 | if ctx.Metrics != nil { |
| 241 | ctx.Metrics.SetBuildDateTime(content) |
| 242 | } |
Nan Zhang | 2e6a4ff | 2018-02-14 13:27:26 -0800 | [diff] [blame] | 243 | err := ioutil.WriteFile(buildDateTimeFile, []byte(content), 0777) |
| 244 | if err != nil { |
| 245 | ctx.Fatalln("Failed to write BUILD_DATETIME to file:", err) |
| 246 | } |
| 247 | ret.environ.Set("BUILD_DATETIME_FILE", buildDateTimeFile) |
| 248 | |
Dan Willemsen | 9b58749 | 2017-07-10 22:13:00 -0700 | [diff] [blame] | 249 | return Config{ret} |
| 250 | } |
| 251 | |
Patrice Arruda | 1384822 | 2019-04-22 17:12:02 -0700 | [diff] [blame] | 252 | // NewBuildActionConfig returns a build configuration based on the build action. The arguments are |
| 253 | // processed based on the build action and extracts any arguments that belongs to the build action. |
| 254 | func NewBuildActionConfig(action BuildAction, dir string, buildDependencies bool, ctx Context, args ...string) Config { |
| 255 | return NewConfig(ctx, getConfigArgs(action, dir, buildDependencies, ctx, args)...) |
| 256 | } |
| 257 | |
| 258 | // getConfigArgs processes the command arguments based on the build action and creates a set of new |
| 259 | // arguments to be accepted by Config. |
| 260 | func getConfigArgs(action BuildAction, dir string, buildDependencies bool, ctx Context, args []string) []string { |
| 261 | // The next block of code verifies that the current directory is the root directory of the source |
| 262 | // tree. It then finds the relative path of dir based on the root directory of the source tree |
| 263 | // and verify that dir is inside of the source tree. |
| 264 | checkTopDir(ctx) |
| 265 | topDir, err := os.Getwd() |
| 266 | if err != nil { |
| 267 | ctx.Fatalf("Error retrieving top directory: %v", err) |
| 268 | } |
| 269 | dir, err = filepath.Abs(dir) |
| 270 | if err != nil { |
| 271 | ctx.Fatalf("Unable to find absolute path %s: %v", dir, err) |
| 272 | } |
| 273 | relDir, err := filepath.Rel(topDir, dir) |
| 274 | if err != nil { |
| 275 | ctx.Fatalf("Unable to find relative path %s of %s: %v", relDir, topDir, err) |
| 276 | } |
| 277 | // If there are ".." in the path, it's not in the source tree. |
| 278 | if strings.Contains(relDir, "..") { |
| 279 | ctx.Fatalf("Directory %s is not under the source tree %s", dir, topDir) |
| 280 | } |
| 281 | |
| 282 | configArgs := args[:] |
| 283 | |
| 284 | // If the arguments contains GET-INSTALL-PATH, change the target name prefix from MODULES-IN- to |
| 285 | // GET-INSTALL-PATH-IN- to extract the installation path instead of building the modules. |
| 286 | targetNamePrefix := "MODULES-IN-" |
| 287 | if inList("GET-INSTALL-PATH", configArgs) { |
| 288 | targetNamePrefix = "GET-INSTALL-PATH-IN-" |
| 289 | configArgs = removeFromList("GET-INSTALL-PATH", configArgs) |
| 290 | } |
| 291 | |
| 292 | var buildFiles []string |
| 293 | var targets []string |
| 294 | |
| 295 | switch action { |
Patrice Arruda | 3928206 | 2019-06-20 16:35:12 -0700 | [diff] [blame^] | 296 | case BUILD_MODULES: |
| 297 | // No additional processing is required when building a list of specific modules or all modules. |
Patrice Arruda | 1384822 | 2019-04-22 17:12:02 -0700 | [diff] [blame] | 298 | case BUILD_MODULES_IN_A_DIRECTORY: |
| 299 | // If dir is the root source tree, all the modules are built of the source tree are built so |
| 300 | // no need to find the build file. |
| 301 | if topDir == dir { |
| 302 | break |
| 303 | } |
| 304 | // Find the build file from the directory where the build action was triggered by traversing up |
| 305 | // the source tree. If a blank build filename is returned, simply use the directory where the build |
| 306 | // action was invoked. |
| 307 | buildFile := findBuildFile(ctx, relDir) |
| 308 | if buildFile == "" { |
| 309 | buildFile = filepath.Join(relDir, "Android.mk") |
| 310 | } |
| 311 | buildFiles = []string{buildFile} |
| 312 | targets = []string{convertToTarget(filepath.Dir(buildFile), targetNamePrefix)} |
| 313 | case BUILD_MODULES_IN_DIRECTORIES: |
| 314 | newConfigArgs, dirs := splitArgs(configArgs) |
| 315 | configArgs = newConfigArgs |
| 316 | targets, buildFiles = getTargetsFromDirs(ctx, relDir, dirs, targetNamePrefix) |
| 317 | } |
| 318 | |
| 319 | // This is to support building modules without building their dependencies. Soon, this will be |
| 320 | // deprecated. |
| 321 | if !buildDependencies && len(buildFiles) > 0 { |
| 322 | if err := os.Setenv("ONE_SHOT_MAKEFILE", strings.Join(buildFiles, " ")); err != nil { |
| 323 | ctx.Fatalf("Unable to set ONE_SHOT_MAKEFILE environment variable: %v", err) |
| 324 | } |
| 325 | } |
| 326 | |
| 327 | // Tidy only override all other specified targets. |
| 328 | tidyOnly := os.Getenv("WITH_TIDY_ONLY") |
| 329 | if tidyOnly == "true" || tidyOnly == "1" { |
| 330 | configArgs = append(configArgs, "tidy_only") |
| 331 | } else { |
| 332 | configArgs = append(configArgs, targets...) |
| 333 | } |
| 334 | |
| 335 | return configArgs |
| 336 | } |
| 337 | |
| 338 | // convertToTarget replaces "/" to "-" in dir and pre-append the targetNamePrefix to the target name. |
| 339 | func convertToTarget(dir string, targetNamePrefix string) string { |
| 340 | return targetNamePrefix + strings.ReplaceAll(dir, "/", "-") |
| 341 | } |
| 342 | |
| 343 | // findBuildFile finds a build file (makefile or blueprint file) by looking at dir first. If not |
| 344 | // found, go up one level and repeat again until one is found and the path of that build file |
| 345 | // relative to the root directory of the source tree is returned. The returned filename of build |
| 346 | // file is "Android.mk". If one was not found, a blank string is returned. |
| 347 | func findBuildFile(ctx Context, dir string) string { |
| 348 | // If the string is empty, assume it is top directory of the source tree. |
| 349 | if dir == "" { |
| 350 | return "" |
| 351 | } |
| 352 | |
| 353 | for ; dir != "."; dir = filepath.Dir(dir) { |
| 354 | for _, buildFile := range []string{"Android.bp", "Android.mk"} { |
| 355 | _, err := os.Stat(filepath.Join(dir, buildFile)) |
| 356 | if err == nil { |
| 357 | // Returning the filename Android.mk as it might be used for ONE_SHOT_MAKEFILE variable. |
| 358 | return filepath.Join(dir, "Android.mk") |
| 359 | } |
| 360 | if !os.IsNotExist(err) { |
| 361 | ctx.Fatalf("Error retrieving the build file stats: %v", err) |
| 362 | } |
| 363 | } |
| 364 | } |
| 365 | |
| 366 | return "" |
| 367 | } |
| 368 | |
| 369 | // splitArgs iterates over the arguments list and splits into two lists: arguments and directories. |
| 370 | func splitArgs(args []string) (newArgs []string, dirs []string) { |
| 371 | specialArgs := map[string]bool{ |
| 372 | "showcommands": true, |
| 373 | "snod": true, |
| 374 | "dist": true, |
| 375 | "checkbuild": true, |
| 376 | } |
| 377 | |
| 378 | newArgs = []string{} |
| 379 | dirs = []string{} |
| 380 | |
| 381 | for _, arg := range args { |
| 382 | // It's a dash argument if it starts with "-" or it's a key=value pair, it's not a directory. |
| 383 | if strings.IndexRune(arg, '-') == 0 || strings.IndexRune(arg, '=') != -1 { |
| 384 | newArgs = append(newArgs, arg) |
| 385 | continue |
| 386 | } |
| 387 | |
| 388 | if _, ok := specialArgs[arg]; ok { |
| 389 | newArgs = append(newArgs, arg) |
| 390 | continue |
| 391 | } |
| 392 | |
| 393 | dirs = append(dirs, arg) |
| 394 | } |
| 395 | |
| 396 | return newArgs, dirs |
| 397 | } |
| 398 | |
| 399 | // getTargetsFromDirs iterates over the dirs list and creates a list of targets to build. If a |
| 400 | // directory from the dirs list does not exist, a fatal error is raised. relDir is related to the |
| 401 | // source root tree where the build action command was invoked. Each directory is validated if the |
| 402 | // build file can be found and follows the format "dir1:target1,target2,...". Target is optional. |
| 403 | func getTargetsFromDirs(ctx Context, relDir string, dirs []string, targetNamePrefix string) (targets []string, buildFiles []string) { |
| 404 | for _, dir := range dirs { |
| 405 | // The directory may have specified specific modules to build. ":" is the separator to separate |
| 406 | // the directory and the list of modules. |
| 407 | s := strings.Split(dir, ":") |
| 408 | l := len(s) |
| 409 | if l > 2 { // more than one ":" was specified. |
| 410 | ctx.Fatalf("%s not in proper directory:target1,target2,... format (\":\" was specified more than once)", dir) |
| 411 | } |
| 412 | |
| 413 | dir = filepath.Join(relDir, s[0]) |
| 414 | if _, err := os.Stat(dir); err != nil { |
| 415 | ctx.Fatalf("couldn't find directory %s", dir) |
| 416 | } |
| 417 | |
| 418 | // Verify that if there are any targets specified after ":". Each target is separated by ",". |
| 419 | var newTargets []string |
| 420 | if l == 2 && s[1] != "" { |
| 421 | newTargets = strings.Split(s[1], ",") |
| 422 | if inList("", newTargets) { |
| 423 | ctx.Fatalf("%s not in proper directory:target1,target2,... format", dir) |
| 424 | } |
| 425 | } |
| 426 | |
| 427 | buildFile := findBuildFile(ctx, dir) |
| 428 | if buildFile == "" { |
| 429 | ctx.Fatalf("Build file not found for %s directory", dir) |
| 430 | } |
| 431 | buildFileDir := filepath.Dir(buildFile) |
| 432 | |
| 433 | // If there are specified targets, find the build file in the directory. If dir does not |
| 434 | // contain the build file, bail out as it is required for one shot build. If there are no |
| 435 | // target specified, build all the modules in dir (or the closest one in the dir path). |
| 436 | if len(newTargets) > 0 { |
| 437 | if buildFileDir != dir { |
| 438 | ctx.Fatalf("Couldn't locate a build file from %s directory", dir) |
| 439 | } |
| 440 | } else { |
| 441 | newTargets = []string{convertToTarget(buildFileDir, targetNamePrefix)} |
| 442 | } |
| 443 | |
| 444 | buildFiles = append(buildFiles, buildFile) |
| 445 | targets = append(targets, newTargets...) |
| 446 | } |
| 447 | |
| 448 | return targets, buildFiles |
| 449 | } |
| 450 | |
Dan Willemsen | 9b58749 | 2017-07-10 22:13:00 -0700 | [diff] [blame] | 451 | func (c *configImpl) parseArgs(ctx Context, args []string) { |
| 452 | for i := 0; i < len(args); i++ { |
| 453 | arg := strings.TrimSpace(args[i]) |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 454 | if arg == "--make-mode" { |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 455 | } else if arg == "showcommands" { |
Dan Willemsen | 9b58749 | 2017-07-10 22:13:00 -0700 | [diff] [blame] | 456 | c.verbose = true |
Dan Willemsen | e0879fc | 2017-08-04 15:06:27 -0700 | [diff] [blame] | 457 | } else if arg == "--skip-make" { |
| 458 | c.skipMake = true |
Dan Willemsen | 6ac63ef | 2017-10-17 20:35:34 -0700 | [diff] [blame] | 459 | } else if len(arg) > 0 && arg[0] == '-' { |
Dan Willemsen | 9b58749 | 2017-07-10 22:13:00 -0700 | [diff] [blame] | 460 | parseArgNum := func(def int) int { |
| 461 | if len(arg) > 2 { |
| 462 | p, err := strconv.ParseUint(arg[2:], 10, 31) |
| 463 | if err != nil { |
| 464 | ctx.Fatalf("Failed to parse %q: %v", arg, err) |
| 465 | } |
| 466 | return int(p) |
| 467 | } else if i+1 < len(args) { |
| 468 | p, err := strconv.ParseUint(args[i+1], 10, 31) |
| 469 | if err == nil { |
| 470 | i++ |
| 471 | return int(p) |
| 472 | } |
| 473 | } |
| 474 | return def |
| 475 | } |
| 476 | |
Dan Willemsen | 6ac63ef | 2017-10-17 20:35:34 -0700 | [diff] [blame] | 477 | if len(arg) > 1 && arg[1] == 'j' { |
Dan Willemsen | 9b58749 | 2017-07-10 22:13:00 -0700 | [diff] [blame] | 478 | c.parallel = parseArgNum(c.parallel) |
Dan Willemsen | 6ac63ef | 2017-10-17 20:35:34 -0700 | [diff] [blame] | 479 | } else if len(arg) > 1 && arg[1] == 'k' { |
Dan Willemsen | 9b58749 | 2017-07-10 22:13:00 -0700 | [diff] [blame] | 480 | c.keepGoing = parseArgNum(0) |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 481 | } else { |
| 482 | ctx.Fatalln("Unknown option:", arg) |
| 483 | } |
Dan Willemsen | 091525e | 2017-07-11 14:17:50 -0700 | [diff] [blame] | 484 | } else if k, v, ok := decodeKeyValue(arg); ok && len(k) > 0 { |
| 485 | c.environ.Set(k, v) |
Dan Willemsen | 2d31a44 | 2018-10-20 21:33:41 -0700 | [diff] [blame] | 486 | } else if arg == "dist" { |
| 487 | c.dist = true |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 488 | } else { |
Dan Willemsen | 2d31a44 | 2018-10-20 21:33:41 -0700 | [diff] [blame] | 489 | if arg == "checkbuild" { |
Colin Cross | 3719349 | 2017-11-16 17:55:00 -0800 | [diff] [blame] | 490 | c.checkbuild = true |
Dan Willemsen | e0879fc | 2017-08-04 15:06:27 -0700 | [diff] [blame] | 491 | } |
Dan Willemsen | 9b58749 | 2017-07-10 22:13:00 -0700 | [diff] [blame] | 492 | c.arguments = append(c.arguments, arg) |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 493 | } |
| 494 | } |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 495 | } |
| 496 | |
Dan Willemsen | ed86952 | 2018-01-08 14:58:46 -0800 | [diff] [blame] | 497 | func (c *configImpl) configureLocale(ctx Context) { |
| 498 | cmd := Command(ctx, Config{c}, "locale", "locale", "-a") |
| 499 | output, err := cmd.Output() |
| 500 | |
| 501 | var locales []string |
| 502 | if err == nil { |
| 503 | locales = strings.Split(string(output), "\n") |
| 504 | } else { |
| 505 | // If we're unable to list the locales, let's assume en_US.UTF-8 |
| 506 | locales = []string{"en_US.UTF-8"} |
| 507 | ctx.Verbosef("Failed to list locales (%q), falling back to %q", err, locales) |
| 508 | } |
| 509 | |
| 510 | // gettext uses LANGUAGE, which is passed directly through |
| 511 | |
| 512 | // For LANG and LC_*, only preserve the evaluated version of |
| 513 | // LC_MESSAGES |
| 514 | user_lang := "" |
| 515 | if lc_all, ok := c.environ.Get("LC_ALL"); ok { |
| 516 | user_lang = lc_all |
| 517 | } else if lc_messages, ok := c.environ.Get("LC_MESSAGES"); ok { |
| 518 | user_lang = lc_messages |
| 519 | } else if lang, ok := c.environ.Get("LANG"); ok { |
| 520 | user_lang = lang |
| 521 | } |
| 522 | |
| 523 | c.environ.UnsetWithPrefix("LC_") |
| 524 | |
| 525 | if user_lang != "" { |
| 526 | c.environ.Set("LC_MESSAGES", user_lang) |
| 527 | } |
| 528 | |
| 529 | // The for LANG, use C.UTF-8 if it exists (Debian currently, proposed |
| 530 | // for others) |
| 531 | if inList("C.UTF-8", locales) { |
| 532 | c.environ.Set("LANG", "C.UTF-8") |
Aaron Kling | d236e0e | 2018-08-07 19:21:36 -0500 | [diff] [blame] | 533 | } else if inList("C.utf8", locales) { |
| 534 | // These normalize to the same thing |
| 535 | c.environ.Set("LANG", "C.UTF-8") |
Dan Willemsen | ed86952 | 2018-01-08 14:58:46 -0800 | [diff] [blame] | 536 | } else if inList("en_US.UTF-8", locales) { |
| 537 | c.environ.Set("LANG", "en_US.UTF-8") |
| 538 | } else if inList("en_US.utf8", locales) { |
| 539 | // These normalize to the same thing |
| 540 | c.environ.Set("LANG", "en_US.UTF-8") |
| 541 | } else { |
| 542 | ctx.Fatalln("System doesn't support either C.UTF-8 or en_US.UTF-8") |
| 543 | } |
| 544 | } |
| 545 | |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 546 | // Lunch configures the environment for a specific product similarly to the |
| 547 | // `lunch` bash function. |
| 548 | func (c *configImpl) Lunch(ctx Context, product, variant string) { |
| 549 | if variant != "eng" && variant != "userdebug" && variant != "user" { |
| 550 | ctx.Fatalf("Invalid variant %q. Must be one of 'user', 'userdebug' or 'eng'", variant) |
| 551 | } |
| 552 | |
| 553 | c.environ.Set("TARGET_PRODUCT", product) |
| 554 | c.environ.Set("TARGET_BUILD_VARIANT", variant) |
| 555 | c.environ.Set("TARGET_BUILD_TYPE", "release") |
| 556 | c.environ.Unset("TARGET_BUILD_APPS") |
| 557 | } |
| 558 | |
| 559 | // Tapas configures the environment to build one or more unbundled apps, |
| 560 | // similarly to the `tapas` bash function. |
| 561 | func (c *configImpl) Tapas(ctx Context, apps []string, arch, variant string) { |
| 562 | if len(apps) == 0 { |
| 563 | apps = []string{"all"} |
| 564 | } |
| 565 | if variant == "" { |
| 566 | variant = "eng" |
| 567 | } |
| 568 | |
| 569 | if variant != "eng" && variant != "userdebug" && variant != "user" { |
| 570 | ctx.Fatalf("Invalid variant %q. Must be one of 'user', 'userdebug' or 'eng'", variant) |
| 571 | } |
| 572 | |
| 573 | var product string |
| 574 | switch arch { |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 575 | case "arm", "": |
| 576 | product = "aosp_arm" |
| 577 | case "arm64": |
| 578 | product = "aosm_arm64" |
| 579 | case "mips": |
| 580 | product = "aosp_mips" |
| 581 | case "mips64": |
| 582 | product = "aosp_mips64" |
| 583 | case "x86": |
| 584 | product = "aosp_x86" |
| 585 | case "x86_64": |
| 586 | product = "aosp_x86_64" |
| 587 | default: |
| 588 | ctx.Fatalf("Invalid architecture: %q", arch) |
| 589 | } |
| 590 | |
| 591 | c.environ.Set("TARGET_PRODUCT", product) |
| 592 | c.environ.Set("TARGET_BUILD_VARIANT", variant) |
| 593 | c.environ.Set("TARGET_BUILD_TYPE", "release") |
| 594 | c.environ.Set("TARGET_BUILD_APPS", strings.Join(apps, " ")) |
| 595 | } |
| 596 | |
| 597 | func (c *configImpl) Environment() *Environment { |
| 598 | return c.environ |
| 599 | } |
| 600 | |
| 601 | func (c *configImpl) Arguments() []string { |
| 602 | return c.arguments |
| 603 | } |
| 604 | |
| 605 | func (c *configImpl) OutDir() string { |
| 606 | if outDir, ok := c.environ.Get("OUT_DIR"); ok { |
Dan Willemsen | 25a5618 | 2018-08-31 20:25:32 -0700 | [diff] [blame] | 607 | return filepath.Clean(outDir) |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 608 | } |
| 609 | return "out" |
| 610 | } |
| 611 | |
Dan Willemsen | 8a073a8 | 2017-02-04 17:30:44 -0800 | [diff] [blame] | 612 | func (c *configImpl) DistDir() string { |
Dan Willemsen | 2d31a44 | 2018-10-20 21:33:41 -0700 | [diff] [blame] | 613 | return c.distDir |
Dan Willemsen | 8a073a8 | 2017-02-04 17:30:44 -0800 | [diff] [blame] | 614 | } |
| 615 | |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 616 | func (c *configImpl) NinjaArgs() []string { |
Dan Willemsen | e0879fc | 2017-08-04 15:06:27 -0700 | [diff] [blame] | 617 | if c.skipMake { |
| 618 | return c.arguments |
| 619 | } |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 620 | return c.ninjaArgs |
| 621 | } |
| 622 | |
| 623 | func (c *configImpl) SoongOutDir() string { |
| 624 | return filepath.Join(c.OutDir(), "soong") |
| 625 | } |
| 626 | |
Jeff Gaston | efc1b41 | 2017-03-29 17:29:06 -0700 | [diff] [blame] | 627 | func (c *configImpl) TempDir() string { |
| 628 | return shared.TempDirForOutDir(c.SoongOutDir()) |
| 629 | } |
| 630 | |
Jeff Gaston | b64fc1c | 2017-08-04 12:30:12 -0700 | [diff] [blame] | 631 | func (c *configImpl) FileListDir() string { |
| 632 | return filepath.Join(c.OutDir(), ".module_paths") |
| 633 | } |
| 634 | |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 635 | func (c *configImpl) KatiSuffix() string { |
| 636 | if c.katiSuffix != "" { |
| 637 | return c.katiSuffix |
| 638 | } |
| 639 | panic("SetKatiSuffix has not been called") |
| 640 | } |
| 641 | |
Colin Cross | 3719349 | 2017-11-16 17:55:00 -0800 | [diff] [blame] | 642 | // Checkbuild returns true if "checkbuild" was one of the build goals, which means that the |
| 643 | // user is interested in additional checks at the expense of build time. |
| 644 | func (c *configImpl) Checkbuild() bool { |
| 645 | return c.checkbuild |
| 646 | } |
| 647 | |
Dan Willemsen | 8a073a8 | 2017-02-04 17:30:44 -0800 | [diff] [blame] | 648 | func (c *configImpl) Dist() bool { |
| 649 | return c.dist |
| 650 | } |
| 651 | |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 652 | func (c *configImpl) IsVerbose() bool { |
| 653 | return c.verbose |
| 654 | } |
| 655 | |
Dan Willemsen | e0879fc | 2017-08-04 15:06:27 -0700 | [diff] [blame] | 656 | func (c *configImpl) SkipMake() bool { |
| 657 | return c.skipMake |
| 658 | } |
| 659 | |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 660 | func (c *configImpl) TargetProduct() string { |
| 661 | if v, ok := c.environ.Get("TARGET_PRODUCT"); ok { |
| 662 | return v |
| 663 | } |
| 664 | panic("TARGET_PRODUCT is not defined") |
| 665 | } |
| 666 | |
Dan Willemsen | 02781d5 | 2017-05-12 19:28:13 -0700 | [diff] [blame] | 667 | func (c *configImpl) TargetDevice() string { |
| 668 | return c.targetDevice |
| 669 | } |
| 670 | |
| 671 | func (c *configImpl) SetTargetDevice(device string) { |
| 672 | c.targetDevice = device |
| 673 | } |
| 674 | |
| 675 | func (c *configImpl) TargetBuildVariant() string { |
| 676 | if v, ok := c.environ.Get("TARGET_BUILD_VARIANT"); ok { |
| 677 | return v |
| 678 | } |
| 679 | panic("TARGET_BUILD_VARIANT is not defined") |
| 680 | } |
| 681 | |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 682 | func (c *configImpl) KatiArgs() []string { |
| 683 | return c.katiArgs |
| 684 | } |
| 685 | |
| 686 | func (c *configImpl) Parallel() int { |
| 687 | return c.parallel |
| 688 | } |
| 689 | |
| 690 | func (c *configImpl) UseGoma() bool { |
| 691 | if v, ok := c.environ.Get("USE_GOMA"); ok { |
| 692 | v = strings.TrimSpace(v) |
| 693 | if v != "" && v != "false" { |
| 694 | return true |
| 695 | } |
| 696 | } |
| 697 | return false |
| 698 | } |
| 699 | |
Yoshisato Yanagisawa | 2cb0e5d | 2019-01-10 10:14:16 +0900 | [diff] [blame] | 700 | func (c *configImpl) StartGoma() bool { |
| 701 | if !c.UseGoma() { |
| 702 | return false |
| 703 | } |
| 704 | |
| 705 | if v, ok := c.environ.Get("NOSTART_GOMA"); ok { |
| 706 | v = strings.TrimSpace(v) |
| 707 | if v != "" && v != "false" { |
| 708 | return false |
| 709 | } |
| 710 | } |
| 711 | return true |
| 712 | } |
| 713 | |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 714 | // RemoteParallel controls how many remote jobs (i.e., commands which contain |
Jeff Gaston | efc1b41 | 2017-03-29 17:29:06 -0700 | [diff] [blame] | 715 | // 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] | 716 | // still limited by Parallel() |
| 717 | func (c *configImpl) RemoteParallel() int { |
| 718 | if v, ok := c.environ.Get("NINJA_REMOTE_NUM_JOBS"); ok { |
| 719 | if i, err := strconv.Atoi(v); err == nil { |
| 720 | return i |
| 721 | } |
| 722 | } |
| 723 | return 500 |
| 724 | } |
| 725 | |
| 726 | func (c *configImpl) SetKatiArgs(args []string) { |
| 727 | c.katiArgs = args |
| 728 | } |
| 729 | |
| 730 | func (c *configImpl) SetNinjaArgs(args []string) { |
| 731 | c.ninjaArgs = args |
| 732 | } |
| 733 | |
| 734 | func (c *configImpl) SetKatiSuffix(suffix string) { |
| 735 | c.katiSuffix = suffix |
| 736 | } |
| 737 | |
Dan Willemsen | e0879fc | 2017-08-04 15:06:27 -0700 | [diff] [blame] | 738 | func (c *configImpl) LastKatiSuffixFile() string { |
| 739 | return filepath.Join(c.OutDir(), "last_kati_suffix") |
| 740 | } |
| 741 | |
| 742 | func (c *configImpl) HasKatiSuffix() bool { |
| 743 | return c.katiSuffix != "" |
| 744 | } |
| 745 | |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 746 | func (c *configImpl) KatiEnvFile() string { |
| 747 | return filepath.Join(c.OutDir(), "env"+c.KatiSuffix()+".sh") |
| 748 | } |
| 749 | |
Dan Willemsen | 2997123 | 2018-09-26 14:58:30 -0700 | [diff] [blame] | 750 | func (c *configImpl) KatiBuildNinjaFile() string { |
| 751 | return filepath.Join(c.OutDir(), "build"+c.KatiSuffix()+katiBuildSuffix+".ninja") |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 752 | } |
| 753 | |
Dan Willemsen | fb1271a | 2018-09-26 15:00:42 -0700 | [diff] [blame] | 754 | func (c *configImpl) KatiPackageNinjaFile() string { |
| 755 | return filepath.Join(c.OutDir(), "build"+c.KatiSuffix()+katiPackageSuffix+".ninja") |
| 756 | } |
| 757 | |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 758 | func (c *configImpl) SoongNinjaFile() string { |
| 759 | return filepath.Join(c.SoongOutDir(), "build.ninja") |
| 760 | } |
| 761 | |
| 762 | func (c *configImpl) CombinedNinjaFile() string { |
Dan Willemsen | e0879fc | 2017-08-04 15:06:27 -0700 | [diff] [blame] | 763 | if c.katiSuffix == "" { |
| 764 | return filepath.Join(c.OutDir(), "combined.ninja") |
| 765 | } |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 766 | return filepath.Join(c.OutDir(), "combined"+c.KatiSuffix()+".ninja") |
| 767 | } |
| 768 | |
| 769 | func (c *configImpl) SoongAndroidMk() string { |
| 770 | return filepath.Join(c.SoongOutDir(), "Android-"+c.TargetProduct()+".mk") |
| 771 | } |
| 772 | |
| 773 | func (c *configImpl) SoongMakeVarsMk() string { |
| 774 | return filepath.Join(c.SoongOutDir(), "make_vars-"+c.TargetProduct()+".mk") |
| 775 | } |
| 776 | |
Dan Willemsen | f052f78 | 2017-05-18 15:29:04 -0700 | [diff] [blame] | 777 | func (c *configImpl) ProductOut() string { |
Dan Willemsen | 4dc4e14 | 2017-09-08 14:35:43 -0700 | [diff] [blame] | 778 | return filepath.Join(c.OutDir(), "target", "product", c.TargetDevice()) |
Dan Willemsen | f052f78 | 2017-05-18 15:29:04 -0700 | [diff] [blame] | 779 | } |
| 780 | |
Dan Willemsen | 02781d5 | 2017-05-12 19:28:13 -0700 | [diff] [blame] | 781 | func (c *configImpl) DevicePreviousProductConfig() string { |
Dan Willemsen | f052f78 | 2017-05-18 15:29:04 -0700 | [diff] [blame] | 782 | return filepath.Join(c.ProductOut(), "previous_build_config.mk") |
| 783 | } |
| 784 | |
Dan Willemsen | fb1271a | 2018-09-26 15:00:42 -0700 | [diff] [blame] | 785 | func (c *configImpl) KatiPackageMkDir() string { |
| 786 | return filepath.Join(c.ProductOut(), "obj", "CONFIG", "kati_packaging") |
| 787 | } |
| 788 | |
Dan Willemsen | f052f78 | 2017-05-18 15:29:04 -0700 | [diff] [blame] | 789 | func (c *configImpl) hostOutRoot() string { |
Dan Willemsen | 4dc4e14 | 2017-09-08 14:35:43 -0700 | [diff] [blame] | 790 | return filepath.Join(c.OutDir(), "host") |
Dan Willemsen | f052f78 | 2017-05-18 15:29:04 -0700 | [diff] [blame] | 791 | } |
| 792 | |
| 793 | func (c *configImpl) HostOut() string { |
| 794 | return filepath.Join(c.hostOutRoot(), c.HostPrebuiltTag()) |
| 795 | } |
| 796 | |
| 797 | // This probably needs to be multi-valued, so not exporting it for now |
| 798 | func (c *configImpl) hostCrossOut() string { |
| 799 | if runtime.GOOS == "linux" { |
| 800 | return filepath.Join(c.hostOutRoot(), "windows-x86") |
| 801 | } else { |
| 802 | return "" |
| 803 | } |
Dan Willemsen | 02781d5 | 2017-05-12 19:28:13 -0700 | [diff] [blame] | 804 | } |
| 805 | |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 806 | func (c *configImpl) HostPrebuiltTag() string { |
| 807 | if runtime.GOOS == "linux" { |
| 808 | return "linux-x86" |
| 809 | } else if runtime.GOOS == "darwin" { |
| 810 | return "darwin-x86" |
| 811 | } else { |
| 812 | panic("Unsupported OS") |
| 813 | } |
| 814 | } |
Dan Willemsen | f173d59 | 2017-04-27 14:28:00 -0700 | [diff] [blame] | 815 | |
Dan Willemsen | 8122bd5 | 2017-10-12 20:20:41 -0700 | [diff] [blame] | 816 | func (c *configImpl) PrebuiltBuildTool(name string) string { |
Dan Willemsen | f173d59 | 2017-04-27 14:28:00 -0700 | [diff] [blame] | 817 | if v, ok := c.environ.Get("SANITIZE_HOST"); ok { |
| 818 | if sanitize := strings.Fields(v); inList("address", sanitize) { |
Dan Willemsen | 8122bd5 | 2017-10-12 20:20:41 -0700 | [diff] [blame] | 819 | asan := filepath.Join("prebuilts/build-tools", c.HostPrebuiltTag(), "asan/bin", name) |
| 820 | if _, err := os.Stat(asan); err == nil { |
| 821 | return asan |
| 822 | } |
Dan Willemsen | f173d59 | 2017-04-27 14:28:00 -0700 | [diff] [blame] | 823 | } |
| 824 | } |
| 825 | return filepath.Join("prebuilts/build-tools", c.HostPrebuiltTag(), "bin", name) |
| 826 | } |
Dan Willemsen | 3d60b11 | 2018-04-04 22:25:56 -0700 | [diff] [blame] | 827 | |
| 828 | func (c *configImpl) SetBuildBrokenDupRules(val bool) { |
| 829 | c.brokenDupRules = val |
| 830 | } |
| 831 | |
| 832 | func (c *configImpl) BuildBrokenDupRules() bool { |
| 833 | return c.brokenDupRules |
| 834 | } |
Dan Willemsen | 6ab79db | 2018-05-02 00:06:28 -0700 | [diff] [blame] | 835 | |
Dan Willemsen | 25e6f09 | 2019-04-09 10:22:43 -0700 | [diff] [blame] | 836 | func (c *configImpl) SetBuildBrokenUsesNetwork(val bool) { |
| 837 | c.brokenUsesNetwork = val |
| 838 | } |
| 839 | |
| 840 | func (c *configImpl) BuildBrokenUsesNetwork() bool { |
| 841 | return c.brokenUsesNetwork |
| 842 | } |
| 843 | |
Dan Willemsen | 6ab79db | 2018-05-02 00:06:28 -0700 | [diff] [blame] | 844 | func (c *configImpl) SetTargetDeviceDir(dir string) { |
| 845 | c.targetDeviceDir = dir |
| 846 | } |
| 847 | |
| 848 | func (c *configImpl) TargetDeviceDir() string { |
| 849 | return c.targetDeviceDir |
| 850 | } |
Dan Willemsen | fa42f3c | 2018-06-15 21:54:47 -0700 | [diff] [blame] | 851 | |
| 852 | func (c *configImpl) SetPdkBuild(pdk bool) { |
| 853 | c.pdkBuild = pdk |
| 854 | } |
| 855 | |
| 856 | func (c *configImpl) IsPdkBuild() bool { |
| 857 | return c.pdkBuild |
| 858 | } |