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 ( |
Kousik Kumar | 3ff037e | 2022-01-25 22:11:01 -0500 | [diff] [blame] | 18 | "encoding/json" |
Jeongik Cha | a87506f | 2023-06-01 23:16:41 +0900 | [diff] [blame] | 19 | "errors" |
Ramy Medhat | 0fc67eb | 2020-08-12 01:26:23 -0400 | [diff] [blame] | 20 | "fmt" |
Kousik Kumar | 3ff037e | 2022-01-25 22:11:01 -0500 | [diff] [blame] | 21 | "io/ioutil" |
Kousik Kumar | 4c180ad | 2022-05-27 07:48:37 -0400 | [diff] [blame] | 22 | "math/rand" |
Dan Willemsen | c2af0be | 2017-01-20 14:10:01 -0800 | [diff] [blame] | 23 | "os" |
Kousik Kumar | 84bd5bf | 2022-01-26 23:32:22 -0500 | [diff] [blame] | 24 | "os/exec" |
Cole Faust | 583dfb4 | 2023-09-28 13:56:30 -0700 | [diff] [blame] | 25 | "os/user" |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 26 | "path/filepath" |
| 27 | "runtime" |
| 28 | "strconv" |
| 29 | "strings" |
Kousik Kumar | 4c180ad | 2022-05-27 07:48:37 -0400 | [diff] [blame] | 30 | "syscall" |
Nan Zhang | 2e6a4ff | 2018-02-14 13:27:26 -0800 | [diff] [blame] | 31 | "time" |
Jeff Gaston | efc1b41 | 2017-03-29 17:29:06 -0700 | [diff] [blame] | 32 | |
| 33 | "android/soong/shared" |
LaMont Jones | 9a91286 | 2023-11-06 22:11:08 +0000 | [diff] [blame] | 34 | "android/soong/ui/metrics" |
Kousik Kumar | ec47864 | 2020-09-21 13:39:24 -0400 | [diff] [blame] | 35 | |
Dan Willemsen | 4591b64 | 2021-05-24 14:24:12 -0700 | [diff] [blame] | 36 | "google.golang.org/protobuf/proto" |
Patrice Arruda | 9685036 | 2020-08-11 20:41:11 +0000 | [diff] [blame] | 37 | |
| 38 | smpb "android/soong/ui/metrics/metrics_proto" |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 39 | ) |
| 40 | |
Kousik Kumar | 3ff037e | 2022-01-25 22:11:01 -0500 | [diff] [blame] | 41 | const ( |
Chris Parsons | 53f68ae | 2022-03-03 12:01:40 -0500 | [diff] [blame] | 42 | envConfigDir = "vendor/google/tools/soong_config" |
| 43 | jsonSuffix = "json" |
Kousik Kumar | 3ff037e | 2022-01-25 22:11:01 -0500 | [diff] [blame] | 44 | ) |
| 45 | |
Kousik Kumar | 4c180ad | 2022-05-27 07:48:37 -0400 | [diff] [blame] | 46 | var ( |
Kevin Dagostino | 096ab2f | 2023-03-03 19:47:17 +0000 | [diff] [blame] | 47 | rbeRandPrefix int |
| 48 | googleProdCredsExistCache bool |
Kousik Kumar | 4c180ad | 2022-05-27 07:48:37 -0400 | [diff] [blame] | 49 | ) |
| 50 | |
| 51 | func init() { |
| 52 | rand.Seed(time.Now().UnixNano()) |
| 53 | rbeRandPrefix = rand.Intn(1000) |
| 54 | } |
| 55 | |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 56 | type Config struct{ *configImpl } |
| 57 | |
| 58 | type configImpl struct { |
Lukacs T. Berki | a1b9372 | 2021-09-02 17:23:06 +0200 | [diff] [blame] | 59 | // Some targets that are implemented in soong_build |
| 60 | // (bp2build, json-module-graph) are not here and have their own bits below. |
Colin Cross | 28f527c | 2019-11-26 16:19:04 -0800 | [diff] [blame] | 61 | arguments []string |
| 62 | goma bool |
| 63 | environ *Environment |
| 64 | distDir string |
| 65 | buildDateTime string |
MarkDacek | 6614d9c | 2022-12-07 21:57:38 +0000 | [diff] [blame] | 66 | logsPrefix string |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 67 | |
| 68 | // From the arguments |
MarkDacek | f47e142 | 2023-04-19 16:47:36 +0000 | [diff] [blame] | 69 | parallel int |
| 70 | keepGoing int |
| 71 | verbose bool |
| 72 | checkbuild bool |
| 73 | dist bool |
| 74 | jsonModuleGraph bool |
MarkDacek | f47e142 | 2023-04-19 16:47:36 +0000 | [diff] [blame] | 75 | queryview bool |
| 76 | reportMkMetrics bool // Collect and report mk2bp migration progress metrics. |
| 77 | soongDocs bool |
MarkDacek | f47e142 | 2023-04-19 16:47:36 +0000 | [diff] [blame] | 78 | skipConfig bool |
| 79 | skipKati bool |
| 80 | skipKatiNinja bool |
| 81 | skipSoong bool |
| 82 | skipNinja bool |
| 83 | skipSoongTests bool |
| 84 | searchApiDir bool // Scan the Android.bp files generated in out/api_surfaces |
| 85 | skipMetricsUpload bool |
| 86 | buildStartedTime int64 // For metrics-upload-only - manually specify a build-started time |
Jihoon Kang | 2a929ad | 2023-06-08 19:02:07 +0000 | [diff] [blame] | 87 | buildFromSourceStub bool |
Colin Cross | 8d411ff | 2023-12-07 10:31:24 -0800 | [diff] [blame] | 88 | ensureAllowlistIntegrity bool // For CI builds - make sure modules are mixed-built |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 89 | |
| 90 | // From the product config |
Dan Willemsen | 6ab79db | 2018-05-02 00:06:28 -0700 | [diff] [blame] | 91 | katiArgs []string |
| 92 | ninjaArgs []string |
| 93 | katiSuffix string |
| 94 | targetDevice string |
| 95 | targetDeviceDir string |
Spandan Das | a3639e6 | 2021-05-25 19:14:02 +0000 | [diff] [blame] | 96 | sandboxConfig *SandboxConfig |
Dan Willemsen | 3d60b11 | 2018-04-04 22:25:56 -0700 | [diff] [blame] | 97 | |
Dan Willemsen | 2bb82d0 | 2019-12-27 09:35:42 -0800 | [diff] [blame] | 98 | // Autodetected |
| 99 | totalRAM uint64 |
| 100 | |
Dan Willemsen | e333635 | 2020-01-02 19:10:38 -0800 | [diff] [blame] | 101 | brokenDupRules bool |
| 102 | brokenUsesNetwork bool |
| 103 | brokenNinjaEnvVars []string |
Dan Willemsen | 1849011 | 2018-05-25 16:30:04 -0700 | [diff] [blame] | 104 | |
| 105 | pathReplaced bool |
Rupert Shuttleworth | 3c9f5ac | 2020-12-10 11:32:38 +0000 | [diff] [blame] | 106 | |
Colin Cross | f3bdbcb | 2021-06-01 11:43:55 -0700 | [diff] [blame] | 107 | // Set by multiproduct_kati |
| 108 | emptyNinjaFile bool |
Yu Liu | 6e13b40 | 2021-07-27 14:29:06 -0700 | [diff] [blame] | 109 | |
| 110 | metricsUploader string |
MarkDacek | d06db5d | 2022-11-29 00:47:59 +0000 | [diff] [blame] | 111 | |
Sam Delmerico | 98a7329 | 2023-02-21 11:50:29 -0500 | [diff] [blame] | 112 | includeTags []string |
| 113 | sourceRootDirs []string |
Jeongik Cha | 0cf44d5 | 2023-03-15 00:10:45 +0900 | [diff] [blame] | 114 | |
| 115 | // Data source to write ninja weight list |
| 116 | ninjaWeightListSource NinjaWeightListSource |
Joe Onorato | e5ed347 | 2024-02-02 14:52:05 -0800 | [diff] [blame] | 117 | |
| 118 | // This file is a detailed dump of all soong-defined modules for debugging purposes. |
| 119 | // There's quite a bit of overlap with module-info.json and soong module graph. We |
| 120 | // could consider merging them. |
| 121 | moduleDebugFile string |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 122 | } |
| 123 | |
Jeongik Cha | 0cf44d5 | 2023-03-15 00:10:45 +0900 | [diff] [blame] | 124 | type NinjaWeightListSource uint |
| 125 | |
| 126 | const ( |
| 127 | // ninja doesn't use weight list. |
| 128 | NOT_USED NinjaWeightListSource = iota |
| 129 | // ninja uses weight list based on previous builds by ninja log |
| 130 | NINJA_LOG |
| 131 | // ninja thinks every task has the same weight. |
| 132 | EVENLY_DISTRIBUTED |
Jeongik Cha | 518f3ea | 2023-03-19 00:12:39 +0900 | [diff] [blame] | 133 | // ninja uses an external custom weight list |
| 134 | EXTERNAL_FILE |
Jeongik Cha | e114e60 | 2023-03-19 00:12:39 +0900 | [diff] [blame] | 135 | // ninja uses a prioritized module list from Soong |
| 136 | HINT_FROM_SOONG |
Jeongik Cha | a87506f | 2023-06-01 23:16:41 +0900 | [diff] [blame] | 137 | // If ninja log exists, use NINJA_LOG, if not, use HINT_FROM_SOONG instead. |
| 138 | // We can assume it is an incremental build if ninja log exists. |
| 139 | DEFAULT |
Jeongik Cha | 0cf44d5 | 2023-03-15 00:10:45 +0900 | [diff] [blame] | 140 | ) |
Dan Willemsen | c2af0be | 2017-01-20 14:10:01 -0800 | [diff] [blame] | 141 | const srcDirFileCheck = "build/soong/root.bp" |
| 142 | |
Patrice Arruda | 9450d0b | 2019-07-08 11:06:46 -0700 | [diff] [blame] | 143 | var buildFiles = []string{"Android.mk", "Android.bp"} |
| 144 | |
Patrice Arruda | 1384822 | 2019-04-22 17:12:02 -0700 | [diff] [blame] | 145 | type BuildAction uint |
| 146 | |
| 147 | const ( |
| 148 | // Builds all of the modules and their dependencies of a specified directory, relative to the root |
| 149 | // directory of the source tree. |
| 150 | BUILD_MODULES_IN_A_DIRECTORY BuildAction = iota |
| 151 | |
| 152 | // Builds all of the modules and their dependencies of a list of specified directories. All specified |
| 153 | // directories are relative to the root directory of the source tree. |
| 154 | BUILD_MODULES_IN_DIRECTORIES |
Patrice Arruda | 3928206 | 2019-06-20 16:35:12 -0700 | [diff] [blame] | 155 | |
| 156 | // Build a list of specified modules. If none was specified, simply build the whole source tree. |
| 157 | BUILD_MODULES |
Patrice Arruda | 1384822 | 2019-04-22 17:12:02 -0700 | [diff] [blame] | 158 | ) |
| 159 | |
| 160 | // checkTopDir validates that the current directory is at the root directory of the source tree. |
| 161 | func checkTopDir(ctx Context) { |
| 162 | if _, err := os.Stat(srcDirFileCheck); err != nil { |
| 163 | if os.IsNotExist(err) { |
| 164 | ctx.Fatalf("Current working directory must be the source tree. %q not found.", srcDirFileCheck) |
| 165 | } |
| 166 | ctx.Fatalln("Error verifying tree state:", err) |
| 167 | } |
| 168 | } |
| 169 | |
MarkDacek | 7901e58 | 2023-01-09 19:48:01 +0000 | [diff] [blame] | 170 | func loadEnvConfig(ctx Context, config *configImpl, bc string) error { |
Kousik Kumar | 3ff037e | 2022-01-25 22:11:01 -0500 | [diff] [blame] | 171 | if bc == "" { |
| 172 | return nil |
| 173 | } |
Kousik Kumar | 84bd5bf | 2022-01-26 23:32:22 -0500 | [diff] [blame] | 174 | |
Kousik Kumar | 3ff037e | 2022-01-25 22:11:01 -0500 | [diff] [blame] | 175 | configDirs := []string{ |
Kousik Kumar | 3ff037e | 2022-01-25 22:11:01 -0500 | [diff] [blame] | 176 | config.OutDir(), |
Kousik Kumar | 84bd5bf | 2022-01-26 23:32:22 -0500 | [diff] [blame] | 177 | os.Getenv("ANDROID_BUILD_ENVIRONMENT_CONFIG_DIR"), |
Kousik Kumar | 3ff037e | 2022-01-25 22:11:01 -0500 | [diff] [blame] | 178 | envConfigDir, |
| 179 | } |
Kousik Kumar | 3ff037e | 2022-01-25 22:11:01 -0500 | [diff] [blame] | 180 | for _, dir := range configDirs { |
Kousik Kumar | 84bd5bf | 2022-01-26 23:32:22 -0500 | [diff] [blame] | 181 | cfgFile := filepath.Join(os.Getenv("TOP"), dir, fmt.Sprintf("%s.%s", bc, jsonSuffix)) |
| 182 | envVarsJSON, err := ioutil.ReadFile(cfgFile) |
| 183 | if err != nil { |
Kousik Kumar | 3ff037e | 2022-01-25 22:11:01 -0500 | [diff] [blame] | 184 | continue |
| 185 | } |
Kousik Kumar | 84bd5bf | 2022-01-26 23:32:22 -0500 | [diff] [blame] | 186 | ctx.Verbosef("Loading config file %v\n", cfgFile) |
| 187 | var envVars map[string]map[string]string |
| 188 | if err := json.Unmarshal(envVarsJSON, &envVars); err != nil { |
| 189 | fmt.Fprintf(os.Stderr, "Env vars config file %s did not parse correctly: %s", cfgFile, err.Error()) |
| 190 | continue |
| 191 | } |
| 192 | for k, v := range envVars["env"] { |
| 193 | if os.Getenv(k) != "" { |
| 194 | continue |
| 195 | } |
| 196 | config.environ.Set(k, v) |
| 197 | } |
| 198 | ctx.Verbosef("Finished loading config file %v\n", cfgFile) |
| 199 | break |
Kousik Kumar | 3ff037e | 2022-01-25 22:11:01 -0500 | [diff] [blame] | 200 | } |
Kousik Kumar | 84bd5bf | 2022-01-26 23:32:22 -0500 | [diff] [blame] | 201 | |
Kousik Kumar | 3ff037e | 2022-01-25 22:11:01 -0500 | [diff] [blame] | 202 | return nil |
| 203 | } |
| 204 | |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 205 | func NewConfig(ctx Context, args ...string) Config { |
| 206 | ret := &configImpl{ |
Jeongik Cha | f2ecf76 | 2023-05-19 14:03:45 +0900 | [diff] [blame] | 207 | environ: OsEnvironment(), |
| 208 | sandboxConfig: &SandboxConfig{}, |
Jeongik Cha | a87506f | 2023-06-01 23:16:41 +0900 | [diff] [blame] | 209 | ninjaWeightListSource: DEFAULT, |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 210 | } |
| 211 | |
Colin Cross | 106d6ef | 2023-10-24 10:34:56 -0700 | [diff] [blame] | 212 | // Skip soong tests by default on Linux |
| 213 | if runtime.GOOS == "linux" { |
| 214 | ret.skipSoongTests = true |
| 215 | } |
| 216 | |
Patrice Arruda | 9010917 | 2020-07-28 18:07:27 +0000 | [diff] [blame] | 217 | // Default matching ninja |
Dan Willemsen | 9b58749 | 2017-07-10 22:13:00 -0700 | [diff] [blame] | 218 | ret.parallel = runtime.NumCPU() + 2 |
| 219 | ret.keepGoing = 1 |
| 220 | |
Dan Willemsen | 2bb82d0 | 2019-12-27 09:35:42 -0800 | [diff] [blame] | 221 | ret.totalRAM = detectTotalRAM(ctx) |
Dan Willemsen | 9b58749 | 2017-07-10 22:13:00 -0700 | [diff] [blame] | 222 | ret.parseArgs(ctx, args) |
Jeongik Cha | e114e60 | 2023-03-19 00:12:39 +0900 | [diff] [blame] | 223 | |
| 224 | if ret.ninjaWeightListSource == HINT_FROM_SOONG { |
Jeongik Cha | a87506f | 2023-06-01 23:16:41 +0900 | [diff] [blame] | 225 | ret.environ.Set("SOONG_GENERATES_NINJA_HINT", "always") |
| 226 | } else if ret.ninjaWeightListSource == DEFAULT { |
| 227 | defaultNinjaWeightListSource := NINJA_LOG |
| 228 | if _, err := os.Stat(filepath.Join(ret.OutDir(), ninjaLogFileName)); errors.Is(err, os.ErrNotExist) { |
| 229 | ctx.Verboseln("$OUT/.ninja_log doesn't exist, use HINT_FROM_SOONG instead") |
| 230 | defaultNinjaWeightListSource = HINT_FROM_SOONG |
| 231 | } else { |
| 232 | ctx.Verboseln("$OUT/.ninja_log exist, use NINJA_LOG") |
| 233 | } |
| 234 | ret.ninjaWeightListSource = defaultNinjaWeightListSource |
| 235 | // soong_build generates ninja hint depending on ninja log existence. |
| 236 | // Set it "depend" to avoid soong re-run due to env variable change. |
| 237 | ret.environ.Set("SOONG_GENERATES_NINJA_HINT", "depend") |
Jeongik Cha | e114e60 | 2023-03-19 00:12:39 +0900 | [diff] [blame] | 238 | } |
Jeongik Cha | a87506f | 2023-06-01 23:16:41 +0900 | [diff] [blame] | 239 | |
Dan Willemsen | 0c3919e | 2017-03-02 15:49:10 -0800 | [diff] [blame] | 240 | // Make sure OUT_DIR is set appropriately |
Dan Willemsen | 02f3add | 2017-05-12 13:50:19 -0700 | [diff] [blame] | 241 | if outDir, ok := ret.environ.Get("OUT_DIR"); ok { |
| 242 | ret.environ.Set("OUT_DIR", filepath.Clean(outDir)) |
| 243 | } else { |
Dan Willemsen | 0c3919e | 2017-03-02 15:49:10 -0800 | [diff] [blame] | 244 | outDir := "out" |
| 245 | if baseDir, ok := ret.environ.Get("OUT_DIR_COMMON_BASE"); ok { |
| 246 | if wd, err := os.Getwd(); err != nil { |
| 247 | ctx.Fatalln("Failed to get working directory:", err) |
| 248 | } else { |
| 249 | outDir = filepath.Join(baseDir, filepath.Base(wd)) |
| 250 | } |
| 251 | } |
| 252 | ret.environ.Set("OUT_DIR", outDir) |
| 253 | } |
| 254 | |
Kousik Kumar | 3ff037e | 2022-01-25 22:11:01 -0500 | [diff] [blame] | 255 | // loadEnvConfig needs to know what the OUT_DIR is, so it should |
| 256 | // be called after we determine the appropriate out directory. |
MarkDacek | 7901e58 | 2023-01-09 19:48:01 +0000 | [diff] [blame] | 257 | bc := os.Getenv("ANDROID_BUILD_ENVIRONMENT_CONFIG") |
| 258 | |
| 259 | if bc != "" { |
Kousik Kumar | c881833 | 2023-01-16 16:33:05 +0000 | [diff] [blame] | 260 | if err := loadEnvConfig(ctx, ret, bc); err != nil { |
MarkDacek | 7901e58 | 2023-01-09 19:48:01 +0000 | [diff] [blame] | 261 | ctx.Fatalln("Failed to parse env config files: %v", err) |
| 262 | } |
Kousik Kumar | 6d1e348 | 2023-07-24 03:44:16 +0000 | [diff] [blame] | 263 | if !ret.canSupportRBE() { |
| 264 | // Explicitly set USE_RBE env variable to false when we cannot run |
| 265 | // an RBE build to avoid ninja local execution pool issues. |
| 266 | ret.environ.Set("USE_RBE", "false") |
| 267 | } |
Kousik Kumar | 3ff037e | 2022-01-25 22:11:01 -0500 | [diff] [blame] | 268 | } |
| 269 | |
Dan Willemsen | 2d31a44 | 2018-10-20 21:33:41 -0700 | [diff] [blame] | 270 | if distDir, ok := ret.environ.Get("DIST_DIR"); ok { |
| 271 | ret.distDir = filepath.Clean(distDir) |
| 272 | } else { |
| 273 | ret.distDir = filepath.Join(ret.OutDir(), "dist") |
| 274 | } |
Dan Willemsen | d50e89f | 2018-10-16 17:49:25 -0700 | [diff] [blame] | 275 | |
Spandan Das | 0506361 | 2021-06-25 01:39:04 +0000 | [diff] [blame] | 276 | if srcDirIsWritable, ok := ret.environ.Get("BUILD_BROKEN_SRC_DIR_IS_WRITABLE"); ok { |
| 277 | ret.sandboxConfig.SetSrcDirIsRO(srcDirIsWritable == "false") |
| 278 | } |
| 279 | |
Joe Onorato | e5ed347 | 2024-02-02 14:52:05 -0800 | [diff] [blame] | 280 | if os.Getenv("GENERATE_SOONG_DEBUG") == "true" { |
| 281 | ret.moduleDebugFile, _ = filepath.Abs(shared.JoinPath(ret.SoongOutDir(), "soong-debug-info.json")) |
| 282 | } |
| 283 | |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 284 | ret.environ.Unset( |
| 285 | // We're already using it |
| 286 | "USE_SOONG_UI", |
| 287 | |
| 288 | // We should never use GOROOT/GOPATH from the shell environment |
| 289 | "GOROOT", |
| 290 | "GOPATH", |
| 291 | |
| 292 | // These should only come from Soong, not the environment. |
| 293 | "CLANG", |
| 294 | "CLANG_CXX", |
| 295 | "CCC_CC", |
| 296 | "CCC_CXX", |
| 297 | |
| 298 | // Used by the goma compiler wrapper, but should only be set by |
| 299 | // gomacc |
| 300 | "GOMACC_PATH", |
Dan Willemsen | 0c3919e | 2017-03-02 15:49:10 -0800 | [diff] [blame] | 301 | |
| 302 | // We handle this above |
| 303 | "OUT_DIR_COMMON_BASE", |
Dan Willemsen | 68a0985 | 2017-04-18 13:56:57 -0700 | [diff] [blame] | 304 | |
Dan Willemsen | 2d31a44 | 2018-10-20 21:33:41 -0700 | [diff] [blame] | 305 | // This is handled above too, and set for individual commands later |
| 306 | "DIST_DIR", |
| 307 | |
Dan Willemsen | 68a0985 | 2017-04-18 13:56:57 -0700 | [diff] [blame] | 308 | // Variables that have caused problems in the past |
Dan Willemsen | 1c504d9 | 2019-11-18 19:13:53 +0000 | [diff] [blame] | 309 | "BASH_ENV", |
Dan Willemsen | ebfe33a | 2018-05-01 10:07:50 -0700 | [diff] [blame] | 310 | "CDPATH", |
Dan Willemsen | 68a0985 | 2017-04-18 13:56:57 -0700 | [diff] [blame] | 311 | "DISPLAY", |
| 312 | "GREP_OPTIONS", |
Nathan Egge | 7b067fb | 2023-02-17 17:54:31 +0000 | [diff] [blame] | 313 | "JAVAC", |
Dan Willemsen | ebfe33a | 2018-05-01 10:07:50 -0700 | [diff] [blame] | 314 | "NDK_ROOT", |
Dan Willemsen | 00fcb26 | 2018-08-15 15:35:38 -0700 | [diff] [blame] | 315 | "POSIXLY_CORRECT", |
Dan Willemsen | c40e10b | 2017-07-11 14:30:00 -0700 | [diff] [blame] | 316 | |
| 317 | // Drop make flags |
| 318 | "MAKEFLAGS", |
| 319 | "MAKELEVEL", |
| 320 | "MFLAGS", |
Dan Willemsen | d9e8f0a | 2017-10-30 13:42:06 -0700 | [diff] [blame] | 321 | |
| 322 | // Set in envsetup.sh, reset in makefiles |
| 323 | "ANDROID_JAVA_TOOLCHAIN", |
Colin Cross | 7f09c40 | 2018-07-11 14:49:31 -0700 | [diff] [blame] | 324 | |
| 325 | // Set by envsetup.sh, but shouldn't be used inside the build because envsetup.sh is optional |
| 326 | "ANDROID_BUILD_TOP", |
| 327 | "ANDROID_HOST_OUT", |
| 328 | "ANDROID_PRODUCT_OUT", |
| 329 | "ANDROID_HOST_OUT_TESTCASES", |
| 330 | "ANDROID_TARGET_OUT_TESTCASES", |
| 331 | "ANDROID_TOOLCHAIN", |
| 332 | "ANDROID_TOOLCHAIN_2ND_ARCH", |
| 333 | "ANDROID_DEV_SCRIPTS", |
| 334 | "ANDROID_EMULATOR_PREBUILTS", |
| 335 | "ANDROID_PRE_BUILD_PATHS", |
Joe Onorato | e5ed347 | 2024-02-02 14:52:05 -0800 | [diff] [blame] | 336 | |
| 337 | // We read it here already, don't let others share in the fun |
| 338 | "GENERATE_SOONG_DEBUG", |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 339 | ) |
| 340 | |
Kousik Kumar | b328f6d | 2020-10-19 01:45:46 -0400 | [diff] [blame] | 341 | if ret.UseGoma() || ret.ForceUseGoma() { |
| 342 | ctx.Println("Goma for Android has been deprecated and replaced with RBE. See go/rbe_for_android for instructions on how to use RBE.") |
| 343 | ctx.Fatalln("USE_GOMA / FORCE_USE_GOMA flag is no longer supported.") |
Kousik Kumar | ec47864 | 2020-09-21 13:39:24 -0400 | [diff] [blame] | 344 | } |
| 345 | |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 346 | // Tell python not to spam the source tree with .pyc files. |
| 347 | ret.environ.Set("PYTHONDONTWRITEBYTECODE", "1") |
| 348 | |
Ramy Medhat | ca1e44c | 2020-07-16 12:18:37 -0400 | [diff] [blame] | 349 | tmpDir := absPath(ctx, ret.TempDir()) |
| 350 | ret.environ.Set("TMPDIR", tmpDir) |
Dan Willemsen | 32a669b | 2018-03-08 19:42:00 -0800 | [diff] [blame] | 351 | |
Dan Willemsen | 70c1ff8 | 2019-08-21 14:56:13 -0700 | [diff] [blame] | 352 | // Always set ASAN_SYMBOLIZER_PATH so that ASAN-based tools can symbolize any crashes |
| 353 | symbolizerPath := filepath.Join("prebuilts/clang/host", ret.HostPrebuiltTag(), |
| 354 | "llvm-binutils-stable/llvm-symbolizer") |
| 355 | ret.environ.Set("ASAN_SYMBOLIZER_PATH", absPath(ctx, symbolizerPath)) |
| 356 | |
Dan Willemsen | c2af0be | 2017-01-20 14:10:01 -0800 | [diff] [blame] | 357 | // Precondition: the current directory is the top of the source tree |
Patrice Arruda | 1384822 | 2019-04-22 17:12:02 -0700 | [diff] [blame] | 358 | checkTopDir(ctx) |
Dan Willemsen | c2af0be | 2017-01-20 14:10:01 -0800 | [diff] [blame] | 359 | |
Yu Liu | 6e13b40 | 2021-07-27 14:29:06 -0700 | [diff] [blame] | 360 | srcDir := absPath(ctx, ".") |
| 361 | if strings.ContainsRune(srcDir, ' ') { |
Colin Cross | 1f6faeb | 2019-09-23 15:52:40 -0700 | [diff] [blame] | 362 | ctx.Println("You are building in a directory whose absolute path contains a space character:") |
| 363 | ctx.Println() |
| 364 | ctx.Printf("%q\n", srcDir) |
| 365 | ctx.Println() |
| 366 | ctx.Fatalln("Directory names containing spaces are not supported") |
Dan Willemsen | db8457c | 2017-05-12 16:38:17 -0700 | [diff] [blame] | 367 | } |
| 368 | |
Yu Liu | 6e13b40 | 2021-07-27 14:29:06 -0700 | [diff] [blame] | 369 | ret.metricsUploader = GetMetricsUploader(srcDir, ret.environ) |
| 370 | |
Dan Willemsen | db8457c | 2017-05-12 16:38:17 -0700 | [diff] [blame] | 371 | if outDir := ret.OutDir(); strings.ContainsRune(outDir, ' ') { |
Colin Cross | 1f6faeb | 2019-09-23 15:52:40 -0700 | [diff] [blame] | 372 | ctx.Println("The absolute path of your output directory ($OUT_DIR) contains a space character:") |
| 373 | ctx.Println() |
| 374 | ctx.Printf("%q\n", outDir) |
| 375 | ctx.Println() |
| 376 | ctx.Fatalln("Directory names containing spaces are not supported") |
Dan Willemsen | db8457c | 2017-05-12 16:38:17 -0700 | [diff] [blame] | 377 | } |
| 378 | |
Rupert Shuttleworth | 3c9f5ac | 2020-12-10 11:32:38 +0000 | [diff] [blame] | 379 | if distDir := ret.RealDistDir(); strings.ContainsRune(distDir, ' ') { |
Colin Cross | 1f6faeb | 2019-09-23 15:52:40 -0700 | [diff] [blame] | 380 | ctx.Println("The absolute path of your dist directory ($DIST_DIR) contains a space character:") |
| 381 | ctx.Println() |
| 382 | ctx.Printf("%q\n", distDir) |
| 383 | ctx.Println() |
| 384 | ctx.Fatalln("Directory names containing spaces are not supported") |
Dan Willemsen | db8457c | 2017-05-12 16:38:17 -0700 | [diff] [blame] | 385 | } |
| 386 | |
Dan Willemsen | d9e8f0a | 2017-10-30 13:42:06 -0700 | [diff] [blame] | 387 | // Configure Java-related variables, including adding it to $PATH |
Tobias Thierer | e59aeff | 2017-12-20 22:40:39 +0000 | [diff] [blame] | 388 | java8Home := filepath.Join("prebuilts/jdk/jdk8", ret.HostPrebuiltTag()) |
Sorin Basca | 0760c89 | 2023-11-29 19:13:55 +0000 | [diff] [blame] | 389 | java21Home := filepath.Join("prebuilts/jdk/jdk21", ret.HostPrebuiltTag()) |
Dan Willemsen | d9e8f0a | 2017-10-30 13:42:06 -0700 | [diff] [blame] | 390 | javaHome := func() string { |
| 391 | if override, ok := ret.environ.Get("OVERRIDE_ANDROID_JAVA_HOME"); ok { |
| 392 | return override |
| 393 | } |
Pete Gillin | a7a3d64 | 2019-11-07 18:58:42 +0000 | [diff] [blame] | 394 | if toolchain11, ok := ret.environ.Get("EXPERIMENTAL_USE_OPENJDK11_TOOLCHAIN"); ok && toolchain11 != "true" { |
Sorin Basca | 5dfa238 | 2024-03-11 17:23:06 +0000 | [diff] [blame] | 395 | ctx.Fatalln("The environment variable EXPERIMENTAL_USE_OPENJDK11_TOOLCHAIN is no longer supported. An OpenJDK 21 toolchain is now the global default.") |
Pete Gillin | 1f52e93 | 2019-10-09 17:10:08 +0100 | [diff] [blame] | 396 | } |
Sorin Basca | 7e094b3 | 2022-10-05 08:20:12 +0000 | [diff] [blame] | 397 | if toolchain17, ok := ret.environ.Get("EXPERIMENTAL_USE_OPENJDK17_TOOLCHAIN"); ok && toolchain17 != "true" { |
Sorin Basca | 5dfa238 | 2024-03-11 17:23:06 +0000 | [diff] [blame] | 398 | ctx.Fatalln("The environment variable EXPERIMENTAL_USE_OPENJDK17_TOOLCHAIN is no longer supported. An OpenJDK 21 toolchain is now the global default.") |
Sorin Basca | 7e094b3 | 2022-10-05 08:20:12 +0000 | [diff] [blame] | 399 | } |
Sorin Basca | 5dfa238 | 2024-03-11 17:23:06 +0000 | [diff] [blame] | 400 | if toolchain21, ok := ret.environ.Get("EXPERIMENTAL_USE_OPENJDK21_TOOLCHAIN"); ok && toolchain21 != "true" { |
| 401 | ctx.Fatalln("The environment variable EXPERIMENTAL_USE_OPENJDK21_TOOLCHAIN is no longer supported. An OpenJDK 21 toolchain is now the global default.") |
| 402 | } |
| 403 | return java21Home |
Dan Willemsen | d9e8f0a | 2017-10-30 13:42:06 -0700 | [diff] [blame] | 404 | }() |
| 405 | absJavaHome := absPath(ctx, javaHome) |
| 406 | |
Dan Willemsen | ed86952 | 2018-01-08 14:58:46 -0800 | [diff] [blame] | 407 | ret.configureLocale(ctx) |
| 408 | |
Dan Willemsen | d9e8f0a | 2017-10-30 13:42:06 -0700 | [diff] [blame] | 409 | newPath := []string{filepath.Join(absJavaHome, "bin")} |
| 410 | if path, ok := ret.environ.Get("PATH"); ok && path != "" { |
| 411 | newPath = append(newPath, path) |
| 412 | } |
Pete Gillin | 1f52e93 | 2019-10-09 17:10:08 +0100 | [diff] [blame] | 413 | |
Dan Willemsen | d9e8f0a | 2017-10-30 13:42:06 -0700 | [diff] [blame] | 414 | ret.environ.Unset("OVERRIDE_ANDROID_JAVA_HOME") |
| 415 | ret.environ.Set("JAVA_HOME", absJavaHome) |
| 416 | ret.environ.Set("ANDROID_JAVA_HOME", javaHome) |
Tobias Thierer | e59aeff | 2017-12-20 22:40:39 +0000 | [diff] [blame] | 417 | ret.environ.Set("ANDROID_JAVA8_HOME", java8Home) |
Dan Willemsen | d9e8f0a | 2017-10-30 13:42:06 -0700 | [diff] [blame] | 418 | ret.environ.Set("PATH", strings.Join(newPath, string(filepath.ListSeparator))) |
| 419 | |
Colin Cross | fe5ed4d | 2023-07-28 09:27:23 -0700 | [diff] [blame] | 420 | // b/286885495, https://bugzilla.redhat.com/show_bug.cgi?id=2227130: some versions of Fedora include patches |
| 421 | // to unzip to enable zipbomb detection that incorrectly handle zip64 and data descriptors and fail on large |
| 422 | // zip files produced by soong_zip. Disable zipbomb detection. |
| 423 | ret.environ.Set("UNZIP_DISABLE_ZIPBOMB_DETECTION", "TRUE") |
| 424 | |
Nan Zhang | 2e6a4ff | 2018-02-14 13:27:26 -0800 | [diff] [blame] | 425 | outDir := ret.OutDir() |
| 426 | buildDateTimeFile := filepath.Join(outDir, "build_date.txt") |
Nan Zhang | 2e6a4ff | 2018-02-14 13:27:26 -0800 | [diff] [blame] | 427 | if buildDateTime, ok := ret.environ.Get("BUILD_DATETIME"); ok && buildDateTime != "" { |
Colin Cross | 28f527c | 2019-11-26 16:19:04 -0800 | [diff] [blame] | 428 | ret.buildDateTime = buildDateTime |
Nan Zhang | 2e6a4ff | 2018-02-14 13:27:26 -0800 | [diff] [blame] | 429 | } else { |
Colin Cross | 28f527c | 2019-11-26 16:19:04 -0800 | [diff] [blame] | 430 | ret.buildDateTime = strconv.FormatInt(time.Now().Unix(), 10) |
Nan Zhang | 2e6a4ff | 2018-02-14 13:27:26 -0800 | [diff] [blame] | 431 | } |
Colin Cross | 28f527c | 2019-11-26 16:19:04 -0800 | [diff] [blame] | 432 | |
Nan Zhang | 2e6a4ff | 2018-02-14 13:27:26 -0800 | [diff] [blame] | 433 | ret.environ.Set("BUILD_DATETIME_FILE", buildDateTimeFile) |
| 434 | |
Cole Faust | 583dfb4 | 2023-09-28 13:56:30 -0700 | [diff] [blame] | 435 | if _, ok := ret.environ.Get("BUILD_USERNAME"); !ok { |
| 436 | username := "unknown" |
| 437 | if u, err := user.Current(); err == nil { |
| 438 | username = u.Username |
| 439 | } else { |
| 440 | ctx.Println("Failed to get current user:", err) |
| 441 | } |
| 442 | ret.environ.Set("BUILD_USERNAME", username) |
| 443 | } |
| 444 | |
Ramy Medhat | ca1e44c | 2020-07-16 12:18:37 -0400 | [diff] [blame] | 445 | if ret.UseRBE() { |
Ramy Medhat | 0fc67eb | 2020-08-12 01:26:23 -0400 | [diff] [blame] | 446 | for k, v := range getRBEVars(ctx, Config{ret}) { |
Ramy Medhat | ca1e44c | 2020-07-16 12:18:37 -0400 | [diff] [blame] | 447 | ret.environ.Set(k, v) |
| 448 | } |
| 449 | } |
| 450 | |
Patrice Arruda | 9685036 | 2020-08-11 20:41:11 +0000 | [diff] [blame] | 451 | c := Config{ret} |
| 452 | storeConfigMetrics(ctx, c) |
| 453 | return c |
Dan Willemsen | 9b58749 | 2017-07-10 22:13:00 -0700 | [diff] [blame] | 454 | } |
| 455 | |
Patrice Arruda | 1384822 | 2019-04-22 17:12:02 -0700 | [diff] [blame] | 456 | // NewBuildActionConfig returns a build configuration based on the build action. The arguments are |
| 457 | // processed based on the build action and extracts any arguments that belongs to the build action. |
Dan Willemsen | ce41e94 | 2019-07-29 23:39:30 -0700 | [diff] [blame] | 458 | func NewBuildActionConfig(action BuildAction, dir string, ctx Context, args ...string) Config { |
| 459 | return NewConfig(ctx, getConfigArgs(action, dir, ctx, args)...) |
Patrice Arruda | 1384822 | 2019-04-22 17:12:02 -0700 | [diff] [blame] | 460 | } |
| 461 | |
LaMont Jones | 9a91286 | 2023-11-06 22:11:08 +0000 | [diff] [blame] | 462 | // Prepare for getting make variables. For them to be accurate, we need to have |
| 463 | // obtained PRODUCT_RELEASE_CONFIG_MAPS. |
| 464 | // |
| 465 | // Returns: |
| 466 | // |
| 467 | // Whether config should be called again. |
| 468 | // |
| 469 | // TODO: when converting product config to a declarative language, make sure |
| 470 | // that PRODUCT_RELEASE_CONFIG_MAPS is properly handled as a separate step in |
| 471 | // that process. |
| 472 | func SetProductReleaseConfigMaps(ctx Context, config Config) bool { |
| 473 | ctx.BeginTrace(metrics.RunKati, "SetProductReleaseConfigMaps") |
| 474 | defer ctx.EndTrace() |
| 475 | |
| 476 | if config.SkipConfig() { |
| 477 | // This duplicates the logic from Build to skip product config |
| 478 | // if the user has explicitly said to. |
| 479 | return false |
| 480 | } |
| 481 | |
| 482 | releaseConfigVars := []string{ |
| 483 | "PRODUCT_RELEASE_CONFIG_MAPS", |
| 484 | } |
| 485 | |
| 486 | origValue, _ := config.environ.Get("PRODUCT_RELEASE_CONFIG_MAPS") |
| 487 | // Get the PRODUCT_RELEASE_CONFIG_MAPS for this product, to avoid polluting the environment |
| 488 | // when we run product config to get the rest of the make vars. |
| 489 | releaseMapVars, err := dumpMakeVars(ctx, config, nil, releaseConfigVars, false, "") |
| 490 | if err != nil { |
| 491 | ctx.Fatalln("Error getting PRODUCT_RELEASE_CONFIG_MAPS:", err) |
| 492 | } |
| 493 | productReleaseConfigMaps := releaseMapVars["PRODUCT_RELEASE_CONFIG_MAPS"] |
| 494 | os.Setenv("PRODUCT_RELEASE_CONFIG_MAPS", productReleaseConfigMaps) |
| 495 | return origValue != productReleaseConfigMaps |
| 496 | } |
| 497 | |
Patrice Arruda | 9685036 | 2020-08-11 20:41:11 +0000 | [diff] [blame] | 498 | // storeConfigMetrics selects a set of configuration information and store in |
| 499 | // the metrics system for further analysis. |
| 500 | func storeConfigMetrics(ctx Context, config Config) { |
| 501 | if ctx.Metrics == nil { |
| 502 | return |
| 503 | } |
| 504 | |
Liz Kammer | ca9cb2e | 2021-07-14 15:29:57 -0400 | [diff] [blame] | 505 | ctx.Metrics.BuildConfig(buildConfig(config)) |
Patrice Arruda | 3edfd48 | 2020-10-13 23:58:41 +0000 | [diff] [blame] | 506 | |
| 507 | s := &smpb.SystemResourceInfo{ |
| 508 | TotalPhysicalMemory: proto.Uint64(config.TotalRAM()), |
| 509 | AvailableCpus: proto.Int32(int32(runtime.NumCPU())), |
| 510 | } |
| 511 | ctx.Metrics.SystemResourceInfo(s) |
Patrice Arruda | 9685036 | 2020-08-11 20:41:11 +0000 | [diff] [blame] | 512 | } |
| 513 | |
Jeongik Cha | 8d63d56 | 2023-03-17 03:52:13 +0900 | [diff] [blame] | 514 | func getNinjaWeightListSourceInMetric(s NinjaWeightListSource) *smpb.BuildConfig_NinjaWeightListSource { |
Jeongik Cha | 0cf44d5 | 2023-03-15 00:10:45 +0900 | [diff] [blame] | 515 | switch s { |
| 516 | case NINJA_LOG: |
Jeongik Cha | 8d63d56 | 2023-03-17 03:52:13 +0900 | [diff] [blame] | 517 | return smpb.BuildConfig_NINJA_LOG.Enum() |
Jeongik Cha | 0cf44d5 | 2023-03-15 00:10:45 +0900 | [diff] [blame] | 518 | case EVENLY_DISTRIBUTED: |
Jeongik Cha | 8d63d56 | 2023-03-17 03:52:13 +0900 | [diff] [blame] | 519 | return smpb.BuildConfig_EVENLY_DISTRIBUTED.Enum() |
Jeongik Cha | 518f3ea | 2023-03-19 00:12:39 +0900 | [diff] [blame] | 520 | case EXTERNAL_FILE: |
| 521 | return smpb.BuildConfig_EXTERNAL_FILE.Enum() |
Jeongik Cha | e114e60 | 2023-03-19 00:12:39 +0900 | [diff] [blame] | 522 | case HINT_FROM_SOONG: |
| 523 | return smpb.BuildConfig_HINT_FROM_SOONG.Enum() |
Jeongik Cha | 0cf44d5 | 2023-03-15 00:10:45 +0900 | [diff] [blame] | 524 | default: |
Jeongik Cha | 8d63d56 | 2023-03-17 03:52:13 +0900 | [diff] [blame] | 525 | return smpb.BuildConfig_NOT_USED.Enum() |
Jeongik Cha | 0cf44d5 | 2023-03-15 00:10:45 +0900 | [diff] [blame] | 526 | } |
| 527 | } |
| 528 | |
Liz Kammer | ca9cb2e | 2021-07-14 15:29:57 -0400 | [diff] [blame] | 529 | func buildConfig(config Config) *smpb.BuildConfig { |
Yu Liu | e737a99 | 2021-10-04 13:21:41 -0700 | [diff] [blame] | 530 | c := &smpb.BuildConfig{ |
Colin Cross | 8d411ff | 2023-12-07 10:31:24 -0800 | [diff] [blame] | 531 | ForceUseGoma: proto.Bool(config.ForceUseGoma()), |
| 532 | UseGoma: proto.Bool(config.UseGoma()), |
| 533 | UseRbe: proto.Bool(config.UseRBE()), |
| 534 | NinjaWeightListSource: getNinjaWeightListSourceInMetric(config.NinjaWeightListSource()), |
Liz Kammer | ca9cb2e | 2021-07-14 15:29:57 -0400 | [diff] [blame] | 535 | } |
Yu Liu | e737a99 | 2021-10-04 13:21:41 -0700 | [diff] [blame] | 536 | c.Targets = append(c.Targets, config.arguments...) |
| 537 | |
| 538 | return c |
Liz Kammer | ca9cb2e | 2021-07-14 15:29:57 -0400 | [diff] [blame] | 539 | } |
| 540 | |
Patrice Arruda | 1384822 | 2019-04-22 17:12:02 -0700 | [diff] [blame] | 541 | // getConfigArgs processes the command arguments based on the build action and creates a set of new |
| 542 | // arguments to be accepted by Config. |
Dan Willemsen | ce41e94 | 2019-07-29 23:39:30 -0700 | [diff] [blame] | 543 | func getConfigArgs(action BuildAction, dir string, ctx Context, args []string) []string { |
Patrice Arruda | 1384822 | 2019-04-22 17:12:02 -0700 | [diff] [blame] | 544 | // The next block of code verifies that the current directory is the root directory of the source |
| 545 | // tree. It then finds the relative path of dir based on the root directory of the source tree |
| 546 | // and verify that dir is inside of the source tree. |
| 547 | checkTopDir(ctx) |
| 548 | topDir, err := os.Getwd() |
| 549 | if err != nil { |
| 550 | ctx.Fatalf("Error retrieving top directory: %v", err) |
| 551 | } |
Patrice Arruda | baba9a9 | 2019-07-03 10:47:34 -0700 | [diff] [blame] | 552 | dir, err = filepath.EvalSymlinks(dir) |
| 553 | if err != nil { |
| 554 | ctx.Fatalf("Unable to evaluate symlink of %s: %v", dir, err) |
| 555 | } |
Patrice Arruda | 1384822 | 2019-04-22 17:12:02 -0700 | [diff] [blame] | 556 | dir, err = filepath.Abs(dir) |
| 557 | if err != nil { |
| 558 | ctx.Fatalf("Unable to find absolute path %s: %v", dir, err) |
| 559 | } |
| 560 | relDir, err := filepath.Rel(topDir, dir) |
| 561 | if err != nil { |
| 562 | ctx.Fatalf("Unable to find relative path %s of %s: %v", relDir, topDir, err) |
| 563 | } |
| 564 | // If there are ".." in the path, it's not in the source tree. |
| 565 | if strings.Contains(relDir, "..") { |
| 566 | ctx.Fatalf("Directory %s is not under the source tree %s", dir, topDir) |
| 567 | } |
| 568 | |
| 569 | configArgs := args[:] |
| 570 | |
| 571 | // If the arguments contains GET-INSTALL-PATH, change the target name prefix from MODULES-IN- to |
| 572 | // GET-INSTALL-PATH-IN- to extract the installation path instead of building the modules. |
| 573 | targetNamePrefix := "MODULES-IN-" |
| 574 | if inList("GET-INSTALL-PATH", configArgs) { |
| 575 | targetNamePrefix = "GET-INSTALL-PATH-IN-" |
| 576 | configArgs = removeFromList("GET-INSTALL-PATH", configArgs) |
| 577 | } |
| 578 | |
Patrice Arruda | 1384822 | 2019-04-22 17:12:02 -0700 | [diff] [blame] | 579 | var targets []string |
| 580 | |
| 581 | switch action { |
Patrice Arruda | 3928206 | 2019-06-20 16:35:12 -0700 | [diff] [blame] | 582 | case BUILD_MODULES: |
| 583 | // 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] | 584 | case BUILD_MODULES_IN_A_DIRECTORY: |
| 585 | // If dir is the root source tree, all the modules are built of the source tree are built so |
| 586 | // no need to find the build file. |
| 587 | if topDir == dir { |
| 588 | break |
| 589 | } |
Patrice Arruda | 0dcf27f | 2019-07-08 17:03:33 -0700 | [diff] [blame] | 590 | |
Patrice Arruda | 1384822 | 2019-04-22 17:12:02 -0700 | [diff] [blame] | 591 | buildFile := findBuildFile(ctx, relDir) |
| 592 | if buildFile == "" { |
Patrice Arruda | 0dcf27f | 2019-07-08 17:03:33 -0700 | [diff] [blame] | 593 | ctx.Fatalf("Build file not found for %s directory", relDir) |
Patrice Arruda | 1384822 | 2019-04-22 17:12:02 -0700 | [diff] [blame] | 594 | } |
Patrice Arruda | 1384822 | 2019-04-22 17:12:02 -0700 | [diff] [blame] | 595 | targets = []string{convertToTarget(filepath.Dir(buildFile), targetNamePrefix)} |
| 596 | case BUILD_MODULES_IN_DIRECTORIES: |
| 597 | newConfigArgs, dirs := splitArgs(configArgs) |
| 598 | configArgs = newConfigArgs |
Dan Willemsen | ce41e94 | 2019-07-29 23:39:30 -0700 | [diff] [blame] | 599 | targets = getTargetsFromDirs(ctx, relDir, dirs, targetNamePrefix) |
Patrice Arruda | 1384822 | 2019-04-22 17:12:02 -0700 | [diff] [blame] | 600 | } |
| 601 | |
| 602 | // Tidy only override all other specified targets. |
| 603 | tidyOnly := os.Getenv("WITH_TIDY_ONLY") |
| 604 | if tidyOnly == "true" || tidyOnly == "1" { |
| 605 | configArgs = append(configArgs, "tidy_only") |
| 606 | } else { |
| 607 | configArgs = append(configArgs, targets...) |
| 608 | } |
| 609 | |
| 610 | return configArgs |
| 611 | } |
| 612 | |
| 613 | // convertToTarget replaces "/" to "-" in dir and pre-append the targetNamePrefix to the target name. |
| 614 | func convertToTarget(dir string, targetNamePrefix string) string { |
| 615 | return targetNamePrefix + strings.ReplaceAll(dir, "/", "-") |
| 616 | } |
| 617 | |
Patrice Arruda | 9450d0b | 2019-07-08 11:06:46 -0700 | [diff] [blame] | 618 | // hasBuildFile returns true if dir contains an Android build file. |
| 619 | func hasBuildFile(ctx Context, dir string) bool { |
| 620 | for _, buildFile := range buildFiles { |
| 621 | _, err := os.Stat(filepath.Join(dir, buildFile)) |
| 622 | if err == nil { |
| 623 | return true |
| 624 | } |
| 625 | if !os.IsNotExist(err) { |
| 626 | ctx.Fatalf("Error retrieving the build file stats: %v", err) |
| 627 | } |
| 628 | } |
| 629 | return false |
| 630 | } |
| 631 | |
Patrice Arruda | 0dcf27f | 2019-07-08 17:03:33 -0700 | [diff] [blame] | 632 | // findBuildFile finds a build file (makefile or blueprint file) by looking if there is a build file |
| 633 | // in the current and any sub directory of dir. If a build file is not found, traverse the path |
| 634 | // up by one directory and repeat again until either a build file is found or reached to the root |
| 635 | // source tree. The returned filename of build file is "Android.mk". If one was not found, a blank |
| 636 | // string is returned. |
Patrice Arruda | 1384822 | 2019-04-22 17:12:02 -0700 | [diff] [blame] | 637 | func findBuildFile(ctx Context, dir string) string { |
Patrice Arruda | 0dcf27f | 2019-07-08 17:03:33 -0700 | [diff] [blame] | 638 | // If the string is empty or ".", assume it is top directory of the source tree. |
| 639 | if dir == "" || dir == "." { |
Patrice Arruda | 1384822 | 2019-04-22 17:12:02 -0700 | [diff] [blame] | 640 | return "" |
| 641 | } |
| 642 | |
Patrice Arruda | 0dcf27f | 2019-07-08 17:03:33 -0700 | [diff] [blame] | 643 | found := false |
| 644 | for buildDir := dir; buildDir != "."; buildDir = filepath.Dir(buildDir) { |
| 645 | err := filepath.Walk(buildDir, func(path string, info os.FileInfo, err error) error { |
| 646 | if err != nil { |
| 647 | return err |
| 648 | } |
| 649 | if found { |
| 650 | return filepath.SkipDir |
| 651 | } |
| 652 | if info.IsDir() { |
| 653 | return nil |
| 654 | } |
| 655 | for _, buildFile := range buildFiles { |
| 656 | if info.Name() == buildFile { |
| 657 | found = true |
| 658 | return filepath.SkipDir |
| 659 | } |
| 660 | } |
| 661 | return nil |
| 662 | }) |
| 663 | if err != nil { |
| 664 | ctx.Fatalf("Error finding Android build file: %v", err) |
| 665 | } |
| 666 | |
| 667 | if found { |
| 668 | return filepath.Join(buildDir, "Android.mk") |
Patrice Arruda | 1384822 | 2019-04-22 17:12:02 -0700 | [diff] [blame] | 669 | } |
| 670 | } |
| 671 | |
| 672 | return "" |
| 673 | } |
| 674 | |
| 675 | // splitArgs iterates over the arguments list and splits into two lists: arguments and directories. |
| 676 | func splitArgs(args []string) (newArgs []string, dirs []string) { |
| 677 | specialArgs := map[string]bool{ |
| 678 | "showcommands": true, |
| 679 | "snod": true, |
| 680 | "dist": true, |
| 681 | "checkbuild": true, |
| 682 | } |
| 683 | |
| 684 | newArgs = []string{} |
| 685 | dirs = []string{} |
| 686 | |
| 687 | for _, arg := range args { |
| 688 | // It's a dash argument if it starts with "-" or it's a key=value pair, it's not a directory. |
| 689 | if strings.IndexRune(arg, '-') == 0 || strings.IndexRune(arg, '=') != -1 { |
| 690 | newArgs = append(newArgs, arg) |
| 691 | continue |
| 692 | } |
| 693 | |
| 694 | if _, ok := specialArgs[arg]; ok { |
| 695 | newArgs = append(newArgs, arg) |
| 696 | continue |
| 697 | } |
| 698 | |
| 699 | dirs = append(dirs, arg) |
| 700 | } |
| 701 | |
| 702 | return newArgs, dirs |
| 703 | } |
| 704 | |
| 705 | // getTargetsFromDirs iterates over the dirs list and creates a list of targets to build. If a |
| 706 | // directory from the dirs list does not exist, a fatal error is raised. relDir is related to the |
| 707 | // source root tree where the build action command was invoked. Each directory is validated if the |
| 708 | // build file can be found and follows the format "dir1:target1,target2,...". Target is optional. |
Dan Willemsen | ce41e94 | 2019-07-29 23:39:30 -0700 | [diff] [blame] | 709 | func getTargetsFromDirs(ctx Context, relDir string, dirs []string, targetNamePrefix string) (targets []string) { |
Patrice Arruda | 1384822 | 2019-04-22 17:12:02 -0700 | [diff] [blame] | 710 | for _, dir := range dirs { |
| 711 | // The directory may have specified specific modules to build. ":" is the separator to separate |
| 712 | // the directory and the list of modules. |
| 713 | s := strings.Split(dir, ":") |
| 714 | l := len(s) |
| 715 | if l > 2 { // more than one ":" was specified. |
| 716 | ctx.Fatalf("%s not in proper directory:target1,target2,... format (\":\" was specified more than once)", dir) |
| 717 | } |
| 718 | |
| 719 | dir = filepath.Join(relDir, s[0]) |
| 720 | if _, err := os.Stat(dir); err != nil { |
| 721 | ctx.Fatalf("couldn't find directory %s", dir) |
| 722 | } |
| 723 | |
| 724 | // Verify that if there are any targets specified after ":". Each target is separated by ",". |
| 725 | var newTargets []string |
| 726 | if l == 2 && s[1] != "" { |
| 727 | newTargets = strings.Split(s[1], ",") |
| 728 | if inList("", newTargets) { |
| 729 | ctx.Fatalf("%s not in proper directory:target1,target2,... format", dir) |
| 730 | } |
| 731 | } |
| 732 | |
Patrice Arruda | 9450d0b | 2019-07-08 11:06:46 -0700 | [diff] [blame] | 733 | // If there are specified targets to build in dir, an android build file must exist for the one |
| 734 | // shot build. For the non-targets case, find the appropriate build file and build all the |
| 735 | // modules in dir (or the closest one in the dir path). |
Patrice Arruda | 1384822 | 2019-04-22 17:12:02 -0700 | [diff] [blame] | 736 | if len(newTargets) > 0 { |
Patrice Arruda | 9450d0b | 2019-07-08 11:06:46 -0700 | [diff] [blame] | 737 | if !hasBuildFile(ctx, dir) { |
Patrice Arruda | 1384822 | 2019-04-22 17:12:02 -0700 | [diff] [blame] | 738 | ctx.Fatalf("Couldn't locate a build file from %s directory", dir) |
| 739 | } |
| 740 | } else { |
Patrice Arruda | 9450d0b | 2019-07-08 11:06:46 -0700 | [diff] [blame] | 741 | buildFile := findBuildFile(ctx, dir) |
| 742 | if buildFile == "" { |
| 743 | ctx.Fatalf("Build file not found for %s directory", dir) |
| 744 | } |
| 745 | newTargets = []string{convertToTarget(filepath.Dir(buildFile), targetNamePrefix)} |
Patrice Arruda | 1384822 | 2019-04-22 17:12:02 -0700 | [diff] [blame] | 746 | } |
| 747 | |
Patrice Arruda | 1384822 | 2019-04-22 17:12:02 -0700 | [diff] [blame] | 748 | targets = append(targets, newTargets...) |
| 749 | } |
| 750 | |
Dan Willemsen | ce41e94 | 2019-07-29 23:39:30 -0700 | [diff] [blame] | 751 | return targets |
Patrice Arruda | 1384822 | 2019-04-22 17:12:02 -0700 | [diff] [blame] | 752 | } |
| 753 | |
Dan Willemsen | 9b58749 | 2017-07-10 22:13:00 -0700 | [diff] [blame] | 754 | func (c *configImpl) parseArgs(ctx Context, args []string) { |
| 755 | for i := 0; i < len(args); i++ { |
| 756 | arg := strings.TrimSpace(args[i]) |
Anton Hansson | 5a7861a | 2021-06-04 10:09:01 +0100 | [diff] [blame] | 757 | if arg == "showcommands" { |
Dan Willemsen | 9b58749 | 2017-07-10 22:13:00 -0700 | [diff] [blame] | 758 | c.verbose = true |
Lukacs T. Berki | cef87b6 | 2021-08-10 15:01:13 +0200 | [diff] [blame] | 759 | } else if arg == "--empty-ninja-file" { |
| 760 | c.emptyNinjaFile = true |
Lukacs T. Berki | d1e3f1f | 2021-03-16 08:55:23 +0100 | [diff] [blame] | 761 | } else if arg == "--skip-ninja" { |
| 762 | c.skipNinja = true |
Dan Willemsen | e0879fc | 2017-08-04 15:06:27 -0700 | [diff] [blame] | 763 | } else if arg == "--skip-make" { |
Colin Cross | 30e444b | 2021-06-18 11:26:19 -0700 | [diff] [blame] | 764 | // TODO(ccross): deprecate this, it has confusing behaviors. It doesn't run kati, |
| 765 | // but it does run a Kati ninja file if the .kati_enabled marker file was created |
| 766 | // by a previous build. |
Anton Hansson | 5e5c48b | 2020-11-27 12:35:20 +0000 | [diff] [blame] | 767 | c.skipConfig = true |
| 768 | c.skipKati = true |
Anton Hansson | 0b55bdb | 2021-06-04 10:08:08 +0100 | [diff] [blame] | 769 | } else if arg == "--soong-only" { |
| 770 | c.skipKati = true |
| 771 | c.skipKatiNinja = true |
Lukacs T. Berki | cef87b6 | 2021-08-10 15:01:13 +0200 | [diff] [blame] | 772 | } else if arg == "--config-only" { |
| 773 | c.skipKati = true |
| 774 | c.skipKatiNinja = true |
| 775 | c.skipSoong = true |
Colin Cross | 30e444b | 2021-06-18 11:26:19 -0700 | [diff] [blame] | 776 | } else if arg == "--skip-config" { |
| 777 | c.skipConfig = true |
Colin Cross | 00a8a3f | 2020-10-29 14:08:31 -0700 | [diff] [blame] | 778 | } else if arg == "--skip-soong-tests" { |
| 779 | c.skipSoongTests = true |
Colin Cross | 106d6ef | 2023-10-24 10:34:56 -0700 | [diff] [blame] | 780 | } else if arg == "--no-skip-soong-tests" { |
| 781 | c.skipSoongTests = false |
MarkDacek | d0e7cd3 | 2022-12-02 22:22:40 +0000 | [diff] [blame] | 782 | } else if arg == "--skip-metrics-upload" { |
| 783 | c.skipMetricsUpload = true |
Chris Parsons | 53f68ae | 2022-03-03 12:01:40 -0500 | [diff] [blame] | 784 | } else if arg == "--mk-metrics" { |
| 785 | c.reportMkMetrics = true |
Spandan Das | 394aa32 | 2022-11-03 17:02:10 +0000 | [diff] [blame] | 786 | } else if arg == "--search-api-dir" { |
| 787 | c.searchApiDir = true |
Jeongik Cha | 0cf44d5 | 2023-03-15 00:10:45 +0900 | [diff] [blame] | 788 | } else if strings.HasPrefix(arg, "--ninja_weight_source=") { |
| 789 | source := strings.TrimPrefix(arg, "--ninja_weight_source=") |
| 790 | if source == "ninja_log" { |
| 791 | c.ninjaWeightListSource = NINJA_LOG |
| 792 | } else if source == "evenly_distributed" { |
| 793 | c.ninjaWeightListSource = EVENLY_DISTRIBUTED |
| 794 | } else if source == "not_used" { |
| 795 | c.ninjaWeightListSource = NOT_USED |
Jeongik Cha | e114e60 | 2023-03-19 00:12:39 +0900 | [diff] [blame] | 796 | } else if source == "soong" { |
| 797 | c.ninjaWeightListSource = HINT_FROM_SOONG |
Jeongik Cha | 518f3ea | 2023-03-19 00:12:39 +0900 | [diff] [blame] | 798 | } else if strings.HasPrefix(source, "file,") { |
| 799 | c.ninjaWeightListSource = EXTERNAL_FILE |
| 800 | filePath := strings.TrimPrefix(source, "file,") |
| 801 | err := validateNinjaWeightList(filePath) |
| 802 | if err != nil { |
| 803 | ctx.Fatalf("Malformed weight list from %s: %s", filePath, err) |
| 804 | } |
| 805 | _, err = copyFile(filePath, filepath.Join(c.OutDir(), ".ninja_weight_list")) |
| 806 | if err != nil { |
| 807 | ctx.Fatalf("Error to copy ninja weight list from %s: %s", filePath, err) |
| 808 | } |
Jeongik Cha | 0cf44d5 | 2023-03-15 00:10:45 +0900 | [diff] [blame] | 809 | } else { |
| 810 | ctx.Fatalf("unknown option for ninja_weight_source: %s", source) |
| 811 | } |
Jihoon Kang | 2a929ad | 2023-06-08 19:02:07 +0000 | [diff] [blame] | 812 | } else if arg == "--build-from-source-stub" { |
| 813 | c.buildFromSourceStub = true |
MarkDacek | b96561e | 2022-12-02 04:34:43 +0000 | [diff] [blame] | 814 | } else if strings.HasPrefix(arg, "--build-command=") { |
| 815 | buildCmd := strings.TrimPrefix(arg, "--build-command=") |
| 816 | // remove quotations |
| 817 | buildCmd = strings.TrimPrefix(buildCmd, "\"") |
| 818 | buildCmd = strings.TrimSuffix(buildCmd, "\"") |
| 819 | ctx.Metrics.SetBuildCommand([]string{buildCmd}) |
MarkDacek | 6614d9c | 2022-12-07 21:57:38 +0000 | [diff] [blame] | 820 | } else if strings.HasPrefix(arg, "--build-started-time-unix-millis=") { |
| 821 | buildTimeStr := strings.TrimPrefix(arg, "--build-started-time-unix-millis=") |
| 822 | val, err := strconv.ParseInt(buildTimeStr, 10, 64) |
| 823 | if err == nil { |
| 824 | c.buildStartedTime = val |
| 825 | } else { |
| 826 | ctx.Fatalf("Error parsing build-time-started-unix-millis", err) |
| 827 | } |
MarkDacek | f47e142 | 2023-04-19 16:47:36 +0000 | [diff] [blame] | 828 | } else if arg == "--ensure-allowlist-integrity" { |
| 829 | c.ensureAllowlistIntegrity = true |
Dan Willemsen | 6ac63ef | 2017-10-17 20:35:34 -0700 | [diff] [blame] | 830 | } else if len(arg) > 0 && arg[0] == '-' { |
Dan Willemsen | 9b58749 | 2017-07-10 22:13:00 -0700 | [diff] [blame] | 831 | parseArgNum := func(def int) int { |
| 832 | if len(arg) > 2 { |
| 833 | p, err := strconv.ParseUint(arg[2:], 10, 31) |
| 834 | if err != nil { |
| 835 | ctx.Fatalf("Failed to parse %q: %v", arg, err) |
| 836 | } |
| 837 | return int(p) |
| 838 | } else if i+1 < len(args) { |
| 839 | p, err := strconv.ParseUint(args[i+1], 10, 31) |
| 840 | if err == nil { |
| 841 | i++ |
| 842 | return int(p) |
| 843 | } |
| 844 | } |
| 845 | return def |
| 846 | } |
| 847 | |
Dan Willemsen | 6ac63ef | 2017-10-17 20:35:34 -0700 | [diff] [blame] | 848 | if len(arg) > 1 && arg[1] == 'j' { |
Dan Willemsen | 9b58749 | 2017-07-10 22:13:00 -0700 | [diff] [blame] | 849 | c.parallel = parseArgNum(c.parallel) |
Dan Willemsen | 6ac63ef | 2017-10-17 20:35:34 -0700 | [diff] [blame] | 850 | } else if len(arg) > 1 && arg[1] == 'k' { |
Dan Willemsen | 9b58749 | 2017-07-10 22:13:00 -0700 | [diff] [blame] | 851 | c.keepGoing = parseArgNum(0) |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 852 | } else { |
| 853 | ctx.Fatalln("Unknown option:", arg) |
| 854 | } |
Dan Willemsen | 091525e | 2017-07-11 14:17:50 -0700 | [diff] [blame] | 855 | } else if k, v, ok := decodeKeyValue(arg); ok && len(k) > 0 { |
Dan Willemsen | 6dfe30a | 2018-09-10 12:41:10 -0700 | [diff] [blame] | 856 | if k == "OUT_DIR" { |
| 857 | ctx.Fatalln("OUT_DIR may only be set in the environment, not as a command line option.") |
| 858 | } |
Dan Willemsen | 091525e | 2017-07-11 14:17:50 -0700 | [diff] [blame] | 859 | c.environ.Set(k, v) |
Dan Willemsen | 2d31a44 | 2018-10-20 21:33:41 -0700 | [diff] [blame] | 860 | } else if arg == "dist" { |
| 861 | c.dist = true |
Lukacs T. Berki | a1b9372 | 2021-09-02 17:23:06 +0200 | [diff] [blame] | 862 | } else if arg == "json-module-graph" { |
| 863 | c.jsonModuleGraph = true |
Lukacs T. Berki | 3a82169 | 2021-09-06 17:08:02 +0200 | [diff] [blame] | 864 | } else if arg == "queryview" { |
| 865 | c.queryview = true |
Lukacs T. Berki | c6012f3 | 2021-09-06 18:31:46 +0200 | [diff] [blame] | 866 | } else if arg == "soong_docs" { |
| 867 | c.soongDocs = true |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 868 | } else { |
Dan Willemsen | 2d31a44 | 2018-10-20 21:33:41 -0700 | [diff] [blame] | 869 | if arg == "checkbuild" { |
Colin Cross | 3719349 | 2017-11-16 17:55:00 -0800 | [diff] [blame] | 870 | c.checkbuild = true |
Dan Willemsen | e0879fc | 2017-08-04 15:06:27 -0700 | [diff] [blame] | 871 | } |
Dan Willemsen | 9b58749 | 2017-07-10 22:13:00 -0700 | [diff] [blame] | 872 | c.arguments = append(c.arguments, arg) |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 873 | } |
| 874 | } |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 875 | } |
| 876 | |
Jeongik Cha | 518f3ea | 2023-03-19 00:12:39 +0900 | [diff] [blame] | 877 | func validateNinjaWeightList(weightListFilePath string) (err error) { |
| 878 | data, err := os.ReadFile(weightListFilePath) |
| 879 | if err != nil { |
| 880 | return |
| 881 | } |
| 882 | lines := strings.Split(strings.TrimSpace(string(data)), "\n") |
| 883 | for _, line := range lines { |
| 884 | fields := strings.Split(line, ",") |
| 885 | if len(fields) != 2 { |
| 886 | return fmt.Errorf("wrong format, each line should have two fields, but '%s'", line) |
| 887 | } |
| 888 | _, err = strconv.Atoi(fields[1]) |
| 889 | if err != nil { |
| 890 | return |
| 891 | } |
| 892 | } |
| 893 | return |
| 894 | } |
| 895 | |
Dan Willemsen | ed86952 | 2018-01-08 14:58:46 -0800 | [diff] [blame] | 896 | func (c *configImpl) configureLocale(ctx Context) { |
| 897 | cmd := Command(ctx, Config{c}, "locale", "locale", "-a") |
| 898 | output, err := cmd.Output() |
| 899 | |
| 900 | var locales []string |
| 901 | if err == nil { |
| 902 | locales = strings.Split(string(output), "\n") |
| 903 | } else { |
| 904 | // If we're unable to list the locales, let's assume en_US.UTF-8 |
| 905 | locales = []string{"en_US.UTF-8"} |
| 906 | ctx.Verbosef("Failed to list locales (%q), falling back to %q", err, locales) |
| 907 | } |
| 908 | |
| 909 | // gettext uses LANGUAGE, which is passed directly through |
| 910 | |
| 911 | // For LANG and LC_*, only preserve the evaluated version of |
| 912 | // LC_MESSAGES |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 913 | userLang := "" |
Dan Willemsen | ed86952 | 2018-01-08 14:58:46 -0800 | [diff] [blame] | 914 | if lc_all, ok := c.environ.Get("LC_ALL"); ok { |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 915 | userLang = lc_all |
Dan Willemsen | ed86952 | 2018-01-08 14:58:46 -0800 | [diff] [blame] | 916 | } else if lc_messages, ok := c.environ.Get("LC_MESSAGES"); ok { |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 917 | userLang = lc_messages |
Dan Willemsen | ed86952 | 2018-01-08 14:58:46 -0800 | [diff] [blame] | 918 | } else if lang, ok := c.environ.Get("LANG"); ok { |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 919 | userLang = lang |
Dan Willemsen | ed86952 | 2018-01-08 14:58:46 -0800 | [diff] [blame] | 920 | } |
| 921 | |
| 922 | c.environ.UnsetWithPrefix("LC_") |
| 923 | |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 924 | if userLang != "" { |
| 925 | c.environ.Set("LC_MESSAGES", userLang) |
Dan Willemsen | ed86952 | 2018-01-08 14:58:46 -0800 | [diff] [blame] | 926 | } |
| 927 | |
| 928 | // The for LANG, use C.UTF-8 if it exists (Debian currently, proposed |
| 929 | // for others) |
| 930 | if inList("C.UTF-8", locales) { |
| 931 | c.environ.Set("LANG", "C.UTF-8") |
Aaron Kling | d236e0e | 2018-08-07 19:21:36 -0500 | [diff] [blame] | 932 | } else if inList("C.utf8", locales) { |
| 933 | // These normalize to the same thing |
| 934 | c.environ.Set("LANG", "C.UTF-8") |
Dan Willemsen | ed86952 | 2018-01-08 14:58:46 -0800 | [diff] [blame] | 935 | } else if inList("en_US.UTF-8", locales) { |
| 936 | c.environ.Set("LANG", "en_US.UTF-8") |
| 937 | } else if inList("en_US.utf8", locales) { |
| 938 | // These normalize to the same thing |
| 939 | c.environ.Set("LANG", "en_US.UTF-8") |
| 940 | } else { |
| 941 | ctx.Fatalln("System doesn't support either C.UTF-8 or en_US.UTF-8") |
| 942 | } |
| 943 | } |
| 944 | |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 945 | func (c *configImpl) Environment() *Environment { |
| 946 | return c.environ |
| 947 | } |
| 948 | |
| 949 | func (c *configImpl) Arguments() []string { |
| 950 | return c.arguments |
| 951 | } |
| 952 | |
Lukacs T. Berki | a1b9372 | 2021-09-02 17:23:06 +0200 | [diff] [blame] | 953 | func (c *configImpl) SoongBuildInvocationNeeded() bool { |
Lukacs T. Berki | a1b9372 | 2021-09-02 17:23:06 +0200 | [diff] [blame] | 954 | if len(c.Arguments()) > 0 { |
| 955 | // Explicit targets requested that are not special targets like b2pbuild |
| 956 | // or the JSON module graph |
| 957 | return true |
| 958 | } |
| 959 | |
Colin Cross | 8d411ff | 2023-12-07 10:31:24 -0800 | [diff] [blame] | 960 | if !c.JsonModuleGraph() && !c.Queryview() && !c.SoongDocs() { |
Lukacs T. Berki | a1b9372 | 2021-09-02 17:23:06 +0200 | [diff] [blame] | 961 | // Command line was empty, the default Ninja target is built |
| 962 | return true |
| 963 | } |
| 964 | |
Colin Cross | 8d411ff | 2023-12-07 10:31:24 -0800 | [diff] [blame] | 965 | if c.Dist() { |
Liz Kammer | 8867742 | 2021-12-15 15:03:19 -0500 | [diff] [blame] | 966 | return true |
| 967 | } |
| 968 | |
Lukacs T. Berki | a1b9372 | 2021-09-02 17:23:06 +0200 | [diff] [blame] | 969 | // build.ninja doesn't need to be generated |
| 970 | return false |
| 971 | } |
| 972 | |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 973 | func (c *configImpl) OutDir() string { |
| 974 | if outDir, ok := c.environ.Get("OUT_DIR"); ok { |
Patrice Arruda | 19bd53e | 2019-07-08 17:26:47 -0700 | [diff] [blame] | 975 | return outDir |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 976 | } |
| 977 | return "out" |
| 978 | } |
| 979 | |
Dan Willemsen | 8a073a8 | 2017-02-04 17:30:44 -0800 | [diff] [blame] | 980 | func (c *configImpl) DistDir() string { |
Chris Parsons | 19ab9a4 | 2022-08-30 13:15:04 -0400 | [diff] [blame] | 981 | return c.distDir |
Rupert Shuttleworth | 3c9f5ac | 2020-12-10 11:32:38 +0000 | [diff] [blame] | 982 | } |
| 983 | |
| 984 | func (c *configImpl) RealDistDir() string { |
Dan Willemsen | 2d31a44 | 2018-10-20 21:33:41 -0700 | [diff] [blame] | 985 | return c.distDir |
Dan Willemsen | 8a073a8 | 2017-02-04 17:30:44 -0800 | [diff] [blame] | 986 | } |
| 987 | |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 988 | func (c *configImpl) NinjaArgs() []string { |
Anton Hansson | 5e5c48b | 2020-11-27 12:35:20 +0000 | [diff] [blame] | 989 | if c.skipKati { |
Dan Willemsen | e0879fc | 2017-08-04 15:06:27 -0700 | [diff] [blame] | 990 | return c.arguments |
| 991 | } |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 992 | return c.ninjaArgs |
| 993 | } |
| 994 | |
| 995 | func (c *configImpl) SoongOutDir() string { |
| 996 | return filepath.Join(c.OutDir(), "soong") |
| 997 | } |
| 998 | |
Spandan Das | 394aa32 | 2022-11-03 17:02:10 +0000 | [diff] [blame] | 999 | func (c *configImpl) ApiSurfacesOutDir() string { |
| 1000 | return filepath.Join(c.OutDir(), "api_surfaces") |
| 1001 | } |
| 1002 | |
Lukacs T. Berki | a806e41 | 2021-09-01 08:57:48 +0200 | [diff] [blame] | 1003 | func (c *configImpl) PrebuiltOS() string { |
| 1004 | switch runtime.GOOS { |
| 1005 | case "linux": |
| 1006 | return "linux-x86" |
| 1007 | case "darwin": |
| 1008 | return "darwin-x86" |
| 1009 | default: |
| 1010 | panic("Unknown GOOS") |
| 1011 | } |
| 1012 | } |
Lukacs T. Berki | 90b4334 | 2021-11-02 14:42:04 +0100 | [diff] [blame] | 1013 | |
Lukacs T. Berki | a806e41 | 2021-09-01 08:57:48 +0200 | [diff] [blame] | 1014 | func (c *configImpl) HostToolDir() string { |
Colin Cross | acfcc1f | 2021-10-25 15:40:32 -0700 | [diff] [blame] | 1015 | if c.SkipKatiNinja() { |
| 1016 | return filepath.Join(c.SoongOutDir(), "host", c.PrebuiltOS(), "bin") |
| 1017 | } else { |
| 1018 | return filepath.Join(c.OutDir(), "host", c.PrebuiltOS(), "bin") |
| 1019 | } |
Lukacs T. Berki | a806e41 | 2021-09-01 08:57:48 +0200 | [diff] [blame] | 1020 | } |
| 1021 | |
Lukacs T. Berki | 89fcdcb | 2021-09-07 09:10:33 +0200 | [diff] [blame] | 1022 | func (c *configImpl) NamedGlobFile(name string) string { |
Lukacs T. Berki | 90b4334 | 2021-11-02 14:42:04 +0100 | [diff] [blame] | 1023 | return shared.JoinPath(c.SoongOutDir(), "globs-"+name+".ninja") |
Lukacs T. Berki | 89fcdcb | 2021-09-07 09:10:33 +0200 | [diff] [blame] | 1024 | } |
| 1025 | |
Lukacs T. Berki | e1df43f | 2021-09-08 15:31:14 +0200 | [diff] [blame] | 1026 | func (c *configImpl) UsedEnvFile(tag string) string { |
Kiyoung Kim | eaa55a8 | 2023-06-05 16:56:49 +0900 | [diff] [blame] | 1027 | if v, ok := c.environ.Get("TARGET_PRODUCT"); ok { |
| 1028 | return shared.JoinPath(c.SoongOutDir(), usedEnvFile+"."+v+"."+tag) |
| 1029 | } |
Lukacs T. Berki | e1df43f | 2021-09-08 15:31:14 +0200 | [diff] [blame] | 1030 | return shared.JoinPath(c.SoongOutDir(), usedEnvFile+"."+tag) |
| 1031 | } |
| 1032 | |
Lukacs T. Berki | c6012f3 | 2021-09-06 18:31:46 +0200 | [diff] [blame] | 1033 | func (c *configImpl) SoongDocsHtml() string { |
| 1034 | return shared.JoinPath(c.SoongOutDir(), "docs/soong_build.html") |
| 1035 | } |
| 1036 | |
Lukacs T. Berki | 3a82169 | 2021-09-06 17:08:02 +0200 | [diff] [blame] | 1037 | func (c *configImpl) QueryviewMarkerFile() string { |
| 1038 | return shared.JoinPath(c.SoongOutDir(), "queryview.marker") |
| 1039 | } |
| 1040 | |
Lukacs T. Berki | e571dc3 | 2021-08-25 14:14:13 +0200 | [diff] [blame] | 1041 | func (c *configImpl) ModuleGraphFile() string { |
| 1042 | return shared.JoinPath(c.SoongOutDir(), "module-graph.json") |
| 1043 | } |
| 1044 | |
kgui | 6700724 | 2022-01-25 13:50:25 +0800 | [diff] [blame] | 1045 | func (c *configImpl) ModuleActionsFile() string { |
| 1046 | return shared.JoinPath(c.SoongOutDir(), "module-actions.json") |
| 1047 | } |
| 1048 | |
Jeff Gaston | efc1b41 | 2017-03-29 17:29:06 -0700 | [diff] [blame] | 1049 | func (c *configImpl) TempDir() string { |
| 1050 | return shared.TempDirForOutDir(c.SoongOutDir()) |
| 1051 | } |
| 1052 | |
Jeff Gaston | b64fc1c | 2017-08-04 12:30:12 -0700 | [diff] [blame] | 1053 | func (c *configImpl) FileListDir() string { |
| 1054 | return filepath.Join(c.OutDir(), ".module_paths") |
| 1055 | } |
| 1056 | |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 1057 | func (c *configImpl) KatiSuffix() string { |
| 1058 | if c.katiSuffix != "" { |
| 1059 | return c.katiSuffix |
| 1060 | } |
| 1061 | panic("SetKatiSuffix has not been called") |
| 1062 | } |
| 1063 | |
Colin Cross | 3719349 | 2017-11-16 17:55:00 -0800 | [diff] [blame] | 1064 | // Checkbuild returns true if "checkbuild" was one of the build goals, which means that the |
| 1065 | // user is interested in additional checks at the expense of build time. |
| 1066 | func (c *configImpl) Checkbuild() bool { |
| 1067 | return c.checkbuild |
| 1068 | } |
| 1069 | |
Dan Willemsen | 8a073a8 | 2017-02-04 17:30:44 -0800 | [diff] [blame] | 1070 | func (c *configImpl) Dist() bool { |
| 1071 | return c.dist |
| 1072 | } |
| 1073 | |
Lukacs T. Berki | a1b9372 | 2021-09-02 17:23:06 +0200 | [diff] [blame] | 1074 | func (c *configImpl) JsonModuleGraph() bool { |
| 1075 | return c.jsonModuleGraph |
| 1076 | } |
| 1077 | |
Lukacs T. Berki | 3a82169 | 2021-09-06 17:08:02 +0200 | [diff] [blame] | 1078 | func (c *configImpl) Queryview() bool { |
| 1079 | return c.queryview |
| 1080 | } |
| 1081 | |
Lukacs T. Berki | c6012f3 | 2021-09-06 18:31:46 +0200 | [diff] [blame] | 1082 | func (c *configImpl) SoongDocs() bool { |
| 1083 | return c.soongDocs |
| 1084 | } |
| 1085 | |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 1086 | func (c *configImpl) IsVerbose() bool { |
| 1087 | return c.verbose |
| 1088 | } |
| 1089 | |
Jeongik Cha | 0cf44d5 | 2023-03-15 00:10:45 +0900 | [diff] [blame] | 1090 | func (c *configImpl) NinjaWeightListSource() NinjaWeightListSource { |
| 1091 | return c.ninjaWeightListSource |
| 1092 | } |
| 1093 | |
Anton Hansson | 5e5c48b | 2020-11-27 12:35:20 +0000 | [diff] [blame] | 1094 | func (c *configImpl) SkipKati() bool { |
| 1095 | return c.skipKati |
| 1096 | } |
| 1097 | |
Anton Hansson | 0b55bdb | 2021-06-04 10:08:08 +0100 | [diff] [blame] | 1098 | func (c *configImpl) SkipKatiNinja() bool { |
| 1099 | return c.skipKatiNinja |
| 1100 | } |
| 1101 | |
Lukacs T. Berki | cef87b6 | 2021-08-10 15:01:13 +0200 | [diff] [blame] | 1102 | func (c *configImpl) SkipSoong() bool { |
| 1103 | return c.skipSoong |
| 1104 | } |
| 1105 | |
Lukacs T. Berki | d1e3f1f | 2021-03-16 08:55:23 +0100 | [diff] [blame] | 1106 | func (c *configImpl) SkipNinja() bool { |
| 1107 | return c.skipNinja |
| 1108 | } |
| 1109 | |
Anton Hansson | 5a7861a | 2021-06-04 10:09:01 +0100 | [diff] [blame] | 1110 | func (c *configImpl) SetSkipNinja(v bool) { |
| 1111 | c.skipNinja = v |
| 1112 | } |
| 1113 | |
Anton Hansson | 5e5c48b | 2020-11-27 12:35:20 +0000 | [diff] [blame] | 1114 | func (c *configImpl) SkipConfig() bool { |
| 1115 | return c.skipConfig |
Dan Willemsen | e0879fc | 2017-08-04 15:06:27 -0700 | [diff] [blame] | 1116 | } |
| 1117 | |
Jihoon Kang | 1bff034 | 2023-01-17 20:40:22 +0000 | [diff] [blame] | 1118 | func (c *configImpl) BuildFromTextStub() bool { |
Jihoon Kang | 2a929ad | 2023-06-08 19:02:07 +0000 | [diff] [blame] | 1119 | return !c.buildFromSourceStub |
Jihoon Kang | 1bff034 | 2023-01-17 20:40:22 +0000 | [diff] [blame] | 1120 | } |
| 1121 | |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 1122 | func (c *configImpl) TargetProduct() string { |
| 1123 | if v, ok := c.environ.Get("TARGET_PRODUCT"); ok { |
| 1124 | return v |
| 1125 | } |
| 1126 | panic("TARGET_PRODUCT is not defined") |
| 1127 | } |
| 1128 | |
Kiyoung Kim | a37d9ba | 2023-04-19 13:13:45 +0900 | [diff] [blame] | 1129 | func (c *configImpl) TargetProductOrErr() (string, error) { |
| 1130 | if v, ok := c.environ.Get("TARGET_PRODUCT"); ok { |
| 1131 | return v, nil |
| 1132 | } |
| 1133 | return "", fmt.Errorf("TARGET_PRODUCT is not defined") |
| 1134 | } |
| 1135 | |
Dan Willemsen | 02781d5 | 2017-05-12 19:28:13 -0700 | [diff] [blame] | 1136 | func (c *configImpl) TargetDevice() string { |
| 1137 | return c.targetDevice |
| 1138 | } |
| 1139 | |
| 1140 | func (c *configImpl) SetTargetDevice(device string) { |
| 1141 | c.targetDevice = device |
| 1142 | } |
| 1143 | |
| 1144 | func (c *configImpl) TargetBuildVariant() string { |
| 1145 | if v, ok := c.environ.Get("TARGET_BUILD_VARIANT"); ok { |
| 1146 | return v |
| 1147 | } |
| 1148 | panic("TARGET_BUILD_VARIANT is not defined") |
| 1149 | } |
| 1150 | |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 1151 | func (c *configImpl) KatiArgs() []string { |
| 1152 | return c.katiArgs |
| 1153 | } |
| 1154 | |
| 1155 | func (c *configImpl) Parallel() int { |
| 1156 | return c.parallel |
| 1157 | } |
| 1158 | |
Sam Delmerico | 98a7329 | 2023-02-21 11:50:29 -0500 | [diff] [blame] | 1159 | func (c *configImpl) GetSourceRootDirs() []string { |
| 1160 | return c.sourceRootDirs |
| 1161 | } |
| 1162 | |
| 1163 | func (c *configImpl) SetSourceRootDirs(i []string) { |
| 1164 | c.sourceRootDirs = i |
| 1165 | } |
| 1166 | |
MarkDacek | 6614d9c | 2022-12-07 21:57:38 +0000 | [diff] [blame] | 1167 | func (c *configImpl) GetLogsPrefix() string { |
| 1168 | return c.logsPrefix |
| 1169 | } |
| 1170 | |
| 1171 | func (c *configImpl) SetLogsPrefix(prefix string) { |
| 1172 | c.logsPrefix = prefix |
| 1173 | } |
| 1174 | |
Colin Cross | 8b8bec3 | 2019-11-15 13:18:43 -0800 | [diff] [blame] | 1175 | func (c *configImpl) HighmemParallel() int { |
| 1176 | if i, ok := c.environ.GetInt("NINJA_HIGHMEM_NUM_JOBS"); ok { |
| 1177 | return i |
| 1178 | } |
| 1179 | |
| 1180 | const minMemPerHighmemProcess = 8 * 1024 * 1024 * 1024 |
| 1181 | parallel := c.Parallel() |
| 1182 | if c.UseRemoteBuild() { |
| 1183 | // Ninja doesn't support nested pools, and when remote builds are enabled the total ninja parallelism |
| 1184 | // is set very high (i.e. 500). Using a large value here would cause the total number of running jobs |
| 1185 | // to be the sum of the sizes of the local and highmem pools, which will cause extra CPU contention. |
| 1186 | // Return 1/16th of the size of the local pool, rounding up. |
| 1187 | return (parallel + 15) / 16 |
| 1188 | } else if c.totalRAM == 0 { |
| 1189 | // Couldn't detect the total RAM, don't restrict highmem processes. |
| 1190 | return parallel |
Dan Willemsen | 570a292 | 2020-05-26 23:02:29 -0700 | [diff] [blame] | 1191 | } else if c.totalRAM <= 16*1024*1024*1024 { |
| 1192 | // Less than 16GB of ram, restrict to 1 highmem processes |
| 1193 | return 1 |
Colin Cross | 8b8bec3 | 2019-11-15 13:18:43 -0800 | [diff] [blame] | 1194 | } else if c.totalRAM <= 32*1024*1024*1024 { |
| 1195 | // Less than 32GB of ram, restrict to 2 highmem processes |
| 1196 | return 2 |
| 1197 | } else if p := int(c.totalRAM / minMemPerHighmemProcess); p < parallel { |
| 1198 | // If less than 8GB total RAM per process, reduce the number of highmem processes |
| 1199 | return p |
| 1200 | } |
| 1201 | // No restriction on highmem processes |
| 1202 | return parallel |
| 1203 | } |
| 1204 | |
Dan Willemsen | 2bb82d0 | 2019-12-27 09:35:42 -0800 | [diff] [blame] | 1205 | func (c *configImpl) TotalRAM() uint64 { |
| 1206 | return c.totalRAM |
| 1207 | } |
| 1208 | |
Kousik Kumar | ec47864 | 2020-09-21 13:39:24 -0400 | [diff] [blame] | 1209 | // ForceUseGoma determines whether we should override Goma deprecation |
| 1210 | // and use Goma for the current build or not. |
| 1211 | func (c *configImpl) ForceUseGoma() bool { |
| 1212 | if v, ok := c.environ.Get("FORCE_USE_GOMA"); ok { |
| 1213 | v = strings.TrimSpace(v) |
| 1214 | if v != "" && v != "false" { |
| 1215 | return true |
| 1216 | } |
| 1217 | } |
| 1218 | return false |
| 1219 | } |
| 1220 | |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 1221 | func (c *configImpl) UseGoma() bool { |
| 1222 | if v, ok := c.environ.Get("USE_GOMA"); ok { |
| 1223 | v = strings.TrimSpace(v) |
| 1224 | if v != "" && v != "false" { |
| 1225 | return true |
| 1226 | } |
| 1227 | } |
| 1228 | return false |
| 1229 | } |
| 1230 | |
Yoshisato Yanagisawa | 2cb0e5d | 2019-01-10 10:14:16 +0900 | [diff] [blame] | 1231 | func (c *configImpl) StartGoma() bool { |
| 1232 | if !c.UseGoma() { |
| 1233 | return false |
| 1234 | } |
| 1235 | |
| 1236 | if v, ok := c.environ.Get("NOSTART_GOMA"); ok { |
| 1237 | v = strings.TrimSpace(v) |
| 1238 | if v != "" && v != "false" { |
| 1239 | return false |
| 1240 | } |
| 1241 | } |
| 1242 | return true |
| 1243 | } |
| 1244 | |
Kousik Kumar | 6d1e348 | 2023-07-24 03:44:16 +0000 | [diff] [blame] | 1245 | func (c *configImpl) canSupportRBE() bool { |
| 1246 | // Do not use RBE with prod credentials in scenarios when stubby doesn't exist, since |
| 1247 | // its unlikely that we will be able to obtain necessary creds without stubby. |
| 1248 | authType, _ := c.rbeAuth() |
| 1249 | if !c.StubbyExists() && strings.Contains(authType, "use_google_prod_creds") { |
| 1250 | return false |
| 1251 | } |
| 1252 | return true |
| 1253 | } |
| 1254 | |
Ramy Medhat | bbf2567 | 2019-07-17 12:30:04 +0000 | [diff] [blame] | 1255 | func (c *configImpl) UseRBE() bool { |
Jingwen Chen | d7ccde1 | 2023-06-28 07:19:26 +0000 | [diff] [blame] | 1256 | // These alternate modes of running Soong do not use RBE / reclient. |
Colin Cross | 8d411ff | 2023-12-07 10:31:24 -0800 | [diff] [blame] | 1257 | if c.Queryview() || c.JsonModuleGraph() { |
Jingwen Chen | d7ccde1 | 2023-06-28 07:19:26 +0000 | [diff] [blame] | 1258 | return false |
| 1259 | } |
| 1260 | |
Kousik Kumar | 6d1e348 | 2023-07-24 03:44:16 +0000 | [diff] [blame] | 1261 | if !c.canSupportRBE() { |
Kousik Kumar | 67ad434 | 2023-06-06 15:09:27 -0400 | [diff] [blame] | 1262 | return false |
| 1263 | } |
Kousik Kumar | 6d1e348 | 2023-07-24 03:44:16 +0000 | [diff] [blame] | 1264 | |
Kousik Kumar | 3ff037e | 2022-01-25 22:11:01 -0500 | [diff] [blame] | 1265 | if v, ok := c.Environment().Get("USE_RBE"); ok { |
Ramy Medhat | bbf2567 | 2019-07-17 12:30:04 +0000 | [diff] [blame] | 1266 | v = strings.TrimSpace(v) |
| 1267 | if v != "" && v != "false" { |
| 1268 | return true |
| 1269 | } |
| 1270 | } |
| 1271 | return false |
| 1272 | } |
| 1273 | |
| 1274 | func (c *configImpl) StartRBE() bool { |
| 1275 | if !c.UseRBE() { |
| 1276 | return false |
| 1277 | } |
| 1278 | |
| 1279 | if v, ok := c.environ.Get("NOSTART_RBE"); ok { |
| 1280 | v = strings.TrimSpace(v) |
| 1281 | if v != "" && v != "false" { |
| 1282 | return false |
| 1283 | } |
| 1284 | } |
| 1285 | return true |
| 1286 | } |
| 1287 | |
Kousik Kumar | 4c180ad | 2022-05-27 07:48:37 -0400 | [diff] [blame] | 1288 | func (c *configImpl) rbeProxyLogsDir() string { |
| 1289 | for _, f := range []string{"RBE_proxy_log_dir", "FLAG_output_dir"} { |
Kousik Kumar | 0d15a72 | 2020-09-23 02:54:11 -0400 | [diff] [blame] | 1290 | if v, ok := c.environ.Get(f); ok { |
| 1291 | return v |
| 1292 | } |
| 1293 | } |
Ramy Medhat | bc06176 | 2023-10-10 18:36:59 +0000 | [diff] [blame] | 1294 | return c.rbeTmpDir() |
| 1295 | } |
| 1296 | |
| 1297 | func (c *configImpl) rbeDownloadTmpDir() string { |
Cole Faust | 06ea531 | 2023-10-18 17:38:40 -0700 | [diff] [blame] | 1298 | for _, f := range []string{"RBE_download_tmp_dir", "FLAG_download_tmp_dir"} { |
Ramy Medhat | bc06176 | 2023-10-10 18:36:59 +0000 | [diff] [blame] | 1299 | if v, ok := c.environ.Get(f); ok { |
| 1300 | return v |
| 1301 | } |
| 1302 | } |
| 1303 | return c.rbeTmpDir() |
| 1304 | } |
| 1305 | |
| 1306 | func (c *configImpl) rbeTmpDir() string { |
Kousik Kumar | 4c180ad | 2022-05-27 07:48:37 -0400 | [diff] [blame] | 1307 | buildTmpDir := shared.TempDirForOutDir(c.SoongOutDir()) |
| 1308 | return filepath.Join(buildTmpDir, "rbe") |
Ramy Medhat | 0fc67eb | 2020-08-12 01:26:23 -0400 | [diff] [blame] | 1309 | } |
| 1310 | |
Ramy Medhat | c8f6cc2 | 2023-03-31 09:50:34 -0400 | [diff] [blame] | 1311 | func (c *configImpl) rbeCacheDir() string { |
| 1312 | for _, f := range []string{"RBE_cache_dir", "FLAG_cache_dir"} { |
| 1313 | if v, ok := c.environ.Get(f); ok { |
| 1314 | return v |
| 1315 | } |
| 1316 | } |
| 1317 | return shared.JoinPath(c.SoongOutDir(), "rbe") |
| 1318 | } |
| 1319 | |
Kousik Kumar | 4c180ad | 2022-05-27 07:48:37 -0400 | [diff] [blame] | 1320 | func (c *configImpl) shouldCleanupRBELogsDir() bool { |
| 1321 | // Perform a log directory cleanup only when the log directory |
| 1322 | // is auto created by the build rather than user-specified. |
| 1323 | for _, f := range []string{"RBE_proxy_log_dir", "FLAG_output_dir"} { |
| 1324 | if _, ok := c.environ.Get(f); ok { |
| 1325 | return false |
Patrice Arruda | 62f1bf2 | 2020-07-07 12:48:26 +0000 | [diff] [blame] | 1326 | } |
| 1327 | } |
Kousik Kumar | 4c180ad | 2022-05-27 07:48:37 -0400 | [diff] [blame] | 1328 | return true |
Ramy Medhat | 0fc67eb | 2020-08-12 01:26:23 -0400 | [diff] [blame] | 1329 | } |
| 1330 | |
| 1331 | func (c *configImpl) rbeExecRoot() string { |
| 1332 | for _, f := range []string{"RBE_exec_root", "FLAG_exec_root"} { |
| 1333 | if v, ok := c.environ.Get(f); ok { |
| 1334 | return v |
| 1335 | } |
| 1336 | } |
| 1337 | wd, err := os.Getwd() |
| 1338 | if err != nil { |
| 1339 | return "" |
| 1340 | } |
| 1341 | return wd |
| 1342 | } |
| 1343 | |
| 1344 | func (c *configImpl) rbeDir() string { |
| 1345 | if v, ok := c.environ.Get("RBE_DIR"); ok { |
| 1346 | return v |
| 1347 | } |
| 1348 | return "prebuilts/remoteexecution-client/live/" |
| 1349 | } |
| 1350 | |
| 1351 | func (c *configImpl) rbeReproxy() string { |
| 1352 | for _, f := range []string{"RBE_re_proxy", "FLAG_re_proxy"} { |
| 1353 | if v, ok := c.environ.Get(f); ok { |
| 1354 | return v |
| 1355 | } |
| 1356 | } |
| 1357 | return filepath.Join(c.rbeDir(), "reproxy") |
| 1358 | } |
| 1359 | |
| 1360 | func (c *configImpl) rbeAuth() (string, string) { |
Kousik Kumar | 93d192c | 2022-03-18 01:39:56 -0400 | [diff] [blame] | 1361 | credFlags := []string{ |
| 1362 | "use_application_default_credentials", |
| 1363 | "use_gce_credentials", |
| 1364 | "credential_file", |
| 1365 | "use_google_prod_creds", |
| 1366 | } |
Ramy Medhat | 0fc67eb | 2020-08-12 01:26:23 -0400 | [diff] [blame] | 1367 | for _, cf := range credFlags { |
| 1368 | for _, f := range []string{"RBE_" + cf, "FLAG_" + cf} { |
| 1369 | if v, ok := c.environ.Get(f); ok { |
| 1370 | v = strings.TrimSpace(v) |
| 1371 | if v != "" && v != "false" && v != "0" { |
| 1372 | return "RBE_" + cf, v |
| 1373 | } |
| 1374 | } |
| 1375 | } |
| 1376 | } |
| 1377 | return "RBE_use_application_default_credentials", "true" |
Patrice Arruda | 62f1bf2 | 2020-07-07 12:48:26 +0000 | [diff] [blame] | 1378 | } |
| 1379 | |
Kousik Kumar | 4c180ad | 2022-05-27 07:48:37 -0400 | [diff] [blame] | 1380 | func (c *configImpl) rbeSockAddr(dir string) (string, error) { |
Andus Yu | c917eb8 | 2024-03-06 21:54:15 +0000 | [diff] [blame] | 1381 | // Absolute path socket addresses have a prefix of //. This should |
| 1382 | // be included in the length limit. |
| 1383 | maxNameLen := len(syscall.RawSockaddrUnix{}.Path) - 2 |
Kousik Kumar | 4c180ad | 2022-05-27 07:48:37 -0400 | [diff] [blame] | 1384 | base := fmt.Sprintf("reproxy_%v.sock", rbeRandPrefix) |
| 1385 | |
| 1386 | name := filepath.Join(dir, base) |
| 1387 | if len(name) < maxNameLen { |
| 1388 | return name, nil |
| 1389 | } |
| 1390 | |
| 1391 | name = filepath.Join("/tmp", base) |
| 1392 | if len(name) < maxNameLen { |
| 1393 | return name, nil |
| 1394 | } |
| 1395 | |
| 1396 | return "", fmt.Errorf("cannot generate a proxy socket address shorter than the limit of %v", maxNameLen) |
| 1397 | } |
| 1398 | |
Kousik Kumar | 7bc7819 | 2022-04-27 14:52:56 -0400 | [diff] [blame] | 1399 | // IsGooglerEnvironment returns true if the current build is running |
| 1400 | // on a Google developer machine and false otherwise. |
| 1401 | func (c *configImpl) IsGooglerEnvironment() bool { |
| 1402 | cf := "ANDROID_BUILD_ENVIRONMENT_CONFIG" |
| 1403 | if v, ok := c.environ.Get(cf); ok { |
| 1404 | return v == "googler" |
| 1405 | } |
| 1406 | return false |
| 1407 | } |
| 1408 | |
| 1409 | // GoogleProdCredsExist determine whether credentials exist on the |
| 1410 | // Googler machine to use remote execution. |
| 1411 | func (c *configImpl) GoogleProdCredsExist() bool { |
Kevin Dagostino | 096ab2f | 2023-03-03 19:47:17 +0000 | [diff] [blame] | 1412 | if googleProdCredsExistCache { |
| 1413 | return googleProdCredsExistCache |
| 1414 | } |
andusyu | 0b3dc03 | 2023-06-21 17:29:32 -0400 | [diff] [blame] | 1415 | if _, err := exec.Command("/usr/bin/gcertstatus", "-nocheck_ssh").Output(); err != nil { |
Kousik Kumar | 7bc7819 | 2022-04-27 14:52:56 -0400 | [diff] [blame] | 1416 | return false |
| 1417 | } |
Kevin Dagostino | 096ab2f | 2023-03-03 19:47:17 +0000 | [diff] [blame] | 1418 | googleProdCredsExistCache = true |
Kousik Kumar | 7bc7819 | 2022-04-27 14:52:56 -0400 | [diff] [blame] | 1419 | return true |
| 1420 | } |
| 1421 | |
| 1422 | // UseRemoteBuild indicates whether to use a remote build acceleration system |
| 1423 | // to speed up the build. |
Colin Cross | 9016b91 | 2019-11-11 14:57:42 -0800 | [diff] [blame] | 1424 | func (c *configImpl) UseRemoteBuild() bool { |
| 1425 | return c.UseGoma() || c.UseRBE() |
| 1426 | } |
| 1427 | |
Kousik Kumar | 7bc7819 | 2022-04-27 14:52:56 -0400 | [diff] [blame] | 1428 | // StubbyExists checks whether the stubby binary exists on the machine running |
| 1429 | // the build. |
| 1430 | func (c *configImpl) StubbyExists() bool { |
| 1431 | if _, err := exec.LookPath("stubby"); err != nil { |
| 1432 | return false |
| 1433 | } |
| 1434 | return true |
| 1435 | } |
| 1436 | |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 1437 | // RemoteParallel controls how many remote jobs (i.e., commands which contain |
Jeff Gaston | efc1b41 | 2017-03-29 17:29:06 -0700 | [diff] [blame] | 1438 | // 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] | 1439 | // still limited by Parallel() |
| 1440 | func (c *configImpl) RemoteParallel() int { |
Colin Cross | 8b8bec3 | 2019-11-15 13:18:43 -0800 | [diff] [blame] | 1441 | if !c.UseRemoteBuild() { |
| 1442 | return 0 |
| 1443 | } |
| 1444 | if i, ok := c.environ.GetInt("NINJA_REMOTE_NUM_JOBS"); ok { |
| 1445 | return i |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 1446 | } |
| 1447 | return 500 |
| 1448 | } |
| 1449 | |
| 1450 | func (c *configImpl) SetKatiArgs(args []string) { |
| 1451 | c.katiArgs = args |
| 1452 | } |
| 1453 | |
| 1454 | func (c *configImpl) SetNinjaArgs(args []string) { |
| 1455 | c.ninjaArgs = args |
| 1456 | } |
| 1457 | |
| 1458 | func (c *configImpl) SetKatiSuffix(suffix string) { |
| 1459 | c.katiSuffix = suffix |
| 1460 | } |
| 1461 | |
Dan Willemsen | e0879fc | 2017-08-04 15:06:27 -0700 | [diff] [blame] | 1462 | func (c *configImpl) LastKatiSuffixFile() string { |
| 1463 | return filepath.Join(c.OutDir(), "last_kati_suffix") |
| 1464 | } |
| 1465 | |
| 1466 | func (c *configImpl) HasKatiSuffix() bool { |
| 1467 | return c.katiSuffix != "" |
| 1468 | } |
| 1469 | |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 1470 | func (c *configImpl) KatiEnvFile() string { |
| 1471 | return filepath.Join(c.OutDir(), "env"+c.KatiSuffix()+".sh") |
| 1472 | } |
| 1473 | |
Dan Willemsen | 2997123 | 2018-09-26 14:58:30 -0700 | [diff] [blame] | 1474 | func (c *configImpl) KatiBuildNinjaFile() string { |
| 1475 | return filepath.Join(c.OutDir(), "build"+c.KatiSuffix()+katiBuildSuffix+".ninja") |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 1476 | } |
| 1477 | |
Dan Willemsen | fb1271a | 2018-09-26 15:00:42 -0700 | [diff] [blame] | 1478 | func (c *configImpl) KatiPackageNinjaFile() string { |
| 1479 | return filepath.Join(c.OutDir(), "build"+c.KatiSuffix()+katiPackageSuffix+".ninja") |
| 1480 | } |
| 1481 | |
Jihoon Kang | 9f4f8a3 | 2022-08-16 00:57:30 +0000 | [diff] [blame] | 1482 | func (c *configImpl) SoongVarsFile() string { |
Kiyoung Kim | a37d9ba | 2023-04-19 13:13:45 +0900 | [diff] [blame] | 1483 | targetProduct, err := c.TargetProductOrErr() |
| 1484 | if err != nil { |
| 1485 | return filepath.Join(c.SoongOutDir(), "soong.variables") |
| 1486 | } else { |
| 1487 | return filepath.Join(c.SoongOutDir(), "soong."+targetProduct+".variables") |
| 1488 | } |
Jihoon Kang | 9f4f8a3 | 2022-08-16 00:57:30 +0000 | [diff] [blame] | 1489 | } |
| 1490 | |
Inseob Kim | 58c802f | 2024-06-11 10:59:00 +0900 | [diff] [blame^] | 1491 | func (c *configImpl) SoongExtraVarsFile() string { |
| 1492 | targetProduct, err := c.TargetProductOrErr() |
| 1493 | if err != nil { |
| 1494 | return filepath.Join(c.SoongOutDir(), "soong.extra.variables") |
| 1495 | } else { |
| 1496 | return filepath.Join(c.SoongOutDir(), "soong."+targetProduct+".extra.variables") |
| 1497 | } |
| 1498 | } |
| 1499 | |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 1500 | func (c *configImpl) SoongNinjaFile() string { |
Kiyoung Kim | a37d9ba | 2023-04-19 13:13:45 +0900 | [diff] [blame] | 1501 | targetProduct, err := c.TargetProductOrErr() |
| 1502 | if err != nil { |
| 1503 | return filepath.Join(c.SoongOutDir(), "build.ninja") |
| 1504 | } else { |
| 1505 | return filepath.Join(c.SoongOutDir(), "build."+targetProduct+".ninja") |
| 1506 | } |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 1507 | } |
| 1508 | |
| 1509 | func (c *configImpl) CombinedNinjaFile() string { |
Dan Willemsen | e0879fc | 2017-08-04 15:06:27 -0700 | [diff] [blame] | 1510 | if c.katiSuffix == "" { |
| 1511 | return filepath.Join(c.OutDir(), "combined.ninja") |
| 1512 | } |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 1513 | return filepath.Join(c.OutDir(), "combined"+c.KatiSuffix()+".ninja") |
| 1514 | } |
| 1515 | |
| 1516 | func (c *configImpl) SoongAndroidMk() string { |
| 1517 | return filepath.Join(c.SoongOutDir(), "Android-"+c.TargetProduct()+".mk") |
| 1518 | } |
| 1519 | |
| 1520 | func (c *configImpl) SoongMakeVarsMk() string { |
| 1521 | return filepath.Join(c.SoongOutDir(), "make_vars-"+c.TargetProduct()+".mk") |
| 1522 | } |
| 1523 | |
Colin Cross | aa9a273 | 2023-10-27 10:54:27 -0700 | [diff] [blame] | 1524 | func (c *configImpl) SoongBuildMetrics() string { |
Colin Cross | b67b061 | 2023-10-31 10:02:45 -0700 | [diff] [blame] | 1525 | return filepath.Join(c.LogsDir(), "soong_build_metrics.pb") |
Colin Cross | aa9a273 | 2023-10-27 10:54:27 -0700 | [diff] [blame] | 1526 | } |
| 1527 | |
Dan Willemsen | f052f78 | 2017-05-18 15:29:04 -0700 | [diff] [blame] | 1528 | func (c *configImpl) ProductOut() string { |
Dan Willemsen | 4dc4e14 | 2017-09-08 14:35:43 -0700 | [diff] [blame] | 1529 | return filepath.Join(c.OutDir(), "target", "product", c.TargetDevice()) |
Dan Willemsen | f052f78 | 2017-05-18 15:29:04 -0700 | [diff] [blame] | 1530 | } |
| 1531 | |
Dan Willemsen | 02781d5 | 2017-05-12 19:28:13 -0700 | [diff] [blame] | 1532 | func (c *configImpl) DevicePreviousProductConfig() string { |
Dan Willemsen | f052f78 | 2017-05-18 15:29:04 -0700 | [diff] [blame] | 1533 | return filepath.Join(c.ProductOut(), "previous_build_config.mk") |
| 1534 | } |
| 1535 | |
Dan Willemsen | fb1271a | 2018-09-26 15:00:42 -0700 | [diff] [blame] | 1536 | func (c *configImpl) KatiPackageMkDir() string { |
| 1537 | return filepath.Join(c.ProductOut(), "obj", "CONFIG", "kati_packaging") |
| 1538 | } |
| 1539 | |
Dan Willemsen | f052f78 | 2017-05-18 15:29:04 -0700 | [diff] [blame] | 1540 | func (c *configImpl) hostOutRoot() string { |
Dan Willemsen | 4dc4e14 | 2017-09-08 14:35:43 -0700 | [diff] [blame] | 1541 | return filepath.Join(c.OutDir(), "host") |
Dan Willemsen | f052f78 | 2017-05-18 15:29:04 -0700 | [diff] [blame] | 1542 | } |
| 1543 | |
| 1544 | func (c *configImpl) HostOut() string { |
| 1545 | return filepath.Join(c.hostOutRoot(), c.HostPrebuiltTag()) |
| 1546 | } |
| 1547 | |
| 1548 | // This probably needs to be multi-valued, so not exporting it for now |
| 1549 | func (c *configImpl) hostCrossOut() string { |
| 1550 | if runtime.GOOS == "linux" { |
| 1551 | return filepath.Join(c.hostOutRoot(), "windows-x86") |
| 1552 | } else { |
| 1553 | return "" |
| 1554 | } |
Dan Willemsen | 02781d5 | 2017-05-12 19:28:13 -0700 | [diff] [blame] | 1555 | } |
| 1556 | |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 1557 | func (c *configImpl) HostPrebuiltTag() string { |
| 1558 | if runtime.GOOS == "linux" { |
| 1559 | return "linux-x86" |
| 1560 | } else if runtime.GOOS == "darwin" { |
| 1561 | return "darwin-x86" |
| 1562 | } else { |
| 1563 | panic("Unsupported OS") |
| 1564 | } |
| 1565 | } |
Dan Willemsen | f173d59 | 2017-04-27 14:28:00 -0700 | [diff] [blame] | 1566 | |
Dan Willemsen | 8122bd5 | 2017-10-12 20:20:41 -0700 | [diff] [blame] | 1567 | func (c *configImpl) PrebuiltBuildTool(name string) string { |
Dan Willemsen | f173d59 | 2017-04-27 14:28:00 -0700 | [diff] [blame] | 1568 | if v, ok := c.environ.Get("SANITIZE_HOST"); ok { |
| 1569 | if sanitize := strings.Fields(v); inList("address", sanitize) { |
Dan Willemsen | 8122bd5 | 2017-10-12 20:20:41 -0700 | [diff] [blame] | 1570 | asan := filepath.Join("prebuilts/build-tools", c.HostPrebuiltTag(), "asan/bin", name) |
| 1571 | if _, err := os.Stat(asan); err == nil { |
| 1572 | return asan |
| 1573 | } |
Dan Willemsen | f173d59 | 2017-04-27 14:28:00 -0700 | [diff] [blame] | 1574 | } |
| 1575 | } |
| 1576 | return filepath.Join("prebuilts/build-tools", c.HostPrebuiltTag(), "bin", name) |
| 1577 | } |
Dan Willemsen | 3d60b11 | 2018-04-04 22:25:56 -0700 | [diff] [blame] | 1578 | |
| 1579 | func (c *configImpl) SetBuildBrokenDupRules(val bool) { |
| 1580 | c.brokenDupRules = val |
| 1581 | } |
| 1582 | |
| 1583 | func (c *configImpl) BuildBrokenDupRules() bool { |
| 1584 | return c.brokenDupRules |
| 1585 | } |
Dan Willemsen | 6ab79db | 2018-05-02 00:06:28 -0700 | [diff] [blame] | 1586 | |
Dan Willemsen | 25e6f09 | 2019-04-09 10:22:43 -0700 | [diff] [blame] | 1587 | func (c *configImpl) SetBuildBrokenUsesNetwork(val bool) { |
| 1588 | c.brokenUsesNetwork = val |
| 1589 | } |
| 1590 | |
| 1591 | func (c *configImpl) BuildBrokenUsesNetwork() bool { |
| 1592 | return c.brokenUsesNetwork |
| 1593 | } |
| 1594 | |
Dan Willemsen | e333635 | 2020-01-02 19:10:38 -0800 | [diff] [blame] | 1595 | func (c *configImpl) SetBuildBrokenNinjaUsesEnvVars(val []string) { |
| 1596 | c.brokenNinjaEnvVars = val |
| 1597 | } |
| 1598 | |
| 1599 | func (c *configImpl) BuildBrokenNinjaUsesEnvVars() []string { |
| 1600 | return c.brokenNinjaEnvVars |
| 1601 | } |
| 1602 | |
Dan Willemsen | 6ab79db | 2018-05-02 00:06:28 -0700 | [diff] [blame] | 1603 | func (c *configImpl) SetTargetDeviceDir(dir string) { |
| 1604 | c.targetDeviceDir = dir |
| 1605 | } |
| 1606 | |
| 1607 | func (c *configImpl) TargetDeviceDir() string { |
| 1608 | return c.targetDeviceDir |
| 1609 | } |
Dan Willemsen | fa42f3c | 2018-06-15 21:54:47 -0700 | [diff] [blame] | 1610 | |
Patrice Arruda | 219eef3 | 2020-06-01 17:29:30 +0000 | [diff] [blame] | 1611 | func (c *configImpl) BuildDateTime() string { |
| 1612 | return c.buildDateTime |
| 1613 | } |
| 1614 | |
| 1615 | func (c *configImpl) MetricsUploaderApp() string { |
Yu Liu | 6e13b40 | 2021-07-27 14:29:06 -0700 | [diff] [blame] | 1616 | return c.metricsUploader |
Patrice Arruda | 219eef3 | 2020-06-01 17:29:30 +0000 | [diff] [blame] | 1617 | } |
Patrice Arruda | 83842d7 | 2020-12-08 19:42:08 +0000 | [diff] [blame] | 1618 | |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 947fdbf | 2021-11-10 09:55:20 -0500 | [diff] [blame] | 1619 | // LogsDir returns the absolute path to the logs directory where build log and |
| 1620 | // metrics files are located. By default, the logs directory is the out |
Patrice Arruda | 83842d7 | 2020-12-08 19:42:08 +0000 | [diff] [blame] | 1621 | // directory. If the argument dist is specified, the logs directory |
| 1622 | // is <dist_dir>/logs. |
| 1623 | func (c *configImpl) LogsDir() string { |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 947fdbf | 2021-11-10 09:55:20 -0500 | [diff] [blame] | 1624 | dir := c.OutDir() |
Patrice Arruda | 83842d7 | 2020-12-08 19:42:08 +0000 | [diff] [blame] | 1625 | if c.Dist() { |
Rupert Shuttleworth | 3c9f5ac | 2020-12-10 11:32:38 +0000 | [diff] [blame] | 1626 | // Always write logs to the real dist dir, even if Bazel is using a rigged dist dir for other files |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 947fdbf | 2021-11-10 09:55:20 -0500 | [diff] [blame] | 1627 | dir = filepath.Join(c.RealDistDir(), "logs") |
Patrice Arruda | 83842d7 | 2020-12-08 19:42:08 +0000 | [diff] [blame] | 1628 | } |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 947fdbf | 2021-11-10 09:55:20 -0500 | [diff] [blame] | 1629 | absDir, err := filepath.Abs(dir) |
| 1630 | if err != nil { |
| 1631 | fmt.Fprintf(os.Stderr, "\nError making log dir '%s' absolute: %s\n", dir, err.Error()) |
| 1632 | os.Exit(1) |
| 1633 | } |
| 1634 | return absDir |
Patrice Arruda | 83842d7 | 2020-12-08 19:42:08 +0000 | [diff] [blame] | 1635 | } |
| 1636 | |
Chris Parsons | 53f68ae | 2022-03-03 12:01:40 -0500 | [diff] [blame] | 1637 | // MkFileMetrics returns the file path for make-related metrics. |
| 1638 | func (c *configImpl) MkMetrics() string { |
| 1639 | return filepath.Join(c.LogsDir(), "mk_metrics.pb") |
| 1640 | } |
| 1641 | |
Colin Cross | f3bdbcb | 2021-06-01 11:43:55 -0700 | [diff] [blame] | 1642 | func (c *configImpl) SetEmptyNinjaFile(v bool) { |
| 1643 | c.emptyNinjaFile = v |
| 1644 | } |
| 1645 | |
| 1646 | func (c *configImpl) EmptyNinjaFile() bool { |
| 1647 | return c.emptyNinjaFile |
| 1648 | } |
Yu Liu | 6e13b40 | 2021-07-27 14:29:06 -0700 | [diff] [blame] | 1649 | |
MarkDacek | d0e7cd3 | 2022-12-02 22:22:40 +0000 | [diff] [blame] | 1650 | func (c *configImpl) SkipMetricsUpload() bool { |
| 1651 | return c.skipMetricsUpload |
| 1652 | } |
| 1653 | |
MarkDacek | f47e142 | 2023-04-19 16:47:36 +0000 | [diff] [blame] | 1654 | func (c *configImpl) EnsureAllowlistIntegrity() bool { |
| 1655 | return c.ensureAllowlistIntegrity |
| 1656 | } |
| 1657 | |
MarkDacek | 6614d9c | 2022-12-07 21:57:38 +0000 | [diff] [blame] | 1658 | // Returns a Time object if one was passed via a command-line flag. |
| 1659 | // Otherwise returns the passed default. |
| 1660 | func (c *configImpl) BuildStartedTimeOrDefault(defaultTime time.Time) time.Time { |
| 1661 | if c.buildStartedTime == 0 { |
| 1662 | return defaultTime |
| 1663 | } |
| 1664 | return time.UnixMilli(c.buildStartedTime) |
| 1665 | } |
| 1666 | |
Yu Liu | 6e13b40 | 2021-07-27 14:29:06 -0700 | [diff] [blame] | 1667 | func GetMetricsUploader(topDir string, env *Environment) string { |
| 1668 | if p, ok := env.Get("METRICS_UPLOADER"); ok { |
| 1669 | metricsUploader := filepath.Join(topDir, p) |
| 1670 | if _, err := os.Stat(metricsUploader); err == nil { |
| 1671 | return metricsUploader |
| 1672 | } |
| 1673 | } |
| 1674 | |
| 1675 | return "" |
| 1676 | } |