Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1 | // Copyright 2015 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 main |
| 16 | |
| 17 | import ( |
| 18 | "flag" |
| 19 | "fmt" |
Lukacs T. Berki | f0b3b94 | 2021-03-23 11:46:47 +0100 | [diff] [blame] | 20 | "io/ioutil" |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 21 | "os" |
| 22 | "path/filepath" |
Jingwen Chen | eb76c43 | 2021-01-28 08:22:12 -0500 | [diff] [blame] | 23 | "strings" |
Lukacs T. Berki | c99c947 | 2021-03-24 10:50:06 +0100 | [diff] [blame] | 24 | "time" |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 25 | |
Lukacs T. Berki | f8e2428 | 2021-04-14 10:31:00 +0200 | [diff] [blame] | 26 | "android/soong/bp2build" |
Lukacs T. Berki | 7690c09 | 2021-02-26 14:27:36 +0100 | [diff] [blame] | 27 | "android/soong/shared" |
Colin Cross | cb33a00 | 2021-04-12 22:25:17 -0700 | [diff] [blame] | 28 | |
Colin Cross | 70b4059 | 2015-03-23 12:57:34 -0700 | [diff] [blame] | 29 | "github.com/google/blueprint/bootstrap" |
Lukacs T. Berki | d518e1a | 2021-04-14 13:49:50 +0200 | [diff] [blame] | 30 | "github.com/google/blueprint/deptools" |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 31 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 32 | "android/soong/android" |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 33 | ) |
| 34 | |
Colin Cross | e87040b | 2017-12-11 15:52:26 -0800 | [diff] [blame] | 35 | var ( |
Lukacs T. Berki | f8e2428 | 2021-04-14 10:31:00 +0200 | [diff] [blame] | 36 | topDir string |
| 37 | outDir string |
| 38 | availableEnvFile string |
| 39 | usedEnvFile string |
| 40 | |
| 41 | delveListen string |
| 42 | delvePath string |
| 43 | |
Jingwen Chen | 50f93d2 | 2020-11-05 07:42:11 -0500 | [diff] [blame] | 44 | docFile string |
| 45 | bazelQueryViewDir string |
Lukacs T. Berki | f8e2428 | 2021-04-14 10:31:00 +0200 | [diff] [blame] | 46 | bp2buildMarker string |
Lukacs T. Berki | f900807 | 2021-08-16 15:24:48 +0200 | [diff] [blame] | 47 | |
| 48 | cmdlineArgs bootstrap.Args |
Colin Cross | e87040b | 2017-12-11 15:52:26 -0800 | [diff] [blame] | 49 | ) |
| 50 | |
| 51 | func init() { |
Lukacs T. Berki | f8e2428 | 2021-04-14 10:31:00 +0200 | [diff] [blame] | 52 | // Flags that make sense in every mode |
Lukacs T. Berki | 7690c09 | 2021-02-26 14:27:36 +0100 | [diff] [blame] | 53 | flag.StringVar(&topDir, "top", "", "Top directory of the Android source tree") |
| 54 | flag.StringVar(&outDir, "out", "", "Soong output directory (usually $TOP/out/soong)") |
Lukacs T. Berki | f8e2428 | 2021-04-14 10:31:00 +0200 | [diff] [blame] | 55 | flag.StringVar(&availableEnvFile, "available_env", "", "File containing available environment variables") |
| 56 | flag.StringVar(&usedEnvFile, "used_env", "", "File containing used environment variables") |
| 57 | |
| 58 | // Debug flags |
Lukacs T. Berki | 7d613bf | 2021-03-02 10:09:41 +0100 | [diff] [blame] | 59 | flag.StringVar(&delveListen, "delve_listen", "", "Delve port to listen on for debugging") |
| 60 | flag.StringVar(&delvePath, "delve_path", "", "Path to Delve. Only used if --delve_listen is set") |
Lukacs T. Berki | f8e2428 | 2021-04-14 10:31:00 +0200 | [diff] [blame] | 61 | |
| 62 | // Flags representing various modes soong_build can run in |
Colin Cross | e87040b | 2017-12-11 15:52:26 -0800 | [diff] [blame] | 63 | flag.StringVar(&docFile, "soong_docs", "", "build documentation file to output") |
Lukacs T. Berki | 47a9d0c | 2021-03-08 16:34:09 +0100 | [diff] [blame] | 64 | flag.StringVar(&bazelQueryViewDir, "bazel_queryview_dir", "", "path to the bazel queryview directory relative to --top") |
Lukacs T. Berki | f8e2428 | 2021-04-14 10:31:00 +0200 | [diff] [blame] | 65 | flag.StringVar(&bp2buildMarker, "bp2build_marker", "", "If set, run bp2build, touch the specified marker file then exit") |
Lukacs T. Berki | f900807 | 2021-08-16 15:24:48 +0200 | [diff] [blame] | 66 | |
| 67 | flag.StringVar(&cmdlineArgs.OutFile, "o", "build.ninja", "the Ninja file to output") |
| 68 | flag.StringVar(&cmdlineArgs.GlobFile, "globFile", "build-globs.ninja", "the Ninja file of globs to output") |
| 69 | flag.StringVar(&cmdlineArgs.GlobListDir, "globListDir", "", "the directory containing the glob list files") |
| 70 | flag.StringVar(&cmdlineArgs.BuildDir, "b", ".", "the build output directory") |
| 71 | flag.StringVar(&cmdlineArgs.NinjaBuildDir, "n", "", "the ninja builddir directory") |
| 72 | flag.StringVar(&cmdlineArgs.DepFile, "d", "", "the dependency file to output") |
| 73 | flag.StringVar(&cmdlineArgs.Cpuprofile, "cpuprofile", "", "write cpu profile to file") |
| 74 | flag.StringVar(&cmdlineArgs.TraceFile, "trace", "", "write trace to file") |
| 75 | flag.StringVar(&cmdlineArgs.Memprofile, "memprofile", "", "write memory profile to file") |
| 76 | flag.BoolVar(&cmdlineArgs.NoGC, "nogc", false, "turn off GC for debugging") |
| 77 | flag.BoolVar(&cmdlineArgs.RunGoTests, "t", false, "build and run go tests during bootstrap") |
| 78 | flag.BoolVar(&cmdlineArgs.UseValidations, "use-validations", false, "use validations to depend on go tests") |
| 79 | flag.StringVar(&cmdlineArgs.ModuleListFile, "l", "", "file that lists filepaths to parse") |
| 80 | flag.BoolVar(&cmdlineArgs.EmptyNinjaFile, "empty-ninja-file", false, "write out a 0-byte ninja file") |
Colin Cross | e87040b | 2017-12-11 15:52:26 -0800 | [diff] [blame] | 81 | } |
| 82 | |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 83 | func newNameResolver(config android.Config) *android.NameResolver { |
| 84 | namespacePathsToExport := make(map[string]bool) |
| 85 | |
Dan Willemsen | 3fb1fae | 2018-03-12 15:30:26 -0700 | [diff] [blame] | 86 | for _, namespaceName := range config.ExportedNamespaces() { |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 87 | namespacePathsToExport[namespaceName] = true |
| 88 | } |
| 89 | |
| 90 | namespacePathsToExport["."] = true // always export the root namespace |
| 91 | |
| 92 | exportFilter := func(namespace *android.Namespace) bool { |
| 93 | return namespacePathsToExport[namespace.Path] |
| 94 | } |
| 95 | |
| 96 | return android.NewNameResolver(exportFilter) |
| 97 | } |
| 98 | |
Lukacs T. Berki | 6790ebc | 2021-04-01 17:55:58 +0200 | [diff] [blame] | 99 | func newContext(configuration android.Config, prepareBuildActions bool) *android.Context { |
Colin Cross | ae8600b | 2020-10-29 17:09:13 -0700 | [diff] [blame] | 100 | ctx := android.NewContext(configuration) |
Jingwen Chen | daa54bc | 2020-12-14 02:58:54 -0500 | [diff] [blame] | 101 | ctx.Register() |
Lukacs T. Berki | 6790ebc | 2021-04-01 17:55:58 +0200 | [diff] [blame] | 102 | if !prepareBuildActions { |
Chris Parsons | f3c96ef | 2020-09-29 02:23:17 -0400 | [diff] [blame] | 103 | configuration.SetStopBefore(bootstrap.StopBeforePrepareBuildActions) |
| 104 | } |
| 105 | ctx.SetNameInterface(newNameResolver(configuration)) |
| 106 | ctx.SetAllowMissingDependencies(configuration.AllowMissingDependencies()) |
| 107 | return ctx |
| 108 | } |
| 109 | |
Lukacs T. Berki | f7e36d8 | 2021-08-16 17:05:09 +0200 | [diff] [blame^] | 110 | func newConfig(outDir string, availableEnv map[string]string) android.Config { |
| 111 | configuration, err := android.NewConfig(outDir, cmdlineArgs.ModuleListFile, availableEnv) |
Chris Parsons | f3c96ef | 2020-09-29 02:23:17 -0400 | [diff] [blame] | 112 | if err != nil { |
| 113 | fmt.Fprintf(os.Stderr, "%s", err) |
| 114 | os.Exit(1) |
| 115 | } |
| 116 | return configuration |
| 117 | } |
| 118 | |
Lukacs T. Berki | 6790ebc | 2021-04-01 17:55:58 +0200 | [diff] [blame] | 119 | // Bazel-enabled mode. Soong runs in two passes. |
| 120 | // First pass: Analyze the build tree, but only store all bazel commands |
| 121 | // needed to correctly evaluate the tree in the second pass. |
| 122 | // TODO(cparsons): Don't output any ninja file, as the second pass will overwrite |
| 123 | // the incorrect results from the first pass, and file I/O is expensive. |
| 124 | func runMixedModeBuild(configuration android.Config, firstCtx *android.Context, extraNinjaDeps []string) { |
Lukacs T. Berki | d518e1a | 2021-04-14 13:49:50 +0200 | [diff] [blame] | 125 | var firstArgs, secondArgs bootstrap.Args |
| 126 | |
Lukacs T. Berki | f900807 | 2021-08-16 15:24:48 +0200 | [diff] [blame] | 127 | firstArgs = cmdlineArgs |
Lukacs T. Berki | 6790ebc | 2021-04-01 17:55:58 +0200 | [diff] [blame] | 128 | configuration.SetStopBefore(bootstrap.StopBeforeWriteNinja) |
Lukacs T. Berki | 6124c9b | 2021-04-15 15:06:40 +0200 | [diff] [blame] | 129 | bootstrap.RunBlueprint(firstArgs, firstCtx.Context, configuration) |
Lukacs T. Berki | d518e1a | 2021-04-14 13:49:50 +0200 | [diff] [blame] | 130 | |
Lukacs T. Berki | 6790ebc | 2021-04-01 17:55:58 +0200 | [diff] [blame] | 131 | // Invoke bazel commands and save results for second pass. |
| 132 | if err := configuration.BazelContext.InvokeBazel(); err != nil { |
| 133 | fmt.Fprintf(os.Stderr, "%s", err) |
| 134 | os.Exit(1) |
| 135 | } |
| 136 | // Second pass: Full analysis, using the bazel command results. Output ninja file. |
Lukacs T. Berki | d518e1a | 2021-04-14 13:49:50 +0200 | [diff] [blame] | 137 | secondConfig, err := android.ConfigForAdditionalRun(configuration) |
Lukacs T. Berki | 6790ebc | 2021-04-01 17:55:58 +0200 | [diff] [blame] | 138 | if err != nil { |
| 139 | fmt.Fprintf(os.Stderr, "%s", err) |
| 140 | os.Exit(1) |
| 141 | } |
Lukacs T. Berki | d518e1a | 2021-04-14 13:49:50 +0200 | [diff] [blame] | 142 | secondCtx := newContext(secondConfig, true) |
Lukacs T. Berki | f900807 | 2021-08-16 15:24:48 +0200 | [diff] [blame] | 143 | secondArgs = cmdlineArgs |
Lukacs T. Berki | 6124c9b | 2021-04-15 15:06:40 +0200 | [diff] [blame] | 144 | ninjaDeps := bootstrap.RunBlueprint(secondArgs, secondCtx.Context, secondConfig) |
| 145 | ninjaDeps = append(ninjaDeps, extraNinjaDeps...) |
Lukacs T. Berki | d518e1a | 2021-04-14 13:49:50 +0200 | [diff] [blame] | 146 | err = deptools.WriteDepFile(shared.JoinPath(topDir, secondArgs.DepFile), secondArgs.OutFile, ninjaDeps) |
| 147 | if err != nil { |
| 148 | fmt.Fprintf(os.Stderr, "Error writing depfile '%s': %s\n", secondArgs.DepFile, err) |
| 149 | os.Exit(1) |
| 150 | } |
Lukacs T. Berki | 6790ebc | 2021-04-01 17:55:58 +0200 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | // Run the code-generation phase to convert BazelTargetModules to BUILD files. |
| 154 | func runQueryView(configuration android.Config, ctx *android.Context) { |
| 155 | codegenContext := bp2build.NewCodegenContext(configuration, *ctx, bp2build.QueryView) |
| 156 | absoluteQueryViewDir := shared.JoinPath(topDir, bazelQueryViewDir) |
| 157 | if err := createBazelQueryView(codegenContext, absoluteQueryViewDir); err != nil { |
| 158 | fmt.Fprintf(os.Stderr, "%s", err) |
| 159 | os.Exit(1) |
| 160 | } |
| 161 | } |
| 162 | |
Lukacs T. Berki | 6124c9b | 2021-04-15 15:06:40 +0200 | [diff] [blame] | 163 | func runSoongDocs(configuration android.Config) { |
Lukacs T. Berki | 6790ebc | 2021-04-01 17:55:58 +0200 | [diff] [blame] | 164 | ctx := newContext(configuration, false) |
Lukacs T. Berki | f900807 | 2021-08-16 15:24:48 +0200 | [diff] [blame] | 165 | soongDocsArgs := cmdlineArgs |
Lukacs T. Berki | 6124c9b | 2021-04-15 15:06:40 +0200 | [diff] [blame] | 166 | bootstrap.RunBlueprint(soongDocsArgs, ctx.Context, configuration) |
Lukacs T. Berki | 6790ebc | 2021-04-01 17:55:58 +0200 | [diff] [blame] | 167 | if err := writeDocs(ctx, configuration, docFile); err != nil { |
| 168 | fmt.Fprintf(os.Stderr, "%s", err) |
| 169 | os.Exit(1) |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | func writeMetrics(configuration android.Config) { |
Lukacs T. Berki | 745380c | 2021-04-12 12:07:44 +0200 | [diff] [blame] | 174 | metricsFile := filepath.Join(configuration.BuildDir(), "soong_build_metrics.pb") |
Lukacs T. Berki | 6790ebc | 2021-04-01 17:55:58 +0200 | [diff] [blame] | 175 | err := android.WriteMetrics(configuration, metricsFile) |
| 176 | if err != nil { |
| 177 | fmt.Fprintf(os.Stderr, "error writing soong_build metrics %s: %s", metricsFile, err) |
| 178 | os.Exit(1) |
| 179 | } |
| 180 | } |
| 181 | |
Lukacs T. Berki | 97bb9f1 | 2021-04-01 18:28:45 +0200 | [diff] [blame] | 182 | func writeJsonModuleGraph(configuration android.Config, ctx *android.Context, path string, extraNinjaDeps []string) { |
| 183 | f, err := os.Create(path) |
| 184 | if err != nil { |
| 185 | fmt.Fprintf(os.Stderr, "%s", err) |
| 186 | os.Exit(1) |
| 187 | } |
| 188 | |
| 189 | defer f.Close() |
| 190 | ctx.Context.PrintJSONGraph(f) |
| 191 | writeFakeNinjaFile(extraNinjaDeps, configuration.BuildDir()) |
| 192 | } |
| 193 | |
Jingwen Chen | 4fabaf5 | 2021-05-25 02:40:29 +0000 | [diff] [blame] | 194 | // doChosenActivity runs Soong for a specific activity, like bp2build, queryview |
| 195 | // or the actual Soong build for the build.ninja file. Returns the top level |
| 196 | // output file of the specific activity. |
Lukacs T. Berki | f8e2428 | 2021-04-14 10:31:00 +0200 | [diff] [blame] | 197 | func doChosenActivity(configuration android.Config, extraNinjaDeps []string) string { |
Chris Parsons | ec1a3dc | 2021-04-20 15:32:07 -0400 | [diff] [blame] | 198 | bazelConversionRequested := bp2buildMarker != "" |
Lukacs T. Berki | 6790ebc | 2021-04-01 17:55:58 +0200 | [diff] [blame] | 199 | mixedModeBuild := configuration.BazelContext.BazelEnabled() |
| 200 | generateQueryView := bazelQueryViewDir != "" |
Lukacs T. Berki | 97bb9f1 | 2021-04-01 18:28:45 +0200 | [diff] [blame] | 201 | jsonModuleFile := configuration.Getenv("SOONG_DUMP_JSON_MODULE_GRAPH") |
| 202 | |
Lukacs T. Berki | f900807 | 2021-08-16 15:24:48 +0200 | [diff] [blame] | 203 | blueprintArgs := cmdlineArgs |
Lukacs T. Berki | 97bb9f1 | 2021-04-01 18:28:45 +0200 | [diff] [blame] | 204 | prepareBuildActions := !generateQueryView && jsonModuleFile == "" |
Lukacs T. Berki | 6790ebc | 2021-04-01 17:55:58 +0200 | [diff] [blame] | 205 | if bazelConversionRequested { |
| 206 | // Run the alternate pipeline of bp2build mutators and singleton to convert |
| 207 | // Blueprint to BUILD files before everything else. |
| 208 | runBp2Build(configuration, extraNinjaDeps) |
Jingwen Chen | 4fabaf5 | 2021-05-25 02:40:29 +0000 | [diff] [blame] | 209 | return bp2buildMarker |
Lukacs T. Berki | 6790ebc | 2021-04-01 17:55:58 +0200 | [diff] [blame] | 210 | } |
| 211 | |
Lukacs T. Berki | 97bb9f1 | 2021-04-01 18:28:45 +0200 | [diff] [blame] | 212 | ctx := newContext(configuration, prepareBuildActions) |
Lukacs T. Berki | 6790ebc | 2021-04-01 17:55:58 +0200 | [diff] [blame] | 213 | if mixedModeBuild { |
| 214 | runMixedModeBuild(configuration, ctx, extraNinjaDeps) |
| 215 | } else { |
Lukacs T. Berki | 6124c9b | 2021-04-15 15:06:40 +0200 | [diff] [blame] | 216 | ninjaDeps := bootstrap.RunBlueprint(blueprintArgs, ctx.Context, configuration) |
| 217 | ninjaDeps = append(ninjaDeps, extraNinjaDeps...) |
Lukacs T. Berki | d518e1a | 2021-04-14 13:49:50 +0200 | [diff] [blame] | 218 | err := deptools.WriteDepFile(shared.JoinPath(topDir, blueprintArgs.DepFile), blueprintArgs.OutFile, ninjaDeps) |
| 219 | if err != nil { |
| 220 | fmt.Fprintf(os.Stderr, "Error writing depfile '%s': %s\n", blueprintArgs.DepFile, err) |
| 221 | os.Exit(1) |
| 222 | } |
Lukacs T. Berki | 6790ebc | 2021-04-01 17:55:58 +0200 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | // Convert the Soong module graph into Bazel BUILD files. |
| 226 | if generateQueryView { |
| 227 | runQueryView(configuration, ctx) |
Lukacs T. Berki | f900807 | 2021-08-16 15:24:48 +0200 | [diff] [blame] | 228 | return cmdlineArgs.OutFile // TODO: This is a lie |
Lukacs T. Berki | 6790ebc | 2021-04-01 17:55:58 +0200 | [diff] [blame] | 229 | } |
Lukacs T. Berki | 97bb9f1 | 2021-04-01 18:28:45 +0200 | [diff] [blame] | 230 | |
| 231 | if jsonModuleFile != "" { |
| 232 | writeJsonModuleGraph(configuration, ctx, jsonModuleFile, extraNinjaDeps) |
Lukacs T. Berki | f900807 | 2021-08-16 15:24:48 +0200 | [diff] [blame] | 233 | return cmdlineArgs.OutFile // TODO: This is a lie |
Lukacs T. Berki | 97bb9f1 | 2021-04-01 18:28:45 +0200 | [diff] [blame] | 234 | } |
| 235 | |
Lukacs T. Berki | 6790ebc | 2021-04-01 17:55:58 +0200 | [diff] [blame] | 236 | writeMetrics(configuration) |
Lukacs T. Berki | f900807 | 2021-08-16 15:24:48 +0200 | [diff] [blame] | 237 | return cmdlineArgs.OutFile |
Lukacs T. Berki | f8e2428 | 2021-04-14 10:31:00 +0200 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | // soong_ui dumps the available environment variables to |
| 241 | // soong.environment.available . Then soong_build itself is run with an empty |
| 242 | // environment so that the only way environment variables can be accessed is |
| 243 | // using Config, which tracks access to them. |
| 244 | |
| 245 | // At the end of the build, a file called soong.environment.used is written |
| 246 | // containing the current value of all used environment variables. The next |
| 247 | // time soong_ui is run, it checks whether any environment variables that was |
| 248 | // used had changed and if so, it deletes soong.environment.used to cause a |
| 249 | // rebuild. |
| 250 | // |
| 251 | // The dependency of build.ninja on soong.environment.used is declared in |
| 252 | // build.ninja.d |
| 253 | func parseAvailableEnv() map[string]string { |
| 254 | if availableEnvFile == "" { |
| 255 | fmt.Fprintf(os.Stderr, "--available_env not set\n") |
| 256 | os.Exit(1) |
| 257 | } |
| 258 | |
| 259 | result, err := shared.EnvFromFile(shared.JoinPath(topDir, availableEnvFile)) |
| 260 | if err != nil { |
| 261 | fmt.Fprintf(os.Stderr, "error reading available environment file '%s': %s\n", availableEnvFile, err) |
| 262 | os.Exit(1) |
| 263 | } |
| 264 | |
| 265 | return result |
Lukacs T. Berki | 6790ebc | 2021-04-01 17:55:58 +0200 | [diff] [blame] | 266 | } |
| 267 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 268 | func main() { |
| 269 | flag.Parse() |
| 270 | |
Lukacs T. Berki | 7d613bf | 2021-03-02 10:09:41 +0100 | [diff] [blame] | 271 | shared.ReexecWithDelveMaybe(delveListen, delvePath) |
Lukacs T. Berki | 7690c09 | 2021-02-26 14:27:36 +0100 | [diff] [blame] | 272 | android.InitSandbox(topDir) |
Lukacs T. Berki | 7690c09 | 2021-02-26 14:27:36 +0100 | [diff] [blame] | 273 | |
Lukacs T. Berki | f8e2428 | 2021-04-14 10:31:00 +0200 | [diff] [blame] | 274 | availableEnv := parseAvailableEnv() |
Lukacs T. Berki | 53b2f36 | 2021-04-12 14:04:24 +0200 | [diff] [blame] | 275 | |
Lukacs T. Berki | f7e36d8 | 2021-08-16 17:05:09 +0200 | [diff] [blame^] | 276 | configuration := newConfig(outDir, availableEnv) |
Lukacs T. Berki | f0b3b94 | 2021-03-23 11:46:47 +0100 | [diff] [blame] | 277 | extraNinjaDeps := []string{ |
| 278 | configuration.ProductVariablesFileName, |
Lukacs T. Berki | d518e1a | 2021-04-14 13:49:50 +0200 | [diff] [blame] | 279 | usedEnvFile, |
Lukacs T. Berki | f0b3b94 | 2021-03-23 11:46:47 +0100 | [diff] [blame] | 280 | } |
Colin Cross | aa812d1 | 2019-06-19 13:33:24 -0700 | [diff] [blame] | 281 | |
Lukacs T. Berki | d1e3f1f | 2021-03-16 08:55:23 +0100 | [diff] [blame] | 282 | if configuration.Getenv("ALLOW_MISSING_DEPENDENCIES") == "true" { |
| 283 | configuration.SetAllowMissingDependencies() |
| 284 | } |
| 285 | |
Lukacs T. Berki | 7d613bf | 2021-03-02 10:09:41 +0100 | [diff] [blame] | 286 | if shared.IsDebugging() { |
Colin Cross | aa812d1 | 2019-06-19 13:33:24 -0700 | [diff] [blame] | 287 | // Add a non-existent file to the dependencies so that soong_build will rerun when the debugger is |
| 288 | // enabled even if it completed successfully. |
| 289 | extraNinjaDeps = append(extraNinjaDeps, filepath.Join(configuration.BuildDir(), "always_rerun_for_delve")) |
| 290 | } |
Jingwen Chen | daa54bc | 2020-12-14 02:58:54 -0500 | [diff] [blame] | 291 | |
Lukacs T. Berki | 6790ebc | 2021-04-01 17:55:58 +0200 | [diff] [blame] | 292 | if docFile != "" { |
| 293 | // We don't write an used variables file when generating documentation |
| 294 | // because that is done from within the actual builds as a Ninja action and |
| 295 | // thus it would overwrite the actual used variables file so this is |
| 296 | // special-cased. |
Lukacs T. Berki | f8e2428 | 2021-04-14 10:31:00 +0200 | [diff] [blame] | 297 | // TODO: Fix this by not passing --used_env to the soong_docs invocation |
Lukacs T. Berki | 6124c9b | 2021-04-15 15:06:40 +0200 | [diff] [blame] | 298 | runSoongDocs(configuration) |
Lukacs T. Berki | 6790ebc | 2021-04-01 17:55:58 +0200 | [diff] [blame] | 299 | return |
Chris Parsons | f3c96ef | 2020-09-29 02:23:17 -0400 | [diff] [blame] | 300 | } |
Jingwen Chen | 4133ce6 | 2020-12-02 04:34:15 -0500 | [diff] [blame] | 301 | |
Lukacs T. Berki | f8e2428 | 2021-04-14 10:31:00 +0200 | [diff] [blame] | 302 | finalOutputFile := doChosenActivity(configuration, extraNinjaDeps) |
| 303 | writeUsedEnvironmentFile(configuration, finalOutputFile) |
Lukacs T. Berki | f0b3b94 | 2021-03-23 11:46:47 +0100 | [diff] [blame] | 304 | } |
| 305 | |
Lukacs T. Berki | f8e2428 | 2021-04-14 10:31:00 +0200 | [diff] [blame] | 306 | func writeUsedEnvironmentFile(configuration android.Config, finalOutputFile string) { |
| 307 | if usedEnvFile == "" { |
| 308 | return |
| 309 | } |
| 310 | |
| 311 | path := shared.JoinPath(topDir, usedEnvFile) |
Lukacs T. Berki | f0b3b94 | 2021-03-23 11:46:47 +0100 | [diff] [blame] | 312 | data, err := shared.EnvFileContents(configuration.EnvDeps()) |
| 313 | if err != nil { |
Lukacs T. Berki | f8e2428 | 2021-04-14 10:31:00 +0200 | [diff] [blame] | 314 | fmt.Fprintf(os.Stderr, "error writing used environment file '%s': %s\n", usedEnvFile, err) |
Lukacs T. Berki | f0b3b94 | 2021-03-23 11:46:47 +0100 | [diff] [blame] | 315 | os.Exit(1) |
| 316 | } |
| 317 | |
| 318 | err = ioutil.WriteFile(path, data, 0666) |
| 319 | if err != nil { |
Lukacs T. Berki | f8e2428 | 2021-04-14 10:31:00 +0200 | [diff] [blame] | 320 | fmt.Fprintf(os.Stderr, "error writing used environment file '%s': %s\n", usedEnvFile, err) |
Lukacs T. Berki | c99c947 | 2021-03-24 10:50:06 +0100 | [diff] [blame] | 321 | os.Exit(1) |
| 322 | } |
| 323 | |
Lukacs T. Berki | f8e2428 | 2021-04-14 10:31:00 +0200 | [diff] [blame] | 324 | // Touch the output file so that it's not older than the file we just |
Lukacs T. Berki | c99c947 | 2021-03-24 10:50:06 +0100 | [diff] [blame] | 325 | // wrote. We can't write the environment file earlier because one an access |
| 326 | // new environment variables while writing it. |
Lukacs T. Berki | f8e2428 | 2021-04-14 10:31:00 +0200 | [diff] [blame] | 327 | touch(shared.JoinPath(topDir, finalOutputFile)) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 328 | } |
Jingwen Chen | 5ba7e47 | 2020-07-15 10:06:41 +0000 | [diff] [blame] | 329 | |
Lukacs T. Berki | 97bb9f1 | 2021-04-01 18:28:45 +0200 | [diff] [blame] | 330 | // Workarounds to support running bp2build in a clean AOSP checkout with no |
| 331 | // prior builds, and exiting early as soon as the BUILD files get generated, |
| 332 | // therefore not creating build.ninja files that soong_ui and callers of |
| 333 | // soong_build expects. |
| 334 | // |
| 335 | // These files are: build.ninja and build.ninja.d. Since Kati hasn't been |
| 336 | // ran as well, and `nothing` is defined in a .mk file, there isn't a ninja |
| 337 | // target called `nothing`, so we manually create it here. |
| 338 | func writeFakeNinjaFile(extraNinjaDeps []string, buildDir string) { |
| 339 | extraNinjaDepsString := strings.Join(extraNinjaDeps, " \\\n ") |
| 340 | |
| 341 | ninjaFileName := "build.ninja" |
| 342 | ninjaFile := shared.JoinPath(topDir, buildDir, ninjaFileName) |
Jingwen Chen | 4fabaf5 | 2021-05-25 02:40:29 +0000 | [diff] [blame] | 343 | ninjaFileD := shared.JoinPath(topDir, buildDir, ninjaFileName+".d") |
Lukacs T. Berki | 97bb9f1 | 2021-04-01 18:28:45 +0200 | [diff] [blame] | 344 | // A workaround to create the 'nothing' ninja target so `m nothing` works, |
| 345 | // since bp2build runs without Kati, and the 'nothing' target is declared in |
| 346 | // a Makefile. |
| 347 | ioutil.WriteFile(ninjaFile, []byte("build nothing: phony\n phony_output = true\n"), 0666) |
| 348 | ioutil.WriteFile(ninjaFileD, |
Jingwen Chen | 4fabaf5 | 2021-05-25 02:40:29 +0000 | [diff] [blame] | 349 | []byte(fmt.Sprintf("%s: \\\n %s\n", ninjaFile, extraNinjaDepsString)), |
Lukacs T. Berki | 97bb9f1 | 2021-04-01 18:28:45 +0200 | [diff] [blame] | 350 | 0666) |
| 351 | } |
| 352 | |
Lukacs T. Berki | f8e2428 | 2021-04-14 10:31:00 +0200 | [diff] [blame] | 353 | func touch(path string) { |
| 354 | f, err := os.OpenFile(path, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0666) |
| 355 | if err != nil { |
| 356 | fmt.Fprintf(os.Stderr, "Error touching '%s': %s\n", path, err) |
| 357 | os.Exit(1) |
| 358 | } |
| 359 | |
| 360 | err = f.Close() |
| 361 | if err != nil { |
| 362 | fmt.Fprintf(os.Stderr, "Error touching '%s': %s\n", path, err) |
| 363 | os.Exit(1) |
| 364 | } |
| 365 | |
| 366 | currentTime := time.Now().Local() |
| 367 | err = os.Chtimes(path, currentTime, currentTime) |
| 368 | if err != nil { |
| 369 | fmt.Fprintf(os.Stderr, "error touching '%s': %s\n", path, err) |
| 370 | os.Exit(1) |
| 371 | } |
| 372 | } |
| 373 | |
Rupert Shuttleworth | 0096079 | 2021-05-12 21:20:13 -0400 | [diff] [blame] | 374 | // Find BUILD files in the srcDir which... |
| 375 | // |
| 376 | // - are not on the allow list (android/bazel.go#ShouldKeepExistingBuildFileForDir()) |
| 377 | // |
| 378 | // - won't be overwritten by corresponding bp2build generated files |
| 379 | // |
| 380 | // And return their paths so they can be left out of the Bazel workspace dir (i.e. ignored) |
Rupert Shuttleworth | e03bb61 | 2021-05-20 19:34:50 -0400 | [diff] [blame] | 381 | func getPathsToIgnoredBuildFiles(topDir string, generatedRoot string, srcDirBazelFiles []string) []string { |
Rupert Shuttleworth | 0096079 | 2021-05-12 21:20:13 -0400 | [diff] [blame] | 382 | paths := make([]string, 0) |
| 383 | |
Rupert Shuttleworth | e03bb61 | 2021-05-20 19:34:50 -0400 | [diff] [blame] | 384 | for _, srcDirBazelFileRelativePath := range srcDirBazelFiles { |
| 385 | srcDirBazelFileFullPath := shared.JoinPath(topDir, srcDirBazelFileRelativePath) |
| 386 | fileInfo, err := os.Stat(srcDirBazelFileFullPath) |
Rupert Shuttleworth | 0096079 | 2021-05-12 21:20:13 -0400 | [diff] [blame] | 387 | if err != nil { |
Rupert Shuttleworth | e03bb61 | 2021-05-20 19:34:50 -0400 | [diff] [blame] | 388 | // Warn about error, but continue trying to check files |
| 389 | fmt.Fprintf(os.Stderr, "WARNING: Error accessing path '%s', err: %s\n", srcDirBazelFileFullPath, err) |
| 390 | continue |
Rupert Shuttleworth | 0096079 | 2021-05-12 21:20:13 -0400 | [diff] [blame] | 391 | } |
Rupert Shuttleworth | e03bb61 | 2021-05-20 19:34:50 -0400 | [diff] [blame] | 392 | if fileInfo.IsDir() { |
Rupert Shuttleworth | 0096079 | 2021-05-12 21:20:13 -0400 | [diff] [blame] | 393 | // Don't ignore entire directories |
Rupert Shuttleworth | e03bb61 | 2021-05-20 19:34:50 -0400 | [diff] [blame] | 394 | continue |
Rupert Shuttleworth | 0096079 | 2021-05-12 21:20:13 -0400 | [diff] [blame] | 395 | } |
Rupert Shuttleworth | e03bb61 | 2021-05-20 19:34:50 -0400 | [diff] [blame] | 396 | if !(fileInfo.Name() == "BUILD" || fileInfo.Name() == "BUILD.bazel") { |
Rupert Shuttleworth | 0096079 | 2021-05-12 21:20:13 -0400 | [diff] [blame] | 397 | // Don't ignore this file - it is not a build file |
Rupert Shuttleworth | e03bb61 | 2021-05-20 19:34:50 -0400 | [diff] [blame] | 398 | continue |
Rupert Shuttleworth | 0096079 | 2021-05-12 21:20:13 -0400 | [diff] [blame] | 399 | } |
Rupert Shuttleworth | e03bb61 | 2021-05-20 19:34:50 -0400 | [diff] [blame] | 400 | srcDirBazelFileDir := filepath.Dir(srcDirBazelFileRelativePath) |
| 401 | if android.ShouldKeepExistingBuildFileForDir(srcDirBazelFileDir) { |
Rupert Shuttleworth | 0096079 | 2021-05-12 21:20:13 -0400 | [diff] [blame] | 402 | // Don't ignore this existing build file |
Rupert Shuttleworth | e03bb61 | 2021-05-20 19:34:50 -0400 | [diff] [blame] | 403 | continue |
Rupert Shuttleworth | 0096079 | 2021-05-12 21:20:13 -0400 | [diff] [blame] | 404 | } |
Rupert Shuttleworth | e03bb61 | 2021-05-20 19:34:50 -0400 | [diff] [blame] | 405 | correspondingBp2BuildFile := shared.JoinPath(topDir, generatedRoot, srcDirBazelFileRelativePath) |
| 406 | if _, err := os.Stat(correspondingBp2BuildFile); err == nil { |
Rupert Shuttleworth | 0096079 | 2021-05-12 21:20:13 -0400 | [diff] [blame] | 407 | // If bp2build generated an alternate BUILD file, don't exclude this workspace path |
| 408 | // BUILD file clash resolution happens later in the symlink forest creation |
Rupert Shuttleworth | e03bb61 | 2021-05-20 19:34:50 -0400 | [diff] [blame] | 409 | continue |
Rupert Shuttleworth | 0096079 | 2021-05-12 21:20:13 -0400 | [diff] [blame] | 410 | } |
Rupert Shuttleworth | e03bb61 | 2021-05-20 19:34:50 -0400 | [diff] [blame] | 411 | fmt.Fprintf(os.Stderr, "Ignoring existing BUILD file: %s\n", srcDirBazelFileRelativePath) |
| 412 | paths = append(paths, srcDirBazelFileRelativePath) |
| 413 | } |
Rupert Shuttleworth | 0096079 | 2021-05-12 21:20:13 -0400 | [diff] [blame] | 414 | |
Rupert Shuttleworth | e03bb61 | 2021-05-20 19:34:50 -0400 | [diff] [blame] | 415 | return paths |
Rupert Shuttleworth | 0096079 | 2021-05-12 21:20:13 -0400 | [diff] [blame] | 416 | } |
| 417 | |
| 418 | // Returns temporary symlink forest excludes necessary for bazel build //external/... (and bazel build //frameworks/...) to work |
| 419 | func getTemporaryExcludes() []string { |
| 420 | excludes := make([]string, 0) |
| 421 | |
| 422 | // FIXME: 'autotest_lib' is a symlink back to external/autotest, and this causes an infinite symlink expansion error for Bazel |
| 423 | excludes = append(excludes, "external/autotest/venv/autotest_lib") |
| 424 | |
| 425 | // FIXME: The external/google-fruit/extras/bazel_root/third_party/fruit dir is poison |
| 426 | // It contains several symlinks back to real source dirs, and those source dirs contain BUILD files we want to ignore |
| 427 | excludes = append(excludes, "external/google-fruit/extras/bazel_root/third_party/fruit") |
| 428 | |
| 429 | // FIXME: 'frameworks/compile/slang' has a filegroup error due to an escaping issue |
| 430 | excludes = append(excludes, "frameworks/compile/slang") |
| 431 | |
| 432 | return excludes |
| 433 | } |
| 434 | |
Rupert Shuttleworth | e03bb61 | 2021-05-20 19:34:50 -0400 | [diff] [blame] | 435 | // Read the bazel.list file that the Soong Finder already dumped earlier (hopefully) |
| 436 | // It contains the locations of BUILD files, BUILD.bazel files, etc. in the source dir |
| 437 | func getExistingBazelRelatedFiles(topDir string) ([]string, error) { |
Lukacs T. Berki | f900807 | 2021-08-16 15:24:48 +0200 | [diff] [blame] | 438 | bazelFinderFile := filepath.Join(filepath.Dir(cmdlineArgs.ModuleListFile), "bazel.list") |
Rupert Shuttleworth | e03bb61 | 2021-05-20 19:34:50 -0400 | [diff] [blame] | 439 | if !filepath.IsAbs(bazelFinderFile) { |
| 440 | // Assume this was a relative path under topDir |
| 441 | bazelFinderFile = filepath.Join(topDir, bazelFinderFile) |
| 442 | } |
| 443 | data, err := ioutil.ReadFile(bazelFinderFile) |
| 444 | if err != nil { |
| 445 | return nil, err |
| 446 | } |
| 447 | files := strings.Split(strings.TrimSpace(string(data)), "\n") |
| 448 | return files, nil |
| 449 | } |
| 450 | |
Jingwen Chen | daa54bc | 2020-12-14 02:58:54 -0500 | [diff] [blame] | 451 | // Run Soong in the bp2build mode. This creates a standalone context that registers |
| 452 | // an alternate pipeline of mutators and singletons specifically for generating |
| 453 | // Bazel BUILD files instead of Ninja files. |
Lukacs T. Berki | 6790ebc | 2021-04-01 17:55:58 +0200 | [diff] [blame] | 454 | func runBp2Build(configuration android.Config, extraNinjaDeps []string) { |
Jingwen Chen | daa54bc | 2020-12-14 02:58:54 -0500 | [diff] [blame] | 455 | // Register an alternate set of singletons and mutators for bazel |
| 456 | // conversion for Bazel conversion. |
| 457 | bp2buildCtx := android.NewContext(configuration) |
Jingwen Chen | eb76c43 | 2021-01-28 08:22:12 -0500 | [diff] [blame] | 458 | |
Lukacs T. Berki | d518e1a | 2021-04-14 13:49:50 +0200 | [diff] [blame] | 459 | // Propagate "allow misssing dependencies" bit. This is normally set in |
| 460 | // newContext(), but we create bp2buildCtx without calling that method. |
| 461 | bp2buildCtx.SetAllowMissingDependencies(configuration.AllowMissingDependencies()) |
Jingwen Chen | daa54bc | 2020-12-14 02:58:54 -0500 | [diff] [blame] | 462 | bp2buildCtx.SetNameInterface(newNameResolver(configuration)) |
Lukacs T. Berki | d518e1a | 2021-04-14 13:49:50 +0200 | [diff] [blame] | 463 | bp2buildCtx.RegisterForBazelConversion() |
Jingwen Chen | eb76c43 | 2021-01-28 08:22:12 -0500 | [diff] [blame] | 464 | |
Jingwen Chen | 7dcc4fc | 2021-02-05 01:28:44 -0500 | [diff] [blame] | 465 | // The bp2build process is a purely functional process that only depends on |
| 466 | // Android.bp files. It must not depend on the values of per-build product |
| 467 | // configurations or variables, since those will generate different BUILD |
| 468 | // files based on how the user has configured their tree. |
Lukacs T. Berki | f900807 | 2021-08-16 15:24:48 +0200 | [diff] [blame] | 469 | bp2buildCtx.SetModuleListFile(cmdlineArgs.ModuleListFile) |
Lukacs T. Berki | f7e36d8 | 2021-08-16 17:05:09 +0200 | [diff] [blame^] | 470 | modulePaths, err := bp2buildCtx.ListModulePaths(".") |
Jingwen Chen | 7dcc4fc | 2021-02-05 01:28:44 -0500 | [diff] [blame] | 471 | if err != nil { |
| 472 | panic(err) |
| 473 | } |
Jingwen Chen | 7dcc4fc | 2021-02-05 01:28:44 -0500 | [diff] [blame] | 474 | |
Lukacs T. Berki | f0b3b94 | 2021-03-23 11:46:47 +0100 | [diff] [blame] | 475 | extraNinjaDeps = append(extraNinjaDeps, modulePaths...) |
| 476 | |
Lukacs T. Berki | d518e1a | 2021-04-14 13:49:50 +0200 | [diff] [blame] | 477 | // No need to generate Ninja build rules/statements from Modules and Singletons. |
| 478 | configuration.SetStopBefore(bootstrap.StopBeforePrepareBuildActions) |
| 479 | |
Jingwen Chen | 7dcc4fc | 2021-02-05 01:28:44 -0500 | [diff] [blame] | 480 | // Run the loading and analysis pipeline to prepare the graph of regular |
| 481 | // Modules parsed from Android.bp files, and the BazelTargetModules mapped |
| 482 | // from the regular Modules. |
Lukacs T. Berki | f900807 | 2021-08-16 15:24:48 +0200 | [diff] [blame] | 483 | blueprintArgs := cmdlineArgs |
Lukacs T. Berki | 6124c9b | 2021-04-15 15:06:40 +0200 | [diff] [blame] | 484 | ninjaDeps := bootstrap.RunBlueprint(blueprintArgs, bp2buildCtx.Context, configuration) |
| 485 | ninjaDeps = append(ninjaDeps, extraNinjaDeps...) |
Lukacs T. Berki | d518e1a | 2021-04-14 13:49:50 +0200 | [diff] [blame] | 486 | |
Jingwen Chen | 53dfa40 | 2021-08-12 09:37:14 +0000 | [diff] [blame] | 487 | // Generate out/soong/.bootstrap/build-globs.ninja with the actions to generate flattened globfiles |
| 488 | // containing the globs seen during bp2build conversion |
| 489 | if blueprintArgs.GlobFile != "" { |
Lukacs T. Berki | 56ebaf3 | 2021-08-12 14:03:55 +0200 | [diff] [blame] | 490 | bootstrap.WriteBuildGlobsNinjaFile(blueprintArgs.GlobListDir, bp2buildCtx.Context, blueprintArgs, configuration) |
Jingwen Chen | 53dfa40 | 2021-08-12 09:37:14 +0000 | [diff] [blame] | 491 | } |
| 492 | // Add the depfile on the expanded globs in out/soong/.primary/globs |
Lukacs T. Berki | 56ebaf3 | 2021-08-12 14:03:55 +0200 | [diff] [blame] | 493 | ninjaDeps = append(ninjaDeps, bootstrap.GlobFileListFiles(configuration, blueprintArgs.GlobListDir)...) |
Lukacs T. Berki | d518e1a | 2021-04-14 13:49:50 +0200 | [diff] [blame] | 494 | |
Lukacs T. Berki | b353cca | 2021-04-16 13:47:36 +0200 | [diff] [blame] | 495 | // Run the code-generation phase to convert BazelTargetModules to BUILD files |
| 496 | // and print conversion metrics to the user. |
| 497 | codegenContext := bp2build.NewCodegenContext(configuration, *bp2buildCtx, bp2build.Bp2Build) |
| 498 | metrics := bp2build.Codegen(codegenContext) |
| 499 | |
| 500 | generatedRoot := shared.JoinPath(configuration.BuildDir(), "bp2build") |
| 501 | workspaceRoot := shared.JoinPath(configuration.BuildDir(), "workspace") |
| 502 | |
| 503 | excludes := []string{ |
| 504 | "bazel-bin", |
| 505 | "bazel-genfiles", |
| 506 | "bazel-out", |
| 507 | "bazel-testlogs", |
| 508 | "bazel-" + filepath.Base(topDir), |
| 509 | } |
| 510 | |
Lukacs T. Berki | f900807 | 2021-08-16 15:24:48 +0200 | [diff] [blame] | 511 | if cmdlineArgs.NinjaBuildDir[0] != '/' { |
| 512 | excludes = append(excludes, cmdlineArgs.NinjaBuildDir) |
Lukacs T. Berki | b353cca | 2021-04-16 13:47:36 +0200 | [diff] [blame] | 513 | } |
| 514 | |
Rupert Shuttleworth | e03bb61 | 2021-05-20 19:34:50 -0400 | [diff] [blame] | 515 | existingBazelRelatedFiles, err := getExistingBazelRelatedFiles(topDir) |
Rupert Shuttleworth | 0096079 | 2021-05-12 21:20:13 -0400 | [diff] [blame] | 516 | if err != nil { |
Rupert Shuttleworth | e03bb61 | 2021-05-20 19:34:50 -0400 | [diff] [blame] | 517 | fmt.Fprintf(os.Stderr, "Error determining existing Bazel-related files: %s\n", err) |
Rupert Shuttleworth | 0096079 | 2021-05-12 21:20:13 -0400 | [diff] [blame] | 518 | os.Exit(1) |
| 519 | } |
Rupert Shuttleworth | e03bb61 | 2021-05-20 19:34:50 -0400 | [diff] [blame] | 520 | |
| 521 | pathsToIgnoredBuildFiles := getPathsToIgnoredBuildFiles(topDir, generatedRoot, existingBazelRelatedFiles) |
Rupert Shuttleworth | 0096079 | 2021-05-12 21:20:13 -0400 | [diff] [blame] | 522 | excludes = append(excludes, pathsToIgnoredBuildFiles...) |
| 523 | |
| 524 | excludes = append(excludes, getTemporaryExcludes()...) |
| 525 | |
Lukacs T. Berki | b353cca | 2021-04-16 13:47:36 +0200 | [diff] [blame] | 526 | symlinkForestDeps := bp2build.PlantSymlinkForest( |
Lukacs T. Berki | f7e36d8 | 2021-08-16 17:05:09 +0200 | [diff] [blame^] | 527 | topDir, workspaceRoot, generatedRoot, ".", excludes) |
Lukacs T. Berki | b353cca | 2021-04-16 13:47:36 +0200 | [diff] [blame] | 528 | |
| 529 | // Only report metrics when in bp2build mode. The metrics aren't relevant |
| 530 | // for queryview, since that's a total repo-wide conversion and there's a |
| 531 | // 1:1 mapping for each module. |
| 532 | metrics.Print() |
| 533 | |
| 534 | ninjaDeps = append(ninjaDeps, codegenContext.AdditionalNinjaDeps()...) |
| 535 | ninjaDeps = append(ninjaDeps, symlinkForestDeps...) |
| 536 | |
Lukacs T. Berki | d518e1a | 2021-04-14 13:49:50 +0200 | [diff] [blame] | 537 | depFile := bp2buildMarker + ".d" |
| 538 | err = deptools.WriteDepFile(shared.JoinPath(topDir, depFile), bp2buildMarker, ninjaDeps) |
| 539 | if err != nil { |
| 540 | fmt.Fprintf(os.Stderr, "Cannot write depfile '%s': %s\n", depFile, err) |
| 541 | os.Exit(1) |
| 542 | } |
Jingwen Chen | daa54bc | 2020-12-14 02:58:54 -0500 | [diff] [blame] | 543 | |
Jingwen Chen | 4fabaf5 | 2021-05-25 02:40:29 +0000 | [diff] [blame] | 544 | // Create an empty bp2build marker file. |
| 545 | touch(shared.JoinPath(topDir, bp2buildMarker)) |
Jingwen Chen | daa54bc | 2020-12-14 02:58:54 -0500 | [diff] [blame] | 546 | } |