diff --git a/android/arch.go b/android/arch.go index cc70eee9c..a7a123e84 100644 --- a/android/arch.go +++ b/android/arch.go @@ -290,28 +290,6 @@ func osByName(name string) OsType { return NoOsType } -// BuildOs returns the OsType for the OS that the build is running on. -var BuildOs = func() OsType { - switch runtime.GOOS { - case "linux": - return Linux - case "darwin": - return Darwin - default: - panic(fmt.Sprintf("unsupported OS: %s", runtime.GOOS)) - } -}() - -// BuildArch returns the ArchType for the CPU that the build is running on. -var BuildArch = func() ArchType { - switch runtime.GOARCH { - case "amd64": - return X86_64 - default: - panic(fmt.Sprintf("unsupported Arch: %s", runtime.GOARCH)) - } -}() - var ( // osTypeList contains a list of all the supported OsTypes, including ones not supported // by the current build host or the target device. @@ -1397,6 +1375,31 @@ func (m *ModuleBase) setArchProperties(ctx BottomUpMutatorContext) { } } +// determineBuildOS stores the OS and architecture used for host targets used during the build into +// config based on the runtime OS and architecture determined by Go. +func determineBuildOS(config *config) { + config.BuildOS = func() OsType { + switch runtime.GOOS { + case "linux": + return Linux + case "darwin": + return Darwin + default: + panic(fmt.Sprintf("unsupported OS: %s", runtime.GOOS)) + } + }() + + config.BuildArch = func() ArchType { + switch runtime.GOARCH { + case "amd64": + return X86_64 + default: + panic(fmt.Sprintf("unsupported Arch: %s", runtime.GOARCH)) + } + }() + +} + // Convert the arch product variables into a list of targets for each OsType. func decodeTargetProductVariables(config *config) (map[OsType][]Target, error) { variables := config.productVariables @@ -1430,9 +1433,9 @@ func decodeTargetProductVariables(config *config) (map[OsType][]Target, error) { hostCross := false if os.Class == Host { var osSupported bool - if os == BuildOs { + if os == config.BuildOS { osSupported = true - } else if BuildOs.Linux() && os.Linux() { + } else if config.BuildOS.Linux() && os.Linux() { // LinuxBionic and Linux are compatible osSupported = true } else { @@ -1470,11 +1473,11 @@ func decodeTargetProductVariables(config *config) (map[OsType][]Target, error) { } // The primary host target, which must always exist. - addTarget(BuildOs, *variables.HostArch, nil, nil, nil, NativeBridgeDisabled, nil, nil) + addTarget(config.BuildOS, *variables.HostArch, nil, nil, nil, NativeBridgeDisabled, nil, nil) // An optional secondary host target. if variables.HostSecondaryArch != nil && *variables.HostSecondaryArch != "" { - addTarget(BuildOs, *variables.HostSecondaryArch, nil, nil, nil, NativeBridgeDisabled, nil, nil) + addTarget(config.BuildOS, *variables.HostSecondaryArch, nil, nil, nil, NativeBridgeDisabled, nil, nil) } // Optional cross-compiled host targets, generally Windows. diff --git a/android/config.go b/android/config.go index 396b1a66b..b9f0d1bfb 100644 --- a/android/config.go +++ b/android/config.go @@ -108,6 +108,12 @@ type config struct { ProductVariablesFileName string + // BuildOS stores the OsType for the OS that the build is running on. + BuildOS OsType + + // BuildArch stores the ArchType for the CPU that the build is running on. + BuildArch ArchType + Targets map[OsType][]Target BuildOSTarget Target // the Target for tools run on the build machine BuildOSCommonTarget Target // the Target for common (java) tools run on the build machine @@ -326,41 +332,43 @@ func TestConfig(buildDir string, env map[string]string, bp string, fs map[string return Config{config} } -func fuchsiaTargets() map[OsType][]Target { +func fuchsiaTargets(config Config) map[OsType][]Target { return map[OsType][]Target{ Fuchsia: { {Fuchsia, Arch{ArchType: Arm64, ArchVariant: "", Abi: []string{"arm64-v8a"}}, NativeBridgeDisabled, "", "", false}, }, - BuildOs: { - {BuildOs, Arch{ArchType: X86_64}, NativeBridgeDisabled, "", "", false}, + config.BuildOS: { + {config.BuildOS, Arch{ArchType: X86_64}, NativeBridgeDisabled, "", "", false}, }, } } var PrepareForTestSetDeviceToFuchsia = FixtureModifyConfig(func(config Config) { - config.Targets = fuchsiaTargets() + config.Targets = fuchsiaTargets(config) }) func modifyTestConfigToSupportArchMutator(testConfig Config) { config := testConfig.config + determineBuildOS(config) + config.Targets = map[OsType][]Target{ Android: []Target{ {Android, Arch{ArchType: Arm64, ArchVariant: "armv8-a", Abi: []string{"arm64-v8a"}}, NativeBridgeDisabled, "", "", false}, {Android, Arch{ArchType: Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}, NativeBridgeDisabled, "", "", false}, }, - BuildOs: []Target{ - {BuildOs, Arch{ArchType: X86_64}, NativeBridgeDisabled, "", "", false}, - {BuildOs, Arch{ArchType: X86}, NativeBridgeDisabled, "", "", false}, + config.BuildOS: []Target{ + {config.BuildOS, Arch{ArchType: X86_64}, NativeBridgeDisabled, "", "", false}, + {config.BuildOS, Arch{ArchType: X86}, NativeBridgeDisabled, "", "", false}, }, } if runtime.GOOS == "darwin" { - config.Targets[BuildOs] = config.Targets[BuildOs][:1] + config.Targets[config.BuildOS] = config.Targets[config.BuildOS][:1] } - config.BuildOSTarget = config.Targets[BuildOs][0] - config.BuildOSCommonTarget = getCommonTargets(config.Targets[BuildOs])[0] + config.BuildOSTarget = config.Targets[config.BuildOS][0] + config.BuildOSCommonTarget = getCommonTargets(config.Targets[config.BuildOS])[0] config.AndroidCommonTarget = getCommonTargets(config.Targets[Android])[0] config.AndroidFirstDeviceTarget = firstTarget(config.Targets[Android], "lib64", "lib32")[0] config.TestProductVariables.DeviceArch = proptools.StringPtr("arm64") @@ -439,6 +447,8 @@ func NewConfig(srcDir, buildDir string, moduleListFile string, availableEnv map[ config.katiEnabled = true } + determineBuildOS(config) + // Sets up the map of target OSes to the finer grained compilation targets // that are configured from the product variables. targets, err := decodeTargetProductVariables(config) @@ -476,8 +486,8 @@ func NewConfig(srcDir, buildDir string, moduleListFile string, availableEnv map[ config.Targets = targets // Compilation targets for host tools. - config.BuildOSTarget = config.Targets[BuildOs][0] - config.BuildOSCommonTarget = getCommonTargets(config.Targets[BuildOs])[0] + config.BuildOSTarget = config.Targets[config.BuildOS][0] + config.BuildOSCommonTarget = getCommonTargets(config.Targets[config.BuildOS])[0] // Compilation targets for Android. if len(config.Targets[Android]) > 0 { diff --git a/android/prebuilt_build_tool.go b/android/prebuilt_build_tool.go index 516d0420a..e5edf9129 100644 --- a/android/prebuilt_build_tool.go +++ b/android/prebuilt_build_tool.go @@ -86,7 +86,7 @@ func (t *prebuiltBuildTool) GenerateAndroidBuildActions(ctx ModuleContext) { func (t *prebuiltBuildTool) MakeVars(ctx MakeVarsModuleContext) { if makeVar := String(t.properties.Export_to_make_var); makeVar != "" { - if t.Target().Os != BuildOs { + if t.Target().Os != ctx.Config().BuildOS { return } ctx.StrictRaw(makeVar, t.toolPath.String()) diff --git a/android/prebuilt_test.go b/android/prebuilt_test.go index dcd77ea46..a1f8e6367 100644 --- a/android/prebuilt_test.go +++ b/android/prebuilt_test.go @@ -21,360 +21,362 @@ import ( "github.com/google/blueprint" ) -var prebuiltsTests = []struct { - name string - replaceBp bool // modules is added to default bp boilerplate if false. - modules string - prebuilt []OsType - preparer FixturePreparer -}{ - { - name: "no prebuilt", - modules: ` - source { - name: "bar", - }`, - prebuilt: nil, - }, - { - name: "no source prebuilt not preferred", - modules: ` - prebuilt { - name: "bar", - prefer: false, - srcs: ["prebuilt_file"], - }`, - prebuilt: []OsType{Android, BuildOs}, - }, - { - name: "no source prebuilt preferred", - modules: ` - prebuilt { - name: "bar", - prefer: true, - srcs: ["prebuilt_file"], - }`, - prebuilt: []OsType{Android, BuildOs}, - }, - { - name: "prebuilt not preferred", - modules: ` - source { - name: "bar", - } +func TestPrebuilts(t *testing.T) { + buildOS := TestArchConfig(t.TempDir(), nil, "", nil).BuildOS - prebuilt { - name: "bar", - prefer: false, - srcs: ["prebuilt_file"], - }`, - prebuilt: nil, - }, - { - name: "prebuilt preferred", - modules: ` - source { - name: "bar", - } + var prebuiltsTests = []struct { + name string + replaceBp bool // modules is added to default bp boilerplate if false. + modules string + prebuilt []OsType + preparer FixturePreparer + }{ + { + name: "no prebuilt", + modules: ` + source { + name: "bar", + }`, + prebuilt: nil, + }, + { + name: "no source prebuilt not preferred", + modules: ` + prebuilt { + name: "bar", + prefer: false, + srcs: ["prebuilt_file"], + }`, + prebuilt: []OsType{Android, buildOS}, + }, + { + name: "no source prebuilt preferred", + modules: ` + prebuilt { + name: "bar", + prefer: true, + srcs: ["prebuilt_file"], + }`, + prebuilt: []OsType{Android, buildOS}, + }, + { + name: "prebuilt not preferred", + modules: ` + source { + name: "bar", + } - prebuilt { - name: "bar", - prefer: true, - srcs: ["prebuilt_file"], - }`, - prebuilt: []OsType{Android, BuildOs}, - }, - { - name: "prebuilt no file not preferred", - modules: ` - source { - name: "bar", - } + prebuilt { + name: "bar", + prefer: false, + srcs: ["prebuilt_file"], + }`, + prebuilt: nil, + }, + { + name: "prebuilt preferred", + modules: ` + source { + name: "bar", + } - prebuilt { - name: "bar", - prefer: false, - }`, - prebuilt: nil, - }, - { - name: "prebuilt no file preferred", - modules: ` - source { - name: "bar", - } + prebuilt { + name: "bar", + prefer: true, + srcs: ["prebuilt_file"], + }`, + prebuilt: []OsType{Android, buildOS}, + }, + { + name: "prebuilt no file not preferred", + modules: ` + source { + name: "bar", + } - prebuilt { - name: "bar", - prefer: true, - }`, - prebuilt: nil, - }, - { - name: "prebuilt file from filegroup preferred", - modules: ` - filegroup { - name: "fg", - srcs: ["prebuilt_file"], - } - prebuilt { - name: "bar", - prefer: true, - srcs: [":fg"], - }`, - prebuilt: []OsType{Android, BuildOs}, - }, - { - name: "prebuilt module for device only", - modules: ` - source { - name: "bar", - } + prebuilt { + name: "bar", + prefer: false, + }`, + prebuilt: nil, + }, + { + name: "prebuilt no file preferred", + modules: ` + source { + name: "bar", + } - prebuilt { - name: "bar", - host_supported: false, - prefer: true, - srcs: ["prebuilt_file"], - }`, - prebuilt: []OsType{Android}, - }, - { - name: "prebuilt file for host only", - modules: ` - source { - name: "bar", - } + prebuilt { + name: "bar", + prefer: true, + }`, + prebuilt: nil, + }, + { + name: "prebuilt file from filegroup preferred", + modules: ` + filegroup { + name: "fg", + srcs: ["prebuilt_file"], + } + prebuilt { + name: "bar", + prefer: true, + srcs: [":fg"], + }`, + prebuilt: []OsType{Android, buildOS}, + }, + { + name: "prebuilt module for device only", + modules: ` + source { + name: "bar", + } - prebuilt { - name: "bar", - prefer: true, - target: { - host: { - srcs: ["prebuilt_file"], - }, - }, - }`, - prebuilt: []OsType{BuildOs}, - }, - { - name: "prebuilt override not preferred", - modules: ` - source { - name: "baz", - } + prebuilt { + name: "bar", + host_supported: false, + prefer: true, + srcs: ["prebuilt_file"], + }`, + prebuilt: []OsType{Android}, + }, + { + name: "prebuilt file for host only", + modules: ` + source { + name: "bar", + } - override_source { - name: "bar", - base: "baz", - } - - prebuilt { - name: "bar", - prefer: false, - srcs: ["prebuilt_file"], - }`, - prebuilt: nil, - }, - { - name: "prebuilt override preferred", - modules: ` - source { - name: "baz", - } - - override_source { - name: "bar", - base: "baz", - } - - prebuilt { - name: "bar", - prefer: true, - srcs: ["prebuilt_file"], - }`, - prebuilt: []OsType{Android, BuildOs}, - }, - { - name: "prebuilt including default-disabled OS", - replaceBp: true, - modules: ` - source { - name: "foo", - deps: [":bar"], - target: { - windows: { - enabled: true, - }, - }, - } - - source { - name: "bar", - target: { - windows: { - enabled: true, - }, - }, - } - - prebuilt { - name: "bar", - prefer: true, - srcs: ["prebuilt_file"], - target: { - windows: { - enabled: true, - }, - }, - }`, - prebuilt: []OsType{Android, BuildOs, Windows}, - }, - { - name: "fall back to source for default-disabled OS", - replaceBp: true, - modules: ` - source { - name: "foo", - deps: [":bar"], - target: { - windows: { - enabled: true, - }, - }, - } - - source { - name: "bar", - target: { - windows: { - enabled: true, - }, - }, - } - - prebuilt { - name: "bar", - prefer: true, - srcs: ["prebuilt_file"], - }`, - prebuilt: []OsType{Android, BuildOs}, - }, - { - name: "prebuilt properties customizable", - replaceBp: true, - modules: ` - source { - name: "foo", - deps: [":bar"], - } - - soong_config_module_type { - name: "prebuilt_with_config", - module_type: "prebuilt", - config_namespace: "any_namespace", - bool_variables: ["bool_var"], - properties: ["prefer"], - } - - prebuilt_with_config { - name: "bar", - prefer: true, - srcs: ["prebuilt_file"], - soong_config_variables: { - bool_var: { - prefer: false, - conditions_default: { - prefer: true, + prebuilt { + name: "bar", + prefer: true, + target: { + host: { + srcs: ["prebuilt_file"], }, }, - }, - }`, - prebuilt: []OsType{Android, BuildOs}, - }, - { - name: "prebuilt use_source_config_var={acme, use_source} - no var specified", - modules: ` - source { - name: "bar", - } + }`, + prebuilt: []OsType{buildOS}, + }, + { + name: "prebuilt override not preferred", + modules: ` + source { + name: "baz", + } - prebuilt { - name: "bar", - use_source_config_var: {config_namespace: "acme", var_name: "use_source"}, - srcs: ["prebuilt_file"], - }`, - // When use_source_env is specified then it will use the prebuilt by default if the environment - // variable is not set. - prebuilt: []OsType{Android, BuildOs}, - }, - { - name: "prebuilt use_source_config_var={acme, use_source} - acme_use_source=false", - modules: ` - source { - name: "bar", - } + override_source { + name: "bar", + base: "baz", + } - prebuilt { - name: "bar", - use_source_config_var: {config_namespace: "acme", var_name: "use_source"}, - srcs: ["prebuilt_file"], - }`, - preparer: FixtureModifyProductVariables(func(variables FixtureProductVariables) { - variables.VendorVars = map[string]map[string]string{ - "acme": { - "use_source": "false", - }, - } - }), - // Setting the environment variable named in use_source_env to false will cause the prebuilt to - // be used. - prebuilt: []OsType{Android, BuildOs}, - }, - { - name: "prebuilt use_source_config_var={acme, use_source} - acme_use_source=true", - modules: ` - source { - name: "bar", - } + prebuilt { + name: "bar", + prefer: false, + srcs: ["prebuilt_file"], + }`, + prebuilt: nil, + }, + { + name: "prebuilt override preferred", + modules: ` + source { + name: "baz", + } - prebuilt { - name: "bar", - use_source_config_var: {config_namespace: "acme", var_name: "use_source"}, - srcs: ["prebuilt_file"], - }`, - preparer: FixtureModifyProductVariables(func(variables FixtureProductVariables) { - variables.VendorVars = map[string]map[string]string{ - "acme": { - "use_source": "true", - }, - } - }), - // Setting the environment variable named in use_source_env to true will cause the source to be - // used. - prebuilt: nil, - }, - { - name: "prebuilt use_source_config_var={acme, use_source} - acme_use_source=true, no source", - modules: ` - prebuilt { - name: "bar", - use_source_config_var: {config_namespace: "acme", var_name: "use_source"}, - srcs: ["prebuilt_file"], - }`, - preparer: FixtureModifyProductVariables(func(variables FixtureProductVariables) { - variables.VendorVars = map[string]map[string]string{ - "acme": { - "use_source": "true", - }, - } - }), - // Although the environment variable says to use source there is no source available. - prebuilt: []OsType{Android, BuildOs}, - }, -} + override_source { + name: "bar", + base: "baz", + } + + prebuilt { + name: "bar", + prefer: true, + srcs: ["prebuilt_file"], + }`, + prebuilt: []OsType{Android, buildOS}, + }, + { + name: "prebuilt including default-disabled OS", + replaceBp: true, + modules: ` + source { + name: "foo", + deps: [":bar"], + target: { + windows: { + enabled: true, + }, + }, + } + + source { + name: "bar", + target: { + windows: { + enabled: true, + }, + }, + } + + prebuilt { + name: "bar", + prefer: true, + srcs: ["prebuilt_file"], + target: { + windows: { + enabled: true, + }, + }, + }`, + prebuilt: []OsType{Android, buildOS, Windows}, + }, + { + name: "fall back to source for default-disabled OS", + replaceBp: true, + modules: ` + source { + name: "foo", + deps: [":bar"], + target: { + windows: { + enabled: true, + }, + }, + } + + source { + name: "bar", + target: { + windows: { + enabled: true, + }, + }, + } + + prebuilt { + name: "bar", + prefer: true, + srcs: ["prebuilt_file"], + }`, + prebuilt: []OsType{Android, buildOS}, + }, + { + name: "prebuilt properties customizable", + replaceBp: true, + modules: ` + source { + name: "foo", + deps: [":bar"], + } + + soong_config_module_type { + name: "prebuilt_with_config", + module_type: "prebuilt", + config_namespace: "any_namespace", + bool_variables: ["bool_var"], + properties: ["prefer"], + } + + prebuilt_with_config { + name: "bar", + prefer: true, + srcs: ["prebuilt_file"], + soong_config_variables: { + bool_var: { + prefer: false, + conditions_default: { + prefer: true, + }, + }, + }, + }`, + prebuilt: []OsType{Android, buildOS}, + }, + { + name: "prebuilt use_source_config_var={acme, use_source} - no var specified", + modules: ` + source { + name: "bar", + } + + prebuilt { + name: "bar", + use_source_config_var: {config_namespace: "acme", var_name: "use_source"}, + srcs: ["prebuilt_file"], + }`, + // When use_source_env is specified then it will use the prebuilt by default if the environment + // variable is not set. + prebuilt: []OsType{Android, buildOS}, + }, + { + name: "prebuilt use_source_config_var={acme, use_source} - acme_use_source=false", + modules: ` + source { + name: "bar", + } + + prebuilt { + name: "bar", + use_source_config_var: {config_namespace: "acme", var_name: "use_source"}, + srcs: ["prebuilt_file"], + }`, + preparer: FixtureModifyProductVariables(func(variables FixtureProductVariables) { + variables.VendorVars = map[string]map[string]string{ + "acme": { + "use_source": "false", + }, + } + }), + // Setting the environment variable named in use_source_env to false will cause the prebuilt to + // be used. + prebuilt: []OsType{Android, buildOS}, + }, + { + name: "prebuilt use_source_config_var={acme, use_source} - acme_use_source=true", + modules: ` + source { + name: "bar", + } + + prebuilt { + name: "bar", + use_source_config_var: {config_namespace: "acme", var_name: "use_source"}, + srcs: ["prebuilt_file"], + }`, + preparer: FixtureModifyProductVariables(func(variables FixtureProductVariables) { + variables.VendorVars = map[string]map[string]string{ + "acme": { + "use_source": "true", + }, + } + }), + // Setting the environment variable named in use_source_env to true will cause the source to be + // used. + prebuilt: nil, + }, + { + name: "prebuilt use_source_config_var={acme, use_source} - acme_use_source=true, no source", + modules: ` + prebuilt { + name: "bar", + use_source_config_var: {config_namespace: "acme", var_name: "use_source"}, + srcs: ["prebuilt_file"], + }`, + preparer: FixtureModifyProductVariables(func(variables FixtureProductVariables) { + variables.VendorVars = map[string]map[string]string{ + "acme": { + "use_source": "true", + }, + } + }), + // Although the environment variable says to use source there is no source available. + prebuilt: []OsType{Android, buildOS}, + }, + } -func TestPrebuilts(t *testing.T) { fs := MockFS{ "prebuilt_file": nil, "source_file": nil, diff --git a/android/test_suites.go b/android/test_suites.go index 6b7b909fc..22f6cf229 100644 --- a/android/test_suites.go +++ b/android/test_suites.go @@ -60,7 +60,7 @@ func robolectricTestSuite(ctx SingletonContext, files map[string]InstallPaths) W for _, module := range SortedStringKeys(files) { installedPaths = append(installedPaths, files[module]...) } - testCasesDir := pathForInstall(ctx, BuildOs, X86, "testcases", false).ToMakePath() + testCasesDir := pathForInstall(ctx, ctx.Config().BuildOS, X86, "testcases", false).ToMakePath() outputFile := PathForOutput(ctx, "packaging", "robolectric-tests.zip") rule := NewRuleBuilder(pctx, ctx) diff --git a/cc/config/global.go b/cc/config/global.go index dfbe6c4f5..55e0d7967 100644 --- a/cc/config/global.go +++ b/cc/config/global.go @@ -15,6 +15,7 @@ package config import ( + "runtime" "strings" "android/soong/android" @@ -282,7 +283,7 @@ var ( var pctx = android.NewPackageContext("android/soong/cc/config") func init() { - if android.BuildOs == android.Linux { + if runtime.GOOS == "linux" { commonGlobalCflags = append(commonGlobalCflags, "-fdebug-prefix-map=/proc/self/cwd=") } diff --git a/cc/makevars.go b/cc/makevars.go index 393170a81..8d7a163e3 100644 --- a/cc/makevars.go +++ b/cc/makevars.go @@ -165,7 +165,7 @@ func makeVarsProvider(ctx android.MakeVarsContext) { sort.Strings(ndkKnownLibs) ctx.Strict("NDK_KNOWN_LIBS", strings.Join(ndkKnownLibs, " ")) - hostTargets := ctx.Config().Targets[android.BuildOs] + hostTargets := ctx.Config().Targets[ctx.Config().BuildOS] makeVarsToolchain(ctx, "", hostTargets[0]) if len(hostTargets) > 1 { makeVarsToolchain(ctx, "2ND_", hostTargets[1]) diff --git a/cc/prebuilt_test.go b/cc/prebuilt_test.go index fa6dd87eb..c8f8103b0 100644 --- a/cc/prebuilt_test.go +++ b/cc/prebuilt_test.go @@ -15,6 +15,7 @@ package cc import ( + "runtime" "testing" "android/soong/android" @@ -271,8 +272,8 @@ func TestPrebuiltLibrarySharedStem(t *testing.T) { } func TestPrebuiltSymlinkedHostBinary(t *testing.T) { - if android.BuildOs != android.Linux { - t.Skipf("Skipping host prebuilt testing that is only supported on %s not %s", android.Linux, android.BuildOs) + if runtime.GOOS != "linux" { + t.Skipf("Skipping host prebuilt testing that is only supported on linux not %s", runtime.GOOS) } ctx := testPrebuilt(t, ` diff --git a/cc/proto_test.go b/cc/proto_test.go index b9c89c744..abcb27304 100644 --- a/cc/proto_test.go +++ b/cc/proto_test.go @@ -51,7 +51,7 @@ func TestProto(t *testing.T) { }, }`) - buildOS := android.BuildOs.String() + buildOS := ctx.Config().BuildOS.String() proto := ctx.ModuleForTests("libfoo", "android_arm_armv7-a-neon_shared").Output("proto/a.pb.cc") foobar := ctx.ModuleForTests("protoc-gen-foobar", buildOS+"_x86_64") diff --git a/etc/prebuilt_etc_test.go b/etc/prebuilt_etc_test.go index 0c5cfe4f4..cf1f6d717 100644 --- a/etc/prebuilt_etc_test.go +++ b/etc/prebuilt_etc_test.go @@ -188,7 +188,7 @@ func TestPrebuiltEtcHost(t *testing.T) { } `) - buildOS := android.BuildOs.String() + buildOS := result.Config.BuildOS.String() p := result.Module("foo.conf", buildOS+"_common").(*PrebuiltEtc) if !p.Host() { t.Errorf("host bit is not set for a prebuilt_etc_host module.") @@ -242,7 +242,7 @@ func TestPrebuiltUserShareHostInstallDirPath(t *testing.T) { } `) - buildOS := android.BuildOs.String() + buildOS := result.Config.BuildOS.String() p := result.Module("foo.conf", buildOS+"_common").(*PrebuiltEtc) expected := filepath.Join("out/soong/host", result.Config.PrebuiltOS(), "usr", "share", "bar") android.AssertPathRelativeToTopEquals(t, "install dir", expected, p.installDirPath) diff --git a/java/dexpreopt_bootjars.go b/java/dexpreopt_bootjars.go index dff9543e4..2c78d7362 100644 --- a/java/dexpreopt_bootjars.go +++ b/java/dexpreopt_bootjars.go @@ -523,14 +523,14 @@ func buildBootImageVariantsForAndroidOs(ctx android.ModuleContext, image *bootIm } // buildBootImageVariantsForBuildOs generates rules to build the boot image variants for the -// android.BuildOs OsType, i.e. the type of OS on which the build is being running. +// config.BuildOS OsType, i.e. the type of OS on which the build is being running. // // The files need to be generated into their predefined location because they are used from there // both within Soong and outside, e.g. for ART based host side testing and also for use by some // cloud based tools. However, they are not needed by callers of this function and so the paths do // not need to be returned from this func, unlike the buildBootImageVariantsForAndroidOs func. func buildBootImageVariantsForBuildOs(ctx android.ModuleContext, image *bootImageConfig, profile android.WritablePath) { - buildBootImageForOsType(ctx, image, profile, android.BuildOs) + buildBootImageForOsType(ctx, image, profile, ctx.Config().BuildOS) } // buildBootImageForOsType takes a bootImageConfig, a profile file and an android.OsType diff --git a/java/dexpreopt_config.go b/java/dexpreopt_config.go index b13955fba..1507aaf00 100644 --- a/java/dexpreopt_config.go +++ b/java/dexpreopt_config.go @@ -32,7 +32,7 @@ func dexpreoptTargets(ctx android.PathContext) []android.Target { } } // We may also need the images on host in order to run host-based tests. - for _, target := range ctx.Config().Targets[android.BuildOs] { + for _, target := range ctx.Config().Targets[ctx.Config().BuildOS] { targets = append(targets, target) } diff --git a/java/dexpreopt_test.go b/java/dexpreopt_test.go index b25deceac..8dc7b798a 100644 --- a/java/dexpreopt_test.go +++ b/java/dexpreopt_test.go @@ -16,6 +16,7 @@ package java import ( "fmt" + "runtime" "testing" "android/soong/android" @@ -173,9 +174,9 @@ func enabledString(enabled bool) string { } func TestDex2oatToolDeps(t *testing.T) { - if android.BuildOs != android.Linux { + if runtime.GOOS != "linux" { // The host binary paths checked below are build OS dependent. - t.Skipf("Unsupported build OS %s", android.BuildOs) + t.Skipf("Unsupported build OS %s", runtime.GOOS) } preparers := android.GroupFixturePreparers( diff --git a/java/java_test.go b/java/java_test.go index 0f9965d03..b6780c20c 100644 --- a/java/java_test.go +++ b/java/java_test.go @@ -441,7 +441,7 @@ func TestBinary(t *testing.T) { } `) - buildOS := android.BuildOs.String() + buildOS := ctx.Config().BuildOS.String() bar := ctx.ModuleForTests("bar", buildOS+"_common") barJar := bar.Output("bar.jar").Output.String() @@ -478,7 +478,7 @@ func TestTest(t *testing.T) { } `) - buildOS := android.BuildOs.String() + buildOS := ctx.Config().BuildOS.String() foo := ctx.ModuleForTests("foo", buildOS+"_common").Module().(*TestHost) @@ -523,7 +523,7 @@ func TestHostBinaryNoJavaDebugInfoOverride(t *testing.T) { } // check that -g is not overridden for host modules - buildOS := android.BuildOs.String() + buildOS := result.Config.BuildOS.String() hostBinary := result.ModuleForTests("host_binary", buildOS+"_common") hostJavaFlags := hostBinary.Module().VariablesForTests()["javacFlags"] if strings.Contains(hostJavaFlags, "-g:source,lines") { @@ -1371,7 +1371,7 @@ func TestDataNativeBinaries(t *testing.T) { } `) - buildOS := android.BuildOs.String() + buildOS := ctx.Config().BuildOS.String() test := ctx.ModuleForTests("foo", buildOS+"_common").Module().(*TestHost) entries := android.AndroidMkEntriesForTest(t, ctx, test)[0] @@ -1387,7 +1387,7 @@ func TestDefaultInstallable(t *testing.T) { } `) - buildOS := android.BuildOs.String() + buildOS := ctx.Config().BuildOS.String() module := ctx.ModuleForTests("foo", buildOS+"_common").Module().(*TestHost) assertDeepEquals(t, "Default installable value should be true.", proptools.BoolPtr(true), module.properties.Installable) diff --git a/java/kotlin_test.go b/java/kotlin_test.go index fd2f3ca61..db3069693 100644 --- a/java/kotlin_test.go +++ b/java/kotlin_test.go @@ -15,10 +15,11 @@ package java import ( - "android/soong/android" "strconv" "strings" "testing" + + "android/soong/android" ) func TestKotlin(t *testing.T) { @@ -114,7 +115,7 @@ func TestKapt(t *testing.T) { t.Run("", func(t *testing.T) { ctx, _ := testJava(t, bp) - buildOS := android.BuildOs.String() + buildOS := ctx.Config().BuildOS.String() kapt := ctx.ModuleForTests("foo", "android_common").Rule("kapt") kotlinc := ctx.ModuleForTests("foo", "android_common").Rule("kotlinc") @@ -182,7 +183,7 @@ func TestKapt(t *testing.T) { android.FixtureMergeEnv(env), ).RunTestWithBp(t, bp) - buildOS := android.BuildOs.String() + buildOS := result.Config.BuildOS.String() kapt := result.ModuleForTests("foo", "android_common").Rule("kapt") javac := result.ModuleForTests("foo", "android_common").Description("javac") diff --git a/java/plugin_test.go b/java/plugin_test.go index c7913d3db..dc29b1c3e 100644 --- a/java/plugin_test.go +++ b/java/plugin_test.go @@ -15,7 +15,6 @@ package java import ( - "android/soong/android" "testing" ) @@ -58,7 +57,7 @@ func TestPlugin(t *testing.T) { } `) - buildOS := android.BuildOs.String() + buildOS := ctx.Config().BuildOS.String() javac := ctx.ModuleForTests("foo", "android_common").Rule("javac") turbine := ctx.ModuleForTests("foo", "android_common").MaybeRule("turbine") @@ -98,7 +97,7 @@ func TestPluginGeneratesApi(t *testing.T) { } `) - buildOS := android.BuildOs.String() + buildOS := ctx.Config().BuildOS.String() javac := ctx.ModuleForTests("foo", "android_common").Rule("javac") turbine := ctx.ModuleForTests("foo", "android_common").MaybeRule("turbine") diff --git a/java/robolectric.go b/java/robolectric.go index a37a118f6..a0c9c7fcd 100644 --- a/java/robolectric.go +++ b/java/robolectric.go @@ -83,6 +83,9 @@ type robolectricTest struct { testConfig android.Path data android.Paths + + forceOSType android.OsType + forceArchType android.ArchType } func (r *robolectricTest) TestSuites() []string { @@ -115,6 +118,9 @@ func (r *robolectricTest) DepsMutator(ctx android.BottomUpMutatorContext) { } func (r *robolectricTest) GenerateAndroidBuildActions(ctx android.ModuleContext) { + r.forceOSType = ctx.Config().BuildOS + r.forceArchType = ctx.Config().BuildArch + r.testConfig = tradefed.AutoGenRobolectricTestConfig(ctx, r.testProperties.Test_config, r.testProperties.Test_config_template, r.testProperties.Test_suites, r.testProperties.Auto_gen_config) @@ -345,7 +351,7 @@ func RobolectricTestFactory() android.Module { func (r *robolectricTest) InstallBypassMake() bool { return true } func (r *robolectricTest) InstallInTestcases() bool { return true } func (r *robolectricTest) InstallForceOS() (*android.OsType, *android.ArchType) { - return &android.BuildOs, &android.BuildArch + return &r.forceOSType, &r.forceArchType } func robolectricRuntimesFactory() android.Module { @@ -366,6 +372,9 @@ type robolectricRuntimes struct { props robolectricRuntimesProperties runtimes []android.InstallPath + + forceOSType android.OsType + forceArchType android.ArchType } func (r *robolectricRuntimes) TestSuites() []string { @@ -385,6 +394,9 @@ func (r *robolectricRuntimes) GenerateAndroidBuildActions(ctx android.ModuleCont return } + r.forceOSType = ctx.Config().BuildOS + r.forceArchType = ctx.Config().BuildArch + files := android.PathsForModuleSrc(ctx, r.props.Jars) androidAllDir := android.PathForModuleInstall(ctx, "android-all") @@ -417,5 +429,5 @@ func (r *robolectricRuntimes) GenerateAndroidBuildActions(ctx android.ModuleCont func (r *robolectricRuntimes) InstallBypassMake() bool { return true } func (r *robolectricRuntimes) InstallInTestcases() bool { return true } func (r *robolectricRuntimes) InstallForceOS() (*android.OsType, *android.ArchType) { - return &android.BuildOs, &android.BuildArch + return &r.forceOSType, &r.forceArchType } diff --git a/java/sdk_test.go b/java/sdk_test.go index bb595a54e..6d6213011 100644 --- a/java/sdk_test.go +++ b/java/sdk_test.go @@ -255,9 +255,11 @@ func TestClasspath(t *testing.T) { ` + testcase.properties + ` }` - variant := "android_common" - if testcase.host == android.Host { - variant = android.BuildOs.String() + "_common" + variant := func(result *android.TestResult) string { + if testcase.host == android.Host { + return result.Config.BuildOS.String() + "_common" + } + return "android_common" } convertModulesToPaths := func(cp []string) []string { @@ -312,7 +314,7 @@ func TestClasspath(t *testing.T) { } checkClasspath := func(t *testing.T, result *android.TestResult, isJava8 bool) { - foo := result.ModuleForTests("foo", variant) + foo := result.ModuleForTests("foo", variant(result)) javac := foo.Rule("javac") var deps []string @@ -376,7 +378,7 @@ func TestClasspath(t *testing.T) { checkClasspath(t, result, true /* isJava8 */) if testcase.host != android.Host { - aidl := result.ModuleForTests("foo", variant).Rule("aidl") + aidl := result.ModuleForTests("foo", variant(result)).Rule("aidl") android.AssertStringDoesContain(t, "aidl command", aidl.RuleParams.Command, testcase.aidl+" -I.") } @@ -389,7 +391,7 @@ func TestClasspath(t *testing.T) { checkClasspath(t, result, false /* isJava8 */) if testcase.host != android.Host { - aidl := result.ModuleForTests("foo", variant).Rule("aidl") + aidl := result.ModuleForTests("foo", variant(result)).Rule("aidl") android.AssertStringDoesContain(t, "aidl command", aidl.RuleParams.Command, testcase.aidl+" -I.") } diff --git a/rust/compiler.go b/rust/compiler.go index 0b28135ae..df77759d6 100644 --- a/rust/compiler.go +++ b/rust/compiler.go @@ -305,7 +305,7 @@ func (compiler *baseCompiler) compilerDeps(ctx DepsContext, deps Deps) Deps { if !Bool(compiler.Properties.No_stdlibs) { for _, stdlib := range config.Stdlibs { // If we're building for the primary arch of the build host, use the compiler's stdlibs - if ctx.Target().Os == android.BuildOs { + if ctx.Target().Os == ctx.Config().BuildOS { stdlib = stdlib + "_" + ctx.toolchain().RustTriple() } deps.Stdlibs = append(deps.Stdlibs, stdlib) diff --git a/rust/project_json_test.go b/rust/project_json_test.go index 09d30dbde..bdd54c59b 100644 --- a/rust/project_json_test.go +++ b/rust/project_json_test.go @@ -176,6 +176,8 @@ func TestProjectJsonBinary(t *testing.T) { } func TestProjectJsonBindGen(t *testing.T) { + buildOS := android.TestConfig(t.TempDir(), nil, "", nil).BuildOS + bp := ` rust_library { name: "libd", @@ -214,9 +216,9 @@ func TestProjectJsonBindGen(t *testing.T) { if strings.Contains(rootModule, "libbindings1") && !strings.Contains(rootModule, "android_arm64") { t.Errorf("The source path for libbindings1 does not contain android_arm64, got %v", rootModule) } - if strings.Contains(rootModule, "libbindings2") && !strings.Contains(rootModule, android.BuildOs.String()) { + if strings.Contains(rootModule, "libbindings2") && !strings.Contains(rootModule, buildOS.String()) { t.Errorf("The source path for libbindings2 does not contain the BuildOs, got %v; want %v", - rootModule, android.BuildOs.String()) + rootModule, buildOS.String()) } // Check that libbindings1 does not depend on itself. if strings.Contains(rootModule, "libbindings1") { diff --git a/sdk/sdk_test.go b/sdk/sdk_test.go index 97fb2485f..85e3d875e 100644 --- a/sdk/sdk_test.go +++ b/sdk/sdk_test.go @@ -15,19 +15,21 @@ package sdk import ( - "android/soong/android" "log" "os" + "runtime" "testing" + "android/soong/android" + "github.com/google/blueprint/proptools" ) // Needed in an _test.go file in this package to ensure tests run correctly, particularly in IDE. func TestMain(m *testing.M) { - if android.BuildOs != android.Linux { + if runtime.GOOS != "linux" { // b/145598135 - Generating host snapshots for anything other than linux is not supported. - log.Printf("Skipping as sdk snapshot generation is only supported on %s not %s", android.Linux, android.BuildOs) + log.Printf("Skipping as sdk snapshot generation is only supported on linux not %s", runtime.GOOS) os.Exit(0) } diff --git a/sh/sh_binary_test.go b/sh/sh_binary_test.go index 20317d88c..865d5f3d1 100644 --- a/sh/sh_binary_test.go +++ b/sh/sh_binary_test.go @@ -115,7 +115,7 @@ func TestShTest_dataModules(t *testing.T) { } `) - buildOS := android.BuildOs.String() + buildOS := config.BuildOS.String() arches := []string{"android_arm64_armv8-a", buildOS + "_x86_64"} for _, arch := range arches { variant := ctx.ModuleForTests("foo", arch) @@ -155,7 +155,7 @@ func TestShTestHost(t *testing.T) { } `) - buildOS := android.BuildOs.String() + buildOS := ctx.Config().BuildOS.String() mod := ctx.ModuleForTests("foo", buildOS+"_x86_64").Module().(*ShTest) if !mod.Host() { t.Errorf("host bit is not set for a sh_test_host module.") @@ -192,7 +192,7 @@ func TestShTestHost_dataDeviceModules(t *testing.T) { } `) - buildOS := android.BuildOs.String() + buildOS := config.BuildOS.String() variant := ctx.ModuleForTests("foo", buildOS+"_x86_64") relocated := variant.Output("relocated/lib64/libbar.so")