bp2build: fix BUILD file generation incrementality bug.

Before this change, changes to any Android.bp file would not trigger a re-run of bp2build/Soong, since the depfile for Soong's main output, the build.ninja file, didn't contain the list of Android.bp files. bp2build only reran when Soong itself changed, which happens regularly while developing bp2build, but not at all while modifying Android.bp files.

This change correctly dumps the list of all Android.bp files in the tree to the depfile for out/soong/build.ninja, therefore correctly triggering a re-run of bp2build when any Android.bp file changes.

Test: GENERATE_BAZEL_FILES=true m nothing; edit an Android.bp file; GENERATE_BAZEL_FILES=true m nothing -> successfully re-runs and regenerates out/soong/bp2build.

Test: inspect out/soong/build.ninja.d manually
Fixes: 179452534

Change-Id: Iad80c381b3afa38a4d4fafca035e46aa2a1f206a
This commit is contained in:
Jingwen Chen 2021-02-05 01:28:44 -05:00
parent 53b2427fc9
commit 7dcc4fcc68
1 changed files with 16 additions and 4 deletions

View File

@ -100,7 +100,7 @@ func main() {
if bazelConversionRequested(configuration) {
// Run the alternate pipeline of bp2build mutators and singleton to convert Blueprint to BUILD files
// before everything else.
runBp2Build(configuration, extraNinjaDeps)
runBp2Build(srcDir, configuration)
// Short-circuit and return.
return
}
@ -162,7 +162,7 @@ func main() {
// Run Soong in the bp2build mode. This creates a standalone context that registers
// an alternate pipeline of mutators and singletons specifically for generating
// Bazel BUILD files instead of Ninja files.
func runBp2Build(configuration android.Config, extraNinjaDeps []string) {
func runBp2Build(srcDir string, configuration android.Config) {
// Register an alternate set of singletons and mutators for bazel
// conversion for Bazel conversion.
bp2buildCtx := android.NewContext(configuration)
@ -172,7 +172,20 @@ func runBp2Build(configuration android.Config, extraNinjaDeps []string) {
configuration.SetStopBefore(bootstrap.StopBeforePrepareBuildActions)
bp2buildCtx.SetNameInterface(newNameResolver(configuration))
// Run the loading and analysis pipeline.
// The bp2build process is a purely functional process that only depends on
// Android.bp files. It must not depend on the values of per-build product
// configurations or variables, since those will generate different BUILD
// files based on how the user has configured their tree.
bp2buildCtx.SetModuleListFile(bootstrap.ModuleListFile)
extraNinjaDeps, err := bp2buildCtx.ListModulePaths(srcDir)
if err != nil {
panic(err)
}
extraNinjaDepsString := strings.Join(extraNinjaDeps, " \\\n ")
// 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.
bootstrap.Main(bp2buildCtx.Context, configuration, extraNinjaDeps...)
// Run the code-generation phase to convert BazelTargetModules to BUILD files.
@ -195,7 +208,6 @@ func runBp2Build(configuration android.Config, extraNinjaDeps []string) {
ninjaFileName := "build.ninja"
ninjaFile := android.PathForOutput(codegenContext, ninjaFileName)
ninjaFileD := android.PathForOutput(codegenContext, ninjaFileName+".d")
extraNinjaDepsString := strings.Join(extraNinjaDeps, " \\\n ")
// A workaround to create the 'nothing' ninja target so `m nothing` works,
// since bp2build runs without Kati, and the 'nothing' target is declared in
// a Makefile.