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