From 98a7329d59a4b47040f25f2b4373fda891c60d32 Mon Sep 17 00:00:00 2001 From: Sam Delmerico Date: Tue, 21 Feb 2023 11:50:29 -0500 Subject: [PATCH] support PRODUCT_SOURCE_ROOT_DIRS product variable Soong analyzes the entire source tree even though not every lunch target needs to know about every module. For example, OEM sources can be ignored for cuttlefish products. This functionality allows blueprint to ignore a list of undesired directories. Bug: 269457150 Change-Id: I1eec5d7b6a268cae4c633d8d89ed485598ebca45 --- android/config.go | 4 ++++ android/namespace.go | 6 +++++- android/register.go | 1 + android/variable.go | 3 ++- cmd/soong_build/main.go | 1 + ui/build/config.go | 11 ++++++++++- ui/build/dumpvars.go | 2 ++ ui/build/soong.go | 1 + 8 files changed, 26 insertions(+), 3 deletions(-) diff --git a/android/config.go b/android/config.go index e0b661bb7..9d530919e 100644 --- a/android/config.go +++ b/android/config.go @@ -1179,6 +1179,10 @@ func (c *config) ExportedNamespaces() []string { return append([]string(nil), c.productVariables.NamespacesToExport...) } +func (c *config) SourceRootDirs() []string { + return c.productVariables.SourceRootDirs +} + func (c *config) IncludeTags() []string { return c.productVariables.IncludeTags } diff --git a/android/namespace.go b/android/namespace.go index b43ffdf19..f357ca7b7 100644 --- a/android/namespace.go +++ b/android/namespace.go @@ -225,6 +225,10 @@ func (r *NameResolver) NewModule(ctx blueprint.NamespaceContext, moduleGroup blu return ns, nil } +func (r *NameResolver) NewSkippedModule(ctx blueprint.NamespaceContext, name string, skipInfo blueprint.SkippedModuleInfo) { + r.rootNamespace.moduleContainer.NewSkippedModule(ctx, name, skipInfo) +} + func (r *NameResolver) AllModules() []blueprint.ModuleGroup { childLists := [][]blueprint.ModuleGroup{} totalCount := 0 @@ -300,7 +304,7 @@ func (r *NameResolver) FindNamespaceImports(namespace *Namespace) (err error) { for _, name := range namespace.importedNamespaceNames { imp, ok := r.namespaceAt(name) if !ok { - return fmt.Errorf("namespace %v does not exist", name) + return fmt.Errorf("namespace %v does not exist; Some necessary modules may have been skipped by Soong. Check if PRODUCT_SOURCE_ROOT_DIRS is pruning necessary Android.bp files.", name) } namespace.visibleNamespaces = append(namespace.visibleNamespaces, imp) } diff --git a/android/register.go b/android/register.go index 9a3d3aa9c..1a3db9d90 100644 --- a/android/register.go +++ b/android/register.go @@ -162,6 +162,7 @@ func NewContext(config Config) *Context { ctx := &Context{blueprint.NewContext(), config} ctx.SetSrcDir(absSrcDir) ctx.AddIncludeTags(config.IncludeTags()...) + ctx.AddSourceRootDirs(config.SourceRootDirs()...) return ctx } diff --git a/android/variable.go b/android/variable.go index 8c5c0bc03..04cc2051b 100644 --- a/android/variable.go +++ b/android/variable.go @@ -461,7 +461,8 @@ type productVariables struct { IgnorePrefer32OnDevice bool `json:",omitempty"` - IncludeTags []string `json:",omitempty"` + IncludeTags []string `json:",omitempty"` + SourceRootDirs []string `json:",omitempty"` } func boolPtr(v bool) *bool { diff --git a/cmd/soong_build/main.go b/cmd/soong_build/main.go index 3a4d71aaf..8a42aa6ca 100644 --- a/cmd/soong_build/main.go +++ b/cmd/soong_build/main.go @@ -104,6 +104,7 @@ func newContext(configuration android.Config) *android.Context { ctx.SetNameInterface(newNameResolver(configuration)) ctx.SetAllowMissingDependencies(configuration.AllowMissingDependencies()) ctx.AddIncludeTags(configuration.IncludeTags()...) + ctx.AddSourceRootDirs(configuration.SourceRootDirs()...) return ctx } diff --git a/ui/build/config.go b/ui/build/config.go index 20cc9fb29..9e02cd6a0 100644 --- a/ui/build/config.go +++ b/ui/build/config.go @@ -117,7 +117,8 @@ type configImpl struct { bazelForceEnabledModules string - includeTags []string + includeTags []string + sourceRootDirs []string // Data source to write ninja weight list ninjaWeightListSource NinjaWeightListSource @@ -1185,6 +1186,14 @@ func (c *configImpl) Parallel() int { return c.parallel } +func (c *configImpl) GetSourceRootDirs() []string { + return c.sourceRootDirs +} + +func (c *configImpl) SetSourceRootDirs(i []string) { + c.sourceRootDirs = i +} + func (c *configImpl) GetIncludeTags() []string { return c.includeTags } diff --git a/ui/build/dumpvars.go b/ui/build/dumpvars.go index a9c298f57..efe747819 100644 --- a/ui/build/dumpvars.go +++ b/ui/build/dumpvars.go @@ -148,6 +148,7 @@ var BannerVars = []string{ "PLATFORM_VERSION_CODENAME", "PLATFORM_VERSION", "PRODUCT_INCLUDE_TAGS", + "PRODUCT_SOURCE_ROOT_DIRS", "TARGET_PRODUCT", "TARGET_BUILD_VARIANT", "TARGET_BUILD_APPS", @@ -299,4 +300,5 @@ func runMakeProductConfig(ctx Context, config Config) { config.SetBuildBrokenUsesNetwork(makeVars["BUILD_BROKEN_USES_NETWORK"] == "true") config.SetBuildBrokenNinjaUsesEnvVars(strings.Fields(makeVars["BUILD_BROKEN_NINJA_USES_ENV_VARS"])) config.SetIncludeTags(strings.Fields(makeVars["PRODUCT_INCLUDE_TAGS"])) + config.SetSourceRootDirs(strings.Fields(makeVars["PRODUCT_SOURCE_ROOT_DIRS"])) } diff --git a/ui/build/soong.go b/ui/build/soong.go index 871e63785..c4c984fb7 100644 --- a/ui/build/soong.go +++ b/ui/build/soong.go @@ -410,6 +410,7 @@ func bootstrapBlueprint(ctx Context, config Config) { blueprintCtx := blueprint.NewContext() blueprintCtx.AddIncludeTags(config.GetIncludeTags()...) + blueprintCtx.AddSourceRootDirs(config.GetSourceRootDirs()...) blueprintCtx.SetIgnoreUnknownModuleTypes(true) blueprintConfig := BlueprintConfig{ soongOutDir: config.SoongOutDir(),