Make Config.ProductVariables private

All access to these should be going through the methods on Config /
DeviceConfig.

Bug: 76168832
Test: m blueprint_tools
Change-Id: I47512dd58fb1a1a3f25838a9b1adaed2c41af8d3
This commit is contained in:
Dan Willemsen 2018-03-09 21:22:06 -08:00
parent 674dc7f7f0
commit 45133ac184
6 changed files with 73 additions and 73 deletions

View file

@ -72,7 +72,7 @@ func (c *androidMkSingleton) GenerateBuildActions(ctx SingletonContext) {
sort.Sort(AndroidModulesByName{androidMkModulesList, ctx}) sort.Sort(AndroidModulesByName{androidMkModulesList, ctx})
transMk := PathForOutput(ctx, "Android"+String(ctx.Config().ProductVariables.Make_suffix)+".mk") transMk := PathForOutput(ctx, "Android"+String(ctx.Config().productVariables.Make_suffix)+".mk")
if ctx.Failed() { if ctx.Failed() {
return return
} }

View file

@ -821,7 +821,7 @@ func forEachInterface(v reflect.Value, f func(reflect.Value)) {
// Convert the arch product variables into a list of targets for each os class structs // Convert the arch product variables into a list of targets for each os class structs
func decodeTargetProductVariables(config *config) (map[OsClass][]Target, error) { func decodeTargetProductVariables(config *config) (map[OsClass][]Target, error) {
variables := config.ProductVariables variables := config.productVariables
targets := make(map[OsClass][]Target) targets := make(map[OsClass][]Target)
var targetErr error var targetErr error

View file

@ -67,7 +67,7 @@ type DeviceConfig struct {
type config struct { type config struct {
FileConfigurableOptions FileConfigurableOptions
ProductVariables productVariables productVariables productVariables
// Only available on configs created by TestConfig // Only available on configs created by TestConfig
TestProductVariables *productVariables TestProductVariables *productVariables
@ -117,7 +117,7 @@ func loadConfig(config *config) error {
return err return err
} }
return loadFromConfigFile(&config.ProductVariables, config.ProductVariablesFileName) return loadFromConfigFile(&config.productVariables, config.ProductVariablesFileName)
} }
// loads configuration options from a JSON file in the cwd. // loads configuration options from a JSON file in the cwd.
@ -184,7 +184,7 @@ func saveToConfigFile(config jsonConfigurable, filename string) error {
// TestConfig returns a Config object suitable for using for tests // TestConfig returns a Config object suitable for using for tests
func TestConfig(buildDir string, env map[string]string) Config { func TestConfig(buildDir string, env map[string]string) Config {
config := &config{ config := &config{
ProductVariables: productVariables{ productVariables: productVariables{
DeviceName: stringPtr("test_device"), DeviceName: stringPtr("test_device"),
Platform_sdk_version: intPtr(26), Platform_sdk_version: intPtr(26),
AAPTConfig: &[]string{"normal", "large", "xlarge", "hdpi", "xhdpi", "xxhdpi"}, AAPTConfig: &[]string{"normal", "large", "xlarge", "hdpi", "xhdpi", "xxhdpi"},
@ -200,7 +200,7 @@ func TestConfig(buildDir string, env map[string]string) Config {
config.deviceConfig = &deviceConfig{ config.deviceConfig = &deviceConfig{
config: config, config: config,
} }
config.TestProductVariables = &config.ProductVariables config.TestProductVariables = &config.productVariables
if err := config.fromEnv(); err != nil { if err := config.fromEnv(); err != nil {
panic(err) panic(err)
@ -432,28 +432,28 @@ func (c *config) EmbeddedInMake() bool {
} }
func (c *config) BuildId() string { func (c *config) BuildId() string {
return String(c.ProductVariables.BuildId) return String(c.productVariables.BuildId)
} }
func (c *config) BuildNumberFromFile() string { func (c *config) BuildNumberFromFile() string {
return String(c.ProductVariables.BuildNumberFromFile) return String(c.productVariables.BuildNumberFromFile)
} }
// DeviceName returns the name of the current device target // DeviceName returns the name of the current device target
// TODO: take an AndroidModuleContext to select the device name for multi-device builds // TODO: take an AndroidModuleContext to select the device name for multi-device builds
func (c *config) DeviceName() string { func (c *config) DeviceName() string {
return *c.ProductVariables.DeviceName return *c.productVariables.DeviceName
} }
func (c *config) ResourceOverlays() []string { func (c *config) ResourceOverlays() []string {
if c.ProductVariables.ResourceOverlays == nil { if c.productVariables.ResourceOverlays == nil {
return nil return nil
} }
return *c.ProductVariables.ResourceOverlays return *c.productVariables.ResourceOverlays
} }
func (c *config) PlatformSdkVersionInt() int { func (c *config) PlatformSdkVersionInt() int {
return *c.ProductVariables.Platform_sdk_version return *c.productVariables.Platform_sdk_version
} }
func (c *config) PlatformSdkVersion() string { func (c *config) PlatformSdkVersion() string {
@ -465,7 +465,7 @@ func (c *config) MinSupportedSdkVersion() int {
} }
func (c *config) DefaultAppTargetSdkInt() int { func (c *config) DefaultAppTargetSdkInt() int {
if Bool(c.ProductVariables.Platform_sdk_final) { if Bool(c.productVariables.Platform_sdk_final) {
return c.PlatformSdkVersionInt() return c.PlatformSdkVersionInt()
} else { } else {
return FutureApiLevel return FutureApiLevel
@ -473,18 +473,18 @@ func (c *config) DefaultAppTargetSdkInt() int {
} }
func (c *config) AppsDefaultVersionName() string { func (c *config) AppsDefaultVersionName() string {
return String(c.ProductVariables.AppsDefaultVersionName) return String(c.productVariables.AppsDefaultVersionName)
} }
// Codenames that are active in the current lunch target. // Codenames that are active in the current lunch target.
func (c *config) PlatformVersionActiveCodenames() []string { func (c *config) PlatformVersionActiveCodenames() []string {
return c.ProductVariables.Platform_version_active_codenames return c.productVariables.Platform_version_active_codenames
} }
// Codenames that are available in the branch but not included in the current // Codenames that are available in the branch but not included in the current
// lunch target. // lunch target.
func (c *config) PlatformVersionFutureCodenames() []string { func (c *config) PlatformVersionFutureCodenames() []string {
return c.ProductVariables.Platform_version_future_codenames return c.productVariables.Platform_version_future_codenames
} }
// All possible codenames in the current branch. NB: Not named AllCodenames // All possible codenames in the current branch. NB: Not named AllCodenames
@ -498,23 +498,23 @@ func (c *config) PlatformVersionCombinedCodenames() []string {
} }
func (c *config) ProductAAPTConfig() []string { func (c *config) ProductAAPTConfig() []string {
return stringSlice(c.ProductVariables.AAPTConfig) return stringSlice(c.productVariables.AAPTConfig)
} }
func (c *config) ProductAAPTPreferredConfig() string { func (c *config) ProductAAPTPreferredConfig() string {
return String(c.ProductVariables.AAPTPreferredConfig) return String(c.productVariables.AAPTPreferredConfig)
} }
func (c *config) ProductAAPTCharacteristics() string { func (c *config) ProductAAPTCharacteristics() string {
return String(c.ProductVariables.AAPTCharacteristics) return String(c.productVariables.AAPTCharacteristics)
} }
func (c *config) ProductAAPTPrebuiltDPI() []string { func (c *config) ProductAAPTPrebuiltDPI() []string {
return stringSlice(c.ProductVariables.AAPTPrebuiltDPI) return stringSlice(c.productVariables.AAPTPrebuiltDPI)
} }
func (c *config) DefaultAppCertificateDir(ctx PathContext) SourcePath { func (c *config) DefaultAppCertificateDir(ctx PathContext) SourcePath {
defaultCert := String(c.ProductVariables.DefaultAppCertificate) defaultCert := String(c.productVariables.DefaultAppCertificate)
if defaultCert != "" { if defaultCert != "" {
return PathForSource(ctx, filepath.Dir(defaultCert)) return PathForSource(ctx, filepath.Dir(defaultCert))
} else { } else {
@ -523,7 +523,7 @@ func (c *config) DefaultAppCertificateDir(ctx PathContext) SourcePath {
} }
func (c *config) DefaultAppCertificate(ctx PathContext) (pem, key SourcePath) { func (c *config) DefaultAppCertificate(ctx PathContext) (pem, key SourcePath) {
defaultCert := String(c.ProductVariables.DefaultAppCertificate) defaultCert := String(c.productVariables.DefaultAppCertificate)
if defaultCert != "" { if defaultCert != "" {
return PathForSource(ctx, defaultCert+".x509.pem"), PathForSource(ctx, defaultCert+".pk8") return PathForSource(ctx, defaultCert+".x509.pem"), PathForSource(ctx, defaultCert+".pk8")
} else { } else {
@ -533,23 +533,23 @@ func (c *config) DefaultAppCertificate(ctx PathContext) (pem, key SourcePath) {
} }
func (c *config) AllowMissingDependencies() bool { func (c *config) AllowMissingDependencies() bool {
return Bool(c.ProductVariables.Allow_missing_dependencies) return Bool(c.productVariables.Allow_missing_dependencies)
} }
func (c *config) UnbundledBuild() bool { func (c *config) UnbundledBuild() bool {
return Bool(c.ProductVariables.Unbundled_build) return Bool(c.productVariables.Unbundled_build)
} }
func (c *config) IsPdkBuild() bool { func (c *config) IsPdkBuild() bool {
return Bool(c.ProductVariables.Pdk) return Bool(c.productVariables.Pdk)
} }
func (c *config) MinimizeJavaDebugInfo() bool { func (c *config) MinimizeJavaDebugInfo() bool {
return Bool(c.ProductVariables.MinimizeJavaDebugInfo) && !Bool(c.ProductVariables.Eng) return Bool(c.productVariables.MinimizeJavaDebugInfo) && !Bool(c.productVariables.Eng)
} }
func (c *config) DevicePrefer32BitExecutables() bool { func (c *config) DevicePrefer32BitExecutables() bool {
return Bool(c.ProductVariables.DevicePrefer32BitExecutables) return Bool(c.productVariables.DevicePrefer32BitExecutables)
} }
func (c *config) SkipDeviceInstall() bool { func (c *config) SkipDeviceInstall() bool {
@ -562,26 +562,26 @@ func (c *config) SkipMegaDeviceInstall(path string) bool {
} }
func (c *config) SanitizeHost() []string { func (c *config) SanitizeHost() []string {
return append([]string(nil), c.ProductVariables.SanitizeHost...) return append([]string(nil), c.productVariables.SanitizeHost...)
} }
func (c *config) SanitizeDevice() []string { func (c *config) SanitizeDevice() []string {
return append([]string(nil), c.ProductVariables.SanitizeDevice...) return append([]string(nil), c.productVariables.SanitizeDevice...)
} }
func (c *config) SanitizeDeviceDiag() []string { func (c *config) SanitizeDeviceDiag() []string {
return append([]string(nil), c.ProductVariables.SanitizeDeviceDiag...) return append([]string(nil), c.productVariables.SanitizeDeviceDiag...)
} }
func (c *config) SanitizeDeviceArch() []string { func (c *config) SanitizeDeviceArch() []string {
return append([]string(nil), c.ProductVariables.SanitizeDeviceArch...) return append([]string(nil), c.productVariables.SanitizeDeviceArch...)
} }
func (c *config) EnableCFI() bool { func (c *config) EnableCFI() bool {
if c.ProductVariables.EnableCFI == nil { if c.productVariables.EnableCFI == nil {
return true return true
} else { } else {
return *c.ProductVariables.EnableCFI return *c.productVariables.EnableCFI
} }
} }
@ -600,7 +600,7 @@ func (c *config) UseD8Desugar() bool {
} }
func (c *config) UseGoma() bool { func (c *config) UseGoma() bool {
return Bool(c.ProductVariables.UseGoma) return Bool(c.productVariables.UseGoma)
} }
// Returns true if OpenJDK9 prebuilts are being used // Returns true if OpenJDK9 prebuilts are being used
@ -614,14 +614,14 @@ func (c *config) TargetOpenJDK9() bool {
} }
func (c *config) ClangTidy() bool { func (c *config) ClangTidy() bool {
return Bool(c.ProductVariables.ClangTidy) return Bool(c.productVariables.ClangTidy)
} }
func (c *config) TidyChecks() string { func (c *config) TidyChecks() string {
if c.ProductVariables.TidyChecks == nil { if c.productVariables.TidyChecks == nil {
return "" return ""
} }
return *c.ProductVariables.TidyChecks return *c.productVariables.TidyChecks
} }
func (c *config) LibartImgHostBaseAddress() string { func (c *config) LibartImgHostBaseAddress() string {
@ -642,11 +642,11 @@ func (c *config) LibartImgDeviceBaseAddress() string {
} }
func (c *config) ArtUseReadBarrier() bool { func (c *config) ArtUseReadBarrier() bool {
return Bool(c.ProductVariables.ArtUseReadBarrier) return Bool(c.productVariables.ArtUseReadBarrier)
} }
func (c *config) EnforceRROForModule(name string) bool { func (c *config) EnforceRROForModule(name string) bool {
enforceList := c.ProductVariables.EnforceRROTargets enforceList := c.productVariables.EnforceRROTargets
if enforceList != nil { if enforceList != nil {
if len(*enforceList) == 1 && (*enforceList)[0] == "*" { if len(*enforceList) == 1 && (*enforceList)[0] == "*" {
return true return true
@ -657,7 +657,7 @@ func (c *config) EnforceRROForModule(name string) bool {
} }
func (c *config) EnforceRROExcludedOverlay(path string) bool { func (c *config) EnforceRROExcludedOverlay(path string) bool {
excluded := c.ProductVariables.EnforceRROExcludedOverlays excluded := c.productVariables.EnforceRROExcludedOverlays
if excluded != nil { if excluded != nil {
for _, exclude := range *excluded { for _, exclude := range *excluded {
if strings.HasPrefix(path, exclude) { if strings.HasPrefix(path, exclude) {
@ -669,11 +669,11 @@ func (c *config) EnforceRROExcludedOverlay(path string) bool {
} }
func (c *config) ExportedNamespaces() []string { func (c *config) ExportedNamespaces() []string {
return append([]string(nil), c.ProductVariables.NamespacesToExport...) return append([]string(nil), c.productVariables.NamespacesToExport...)
} }
func (c *config) HostStaticBinaries() bool { func (c *config) HostStaticBinaries() bool {
return Bool(c.ProductVariables.HostStaticBinaries) return Bool(c.productVariables.HostStaticBinaries)
} }
func (c *deviceConfig) Arches() []Arch { func (c *deviceConfig) Arches() []Arch {
@ -685,7 +685,7 @@ func (c *deviceConfig) Arches() []Arch {
} }
func (c *deviceConfig) BinderBitness() string { func (c *deviceConfig) BinderBitness() string {
is32BitBinder := c.config.ProductVariables.Binder32bit is32BitBinder := c.config.productVariables.Binder32bit
if is32BitBinder != nil && *is32BitBinder { if is32BitBinder != nil && *is32BitBinder {
return "32" return "32"
} }
@ -693,70 +693,70 @@ func (c *deviceConfig) BinderBitness() string {
} }
func (c *deviceConfig) VendorPath() string { func (c *deviceConfig) VendorPath() string {
if c.config.ProductVariables.VendorPath != nil { if c.config.productVariables.VendorPath != nil {
return *c.config.ProductVariables.VendorPath return *c.config.productVariables.VendorPath
} }
return "vendor" return "vendor"
} }
func (c *deviceConfig) VndkVersion() string { func (c *deviceConfig) VndkVersion() string {
return String(c.config.ProductVariables.DeviceVndkVersion) return String(c.config.productVariables.DeviceVndkVersion)
} }
func (c *deviceConfig) PlatformVndkVersion() string { func (c *deviceConfig) PlatformVndkVersion() string {
return String(c.config.ProductVariables.Platform_vndk_version) return String(c.config.productVariables.Platform_vndk_version)
} }
func (c *deviceConfig) ExtraVndkVersions() []string { func (c *deviceConfig) ExtraVndkVersions() []string {
return c.config.ProductVariables.ExtraVndkVersions return c.config.productVariables.ExtraVndkVersions
} }
func (c *deviceConfig) SystemSdkVersions() []string { func (c *deviceConfig) SystemSdkVersions() []string {
if c.config.ProductVariables.DeviceSystemSdkVersions == nil { if c.config.productVariables.DeviceSystemSdkVersions == nil {
return nil return nil
} }
return *c.config.ProductVariables.DeviceSystemSdkVersions return *c.config.productVariables.DeviceSystemSdkVersions
} }
func (c *deviceConfig) PlatformSystemSdkVersions() []string { func (c *deviceConfig) PlatformSystemSdkVersions() []string {
return c.config.ProductVariables.Platform_systemsdk_versions return c.config.productVariables.Platform_systemsdk_versions
} }
func (c *deviceConfig) OdmPath() string { func (c *deviceConfig) OdmPath() string {
if c.config.ProductVariables.OdmPath != nil { if c.config.productVariables.OdmPath != nil {
return *c.config.ProductVariables.OdmPath return *c.config.productVariables.OdmPath
} }
return "odm" return "odm"
} }
func (c *deviceConfig) ProductPath() string { func (c *deviceConfig) ProductPath() string {
if c.config.ProductVariables.ProductPath != nil { if c.config.productVariables.ProductPath != nil {
return *c.config.ProductVariables.ProductPath return *c.config.productVariables.ProductPath
} }
return "product" return "product"
} }
func (c *deviceConfig) BtConfigIncludeDir() string { func (c *deviceConfig) BtConfigIncludeDir() string {
return String(c.config.ProductVariables.BtConfigIncludeDir) return String(c.config.productVariables.BtConfigIncludeDir)
} }
func (c *deviceConfig) DeviceKernelHeaderDirs() []string { func (c *deviceConfig) DeviceKernelHeaderDirs() []string {
return c.config.ProductVariables.DeviceKernelHeaders return c.config.productVariables.DeviceKernelHeaders
} }
func (c *deviceConfig) NativeCoverageEnabled() bool { func (c *deviceConfig) NativeCoverageEnabled() bool {
return Bool(c.config.ProductVariables.NativeCoverage) return Bool(c.config.productVariables.NativeCoverage)
} }
func (c *deviceConfig) CoverageEnabledForPath(path string) bool { func (c *deviceConfig) CoverageEnabledForPath(path string) bool {
coverage := false coverage := false
if c.config.ProductVariables.CoveragePaths != nil { if c.config.productVariables.CoveragePaths != nil {
if PrefixInList(path, *c.config.ProductVariables.CoveragePaths) { if PrefixInList(path, *c.config.productVariables.CoveragePaths) {
coverage = true coverage = true
} }
} }
if coverage && c.config.ProductVariables.CoverageExcludePaths != nil { if coverage && c.config.productVariables.CoverageExcludePaths != nil {
if PrefixInList(path, *c.config.ProductVariables.CoverageExcludePaths) { if PrefixInList(path, *c.config.productVariables.CoverageExcludePaths) {
coverage = false coverage = false
} }
} }
@ -764,28 +764,28 @@ func (c *deviceConfig) CoverageEnabledForPath(path string) bool {
} }
func (c *deviceConfig) PgoAdditionalProfileDirs() []string { func (c *deviceConfig) PgoAdditionalProfileDirs() []string {
return c.config.ProductVariables.PgoAdditionalProfileDirs return c.config.productVariables.PgoAdditionalProfileDirs
} }
func (c *config) IntegerOverflowDisabledForPath(path string) bool { func (c *config) IntegerOverflowDisabledForPath(path string) bool {
if c.ProductVariables.IntegerOverflowExcludePaths == nil { if c.productVariables.IntegerOverflowExcludePaths == nil {
return false return false
} }
return PrefixInList(path, *c.ProductVariables.IntegerOverflowExcludePaths) return PrefixInList(path, *c.productVariables.IntegerOverflowExcludePaths)
} }
func (c *config) CFIDisabledForPath(path string) bool { func (c *config) CFIDisabledForPath(path string) bool {
if c.ProductVariables.CFIExcludePaths == nil { if c.productVariables.CFIExcludePaths == nil {
return false return false
} }
return PrefixInList(path, *c.ProductVariables.CFIExcludePaths) return PrefixInList(path, *c.productVariables.CFIExcludePaths)
} }
func (c *config) CFIEnabledForPath(path string) bool { func (c *config) CFIEnabledForPath(path string) bool {
if c.ProductVariables.CFIIncludePaths == nil { if c.productVariables.CFIIncludePaths == nil {
return false return false
} }
return PrefixInList(path, *c.ProductVariables.CFIIncludePaths) return PrefixInList(path, *c.productVariables.CFIIncludePaths)
} }
func stringSlice(s *[]string) []string { func stringSlice(s *[]string) []string {

View file

@ -111,7 +111,7 @@ func (s *makeVarsSingleton) GenerateBuildActions(ctx SingletonContext) {
return return
} }
outFile := PathForOutput(ctx, "make_vars"+proptools.String(ctx.Config().ProductVariables.Make_suffix)+".mk").String() outFile := PathForOutput(ctx, "make_vars"+proptools.String(ctx.Config().productVariables.Make_suffix)+".mk").String()
if ctx.Failed() { if ctx.Failed() {
return return

View file

@ -719,14 +719,14 @@ func PathForDist(ctx PathContext, pathComponents ...string) DistPath {
func (p DistPath) writablePath() {} func (p DistPath) writablePath() {}
func (p DistPath) Valid() bool { func (p DistPath) Valid() bool {
return p.config.ProductVariables.DistDir != nil && *p.config.ProductVariables.DistDir != "" return p.config.productVariables.DistDir != nil && *p.config.productVariables.DistDir != ""
} }
func (p DistPath) String() string { func (p DistPath) String() string {
if !p.Valid() { if !p.Valid() {
panic("Requesting an invalid path") panic("Requesting an invalid path")
} }
return filepath.Join(*p.config.ProductVariables.DistDir, p.path) return filepath.Join(*p.config.productVariables.DistDir, p.path)
} }
func (p DistPath) RelPathString() string { func (p DistPath) RelPathString() string {

View file

@ -272,7 +272,7 @@ func variableMutator(mctx BottomUpMutatorContext) {
property := "product_variables." + proptools.PropertyNameForField(name) property := "product_variables." + proptools.PropertyNameForField(name)
// Check that the variable was set for the product // Check that the variable was set for the product
val := reflect.ValueOf(mctx.Config().ProductVariables).FieldByName(name) val := reflect.ValueOf(mctx.Config().productVariables).FieldByName(name)
if !val.IsValid() || val.Kind() != reflect.Ptr || val.IsNil() { if !val.IsValid() || val.Kind() != reflect.Ptr || val.IsNil() {
continue continue
} }