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