Merge "Pass StopBefore as an argument to RunBlueprint."

This commit is contained in:
Lukács T. Berki
2021-09-08 06:22:29 +00:00
committed by Gerrit Code Review
3 changed files with 18 additions and 31 deletions

View File

@@ -157,8 +157,6 @@ type config struct {
captureBuild bool // true for tests, saves build parameters for each module captureBuild bool // true for tests, saves build parameters for each module
ignoreEnvironment bool // true for tests, returns empty from all Getenv calls ignoreEnvironment bool // true for tests, returns empty from all Getenv calls
stopBefore bootstrap.StopBefore
fs pathtools.FileSystem fs pathtools.FileSystem
mockBpList string mockBpList string
@@ -565,21 +563,10 @@ func (c *config) mockFileSystem(bp string, fs map[string][]byte) {
c.mockBpList = blueprint.MockModuleListFile 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() { func (c *config) SetAllowMissingDependencies() {
c.productVariables.Allow_missing_dependencies = proptools.BoolPtr(true) c.productVariables.Allow_missing_dependencies = proptools.BoolPtr(true)
} }
var _ bootstrap.ConfigStopBefore = (*config)(nil)
// BlueprintToolLocation returns the directory containing build system tools // BlueprintToolLocation returns the directory containing build system tools
// from Blueprint, like soong_zip and merge_zips. // from Blueprint, like soong_zip and merge_zips.
func (c *config) HostToolDir() string { func (c *config) HostToolDir() string {

View File

@@ -101,12 +101,9 @@ func newNameResolver(config android.Config) *android.NameResolver {
return android.NewNameResolver(exportFilter) 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 := android.NewContext(configuration)
ctx.Register() ctx.Register()
if !prepareBuildActions {
configuration.SetStopBefore(bootstrap.StopBeforePrepareBuildActions)
}
ctx.SetNameInterface(newNameResolver(configuration)) ctx.SetNameInterface(newNameResolver(configuration))
ctx.SetAllowMissingDependencies(configuration.AllowMissingDependencies()) ctx.SetAllowMissingDependencies(configuration.AllowMissingDependencies())
return ctx return ctx
@@ -130,8 +127,7 @@ func runMixedModeBuild(configuration android.Config, firstCtx *android.Context,
var firstArgs, secondArgs bootstrap.Args var firstArgs, secondArgs bootstrap.Args
firstArgs = cmdlineArgs firstArgs = cmdlineArgs
configuration.SetStopBefore(bootstrap.StopBeforeWriteNinja) bootstrap.RunBlueprint(firstArgs, bootstrap.StopBeforeWriteNinja, firstCtx.Context, configuration)
bootstrap.RunBlueprint(firstArgs, firstCtx.Context, configuration)
// Invoke bazel commands and save results for second pass. // Invoke bazel commands and save results for second pass.
if err := configuration.BazelContext.InvokeBazel(); err != nil { 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) fmt.Fprintf(os.Stderr, "%s", err)
os.Exit(1) os.Exit(1)
} }
secondCtx := newContext(secondConfig, true) secondCtx := newContext(secondConfig)
ninjaDeps := bootstrap.RunBlueprint(secondArgs, secondCtx.Context, secondConfig) ninjaDeps := bootstrap.RunBlueprint(secondArgs, bootstrap.DoEverything, secondCtx.Context, secondConfig)
ninjaDeps = append(ninjaDeps, extraNinjaDeps...) ninjaDeps = append(ninjaDeps, extraNinjaDeps...)
globListFiles := writeBuildGlobsNinjaFile(secondCtx.SrcDir(), configuration.SoongOutDir(), secondCtx.Globs, configuration) 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) { func runSoongDocs(configuration android.Config) {
ctx := newContext(configuration, false) ctx := newContext(configuration)
soongDocsArgs := cmdlineArgs soongDocsArgs := cmdlineArgs
bootstrap.RunBlueprint(soongDocsArgs, ctx.Context, configuration) bootstrap.RunBlueprint(soongDocsArgs, bootstrap.StopBeforePrepareBuildActions, ctx.Context, configuration)
if err := writeDocs(ctx, configuration, docFile); err != nil { if err := writeDocs(ctx, configuration, docFile); err != nil {
fmt.Fprintf(os.Stderr, "%s", err) fmt.Fprintf(os.Stderr, "%s", err)
os.Exit(1) os.Exit(1)
@@ -226,7 +222,14 @@ func doChosenActivity(configuration android.Config, extraNinjaDeps []string) str
generateQueryView := bazelQueryViewDir != "" generateQueryView := bazelQueryViewDir != ""
blueprintArgs := cmdlineArgs blueprintArgs := cmdlineArgs
prepareBuildActions := !generateQueryView && moduleGraphFile == ""
var stopBefore bootstrap.StopBefore
if !generateQueryView && moduleGraphFile == "" {
stopBefore = bootstrap.DoEverything
} else {
stopBefore = bootstrap.StopBeforePrepareBuildActions
}
if bazelConversionRequested { if bazelConversionRequested {
// Run the alternate pipeline of bp2build mutators and singleton to convert // Run the alternate pipeline of bp2build mutators and singleton to convert
// Blueprint to BUILD files before everything else. // Blueprint to BUILD files before everything else.
@@ -234,11 +237,11 @@ func doChosenActivity(configuration android.Config, extraNinjaDeps []string) str
return bp2buildMarker return bp2buildMarker
} }
ctx := newContext(configuration, prepareBuildActions) ctx := newContext(configuration)
if mixedModeBuild { if mixedModeBuild {
runMixedModeBuild(configuration, ctx, extraNinjaDeps) runMixedModeBuild(configuration, ctx, extraNinjaDeps)
} else { } else {
ninjaDeps := bootstrap.RunBlueprint(blueprintArgs, ctx.Context, configuration) ninjaDeps := bootstrap.RunBlueprint(blueprintArgs, stopBefore, ctx.Context, configuration)
ninjaDeps = append(ninjaDeps, extraNinjaDeps...) ninjaDeps = append(ninjaDeps, extraNinjaDeps...)
globListFiles := writeBuildGlobsNinjaFile(ctx.SrcDir(), configuration.SoongOutDir(), ctx.Globs, configuration) globListFiles := writeBuildGlobsNinjaFile(ctx.SrcDir(), configuration.SoongOutDir(), ctx.Globs, configuration)
@@ -479,14 +482,11 @@ func runBp2Build(configuration android.Config, extraNinjaDeps []string) {
extraNinjaDeps = append(extraNinjaDeps, modulePaths...) 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 // Run the loading and analysis pipeline to prepare the graph of regular
// Modules parsed from Android.bp files, and the BazelTargetModules mapped // Modules parsed from Android.bp files, and the BazelTargetModules mapped
// from the regular Modules. // from the regular Modules.
blueprintArgs := cmdlineArgs blueprintArgs := cmdlineArgs
ninjaDeps := bootstrap.RunBlueprint(blueprintArgs, bp2buildCtx.Context, configuration) ninjaDeps := bootstrap.RunBlueprint(blueprintArgs, bootstrap.StopBeforePrepareBuildActions, bp2buildCtx.Context, configuration)
ninjaDeps = append(ninjaDeps, extraNinjaDeps...) ninjaDeps = append(ninjaDeps, extraNinjaDeps...)
globListFiles := writeBuildGlobsNinjaFile(bp2buildCtx.SrcDir(), configuration.SoongOutDir(), bp2buildCtx.Globs, configuration) globListFiles := writeBuildGlobsNinjaFile(bp2buildCtx.SrcDir(), configuration.SoongOutDir(), bp2buildCtx.Globs, configuration)

View File

@@ -263,7 +263,7 @@ func bootstrapBlueprint(ctx Context, config Config) {
} }
args.EmptyNinjaFile = false args.EmptyNinjaFile = false
bootstrapDeps := bootstrap.RunBlueprint(args, blueprintCtx, blueprintConfig) bootstrapDeps := bootstrap.RunBlueprint(args, bootstrap.DoEverything, blueprintCtx, blueprintConfig)
err := deptools.WriteDepFile(bootstrapDepFile, args.OutFile, bootstrapDeps) err := deptools.WriteDepFile(bootstrapDepFile, args.OutFile, bootstrapDeps)
if err != nil { if err != nil {
ctx.Fatalf("Error writing depfile '%s': %s", bootstrapDepFile, err) ctx.Fatalf("Error writing depfile '%s': %s", bootstrapDepFile, err)