From 394aa32e8b10bf69414c1f326ff5ecf4007e11d1 Mon Sep 17 00:00:00 2001 From: Spandan Das Date: Thu, 3 Nov 2022 17:02:10 +0000 Subject: [PATCH] Special-case Soong finder to look in out/api_surfaces Add a new argument in soong_ui that will be used to gate this behavior. This approach is expected to solve incrementality issues in multi-tree. As part of soong's bootstrap process, all source dirs are added to deps of out/soong/build.ninja (via globs). Since multitree_build writes to the "source" api_surfaces directory, it changes its mtime and causes a recompilation of out/soong/build.ninja in the subsequent invocation. Test: TH (for single-tree) Test: Inspected ninja files (for multi-tree) (Run a full build) touch out/api_surfaces/vendorapi/libc/.../math.h orchestrator/prebuilts/build-tools/linux-x86/bin/nsjail --config out/trees/vendor_aosp_cf_arm64_phone/nsjail.cfg -- prebuilts/build-tools/linux-x86/bin/ninja -f out/soong/bootstrap.ninja -d explain -n out/soong/build.ninja (ninja: no work to do) Change-Id: Ib823163ec1153344a2f593daa8d7156c24ff5bc3 --- cmd/soong_build/main.go | 5 +++++ ui/build/config.go | 7 +++++++ ui/build/finder.go | 11 ++++++++++- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/cmd/soong_build/main.go b/cmd/soong_build/main.go index 0669f65db..7d4930dca 100644 --- a/cmd/soong_build/main.go +++ b/cmd/soong_build/main.go @@ -256,6 +256,11 @@ func runApiBp2build(configuration android.Config, extraNinjaDeps []string) strin // Exclude all src BUILD files excludes = append(excludes, apiBuildFileExcludes()...) + // Android.bp files for api surfaces are mounted to out/, but out/ should not be a + // dep for api_bp2build. + // Otherwise api_bp2build will be run every single time + excludes = append(excludes, configuration.OutDir()) + // Create the symlink forest symlinkDeps := bp2build.PlantSymlinkForest( configuration.IsEnvTrue("BP2BUILD_VERBOSE"), diff --git a/ui/build/config.go b/ui/build/config.go index 36119f0f1..dff7c4ff8 100644 --- a/ui/build/config.go +++ b/ui/build/config.go @@ -82,6 +82,7 @@ type configImpl struct { skipSoong bool skipNinja bool skipSoongTests bool + searchApiDir bool // Scan the Android.bp files generated in out/api_surfaces // From the product config katiArgs []string @@ -725,6 +726,8 @@ func (c *configImpl) parseArgs(ctx Context, args []string) { c.bazelDevMode = true } else if arg == "--bazel-mode-staging" { c.bazelStagingMode = true + } else if arg == "--search-api-dir" { + c.searchApiDir = true } else if len(arg) > 0 && arg[0] == '-' { parseArgNum := func(def int) int { if len(arg) > 2 { @@ -884,6 +887,10 @@ func (c *configImpl) SoongOutDir() string { return filepath.Join(c.OutDir(), "soong") } +func (c *configImpl) ApiSurfacesOutDir() string { + return filepath.Join(c.OutDir(), "api_surfaces") +} + func (c *configImpl) PrebuiltOS() string { switch runtime.GOOS { case "linux": diff --git a/ui/build/finder.go b/ui/build/finder.go index 4d6ad426f..3f628cf7b 100644 --- a/ui/build/finder.go +++ b/ui/build/finder.go @@ -63,7 +63,7 @@ func NewSourceFinder(ctx Context, config Config) (f *finder.Finder) { // Set up configuration parameters for the Finder cache. cacheParams := finder.CacheParams{ WorkingDirectory: dir, - RootDirs: []string{"."}, + RootDirs: androidBpSearchDirs(config), FollowSymlinks: config.environ.IsEnvTrue("ALLOW_BP_UNDER_SYMLINKS"), ExcludeDirs: []string{".git", ".repo"}, PruneFiles: pruneFiles, @@ -100,6 +100,15 @@ func NewSourceFinder(ctx Context, config Config) (f *finder.Finder) { return f } +func androidBpSearchDirs(config Config) []string { + dirs := []string{"."} // always search from root of source tree. + if config.searchApiDir { + // Search in out/api_surfaces + dirs = append(dirs, config.ApiSurfacesOutDir()) + } + return dirs +} + // Finds the list of Bazel-related files (BUILD, WORKSPACE and Starlark) in the tree. func findBazelFiles(entries finder.DirEntries) (dirNames []string, fileNames []string) { matches := []string{}