From 82747779baa334116d0337fb13edd1c0fdca5324 Mon Sep 17 00:00:00 2001 From: Spandan Das Date: Tue, 8 Nov 2022 18:42:16 +0000 Subject: Create a new product variable to gate blueprint files Bug: 270654958 Users can use this feature by 1. Setting PRODUCT_INCLUDE_TAGS += in their product mk files 2. Set ``` blueprint_packge_includes { match_al: [""], } other_module_type {name: foo} other_module_type {name: bar} ``` bar and foo will be included if and only if is set Test: Unit tests in blueprint Test: TH Change-Id: I32eed4e3b5ac47fb565c62d13d8881fa984c86f4 Merged-In: I32eed4e3b5ac47fb565c62d13d8881fa984c86f4 (cherry picked from commit b45fbfbabe69d368d50e149ab37da3476a431a96) --- android/config.go | 4 ++++ android/register.go | 1 + android/variable.go | 2 ++ cmd/soong_build/main.go | 1 + ui/build/config.go | 10 ++++++++++ ui/build/dumpvars.go | 2 ++ ui/build/soong.go | 1 + 7 files changed, 21 insertions(+) diff --git a/android/config.go b/android/config.go index 3c99659f9..cbf186e46 100644 --- a/android/config.go +++ b/android/config.go @@ -1093,6 +1093,10 @@ func (c *config) ExportedNamespaces() []string { return append([]string(nil), c.productVariables.NamespacesToExport...) } +func (c *config) IncludeTags() []string { + return c.productVariables.IncludeTags +} + func (c *config) HostStaticBinaries() bool { return Bool(c.productVariables.HostStaticBinaries) } diff --git a/android/register.go b/android/register.go index c50583322..a29cfeaf1 100644 --- a/android/register.go +++ b/android/register.go @@ -160,6 +160,7 @@ type Context struct { func NewContext(config Config) *Context { ctx := &Context{blueprint.NewContext(), config} ctx.SetSrcDir(absSrcDir) + ctx.AddIncludeTags(config.IncludeTags()...) return ctx } diff --git a/android/variable.go b/android/variable.go index 442068423..8d96e31cb 100644 --- a/android/variable.go +++ b/android/variable.go @@ -445,6 +445,8 @@ type productVariables struct { GenerateAidlNdkPlatformBackend bool `json:",omitempty"` ForceMultilibFirstOnDevice bool `json:",omitempty"` + + IncludeTags []string `json:",omitempty"` } func boolPtr(v bool) *bool { diff --git a/cmd/soong_build/main.go b/cmd/soong_build/main.go index 4b3161b33..f1884a795 100644 --- a/cmd/soong_build/main.go +++ b/cmd/soong_build/main.go @@ -117,6 +117,7 @@ func newContext(configuration android.Config) *android.Context { ctx.Register() ctx.SetNameInterface(newNameResolver(configuration)) ctx.SetAllowMissingDependencies(configuration.AllowMissingDependencies()) + ctx.AddIncludeTags(configuration.IncludeTags()...) return ctx } diff --git a/ui/build/config.go b/ui/build/config.go index e271bfca2..a6763214f 100644 --- a/ui/build/config.go +++ b/ui/build/config.go @@ -98,6 +98,8 @@ type configImpl struct { emptyNinjaFile bool metricsUploader string + + includeTags []string } const srcDirFileCheck = "build/soong/root.bp" @@ -1038,6 +1040,14 @@ func (c *configImpl) Parallel() int { return c.parallel } +func (c *configImpl) GetIncludeTags() []string { + return c.includeTags +} + +func (c *configImpl) SetIncludeTags(i []string) { + c.includeTags = i +} + func (c *configImpl) HighmemParallel() int { if i, ok := c.environ.GetInt("NINJA_HIGHMEM_NUM_JOBS"); ok { return i diff --git a/ui/build/dumpvars.go b/ui/build/dumpvars.go index 285f1569b..cc796ce3f 100644 --- a/ui/build/dumpvars.go +++ b/ui/build/dumpvars.go @@ -139,6 +139,7 @@ func dumpMakeVars(ctx Context, config Config, goals, vars []string, write_soong_ var BannerVars = []string{ "PLATFORM_VERSION_CODENAME", "PLATFORM_VERSION", + "PRODUCT_INCLUDE_TAGS", "TARGET_PRODUCT", "TARGET_BUILD_VARIANT", "TARGET_BUILD_TYPE", @@ -295,4 +296,5 @@ func runMakeProductConfig(ctx Context, config Config) { config.SetBuildBrokenDupRules(makeVars["BUILD_BROKEN_DUP_RULES"] == "true") 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"])) } diff --git a/ui/build/soong.go b/ui/build/soong.go index c7f22f946..a0ab1cc10 100644 --- a/ui/build/soong.go +++ b/ui/build/soong.go @@ -332,6 +332,7 @@ func bootstrapBlueprint(ctx Context, config Config) { blueprintArgs.EmptyNinjaFile = false blueprintCtx := blueprint.NewContext() + blueprintCtx.AddIncludeTags(config.GetIncludeTags()...) blueprintCtx.SetIgnoreUnknownModuleTypes(true) blueprintConfig := BlueprintConfig{ soongOutDir: config.SoongOutDir(), -- cgit v1.2.3