From ffc9e8d8123aad8c98748b5f04da7090fca44e5d Mon Sep 17 00:00:00 2001 From: "Lukacs T. Berki" Date: Tue, 7 Sep 2021 17:54:38 +0200 Subject: [PATCH] Pass StopBefore as an argument to RunBlueprint. Its value is a function of the call site, so it doesn't make a lot of sense to plumb it through the configuration. Test: Presubmits. Change-Id: If928b34de075969fd42932212ce9187808cbdf86 --- android/config.go | 13 ------------- cmd/soong_build/main.go | 34 +++++++++++++++++----------------- ui/build/soong.go | 2 +- 3 files changed, 18 insertions(+), 31 deletions(-) diff --git a/android/config.go b/android/config.go index e0fc266dc..1587f103c 100644 --- a/android/config.go +++ b/android/config.go @@ -157,8 +157,6 @@ type config struct { captureBuild bool // true for tests, saves build parameters for each module ignoreEnvironment bool // true for tests, returns empty from all Getenv calls - stopBefore bootstrap.StopBefore - fs pathtools.FileSystem mockBpList string @@ -565,21 +563,10 @@ func (c *config) mockFileSystem(bp string, fs map[string][]byte) { c.mockBpList = blueprint.MockModuleListFile } -func (c *config) StopBefore() bootstrap.StopBefore { - return c.stopBefore -} - -// SetStopBefore configures soong_build to exit earlier at a specific point. -func (c *config) SetStopBefore(stopBefore bootstrap.StopBefore) { - c.stopBefore = stopBefore -} - func (c *config) SetAllowMissingDependencies() { c.productVariables.Allow_missing_dependencies = proptools.BoolPtr(true) } -var _ bootstrap.ConfigStopBefore = (*config)(nil) - // BlueprintToolLocation returns the directory containing build system tools // from Blueprint, like soong_zip and merge_zips. func (c *config) HostToolDir() string { diff --git a/cmd/soong_build/main.go b/cmd/soong_build/main.go index 2cad78595..684160f5b 100644 --- a/cmd/soong_build/main.go +++ b/cmd/soong_build/main.go @@ -101,12 +101,9 @@ func newNameResolver(config android.Config) *android.NameResolver { return android.NewNameResolver(exportFilter) } -func newContext(configuration android.Config, prepareBuildActions bool) *android.Context { +func newContext(configuration android.Config) *android.Context { ctx := android.NewContext(configuration) ctx.Register() - if !prepareBuildActions { - configuration.SetStopBefore(bootstrap.StopBeforePrepareBuildActions) - } ctx.SetNameInterface(newNameResolver(configuration)) ctx.SetAllowMissingDependencies(configuration.AllowMissingDependencies()) return ctx @@ -130,8 +127,7 @@ func runMixedModeBuild(configuration android.Config, firstCtx *android.Context, var firstArgs, secondArgs bootstrap.Args firstArgs = cmdlineArgs - configuration.SetStopBefore(bootstrap.StopBeforeWriteNinja) - bootstrap.RunBlueprint(firstArgs, firstCtx.Context, configuration) + bootstrap.RunBlueprint(firstArgs, bootstrap.StopBeforeWriteNinja, firstCtx.Context, configuration) // Invoke bazel commands and save results for second pass. if err := configuration.BazelContext.InvokeBazel(); err != nil { @@ -145,8 +141,8 @@ func runMixedModeBuild(configuration android.Config, firstCtx *android.Context, fmt.Fprintf(os.Stderr, "%s", err) os.Exit(1) } - secondCtx := newContext(secondConfig, true) - ninjaDeps := bootstrap.RunBlueprint(secondArgs, secondCtx.Context, secondConfig) + secondCtx := newContext(secondConfig) + ninjaDeps := bootstrap.RunBlueprint(secondArgs, bootstrap.DoEverything, secondCtx.Context, secondConfig) ninjaDeps = append(ninjaDeps, extraNinjaDeps...) globListFiles := writeBuildGlobsNinjaFile(secondCtx.SrcDir(), configuration.SoongOutDir(), secondCtx.Globs, configuration) @@ -168,9 +164,9 @@ func runQueryView(queryviewDir, queryviewMarker string, configuration android.Co } func runSoongDocs(configuration android.Config) { - ctx := newContext(configuration, false) + ctx := newContext(configuration) soongDocsArgs := cmdlineArgs - bootstrap.RunBlueprint(soongDocsArgs, ctx.Context, configuration) + bootstrap.RunBlueprint(soongDocsArgs, bootstrap.StopBeforePrepareBuildActions, ctx.Context, configuration) if err := writeDocs(ctx, configuration, docFile); err != nil { fmt.Fprintf(os.Stderr, "%s", err) os.Exit(1) @@ -226,7 +222,14 @@ func doChosenActivity(configuration android.Config, extraNinjaDeps []string) str generateQueryView := bazelQueryViewDir != "" blueprintArgs := cmdlineArgs - prepareBuildActions := !generateQueryView && moduleGraphFile == "" + + var stopBefore bootstrap.StopBefore + if !generateQueryView && moduleGraphFile == "" { + stopBefore = bootstrap.DoEverything + } else { + stopBefore = bootstrap.StopBeforePrepareBuildActions + } + if bazelConversionRequested { // Run the alternate pipeline of bp2build mutators and singleton to convert // Blueprint to BUILD files before everything else. @@ -234,11 +237,11 @@ func doChosenActivity(configuration android.Config, extraNinjaDeps []string) str return bp2buildMarker } - ctx := newContext(configuration, prepareBuildActions) + ctx := newContext(configuration) if mixedModeBuild { runMixedModeBuild(configuration, ctx, extraNinjaDeps) } else { - ninjaDeps := bootstrap.RunBlueprint(blueprintArgs, ctx.Context, configuration) + ninjaDeps := bootstrap.RunBlueprint(blueprintArgs, stopBefore, ctx.Context, configuration) ninjaDeps = append(ninjaDeps, extraNinjaDeps...) globListFiles := writeBuildGlobsNinjaFile(ctx.SrcDir(), configuration.SoongOutDir(), ctx.Globs, configuration) @@ -479,14 +482,11 @@ func runBp2Build(configuration android.Config, extraNinjaDeps []string) { extraNinjaDeps = append(extraNinjaDeps, modulePaths...) - // No need to generate Ninja build rules/statements from Modules and Singletons. - configuration.SetStopBefore(bootstrap.StopBeforePrepareBuildActions) - // Run the loading and analysis pipeline to prepare the graph of regular // Modules parsed from Android.bp files, and the BazelTargetModules mapped // from the regular Modules. blueprintArgs := cmdlineArgs - ninjaDeps := bootstrap.RunBlueprint(blueprintArgs, bp2buildCtx.Context, configuration) + ninjaDeps := bootstrap.RunBlueprint(blueprintArgs, bootstrap.StopBeforePrepareBuildActions, bp2buildCtx.Context, configuration) ninjaDeps = append(ninjaDeps, extraNinjaDeps...) globListFiles := writeBuildGlobsNinjaFile(bp2buildCtx.SrcDir(), configuration.SoongOutDir(), bp2buildCtx.Globs, configuration) diff --git a/ui/build/soong.go b/ui/build/soong.go index 04d106bb6..26afd43ea 100644 --- a/ui/build/soong.go +++ b/ui/build/soong.go @@ -263,7 +263,7 @@ func bootstrapBlueprint(ctx Context, config Config) { } args.EmptyNinjaFile = false - bootstrapDeps := bootstrap.RunBlueprint(args, blueprintCtx, blueprintConfig) + bootstrapDeps := bootstrap.RunBlueprint(args, bootstrap.DoEverything, blueprintCtx, blueprintConfig) err := deptools.WriteDepFile(bootstrapDepFile, args.OutFile, bootstrapDeps) if err != nil { ctx.Fatalf("Error writing depfile '%s': %s", bootstrapDepFile, err)