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