Replace android.BuildOs with Config.BuildOS
Replace the android.BuildOs constant with Config.BuildOS so that it
can vary based on the product config.
Bug: 190084016
Test: all Soong tests
Change-Id: Ia67f872d8b2ab788747a22e3a9659dc21c9775cd
diff --git a/android/arch.go b/android/arch.go
index cc70eee..a7a123e 100644
--- a/android/arch.go
+++ b/android/arch.go
@@ -290,28 +290,6 @@
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 @@
}
}
+// 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 @@
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 @@
}
// 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 396b1a6..b9f0d1b 100644
--- a/android/config.go
+++ b/android/config.go
@@ -108,6 +108,12 @@
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 @@
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 @@
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 @@
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 516d042..e5edf91 100644
--- a/android/prebuilt_build_tool.go
+++ b/android/prebuilt_build_tool.go
@@ -86,7 +86,7 @@
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 dcd77ea..a1f8e63 100644
--- a/android/prebuilt_test.go
+++ b/android/prebuilt_test.go
@@ -21,360 +21,362 @@
"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",
+ }
-func TestPrebuilts(t *testing.T) {
+ 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},
+ },
+ }
+
fs := MockFS{
"prebuilt_file": nil,
"source_file": nil,
diff --git a/android/test_suites.go b/android/test_suites.go
index 6b7b909..22f6cf2 100644
--- a/android/test_suites.go
+++ b/android/test_suites.go
@@ -60,7 +60,7 @@
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 dfbe6c4..55e0d79 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 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 393170a..8d7a163 100644
--- a/cc/makevars.go
+++ b/cc/makevars.go
@@ -165,7 +165,7 @@
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 fa6dd87..c8f8103 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 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 b9c89c7..abcb273 100644
--- a/cc/proto_test.go
+++ b/cc/proto_test.go
@@ -51,7 +51,7 @@
},
}`)
- 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 354f6bb..d2ffd4b 100644
--- a/etc/prebuilt_etc_test.go
+++ b/etc/prebuilt_etc_test.go
@@ -172,7 +172,7 @@
}
`)
- 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.")
@@ -226,7 +226,7 @@
}
`)
- 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 dff9543..2c78d73 100644
--- a/java/dexpreopt_bootjars.go
+++ b/java/dexpreopt_bootjars.go
@@ -523,14 +523,14 @@
}
// 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 b13955f..1507aaf 100644
--- a/java/dexpreopt_config.go
+++ b/java/dexpreopt_config.go
@@ -32,7 +32,7 @@
}
}
// 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 b25dece..8dc7b79 100644
--- a/java/dexpreopt_test.go
+++ b/java/dexpreopt_test.go
@@ -16,6 +16,7 @@
import (
"fmt"
+ "runtime"
"testing"
"android/soong/android"
@@ -173,9 +174,9 @@
}
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 0f9965d..b6780c2 100644
--- a/java/java_test.go
+++ b/java/java_test.go
@@ -441,7 +441,7 @@
}
`)
- 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 @@
}
`)
- buildOS := android.BuildOs.String()
+ buildOS := ctx.Config().BuildOS.String()
foo := ctx.ModuleForTests("foo", buildOS+"_common").Module().(*TestHost)
@@ -523,7 +523,7 @@
}
// 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 @@
}
`)
- 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 @@
}
`)
- 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 fd2f3ca..db30696 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 @@
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 @@
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 c7913d3..dc29b1c 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 @@
}
`)
- 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 @@
}
`)
- 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 a37a118..a0c9c7f 100644
--- a/java/robolectric.go
+++ b/java/robolectric.go
@@ -83,6 +83,9 @@
testConfig android.Path
data android.Paths
+
+ forceOSType android.OsType
+ forceArchType android.ArchType
}
func (r *robolectricTest) TestSuites() []string {
@@ -115,6 +118,9 @@
}
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 (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 @@
props robolectricRuntimesProperties
runtimes []android.InstallPath
+
+ forceOSType android.OsType
+ forceArchType android.ArchType
}
func (r *robolectricRuntimes) TestSuites() []string {
@@ -385,6 +394,9 @@
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) 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 bb595a5..6d62130 100644
--- a/java/sdk_test.go
+++ b/java/sdk_test.go
@@ -255,9 +255,11 @@
` + 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 @@
}
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 @@
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 @@
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 0b28135..df77759 100644
--- a/rust/compiler.go
+++ b/rust/compiler.go
@@ -305,7 +305,7 @@
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 09d30db..bdd54c5 100644
--- a/rust/project_json_test.go
+++ b/rust/project_json_test.go
@@ -176,6 +176,8 @@
}
func TestProjectJsonBindGen(t *testing.T) {
+ buildOS := android.TestConfig(t.TempDir(), nil, "", nil).BuildOS
+
bp := `
rust_library {
name: "libd",
@@ -214,9 +216,9 @@
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 97fb248..85e3d87 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 20317d8..865d5f3 100644
--- a/sh/sh_binary_test.go
+++ b/sh/sh_binary_test.go
@@ -115,7 +115,7 @@
}
`)
- 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 @@
}
`)
- 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 @@
}
`)
- buildOS := android.BuildOs.String()
+ buildOS := config.BuildOS.String()
variant := ctx.ModuleForTests("foo", buildOS+"_x86_64")
relocated := variant.Output("relocated/lib64/libbar.so")