Use Config/DeviceConfig functions to access ProductVariables
An upcoming change will stop exporting ProductVariables from Config, so
switch to using existing accessor functions, and add more when they're
missing.
Bug: 76168832
Test: out/soong/build.ninja is identical
Change-Id: Ie0135bdbd2df3258ef3ddb53e5f8fc00aa9b97f7
diff --git a/android/config.go b/android/config.go
index db833ec..e14f42e 100644
--- a/android/config.go
+++ b/android/config.go
@@ -641,6 +641,37 @@
return Bool(c.ProductVariables.ArtUseReadBarrier)
}
+func (c *config) EnforceRROForModule(name string) bool {
+ enforceList := c.ProductVariables.EnforceRROTargets
+ if enforceList != nil {
+ if len(*enforceList) == 1 && (*enforceList)[0] == "*" {
+ return true
+ }
+ return InList(name, *enforceList)
+ }
+ return false
+}
+
+func (c *config) EnforceRROExcludedOverlay(path string) bool {
+ excluded := c.ProductVariables.EnforceRROExcludedOverlays
+ if excluded != nil {
+ for _, exclude := range *excluded {
+ if strings.HasPrefix(path, exclude) {
+ return true
+ }
+ }
+ }
+ return false
+}
+
+func (c *config) ExportedNamespaces() []string {
+ return append([]string(nil), c.ProductVariables.NamespacesToExport...)
+}
+
+func (c *config) HostStaticBinaries() bool {
+ return Bool(c.ProductVariables.HostStaticBinaries)
+}
+
func (c *deviceConfig) Arches() []Arch {
var arches []Arch
for _, target := range c.config.Targets[Device] {
diff --git a/android/makevars.go b/android/makevars.go
index b6cd571..3792357 100644
--- a/android/makevars.go
+++ b/android/makevars.go
@@ -36,6 +36,7 @@
// Interface for other packages to use to declare make variables
type MakeVarsContext interface {
Config() Config
+ DeviceConfig() DeviceConfig
SingletonContext() SingletonContext
// Verify the make variable matches the Soong version, fail the build
@@ -231,6 +232,10 @@
return c.config
}
+func (c *makeVarsContext) DeviceConfig() DeviceConfig {
+ return DeviceConfig{c.config.deviceConfig}
+}
+
func (c *makeVarsContext) SingletonContext() SingletonContext {
return c.ctx
}
diff --git a/cc/binary.go b/cc/binary.go
index c3e899a..9e7b70b 100644
--- a/cc/binary.go
+++ b/cc/binary.go
@@ -192,7 +192,7 @@
if !ctx.toolchain().Bionic() {
if ctx.Os() == android.Linux {
- if binary.Properties.Static_executable == nil && Bool(ctx.Config().ProductVariables.HostStaticBinaries) {
+ if binary.Properties.Static_executable == nil && ctx.Config().HostStaticBinaries() {
binary.Properties.Static_executable = BoolPtr(true)
}
} else {
diff --git a/cc/makevars.go b/cc/makevars.go
index 2664ee1..83a662f 100644
--- a/cc/makevars.go
+++ b/cc/makevars.go
@@ -89,11 +89,7 @@
ctx.Strict("GLOBAL_CLANG_CPPFLAGS_NO_OVERRIDE", "")
ctx.Strict("NDK_PREBUILT_SHARED_LIBRARIES", strings.Join(ndkPrebuiltSharedLibs, " "))
- if ctx.Config().ProductVariables.DeviceVndkVersion != nil {
- ctx.Strict("BOARD_VNDK_VERSION", *ctx.Config().ProductVariables.DeviceVndkVersion)
- } else {
- ctx.Strict("BOARD_VNDK_VERSION", "")
- }
+ ctx.Strict("BOARD_VNDK_VERSION", ctx.DeviceConfig().VndkVersion())
ctx.Strict("VNDK_CORE_LIBRARIES", strings.Join(vndkCoreLibraries, " "))
ctx.Strict("VNDK_SAMEPROCESS_LIBRARIES", strings.Join(vndkSpLibraries, " "))
@@ -211,7 +207,7 @@
hod = "Device"
}
- if target.Os.Class == android.Host && Bool(ctx.Config().ProductVariables.HostStaticBinaries) {
+ if target.Os.Class == android.Host && ctx.Config().HostStaticBinaries() {
productExtraLdflags += "-static"
}
diff --git a/cmd/soong_build/main.go b/cmd/soong_build/main.go
index 40beab8..a4c6898 100644
--- a/cmd/soong_build/main.go
+++ b/cmd/soong_build/main.go
@@ -36,7 +36,7 @@
func newNameResolver(config android.Config) *android.NameResolver {
namespacePathsToExport := make(map[string]bool)
- for _, namespaceName := range config.ProductVariables.NamespacesToExport {
+ for _, namespaceName := range config.ExportedNamespaces() {
namespacePathsToExport[namespaceName] = true
}
diff --git a/java/app.go b/java/app.go
index ac88df7..c94d22f 100644
--- a/java/app.go
+++ b/java/app.go
@@ -362,15 +362,7 @@
overlayData := ctx.Config().Get(overlayDataKey).([]overlayGlobResult)
// Runtime resource overlays (RRO) may be turned on by the product config for some modules
- rroEnabled := false
- enforceRROTargets := ctx.Config().ProductVariables.EnforceRROTargets
- if enforceRROTargets != nil {
- if len(*enforceRROTargets) == 1 && (*enforceRROTargets)[0] == "*" {
- rroEnabled = true
- } else if inList(ctx.ModuleName(), *enforceRROTargets) {
- rroEnabled = true
- }
- }
+ rroEnabled := ctx.Config().EnforceRROForModule(ctx.ModuleName())
for _, data := range overlayData {
files := data.paths.PathsInDirectory(filepath.Join(data.dir, dir.String()))
@@ -400,13 +392,6 @@
type overlaySingleton struct{}
func (overlaySingleton) GenerateBuildActions(ctx android.SingletonContext) {
-
- // Specific overlays may be excluded from Runtime Resource Overlays by the product config
- var rroExcludedOverlays []string
- if ctx.Config().ProductVariables.EnforceRROExcludedOverlays != nil {
- rroExcludedOverlays = *ctx.Config().ProductVariables.EnforceRROExcludedOverlays
- }
-
var overlayData []overlayGlobResult
overlayDirs := ctx.Config().ResourceOverlays()
for i := range overlayDirs {
@@ -417,11 +402,8 @@
result.dir = overlay
// Mark overlays that will not have Runtime Resource Overlays enforced on them
- for _, exclude := range rroExcludedOverlays {
- if strings.HasPrefix(overlay, exclude) {
- result.excludeFromRRO = true
- }
- }
+ // based on the product config
+ result.excludeFromRRO = ctx.Config().EnforceRROExcludedOverlay(overlay)
files, err := ctx.GlobWithDeps(filepath.Join(overlay, "**/*"), aaptIgnoreFilenames)
if err != nil {