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 ( |
Colin Cross | 9191df2 | 2021-10-29 13:11:32 -0700 | [diff] [blame] | 18 | "fmt" |
Colin Cross | b72c909 | 2020-02-10 11:23:49 -0800 | [diff] [blame] | 19 | "io/ioutil" |
Dan Willemsen | 99a75cd | 2017-08-04 16:04:04 -0700 | [diff] [blame] | 20 | "os" |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 21 | "path/filepath" |
Dan Willemsen | 99a75cd | 2017-08-04 16:04:04 -0700 | [diff] [blame] | 22 | "strconv" |
Dan Willemsen | 99a75cd | 2017-08-04 16:04:04 -0700 | [diff] [blame] | 23 | |
Dan Willemsen | 4591b64 | 2021-05-24 14:24:12 -0700 | [diff] [blame] | 24 | "android/soong/ui/metrics" |
Colin Cross | b72c909 | 2020-02-10 11:23:49 -0800 | [diff] [blame] | 25 | soong_metrics_proto "android/soong/ui/metrics/metrics_proto" |
Dan Willemsen | 4591b64 | 2021-05-24 14:24:12 -0700 | [diff] [blame] | 26 | "android/soong/ui/status" |
| 27 | |
| 28 | "android/soong/shared" |
| 29 | |
Lukacs T. Berki | d1e3f1f | 2021-03-16 08:55:23 +0100 | [diff] [blame] | 30 | "github.com/google/blueprint" |
| 31 | "github.com/google/blueprint/bootstrap" |
Dan Willemsen | 4591b64 | 2021-05-24 14:24:12 -0700 | [diff] [blame] | 32 | "github.com/google/blueprint/deptools" |
Dan Willemsen | 99a75cd | 2017-08-04 16:04:04 -0700 | [diff] [blame] | 33 | "github.com/google/blueprint/microfactory" |
Dan Willemsen | b82471a | 2018-05-17 16:37:09 -0700 | [diff] [blame] | 34 | |
Dan Willemsen | 4591b64 | 2021-05-24 14:24:12 -0700 | [diff] [blame] | 35 | "google.golang.org/protobuf/proto" |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 36 | ) |
| 37 | |
Lukacs T. Berki | f8e2428 | 2021-04-14 10:31:00 +0200 | [diff] [blame] | 38 | const ( |
| 39 | availableEnvFile = "soong.environment.available" |
| 40 | usedEnvFile = "soong.environment.used" |
Lukacs T. Berki | 89fcdcb | 2021-09-07 09:10:33 +0200 | [diff] [blame] | 41 | |
| 42 | soongBuildTag = "build" |
| 43 | bp2buildTag = "bp2build" |
| 44 | jsonModuleGraphTag = "modulegraph" |
| 45 | queryviewTag = "queryview" |
| 46 | soongDocsTag = "soong_docs" |
Colin Cross | 9191df2 | 2021-10-29 13:11:32 -0700 | [diff] [blame] | 47 | |
| 48 | // bootstrapEpoch is used to determine if an incremental build is incompatible with the current |
| 49 | // version of bootstrap and needs cleaning before continuing the build. Increment this for |
| 50 | // incompatible changes, for example when moving the location of the bpglob binary that is |
| 51 | // executed during bootstrap before the primary builder has had a chance to update the path. |
Lukacs T. Berki | 9985d9a | 2021-11-04 11:47:42 +0100 | [diff] [blame] | 52 | bootstrapEpoch = 1 |
Lukacs T. Berki | f8e2428 | 2021-04-14 10:31:00 +0200 | [diff] [blame] | 53 | ) |
| 54 | |
Lukacs T. Berki | 7690c09 | 2021-02-26 14:27:36 +0100 | [diff] [blame] | 55 | func writeEnvironmentFile(ctx Context, envFile string, envDeps map[string]string) error { |
| 56 | data, err := shared.EnvFileContents(envDeps) |
| 57 | if err != nil { |
| 58 | return err |
| 59 | } |
| 60 | |
| 61 | return ioutil.WriteFile(envFile, data, 0644) |
| 62 | } |
| 63 | |
Rupert Shuttleworth | b7d9710 | 2020-11-25 10:19:29 +0000 | [diff] [blame] | 64 | // This uses Android.bp files and various tools to generate <builddir>/build.ninja. |
| 65 | // |
Lukacs T. Berki | d1e3f1f | 2021-03-16 08:55:23 +0100 | [diff] [blame] | 66 | // However, the execution of <builddir>/build.ninja happens later in |
| 67 | // build/soong/ui/build/build.go#Build() |
Rupert Shuttleworth | b7d9710 | 2020-11-25 10:19:29 +0000 | [diff] [blame] | 68 | // |
Lukacs T. Berki | d1e3f1f | 2021-03-16 08:55:23 +0100 | [diff] [blame] | 69 | // We want to rely on as few prebuilts as possible, so we need to bootstrap |
| 70 | // Soong. The process is as follows: |
Rupert Shuttleworth | b7d9710 | 2020-11-25 10:19:29 +0000 | [diff] [blame] | 71 | // |
Lukacs T. Berki | d1e3f1f | 2021-03-16 08:55:23 +0100 | [diff] [blame] | 72 | // 1. We use "Microfactory", a simple tool to compile Go code, to build |
| 73 | // first itself, then soong_ui from soong_ui.bash. This binary contains |
| 74 | // parts of soong_build that are needed to build itself. |
| 75 | // 2. This simplified version of soong_build then reads the Blueprint files |
| 76 | // that describe itself and emits .bootstrap/build.ninja that describes |
| 77 | // how to build its full version and use that to produce the final Ninja |
| 78 | // file Soong emits. |
| 79 | // 3. soong_ui executes .bootstrap/build.ninja |
Rupert Shuttleworth | b7d9710 | 2020-11-25 10:19:29 +0000 | [diff] [blame] | 80 | // |
Lukacs T. Berki | d1e3f1f | 2021-03-16 08:55:23 +0100 | [diff] [blame] | 81 | // (After this, Kati is executed to parse the Makefiles, but that's not part of |
| 82 | // bootstrapping Soong) |
| 83 | |
| 84 | // A tiny struct used to tell Blueprint that it's in bootstrap mode. It would |
| 85 | // probably be nicer to use a flag in bootstrap.Args instead. |
| 86 | type BlueprintConfig struct { |
Lukacs T. Berki | ea1a31c | 2021-09-02 09:58:09 +0200 | [diff] [blame] | 87 | toolDir string |
| 88 | soongOutDir string |
| 89 | outDir string |
| 90 | runGoTests bool |
Lukacs T. Berki | ea1a31c | 2021-09-02 09:58:09 +0200 | [diff] [blame] | 91 | debugCompilation bool |
| 92 | subninjas []string |
| 93 | primaryBuilderInvocations []bootstrap.PrimaryBuilderInvocation |
Lukacs T. Berki | d1e3f1f | 2021-03-16 08:55:23 +0100 | [diff] [blame] | 94 | } |
| 95 | |
Lukacs T. Berki | a806e41 | 2021-09-01 08:57:48 +0200 | [diff] [blame] | 96 | func (c BlueprintConfig) HostToolDir() string { |
| 97 | return c.toolDir |
| 98 | } |
| 99 | |
Lukacs T. Berki | 9f6c24a | 2021-08-26 15:07:24 +0200 | [diff] [blame] | 100 | func (c BlueprintConfig) SoongOutDir() string { |
| 101 | return c.soongOutDir |
Lukacs T. Berki | d1e3f1f | 2021-03-16 08:55:23 +0100 | [diff] [blame] | 102 | } |
| 103 | |
Lukacs T. Berki | 9f6c24a | 2021-08-26 15:07:24 +0200 | [diff] [blame] | 104 | func (c BlueprintConfig) OutDir() string { |
| 105 | return c.outDir |
Lukacs T. Berki | d1e3f1f | 2021-03-16 08:55:23 +0100 | [diff] [blame] | 106 | } |
| 107 | |
Lukacs T. Berki | ea1a31c | 2021-09-02 09:58:09 +0200 | [diff] [blame] | 108 | func (c BlueprintConfig) RunGoTests() bool { |
| 109 | return c.runGoTests |
| 110 | } |
| 111 | |
Lukacs T. Berki | 5f6cb1d | 2021-03-17 15:03:14 +0100 | [diff] [blame] | 112 | func (c BlueprintConfig) DebugCompilation() bool { |
| 113 | return c.debugCompilation |
| 114 | } |
| 115 | |
Lukacs T. Berki | ea1a31c | 2021-09-02 09:58:09 +0200 | [diff] [blame] | 116 | func (c BlueprintConfig) Subninjas() []string { |
| 117 | return c.subninjas |
| 118 | } |
| 119 | |
| 120 | func (c BlueprintConfig) PrimaryBuilderInvocations() []bootstrap.PrimaryBuilderInvocation { |
| 121 | return c.primaryBuilderInvocations |
| 122 | } |
| 123 | |
Lukacs T. Berki | e1df43f | 2021-09-08 15:31:14 +0200 | [diff] [blame] | 124 | func environmentArgs(config Config, tag string) []string { |
Lukacs T. Berki | f8e2428 | 2021-04-14 10:31:00 +0200 | [diff] [blame] | 125 | return []string{ |
| 126 | "--available_env", shared.JoinPath(config.SoongOutDir(), availableEnvFile), |
Lukacs T. Berki | e1df43f | 2021-09-08 15:31:14 +0200 | [diff] [blame] | 127 | "--used_env", config.UsedEnvFile(tag), |
Lukacs T. Berki | f8e2428 | 2021-04-14 10:31:00 +0200 | [diff] [blame] | 128 | } |
| 129 | } |
Spandan Das | 8f99ae6 | 2021-06-11 16:48:06 +0000 | [diff] [blame] | 130 | |
Colin Cross | 9191df2 | 2021-10-29 13:11:32 -0700 | [diff] [blame] | 131 | func writeEmptyFile(ctx Context, path string) { |
Spandan Das | 8f99ae6 | 2021-06-11 16:48:06 +0000 | [diff] [blame] | 132 | err := os.MkdirAll(filepath.Dir(path), 0777) |
| 133 | if err != nil { |
Colin Cross | 9191df2 | 2021-10-29 13:11:32 -0700 | [diff] [blame] | 134 | ctx.Fatalf("Failed to create parent directories of empty file '%s': %s", path, err) |
Spandan Das | 8f99ae6 | 2021-06-11 16:48:06 +0000 | [diff] [blame] | 135 | } |
| 136 | |
Colin Cross | 9191df2 | 2021-10-29 13:11:32 -0700 | [diff] [blame] | 137 | if exists, err := fileExists(path); err != nil { |
| 138 | ctx.Fatalf("Failed to check if file '%s' exists: %s", path, err) |
| 139 | } else if !exists { |
Spandan Das | 8f99ae6 | 2021-06-11 16:48:06 +0000 | [diff] [blame] | 140 | err = ioutil.WriteFile(path, nil, 0666) |
| 141 | if err != nil { |
Colin Cross | 9191df2 | 2021-10-29 13:11:32 -0700 | [diff] [blame] | 142 | ctx.Fatalf("Failed to create empty file '%s': %s", path, err) |
Spandan Das | 8f99ae6 | 2021-06-11 16:48:06 +0000 | [diff] [blame] | 143 | } |
| 144 | } |
| 145 | } |
| 146 | |
Colin Cross | 9191df2 | 2021-10-29 13:11:32 -0700 | [diff] [blame] | 147 | func fileExists(path string) (bool, error) { |
| 148 | if _, err := os.Stat(path); os.IsNotExist(err) { |
| 149 | return false, nil |
| 150 | } else if err != nil { |
| 151 | return false, err |
| 152 | } |
| 153 | return true, nil |
| 154 | } |
| 155 | |
Jingwen Chen | 78fd87f | 2021-12-06 13:27:43 +0000 | [diff] [blame] | 156 | func primaryBuilderInvocation( |
| 157 | config Config, |
| 158 | name string, |
| 159 | output string, |
| 160 | specificArgs []string, |
| 161 | description string) bootstrap.PrimaryBuilderInvocation { |
Lukacs T. Berki | 89fcdcb | 2021-09-07 09:10:33 +0200 | [diff] [blame] | 162 | commonArgs := make([]string, 0, 0) |
| 163 | |
| 164 | if !config.skipSoongTests { |
| 165 | commonArgs = append(commonArgs, "-t") |
| 166 | } |
| 167 | |
| 168 | commonArgs = append(commonArgs, "-l", filepath.Join(config.FileListDir(), "Android.bp.list")) |
Lukacs T. Berki | 1364427 | 2022-01-05 10:29:56 +0100 | [diff] [blame] | 169 | invocationEnv := make(map[string]string) |
| 170 | debugMode := os.Getenv("SOONG_DELVE") != "" |
Lukacs T. Berki | 89fcdcb | 2021-09-07 09:10:33 +0200 | [diff] [blame] | 171 | |
Lukacs T. Berki | 1364427 | 2022-01-05 10:29:56 +0100 | [diff] [blame] | 172 | if debugMode { |
Lukacs T. Berki | 89fcdcb | 2021-09-07 09:10:33 +0200 | [diff] [blame] | 173 | commonArgs = append(commonArgs, "--delve_listen", os.Getenv("SOONG_DELVE")) |
| 174 | commonArgs = append(commonArgs, "--delve_path", shared.ResolveDelveBinary()) |
Lukacs T. Berki | 1364427 | 2022-01-05 10:29:56 +0100 | [diff] [blame] | 175 | // GODEBUG=asyncpreemptoff=1 disables the preemption of goroutines. This |
| 176 | // is useful because the preemption happens by sending SIGURG to the OS |
| 177 | // thread hosting the goroutine in question and each signal results in |
| 178 | // work that needs to be done by Delve; it uses ptrace to debug the Go |
| 179 | // process and the tracer process must deal with every signal (it is not |
| 180 | // possible to selectively ignore SIGURG). This makes debugging slower, |
| 181 | // sometimes by an order of magnitude depending on luck. |
| 182 | // The original reason for adding async preemption to Go is here: |
| 183 | // https://github.com/golang/proposal/blob/master/design/24543-non-cooperative-preemption.md |
| 184 | invocationEnv["GODEBUG"] = "asyncpreemptoff=1" |
Lukacs T. Berki | 89fcdcb | 2021-09-07 09:10:33 +0200 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | allArgs := make([]string, 0, 0) |
| 188 | allArgs = append(allArgs, specificArgs...) |
| 189 | allArgs = append(allArgs, |
| 190 | "--globListDir", name, |
| 191 | "--globFile", config.NamedGlobFile(name)) |
| 192 | |
| 193 | allArgs = append(allArgs, commonArgs...) |
| 194 | allArgs = append(allArgs, environmentArgs(config, name)...) |
| 195 | allArgs = append(allArgs, "Android.bp") |
| 196 | |
| 197 | return bootstrap.PrimaryBuilderInvocation{ |
Jingwen Chen | 78fd87f | 2021-12-06 13:27:43 +0000 | [diff] [blame] | 198 | Inputs: []string{"Android.bp"}, |
| 199 | Outputs: []string{output}, |
| 200 | Args: allArgs, |
| 201 | Description: description, |
Lukacs T. Berki | 2fad341 | 2022-01-04 14:40:13 +0100 | [diff] [blame] | 202 | // NB: Changing the value of this environment variable will not result in a |
| 203 | // rebuild. The bootstrap Ninja file will change, but apparently Ninja does |
| 204 | // not consider changing the pool specified in a statement a change that's |
| 205 | // worth rebuilding for. |
| 206 | Console: os.Getenv("SOONG_UNBUFFERED_OUTPUT") == "1", |
Lukacs T. Berki | 1364427 | 2022-01-05 10:29:56 +0100 | [diff] [blame] | 207 | Env: invocationEnv, |
Lukacs T. Berki | 89fcdcb | 2021-09-07 09:10:33 +0200 | [diff] [blame] | 208 | } |
| 209 | } |
| 210 | |
Colin Cross | 9191df2 | 2021-10-29 13:11:32 -0700 | [diff] [blame] | 211 | // bootstrapEpochCleanup deletes files used by bootstrap during incremental builds across |
| 212 | // incompatible changes. Incompatible changes are marked by incrementing the bootstrapEpoch |
| 213 | // constant. A tree is considered out of date for the current epoch of the |
| 214 | // .soong.bootstrap.epoch.<epoch> file doesn't exist. |
| 215 | func bootstrapEpochCleanup(ctx Context, config Config) { |
| 216 | epochFile := fmt.Sprintf(".soong.bootstrap.epoch.%d", bootstrapEpoch) |
| 217 | epochPath := filepath.Join(config.SoongOutDir(), epochFile) |
| 218 | if exists, err := fileExists(epochPath); err != nil { |
| 219 | ctx.Fatalf("failed to check if bootstrap epoch file %q exists: %q", epochPath, err) |
| 220 | } else if !exists { |
| 221 | // The tree is out of date for the current epoch, delete files used by bootstrap |
| 222 | // and force the primary builder to rerun. |
| 223 | os.Remove(filepath.Join(config.SoongOutDir(), "build.ninja")) |
| 224 | for _, globFile := range bootstrapGlobFileList(config) { |
| 225 | os.Remove(globFile) |
| 226 | } |
| 227 | |
| 228 | // Mark the tree as up to date with the current epoch by writing the epoch marker file. |
| 229 | writeEmptyFile(ctx, epochPath) |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | func bootstrapGlobFileList(config Config) []string { |
| 234 | return []string{ |
| 235 | config.NamedGlobFile(soongBuildTag), |
| 236 | config.NamedGlobFile(bp2buildTag), |
| 237 | config.NamedGlobFile(jsonModuleGraphTag), |
| 238 | config.NamedGlobFile(queryviewTag), |
| 239 | config.NamedGlobFile(soongDocsTag), |
| 240 | } |
| 241 | } |
| 242 | |
Lukacs T. Berki | 56ebaf3 | 2021-08-12 14:03:55 +0200 | [diff] [blame] | 243 | func bootstrapBlueprint(ctx Context, config Config) { |
Lukacs T. Berki | d1e3f1f | 2021-03-16 08:55:23 +0100 | [diff] [blame] | 244 | ctx.BeginTrace(metrics.RunSoong, "blueprint bootstrap") |
| 245 | defer ctx.EndTrace() |
| 246 | |
Colin Cross | 9191df2 | 2021-10-29 13:11:32 -0700 | [diff] [blame] | 247 | // Clean up some files for incremental builds across incompatible changes. |
| 248 | bootstrapEpochCleanup(ctx, config) |
| 249 | |
Cole Faust | 65f298c | 2021-10-28 16:05:13 -0700 | [diff] [blame] | 250 | mainSoongBuildExtraArgs := []string{"-o", config.SoongNinjaFile()} |
Lukacs T. Berki | 89fcdcb | 2021-09-07 09:10:33 +0200 | [diff] [blame] | 251 | if config.EmptyNinjaFile() { |
| 252 | mainSoongBuildExtraArgs = append(mainSoongBuildExtraArgs, "--empty-ninja-file") |
Lukacs T. Berki | 745380c | 2021-04-12 12:07:44 +0200 | [diff] [blame] | 253 | } |
| 254 | |
Lukacs T. Berki | 89fcdcb | 2021-09-07 09:10:33 +0200 | [diff] [blame] | 255 | mainSoongBuildInvocation := primaryBuilderInvocation( |
| 256 | config, |
| 257 | soongBuildTag, |
Cole Faust | 65f298c | 2021-10-28 16:05:13 -0700 | [diff] [blame] | 258 | config.SoongNinjaFile(), |
Jingwen Chen | 78fd87f | 2021-12-06 13:27:43 +0000 | [diff] [blame] | 259 | mainSoongBuildExtraArgs, |
| 260 | fmt.Sprintf("analyzing Android.bp files and generating ninja file at %s", config.SoongNinjaFile()), |
| 261 | ) |
Lukacs T. Berki | f8e2428 | 2021-04-14 10:31:00 +0200 | [diff] [blame] | 262 | |
Lukacs T. Berki | 56ebaf3 | 2021-08-12 14:03:55 +0200 | [diff] [blame] | 263 | if config.bazelBuildMode() == mixedBuild { |
Lukacs T. Berki | 89fcdcb | 2021-09-07 09:10:33 +0200 | [diff] [blame] | 264 | // Mixed builds call Bazel from soong_build and they therefore need the |
| 265 | // Bazel workspace to be available. Make that so by adding a dependency on |
| 266 | // the bp2build marker file to the action that invokes soong_build . |
| 267 | mainSoongBuildInvocation.Inputs = append(mainSoongBuildInvocation.Inputs, |
| 268 | config.Bp2BuildMarkerFile()) |
Lukacs T. Berki | f8e2428 | 2021-04-14 10:31:00 +0200 | [diff] [blame] | 269 | } |
| 270 | |
Lukacs T. Berki | 89fcdcb | 2021-09-07 09:10:33 +0200 | [diff] [blame] | 271 | bp2buildInvocation := primaryBuilderInvocation( |
| 272 | config, |
| 273 | bp2buildTag, |
| 274 | config.Bp2BuildMarkerFile(), |
| 275 | []string{ |
| 276 | "--bp2build_marker", config.Bp2BuildMarkerFile(), |
Jingwen Chen | 78fd87f | 2021-12-06 13:27:43 +0000 | [diff] [blame] | 277 | }, |
| 278 | fmt.Sprintf("converting Android.bp files to BUILD files at %s/bp2build", config.SoongOutDir()), |
| 279 | ) |
Lukacs T. Berki | 89fcdcb | 2021-09-07 09:10:33 +0200 | [diff] [blame] | 280 | |
| 281 | jsonModuleGraphInvocation := primaryBuilderInvocation( |
| 282 | config, |
| 283 | jsonModuleGraphTag, |
| 284 | config.ModuleGraphFile(), |
| 285 | []string{ |
| 286 | "--module_graph_file", config.ModuleGraphFile(), |
kgui | 6700724 | 2022-01-25 13:50:25 +0800 | [diff] [blame] | 287 | "--module_actions_file", config.ModuleActionsFile(), |
Jingwen Chen | 78fd87f | 2021-12-06 13:27:43 +0000 | [diff] [blame] | 288 | }, |
| 289 | fmt.Sprintf("generating the Soong module graph at %s", config.ModuleGraphFile()), |
| 290 | ) |
Lukacs T. Berki | 89fcdcb | 2021-09-07 09:10:33 +0200 | [diff] [blame] | 291 | |
Jingwen Chen | 78fd87f | 2021-12-06 13:27:43 +0000 | [diff] [blame] | 292 | queryviewDir := filepath.Join(config.SoongOutDir(), "queryview") |
Lukacs T. Berki | 89fcdcb | 2021-09-07 09:10:33 +0200 | [diff] [blame] | 293 | queryviewInvocation := primaryBuilderInvocation( |
| 294 | config, |
| 295 | queryviewTag, |
| 296 | config.QueryviewMarkerFile(), |
| 297 | []string{ |
Jingwen Chen | 78fd87f | 2021-12-06 13:27:43 +0000 | [diff] [blame] | 298 | "--bazel_queryview_dir", queryviewDir, |
| 299 | }, |
| 300 | fmt.Sprintf("generating the Soong module graph as a Bazel workspace at %s", queryviewDir), |
| 301 | ) |
Lukacs T. Berki | 89fcdcb | 2021-09-07 09:10:33 +0200 | [diff] [blame] | 302 | |
| 303 | soongDocsInvocation := primaryBuilderInvocation( |
| 304 | config, |
| 305 | soongDocsTag, |
| 306 | config.SoongDocsHtml(), |
| 307 | []string{ |
| 308 | "--soong_docs", config.SoongDocsHtml(), |
Jingwen Chen | 78fd87f | 2021-12-06 13:27:43 +0000 | [diff] [blame] | 309 | }, |
| 310 | fmt.Sprintf("generating Soong docs at %s", config.SoongDocsHtml()), |
| 311 | ) |
Lukacs T. Berki | 89fcdcb | 2021-09-07 09:10:33 +0200 | [diff] [blame] | 312 | |
| 313 | globFiles := []string{ |
| 314 | config.NamedGlobFile(soongBuildTag), |
| 315 | config.NamedGlobFile(bp2buildTag), |
| 316 | config.NamedGlobFile(jsonModuleGraphTag), |
| 317 | config.NamedGlobFile(queryviewTag), |
| 318 | config.NamedGlobFile(soongDocsTag), |
Lukacs T. Berki | 56ebaf3 | 2021-08-12 14:03:55 +0200 | [diff] [blame] | 319 | } |
| 320 | |
Lukacs T. Berki | 89fcdcb | 2021-09-07 09:10:33 +0200 | [diff] [blame] | 321 | // The glob .ninja files are subninja'd. However, they are generated during |
| 322 | // the build itself so we write an empty file if the file does not exist yet |
| 323 | // so that the subninja doesn't fail on clean builds |
Colin Cross | 9191df2 | 2021-10-29 13:11:32 -0700 | [diff] [blame] | 324 | for _, globFile := range bootstrapGlobFileList(config) { |
| 325 | writeEmptyFile(ctx, globFile) |
Lukacs T. Berki | f8e2428 | 2021-04-14 10:31:00 +0200 | [diff] [blame] | 326 | } |
| 327 | |
Lukacs T. Berki | 89fcdcb | 2021-09-07 09:10:33 +0200 | [diff] [blame] | 328 | var blueprintArgs bootstrap.Args |
Lukacs T. Berki | f8e2428 | 2021-04-14 10:31:00 +0200 | [diff] [blame] | 329 | |
Lukacs T. Berki | 89fcdcb | 2021-09-07 09:10:33 +0200 | [diff] [blame] | 330 | blueprintArgs.ModuleListFile = filepath.Join(config.FileListDir(), "Android.bp.list") |
Lukacs T. Berki | 90b4334 | 2021-11-02 14:42:04 +0100 | [diff] [blame] | 331 | blueprintArgs.OutFile = shared.JoinPath(config.SoongOutDir(), "bootstrap.ninja") |
Lukacs T. Berki | 89fcdcb | 2021-09-07 09:10:33 +0200 | [diff] [blame] | 332 | blueprintArgs.EmptyNinjaFile = false |
Lukacs T. Berki | f8e2428 | 2021-04-14 10:31:00 +0200 | [diff] [blame] | 333 | |
Lukacs T. Berki | d1e3f1f | 2021-03-16 08:55:23 +0100 | [diff] [blame] | 334 | blueprintCtx := blueprint.NewContext() |
| 335 | blueprintCtx.SetIgnoreUnknownModuleTypes(true) |
| 336 | blueprintConfig := BlueprintConfig{ |
Lukacs T. Berki | e1df43f | 2021-09-08 15:31:14 +0200 | [diff] [blame] | 337 | soongOutDir: config.SoongOutDir(), |
| 338 | toolDir: config.HostToolDir(), |
| 339 | outDir: config.OutDir(), |
| 340 | runGoTests: !config.skipSoongTests, |
Lukacs T. Berki | 89fcdcb | 2021-09-07 09:10:33 +0200 | [diff] [blame] | 341 | // If we want to debug soong_build, we need to compile it for debugging |
| 342 | debugCompilation: os.Getenv("SOONG_DELVE") != "", |
| 343 | subninjas: globFiles, |
| 344 | primaryBuilderInvocations: []bootstrap.PrimaryBuilderInvocation{ |
| 345 | mainSoongBuildInvocation, |
| 346 | bp2buildInvocation, |
| 347 | jsonModuleGraphInvocation, |
| 348 | queryviewInvocation, |
| 349 | soongDocsInvocation}, |
Lukacs T. Berki | d1e3f1f | 2021-03-16 08:55:23 +0100 | [diff] [blame] | 350 | } |
| 351 | |
Lukacs T. Berki | 89fcdcb | 2021-09-07 09:10:33 +0200 | [diff] [blame] | 352 | bootstrapDeps := bootstrap.RunBlueprint(blueprintArgs, bootstrap.DoEverything, blueprintCtx, blueprintConfig) |
Lukacs T. Berki | 90b4334 | 2021-11-02 14:42:04 +0100 | [diff] [blame] | 353 | bootstrapDepFile := shared.JoinPath(config.SoongOutDir(), "bootstrap.ninja.d") |
Lukacs T. Berki | 89fcdcb | 2021-09-07 09:10:33 +0200 | [diff] [blame] | 354 | err := deptools.WriteDepFile(bootstrapDepFile, blueprintArgs.OutFile, bootstrapDeps) |
Lukacs T. Berki | d518e1a | 2021-04-14 13:49:50 +0200 | [diff] [blame] | 355 | if err != nil { |
| 356 | ctx.Fatalf("Error writing depfile '%s': %s", bootstrapDepFile, err) |
| 357 | } |
Lukacs T. Berki | d1e3f1f | 2021-03-16 08:55:23 +0100 | [diff] [blame] | 358 | } |
| 359 | |
Lukacs T. Berki | f8e2428 | 2021-04-14 10:31:00 +0200 | [diff] [blame] | 360 | func checkEnvironmentFile(currentEnv *Environment, envFile string) { |
| 361 | getenv := func(k string) string { |
| 362 | v, _ := currentEnv.Get(k) |
| 363 | return v |
| 364 | } |
Lukacs T. Berki | e1df43f | 2021-09-08 15:31:14 +0200 | [diff] [blame] | 365 | |
Lukacs T. Berki | f8e2428 | 2021-04-14 10:31:00 +0200 | [diff] [blame] | 366 | if stale, _ := shared.StaleEnvFile(envFile, getenv); stale { |
| 367 | os.Remove(envFile) |
| 368 | } |
| 369 | } |
| 370 | |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 371 | func runSoong(ctx Context, config Config) { |
Nan Zhang | 17f2767 | 2018-12-12 16:01:49 -0800 | [diff] [blame] | 372 | ctx.BeginTrace(metrics.RunSoong, "soong") |
Dan Willemsen | d9f6fa2 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 373 | defer ctx.EndTrace() |
| 374 | |
Lukacs T. Berki | 7690c09 | 2021-02-26 14:27:36 +0100 | [diff] [blame] | 375 | // We have two environment files: .available is the one with every variable, |
| 376 | // .used with the ones that were actually used. The latter is used to |
| 377 | // determine whether Soong needs to be re-run since why re-run it if only |
| 378 | // unused variables were changed? |
Lukacs T. Berki | f8e2428 | 2021-04-14 10:31:00 +0200 | [diff] [blame] | 379 | envFile := filepath.Join(config.SoongOutDir(), availableEnvFile) |
Lukacs T. Berki | 7690c09 | 2021-02-26 14:27:36 +0100 | [diff] [blame] | 380 | |
Chris Parsons | ec1a3dc | 2021-04-20 15:32:07 -0400 | [diff] [blame] | 381 | buildMode := config.bazelBuildMode() |
Lukacs T. Berki | a1b9372 | 2021-09-02 17:23:06 +0200 | [diff] [blame] | 382 | integratedBp2Build := buildMode == mixedBuild |
Lukacs T. Berki | f8e2428 | 2021-04-14 10:31:00 +0200 | [diff] [blame] | 383 | |
Lukacs T. Berki | d1e3f1f | 2021-03-16 08:55:23 +0100 | [diff] [blame] | 384 | // This is done unconditionally, but does not take a measurable amount of time |
Lukacs T. Berki | 56ebaf3 | 2021-08-12 14:03:55 +0200 | [diff] [blame] | 385 | bootstrapBlueprint(ctx, config) |
Dan Willemsen | 99a75cd | 2017-08-04 16:04:04 -0700 | [diff] [blame] | 386 | |
Lukacs T. Berki | 7690c09 | 2021-02-26 14:27:36 +0100 | [diff] [blame] | 387 | soongBuildEnv := config.Environment().Copy() |
| 388 | soongBuildEnv.Set("TOP", os.Getenv("TOP")) |
Lukacs T. Berki | 7690c09 | 2021-02-26 14:27:36 +0100 | [diff] [blame] | 389 | // For Bazel mixed builds. |
| 390 | soongBuildEnv.Set("BAZEL_PATH", "./tools/bazel") |
| 391 | soongBuildEnv.Set("BAZEL_HOME", filepath.Join(config.BazelOutDir(), "bazelhome")) |
| 392 | soongBuildEnv.Set("BAZEL_OUTPUT_BASE", filepath.Join(config.BazelOutDir(), "output")) |
| 393 | soongBuildEnv.Set("BAZEL_WORKSPACE", absPath(ctx, ".")) |
| 394 | soongBuildEnv.Set("BAZEL_METRICS_DIR", config.BazelMetricsDir()) |
Alex Márquez Pérez MuñÃz DÃaz Púras Thaureaux | 947fdbf | 2021-11-10 09:55:20 -0500 | [diff] [blame] | 395 | soongBuildEnv.Set("LOG_DIR", config.LogsDir()) |
Lukacs T. Berki | 7690c09 | 2021-02-26 14:27:36 +0100 | [diff] [blame] | 396 | |
Lukacs T. Berki | d1e3f1f | 2021-03-16 08:55:23 +0100 | [diff] [blame] | 397 | // For Soong bootstrapping tests |
| 398 | if os.Getenv("ALLOW_MISSING_DEPENDENCIES") == "true" { |
| 399 | soongBuildEnv.Set("ALLOW_MISSING_DEPENDENCIES", "true") |
| 400 | } |
| 401 | |
Paul Duffin | 5e85c66 | 2021-03-05 12:26:14 +0000 | [diff] [blame] | 402 | err := writeEnvironmentFile(ctx, envFile, soongBuildEnv.AsMap()) |
| 403 | if err != nil { |
| 404 | ctx.Fatalf("failed to write environment file %s: %s", envFile, err) |
| 405 | } |
Lukacs T. Berki | 7690c09 | 2021-02-26 14:27:36 +0100 | [diff] [blame] | 406 | |
Dan Willemsen | 99a75cd | 2017-08-04 16:04:04 -0700 | [diff] [blame] | 407 | func() { |
Nan Zhang | 17f2767 | 2018-12-12 16:01:49 -0800 | [diff] [blame] | 408 | ctx.BeginTrace(metrics.RunSoong, "environment check") |
Dan Willemsen | 99a75cd | 2017-08-04 16:04:04 -0700 | [diff] [blame] | 409 | defer ctx.EndTrace() |
| 410 | |
Lukacs T. Berki | e1df43f | 2021-09-08 15:31:14 +0200 | [diff] [blame] | 411 | checkEnvironmentFile(soongBuildEnv, config.UsedEnvFile(soongBuildTag)) |
Lukacs T. Berki | f8e2428 | 2021-04-14 10:31:00 +0200 | [diff] [blame] | 412 | |
Lukacs T. Berki | 89fcdcb | 2021-09-07 09:10:33 +0200 | [diff] [blame] | 413 | if integratedBp2Build || config.Bp2Build() { |
Lukacs T. Berki | e1df43f | 2021-09-08 15:31:14 +0200 | [diff] [blame] | 414 | checkEnvironmentFile(soongBuildEnv, config.UsedEnvFile(bp2buildTag)) |
Lukacs T. Berki | 89fcdcb | 2021-09-07 09:10:33 +0200 | [diff] [blame] | 415 | } |
| 416 | |
| 417 | if config.JsonModuleGraph() { |
Lukacs T. Berki | e1df43f | 2021-09-08 15:31:14 +0200 | [diff] [blame] | 418 | checkEnvironmentFile(soongBuildEnv, config.UsedEnvFile(jsonModuleGraphTag)) |
Lukacs T. Berki | 89fcdcb | 2021-09-07 09:10:33 +0200 | [diff] [blame] | 419 | } |
| 420 | |
| 421 | if config.Queryview() { |
Lukacs T. Berki | e1df43f | 2021-09-08 15:31:14 +0200 | [diff] [blame] | 422 | checkEnvironmentFile(soongBuildEnv, config.UsedEnvFile(queryviewTag)) |
Lukacs T. Berki | 89fcdcb | 2021-09-07 09:10:33 +0200 | [diff] [blame] | 423 | } |
| 424 | |
| 425 | if config.SoongDocs() { |
Lukacs T. Berki | e1df43f | 2021-09-08 15:31:14 +0200 | [diff] [blame] | 426 | checkEnvironmentFile(soongBuildEnv, config.UsedEnvFile(soongDocsTag)) |
Dan Willemsen | 99a75cd | 2017-08-04 16:04:04 -0700 | [diff] [blame] | 427 | } |
| 428 | }() |
| 429 | |
Colin Cross | 9191df2 | 2021-10-29 13:11:32 -0700 | [diff] [blame] | 430 | runMicrofactory(ctx, config, "bpglob", "github.com/google/blueprint/bootstrap/bpglob", |
Sasha Smundak | 7ae80a7 | 2021-04-09 12:03:51 -0700 | [diff] [blame] | 431 | map[string]string{"github.com/google/blueprint": "build/blueprint"}) |
Dan Willemsen | 5af1cbe | 2018-07-05 21:46:51 -0700 | [diff] [blame] | 432 | |
Lukacs T. Berki | 56ebaf3 | 2021-08-12 14:03:55 +0200 | [diff] [blame] | 433 | ninja := func(name, ninjaFile string, targets ...string) { |
Nan Zhang | 17f2767 | 2018-12-12 16:01:49 -0800 | [diff] [blame] | 434 | ctx.BeginTrace(metrics.RunSoong, name) |
Dan Willemsen | 99a75cd | 2017-08-04 16:04:04 -0700 | [diff] [blame] | 435 | defer ctx.EndTrace() |
| 436 | |
Dan Willemsen | b82471a | 2018-05-17 16:37:09 -0700 | [diff] [blame] | 437 | fifo := filepath.Join(config.OutDir(), ".ninja_fifo") |
Colin Cross | b98d3bc | 2019-03-21 16:02:58 -0700 | [diff] [blame] | 438 | nr := status.NewNinjaReader(ctx, ctx.Status.StartTool(), fifo) |
| 439 | defer nr.Close() |
Dan Willemsen | b82471a | 2018-05-17 16:37:09 -0700 | [diff] [blame] | 440 | |
Lukacs T. Berki | 56ebaf3 | 2021-08-12 14:03:55 +0200 | [diff] [blame] | 441 | ninjaArgs := []string{ |
Dan Willemsen | 99a75cd | 2017-08-04 16:04:04 -0700 | [diff] [blame] | 442 | "-d", "keepdepfile", |
Dan Willemsen | 0821822 | 2020-05-18 14:02:02 -0700 | [diff] [blame] | 443 | "-d", "stats", |
Dan Willemsen | 6587bed | 2020-04-18 20:25:59 -0700 | [diff] [blame] | 444 | "-o", "usesphonyoutputs=yes", |
| 445 | "-o", "preremoveoutputs=yes", |
Dan Willemsen | 99a75cd | 2017-08-04 16:04:04 -0700 | [diff] [blame] | 446 | "-w", "dupbuild=err", |
Dan Willemsen | 6587bed | 2020-04-18 20:25:59 -0700 | [diff] [blame] | 447 | "-w", "outputdir=err", |
| 448 | "-w", "missingoutfile=err", |
Dan Willemsen | 99a75cd | 2017-08-04 16:04:04 -0700 | [diff] [blame] | 449 | "-j", strconv.Itoa(config.Parallel()), |
Dan Willemsen | 0273667 | 2018-07-17 17:54:31 -0700 | [diff] [blame] | 450 | "--frontend_file", fifo, |
Lukacs T. Berki | 56ebaf3 | 2021-08-12 14:03:55 +0200 | [diff] [blame] | 451 | "-f", filepath.Join(config.SoongOutDir(), ninjaFile), |
| 452 | } |
| 453 | |
| 454 | ninjaArgs = append(ninjaArgs, targets...) |
| 455 | cmd := Command(ctx, config, "soong "+name, |
| 456 | config.PrebuiltBuildTool("ninja"), ninjaArgs...) |
Jingwen Chen | 7c6089a | 2020-11-02 02:56:20 -0500 | [diff] [blame] | 457 | |
Lukacs T. Berki | b14ad7b | 2021-03-09 10:43:57 +0100 | [diff] [blame] | 458 | var ninjaEnv Environment |
Lukacs T. Berki | 73ab928 | 2021-03-10 10:48:39 +0100 | [diff] [blame] | 459 | |
| 460 | // This is currently how the command line to invoke soong_build finds the |
| 461 | // root of the source tree and the output root |
Lukacs T. Berki | b14ad7b | 2021-03-09 10:43:57 +0100 | [diff] [blame] | 462 | ninjaEnv.Set("TOP", os.Getenv("TOP")) |
Lukacs T. Berki | 7d613bf | 2021-03-02 10:09:41 +0100 | [diff] [blame] | 463 | |
Lukacs T. Berki | b14ad7b | 2021-03-09 10:43:57 +0100 | [diff] [blame] | 464 | cmd.Environment = &ninjaEnv |
Dan Willemsen | 99a75cd | 2017-08-04 16:04:04 -0700 | [diff] [blame] | 465 | cmd.Sandbox = soongSandbox |
Colin Cross | 7b97ecd | 2019-06-19 13:17:59 -0700 | [diff] [blame] | 466 | cmd.RunAndStreamOrFatal() |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 467 | } |
Lukacs T. Berki | 56ebaf3 | 2021-08-12 14:03:55 +0200 | [diff] [blame] | 468 | |
Lukacs T. Berki | a1b9372 | 2021-09-02 17:23:06 +0200 | [diff] [blame] | 469 | targets := make([]string, 0, 0) |
Lukacs T. Berki | 56ebaf3 | 2021-08-12 14:03:55 +0200 | [diff] [blame] | 470 | |
Lukacs T. Berki | a1b9372 | 2021-09-02 17:23:06 +0200 | [diff] [blame] | 471 | if config.JsonModuleGraph() { |
| 472 | targets = append(targets, config.ModuleGraphFile()) |
Lukacs T. Berki | 56ebaf3 | 2021-08-12 14:03:55 +0200 | [diff] [blame] | 473 | } |
| 474 | |
Lukacs T. Berki | a1b9372 | 2021-09-02 17:23:06 +0200 | [diff] [blame] | 475 | if config.Bp2Build() { |
| 476 | targets = append(targets, config.Bp2BuildMarkerFile()) |
| 477 | } |
| 478 | |
Lukacs T. Berki | 3a82169 | 2021-09-06 17:08:02 +0200 | [diff] [blame] | 479 | if config.Queryview() { |
| 480 | targets = append(targets, config.QueryviewMarkerFile()) |
| 481 | } |
| 482 | |
Lukacs T. Berki | c6012f3 | 2021-09-06 18:31:46 +0200 | [diff] [blame] | 483 | if config.SoongDocs() { |
| 484 | targets = append(targets, config.SoongDocsHtml()) |
| 485 | } |
| 486 | |
Lukacs T. Berki | a1b9372 | 2021-09-02 17:23:06 +0200 | [diff] [blame] | 487 | if config.SoongBuildInvocationNeeded() { |
| 488 | // This build generates <builddir>/build.ninja, which is used later by build/soong/ui/build/build.go#Build(). |
Cole Faust | 65f298c | 2021-10-28 16:05:13 -0700 | [diff] [blame] | 489 | targets = append(targets, config.SoongNinjaFile()) |
Lukacs T. Berki | a1b9372 | 2021-09-02 17:23:06 +0200 | [diff] [blame] | 490 | } |
| 491 | |
Lukacs T. Berki | 90b4334 | 2021-11-02 14:42:04 +0100 | [diff] [blame] | 492 | ninja("bootstrap", "bootstrap.ninja", targets...) |
Colin Cross | b72c909 | 2020-02-10 11:23:49 -0800 | [diff] [blame] | 493 | |
Jingwen Chen | eb76c43 | 2021-01-28 08:22:12 -0500 | [diff] [blame] | 494 | var soongBuildMetrics *soong_metrics_proto.SoongBuildMetrics |
| 495 | if shouldCollectBuildSoongMetrics(config) { |
| 496 | soongBuildMetrics := loadSoongBuildMetrics(ctx, config) |
| 497 | logSoongBuildMetrics(ctx, soongBuildMetrics) |
| 498 | } |
Colin Cross | b72c909 | 2020-02-10 11:23:49 -0800 | [diff] [blame] | 499 | |
Colin Cross | 8ba7d47 | 2020-06-25 11:27:52 -0700 | [diff] [blame] | 500 | distGzipFile(ctx, config, config.SoongNinjaFile(), "soong") |
| 501 | |
Anton Hansson | 5e5c48b | 2020-11-27 12:35:20 +0000 | [diff] [blame] | 502 | if !config.SkipKati() { |
Colin Cross | 8ba7d47 | 2020-06-25 11:27:52 -0700 | [diff] [blame] | 503 | distGzipFile(ctx, config, config.SoongAndroidMk(), "soong") |
| 504 | distGzipFile(ctx, config, config.SoongMakeVarsMk(), "soong") |
| 505 | } |
| 506 | |
Jingwen Chen | eb76c43 | 2021-01-28 08:22:12 -0500 | [diff] [blame] | 507 | if shouldCollectBuildSoongMetrics(config) && ctx.Metrics != nil { |
Colin Cross | b72c909 | 2020-02-10 11:23:49 -0800 | [diff] [blame] | 508 | ctx.Metrics.SetSoongBuildMetrics(soongBuildMetrics) |
| 509 | } |
Rob Seymour | 33cd10d | 2022-03-02 23:10:25 +0000 | [diff] [blame] | 510 | if config.JsonModuleGraph() { |
| 511 | distGzipFile(ctx, config, config.ModuleGraphFile(), "soong") |
| 512 | } |
Colin Cross | b72c909 | 2020-02-10 11:23:49 -0800 | [diff] [blame] | 513 | } |
| 514 | |
Lukacs T. Berki | 90b4334 | 2021-11-02 14:42:04 +0100 | [diff] [blame] | 515 | func runMicrofactory(ctx Context, config Config, name string, pkg string, mapping map[string]string) { |
Sasha Smundak | 7ae80a7 | 2021-04-09 12:03:51 -0700 | [diff] [blame] | 516 | ctx.BeginTrace(metrics.RunSoong, name) |
| 517 | defer ctx.EndTrace() |
| 518 | cfg := microfactory.Config{TrimPath: absPath(ctx, ".")} |
| 519 | for pkgPrefix, pathPrefix := range mapping { |
| 520 | cfg.Map(pkgPrefix, pathPrefix) |
| 521 | } |
| 522 | |
Lukacs T. Berki | 90b4334 | 2021-11-02 14:42:04 +0100 | [diff] [blame] | 523 | exePath := filepath.Join(config.SoongOutDir(), name) |
Sasha Smundak | 7ae80a7 | 2021-04-09 12:03:51 -0700 | [diff] [blame] | 524 | dir := filepath.Dir(exePath) |
| 525 | if err := os.MkdirAll(dir, 0777); err != nil { |
| 526 | ctx.Fatalf("cannot create %s: %s", dir, err) |
| 527 | } |
| 528 | if _, err := microfactory.Build(&cfg, exePath, pkg); err != nil { |
| 529 | ctx.Fatalf("failed to build %s: %s", name, err) |
| 530 | } |
| 531 | } |
| 532 | |
Jingwen Chen | eb76c43 | 2021-01-28 08:22:12 -0500 | [diff] [blame] | 533 | func shouldCollectBuildSoongMetrics(config Config) bool { |
Jingwen Chen | dd9725c | 2021-06-24 08:41:16 +0000 | [diff] [blame] | 534 | // Do not collect metrics protobuf if the soong_build binary ran as the |
| 535 | // bp2build converter or the JSON graph dump. |
Lukacs T. Berki | a1b9372 | 2021-09-02 17:23:06 +0200 | [diff] [blame] | 536 | return config.SoongBuildInvocationNeeded() |
Jingwen Chen | eb76c43 | 2021-01-28 08:22:12 -0500 | [diff] [blame] | 537 | } |
| 538 | |
Colin Cross | b72c909 | 2020-02-10 11:23:49 -0800 | [diff] [blame] | 539 | func loadSoongBuildMetrics(ctx Context, config Config) *soong_metrics_proto.SoongBuildMetrics { |
| 540 | soongBuildMetricsFile := filepath.Join(config.OutDir(), "soong", "soong_build_metrics.pb") |
| 541 | buf, err := ioutil.ReadFile(soongBuildMetricsFile) |
| 542 | if err != nil { |
| 543 | ctx.Fatalf("Failed to load %s: %s", soongBuildMetricsFile, err) |
| 544 | } |
| 545 | soongBuildMetrics := &soong_metrics_proto.SoongBuildMetrics{} |
| 546 | err = proto.Unmarshal(buf, soongBuildMetrics) |
| 547 | if err != nil { |
| 548 | ctx.Fatalf("Failed to unmarshal %s: %s", soongBuildMetricsFile, err) |
| 549 | } |
| 550 | return soongBuildMetrics |
| 551 | } |
| 552 | |
| 553 | func logSoongBuildMetrics(ctx Context, metrics *soong_metrics_proto.SoongBuildMetrics) { |
| 554 | ctx.Verbosef("soong_build metrics:") |
| 555 | ctx.Verbosef(" modules: %v", metrics.GetModules()) |
| 556 | ctx.Verbosef(" variants: %v", metrics.GetVariants()) |
| 557 | ctx.Verbosef(" max heap size: %v MB", metrics.GetMaxHeapSize()/1e6) |
| 558 | ctx.Verbosef(" total allocation count: %v", metrics.GetTotalAllocCount()) |
| 559 | ctx.Verbosef(" total allocation size: %v MB", metrics.GetTotalAllocSize()/1e6) |
| 560 | |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 561 | } |