Merge "Replace android.BuildOs with Config.BuildOS"

This commit is contained in:
Colin Cross
2021-07-23 00:07:01 +00:00
committed by Gerrit Code Review
22 changed files with 457 additions and 421 deletions

View File

@@ -290,28 +290,6 @@ func osByName(name string) OsType {
return NoOsType 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 ( var (
// osTypeList contains a list of all the supported OsTypes, including ones not supported // osTypeList contains a list of all the supported OsTypes, including ones not supported
// by the current build host or the target device. // 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. // Convert the arch product variables into a list of targets for each OsType.
func decodeTargetProductVariables(config *config) (map[OsType][]Target, error) { func decodeTargetProductVariables(config *config) (map[OsType][]Target, error) {
variables := config.productVariables variables := config.productVariables
@@ -1430,9 +1433,9 @@ func decodeTargetProductVariables(config *config) (map[OsType][]Target, error) {
hostCross := false hostCross := false
if os.Class == Host { if os.Class == Host {
var osSupported bool var osSupported bool
if os == BuildOs { if os == config.BuildOS {
osSupported = true osSupported = true
} else if BuildOs.Linux() && os.Linux() { } else if config.BuildOS.Linux() && os.Linux() {
// LinuxBionic and Linux are compatible // LinuxBionic and Linux are compatible
osSupported = true osSupported = true
} else { } else {
@@ -1470,11 +1473,11 @@ func decodeTargetProductVariables(config *config) (map[OsType][]Target, error) {
} }
// The primary host target, which must always exist. // 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. // An optional secondary host target.
if variables.HostSecondaryArch != nil && *variables.HostSecondaryArch != "" { 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. // Optional cross-compiled host targets, generally Windows.

View File

@@ -108,6 +108,12 @@ type config struct {
ProductVariablesFileName string 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 Targets map[OsType][]Target
BuildOSTarget Target // the Target for tools run on the build machine BuildOSTarget Target // the Target for tools run on the build machine
BuildOSCommonTarget Target // the Target for common (java) 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} return Config{config}
} }
func fuchsiaTargets() map[OsType][]Target { func fuchsiaTargets(config Config) map[OsType][]Target {
return map[OsType][]Target{ return map[OsType][]Target{
Fuchsia: { Fuchsia: {
{Fuchsia, Arch{ArchType: Arm64, ArchVariant: "", Abi: []string{"arm64-v8a"}}, NativeBridgeDisabled, "", "", false}, {Fuchsia, Arch{ArchType: Arm64, ArchVariant: "", Abi: []string{"arm64-v8a"}}, NativeBridgeDisabled, "", "", false},
}, },
BuildOs: { config.BuildOS: {
{BuildOs, Arch{ArchType: X86_64}, NativeBridgeDisabled, "", "", false}, {config.BuildOS, Arch{ArchType: X86_64}, NativeBridgeDisabled, "", "", false},
}, },
} }
} }
var PrepareForTestSetDeviceToFuchsia = FixtureModifyConfig(func(config Config) { var PrepareForTestSetDeviceToFuchsia = FixtureModifyConfig(func(config Config) {
config.Targets = fuchsiaTargets() config.Targets = fuchsiaTargets(config)
}) })
func modifyTestConfigToSupportArchMutator(testConfig Config) { func modifyTestConfigToSupportArchMutator(testConfig Config) {
config := testConfig.config config := testConfig.config
determineBuildOS(config)
config.Targets = map[OsType][]Target{ config.Targets = map[OsType][]Target{
Android: []Target{ Android: []Target{
{Android, Arch{ArchType: Arm64, ArchVariant: "armv8-a", Abi: []string{"arm64-v8a"}}, NativeBridgeDisabled, "", "", false}, {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}, {Android, Arch{ArchType: Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}, NativeBridgeDisabled, "", "", false},
}, },
BuildOs: []Target{ config.BuildOS: []Target{
{BuildOs, Arch{ArchType: X86_64}, NativeBridgeDisabled, "", "", false}, {config.BuildOS, Arch{ArchType: X86_64}, NativeBridgeDisabled, "", "", false},
{BuildOs, Arch{ArchType: X86}, NativeBridgeDisabled, "", "", false}, {config.BuildOS, Arch{ArchType: X86}, NativeBridgeDisabled, "", "", false},
}, },
} }
if runtime.GOOS == "darwin" { 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.BuildOSTarget = config.Targets[config.BuildOS][0]
config.BuildOSCommonTarget = getCommonTargets(config.Targets[BuildOs])[0] config.BuildOSCommonTarget = getCommonTargets(config.Targets[config.BuildOS])[0]
config.AndroidCommonTarget = getCommonTargets(config.Targets[Android])[0] config.AndroidCommonTarget = getCommonTargets(config.Targets[Android])[0]
config.AndroidFirstDeviceTarget = firstTarget(config.Targets[Android], "lib64", "lib32")[0] config.AndroidFirstDeviceTarget = firstTarget(config.Targets[Android], "lib64", "lib32")[0]
config.TestProductVariables.DeviceArch = proptools.StringPtr("arm64") config.TestProductVariables.DeviceArch = proptools.StringPtr("arm64")
@@ -439,6 +447,8 @@ func NewConfig(srcDir, buildDir string, moduleListFile string, availableEnv map[
config.katiEnabled = true config.katiEnabled = true
} }
determineBuildOS(config)
// Sets up the map of target OSes to the finer grained compilation targets // Sets up the map of target OSes to the finer grained compilation targets
// that are configured from the product variables. // that are configured from the product variables.
targets, err := decodeTargetProductVariables(config) targets, err := decodeTargetProductVariables(config)
@@ -476,8 +486,8 @@ func NewConfig(srcDir, buildDir string, moduleListFile string, availableEnv map[
config.Targets = targets config.Targets = targets
// Compilation targets for host tools. // Compilation targets for host tools.
config.BuildOSTarget = config.Targets[BuildOs][0] config.BuildOSTarget = config.Targets[config.BuildOS][0]
config.BuildOSCommonTarget = getCommonTargets(config.Targets[BuildOs])[0] config.BuildOSCommonTarget = getCommonTargets(config.Targets[config.BuildOS])[0]
// Compilation targets for Android. // Compilation targets for Android.
if len(config.Targets[Android]) > 0 { if len(config.Targets[Android]) > 0 {

View File

@@ -86,7 +86,7 @@ func (t *prebuiltBuildTool) GenerateAndroidBuildActions(ctx ModuleContext) {
func (t *prebuiltBuildTool) MakeVars(ctx MakeVarsModuleContext) { func (t *prebuiltBuildTool) MakeVars(ctx MakeVarsModuleContext) {
if makeVar := String(t.properties.Export_to_make_var); makeVar != "" { if makeVar := String(t.properties.Export_to_make_var); makeVar != "" {
if t.Target().Os != BuildOs { if t.Target().Os != ctx.Config().BuildOS {
return return
} }
ctx.StrictRaw(makeVar, t.toolPath.String()) ctx.StrictRaw(makeVar, t.toolPath.String())

View File

@@ -21,13 +21,16 @@ import (
"github.com/google/blueprint" "github.com/google/blueprint"
) )
var prebuiltsTests = []struct { func TestPrebuilts(t *testing.T) {
buildOS := TestArchConfig(t.TempDir(), nil, "", nil).BuildOS
var prebuiltsTests = []struct {
name string name string
replaceBp bool // modules is added to default bp boilerplate if false. replaceBp bool // modules is added to default bp boilerplate if false.
modules string modules string
prebuilt []OsType prebuilt []OsType
preparer FixturePreparer preparer FixturePreparer
}{ }{
{ {
name: "no prebuilt", name: "no prebuilt",
modules: ` modules: `
@@ -44,7 +47,7 @@ var prebuiltsTests = []struct {
prefer: false, prefer: false,
srcs: ["prebuilt_file"], srcs: ["prebuilt_file"],
}`, }`,
prebuilt: []OsType{Android, BuildOs}, prebuilt: []OsType{Android, buildOS},
}, },
{ {
name: "no source prebuilt preferred", name: "no source prebuilt preferred",
@@ -54,7 +57,7 @@ var prebuiltsTests = []struct {
prefer: true, prefer: true,
srcs: ["prebuilt_file"], srcs: ["prebuilt_file"],
}`, }`,
prebuilt: []OsType{Android, BuildOs}, prebuilt: []OsType{Android, buildOS},
}, },
{ {
name: "prebuilt not preferred", name: "prebuilt not preferred",
@@ -82,7 +85,7 @@ var prebuiltsTests = []struct {
prefer: true, prefer: true,
srcs: ["prebuilt_file"], srcs: ["prebuilt_file"],
}`, }`,
prebuilt: []OsType{Android, BuildOs}, prebuilt: []OsType{Android, buildOS},
}, },
{ {
name: "prebuilt no file not preferred", name: "prebuilt no file not preferred",
@@ -122,7 +125,7 @@ var prebuiltsTests = []struct {
prefer: true, prefer: true,
srcs: [":fg"], srcs: [":fg"],
}`, }`,
prebuilt: []OsType{Android, BuildOs}, prebuilt: []OsType{Android, buildOS},
}, },
{ {
name: "prebuilt module for device only", name: "prebuilt module for device only",
@@ -155,7 +158,7 @@ var prebuiltsTests = []struct {
}, },
}, },
}`, }`,
prebuilt: []OsType{BuildOs}, prebuilt: []OsType{buildOS},
}, },
{ {
name: "prebuilt override not preferred", name: "prebuilt override not preferred",
@@ -193,7 +196,7 @@ var prebuiltsTests = []struct {
prefer: true, prefer: true,
srcs: ["prebuilt_file"], srcs: ["prebuilt_file"],
}`, }`,
prebuilt: []OsType{Android, BuildOs}, prebuilt: []OsType{Android, buildOS},
}, },
{ {
name: "prebuilt including default-disabled OS", name: "prebuilt including default-disabled OS",
@@ -228,7 +231,7 @@ var prebuiltsTests = []struct {
}, },
}, },
}`, }`,
prebuilt: []OsType{Android, BuildOs, Windows}, prebuilt: []OsType{Android, buildOS, Windows},
}, },
{ {
name: "fall back to source for default-disabled OS", name: "fall back to source for default-disabled OS",
@@ -258,7 +261,7 @@ var prebuiltsTests = []struct {
prefer: true, prefer: true,
srcs: ["prebuilt_file"], srcs: ["prebuilt_file"],
}`, }`,
prebuilt: []OsType{Android, BuildOs}, prebuilt: []OsType{Android, buildOS},
}, },
{ {
name: "prebuilt properties customizable", name: "prebuilt properties customizable",
@@ -290,7 +293,7 @@ var prebuiltsTests = []struct {
}, },
}, },
}`, }`,
prebuilt: []OsType{Android, BuildOs}, prebuilt: []OsType{Android, buildOS},
}, },
{ {
name: "prebuilt use_source_config_var={acme, use_source} - no var specified", name: "prebuilt use_source_config_var={acme, use_source} - no var specified",
@@ -306,7 +309,7 @@ var prebuiltsTests = []struct {
}`, }`,
// When use_source_env is specified then it will use the prebuilt by default if the environment // When use_source_env is specified then it will use the prebuilt by default if the environment
// variable is not set. // variable is not set.
prebuilt: []OsType{Android, BuildOs}, prebuilt: []OsType{Android, buildOS},
}, },
{ {
name: "prebuilt use_source_config_var={acme, use_source} - acme_use_source=false", name: "prebuilt use_source_config_var={acme, use_source} - acme_use_source=false",
@@ -329,7 +332,7 @@ var prebuiltsTests = []struct {
}), }),
// Setting the environment variable named in use_source_env to false will cause the prebuilt to // Setting the environment variable named in use_source_env to false will cause the prebuilt to
// be used. // be used.
prebuilt: []OsType{Android, BuildOs}, prebuilt: []OsType{Android, buildOS},
}, },
{ {
name: "prebuilt use_source_config_var={acme, use_source} - acme_use_source=true", name: "prebuilt use_source_config_var={acme, use_source} - acme_use_source=true",
@@ -370,11 +373,10 @@ var prebuiltsTests = []struct {
} }
}), }),
// Although the environment variable says to use source there is no source available. // Although the environment variable says to use source there is no source available.
prebuilt: []OsType{Android, BuildOs}, prebuilt: []OsType{Android, buildOS},
}, },
} }
func TestPrebuilts(t *testing.T) {
fs := MockFS{ fs := MockFS{
"prebuilt_file": nil, "prebuilt_file": nil,
"source_file": nil, "source_file": nil,

View File

@@ -60,7 +60,7 @@ func robolectricTestSuite(ctx SingletonContext, files map[string]InstallPaths) W
for _, module := range SortedStringKeys(files) { for _, module := range SortedStringKeys(files) {
installedPaths = append(installedPaths, files[module]...) 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") outputFile := PathForOutput(ctx, "packaging", "robolectric-tests.zip")
rule := NewRuleBuilder(pctx, ctx) rule := NewRuleBuilder(pctx, ctx)

View File

@@ -15,6 +15,7 @@
package config package config
import ( import (
"runtime"
"strings" "strings"
"android/soong/android" "android/soong/android"
@@ -282,7 +283,7 @@ var (
var pctx = android.NewPackageContext("android/soong/cc/config") var pctx = android.NewPackageContext("android/soong/cc/config")
func init() { func init() {
if android.BuildOs == android.Linux { if runtime.GOOS == "linux" {
commonGlobalCflags = append(commonGlobalCflags, "-fdebug-prefix-map=/proc/self/cwd=") commonGlobalCflags = append(commonGlobalCflags, "-fdebug-prefix-map=/proc/self/cwd=")
} }

View File

@@ -165,7 +165,7 @@ func makeVarsProvider(ctx android.MakeVarsContext) {
sort.Strings(ndkKnownLibs) sort.Strings(ndkKnownLibs)
ctx.Strict("NDK_KNOWN_LIBS", strings.Join(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]) makeVarsToolchain(ctx, "", hostTargets[0])
if len(hostTargets) > 1 { if len(hostTargets) > 1 {
makeVarsToolchain(ctx, "2ND_", hostTargets[1]) makeVarsToolchain(ctx, "2ND_", hostTargets[1])

View File

@@ -15,6 +15,7 @@
package cc package cc
import ( import (
"runtime"
"testing" "testing"
"android/soong/android" "android/soong/android"
@@ -271,8 +272,8 @@ func TestPrebuiltLibrarySharedStem(t *testing.T) {
} }
func TestPrebuiltSymlinkedHostBinary(t *testing.T) { func TestPrebuiltSymlinkedHostBinary(t *testing.T) {
if android.BuildOs != android.Linux { if runtime.GOOS != "linux" {
t.Skipf("Skipping host prebuilt testing that is only supported on %s not %s", android.Linux, android.BuildOs) t.Skipf("Skipping host prebuilt testing that is only supported on linux not %s", runtime.GOOS)
} }
ctx := testPrebuilt(t, ` ctx := testPrebuilt(t, `

View File

@@ -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") proto := ctx.ModuleForTests("libfoo", "android_arm_armv7-a-neon_shared").Output("proto/a.pb.cc")
foobar := ctx.ModuleForTests("protoc-gen-foobar", buildOS+"_x86_64") foobar := ctx.ModuleForTests("protoc-gen-foobar", buildOS+"_x86_64")

View File

@@ -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) p := result.Module("foo.conf", buildOS+"_common").(*PrebuiltEtc)
if !p.Host() { if !p.Host() {
t.Errorf("host bit is not set for a prebuilt_etc_host module.") 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) p := result.Module("foo.conf", buildOS+"_common").(*PrebuiltEtc)
expected := filepath.Join("out/soong/host", result.Config.PrebuiltOS(), "usr", "share", "bar") expected := filepath.Join("out/soong/host", result.Config.PrebuiltOS(), "usr", "share", "bar")
android.AssertPathRelativeToTopEquals(t, "install dir", expected, p.installDirPath) android.AssertPathRelativeToTopEquals(t, "install dir", expected, p.installDirPath)

View File

@@ -523,14 +523,14 @@ func buildBootImageVariantsForAndroidOs(ctx android.ModuleContext, image *bootIm
} }
// buildBootImageVariantsForBuildOs generates rules to build the boot image variants for the // 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 // 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 // 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 // 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. // not need to be returned from this func, unlike the buildBootImageVariantsForAndroidOs func.
func buildBootImageVariantsForBuildOs(ctx android.ModuleContext, image *bootImageConfig, profile android.WritablePath) { 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 // buildBootImageForOsType takes a bootImageConfig, a profile file and an android.OsType

View File

@@ -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. // 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) targets = append(targets, target)
} }

View File

@@ -16,6 +16,7 @@ package java
import ( import (
"fmt" "fmt"
"runtime"
"testing" "testing"
"android/soong/android" "android/soong/android"
@@ -173,9 +174,9 @@ func enabledString(enabled bool) string {
} }
func TestDex2oatToolDeps(t *testing.T) { func TestDex2oatToolDeps(t *testing.T) {
if android.BuildOs != android.Linux { if runtime.GOOS != "linux" {
// The host binary paths checked below are build OS dependent. // 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( preparers := android.GroupFixturePreparers(

View File

@@ -441,7 +441,7 @@ func TestBinary(t *testing.T) {
} }
`) `)
buildOS := android.BuildOs.String() buildOS := ctx.Config().BuildOS.String()
bar := ctx.ModuleForTests("bar", buildOS+"_common") bar := ctx.ModuleForTests("bar", buildOS+"_common")
barJar := bar.Output("bar.jar").Output.String() 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) 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 // 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") hostBinary := result.ModuleForTests("host_binary", buildOS+"_common")
hostJavaFlags := hostBinary.Module().VariablesForTests()["javacFlags"] hostJavaFlags := hostBinary.Module().VariablesForTests()["javacFlags"]
if strings.Contains(hostJavaFlags, "-g:source,lines") { 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) test := ctx.ModuleForTests("foo", buildOS+"_common").Module().(*TestHost)
entries := android.AndroidMkEntriesForTest(t, ctx, test)[0] 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) module := ctx.ModuleForTests("foo", buildOS+"_common").Module().(*TestHost)
assertDeepEquals(t, "Default installable value should be true.", proptools.BoolPtr(true), assertDeepEquals(t, "Default installable value should be true.", proptools.BoolPtr(true),
module.properties.Installable) module.properties.Installable)

View File

@@ -15,10 +15,11 @@
package java package java
import ( import (
"android/soong/android"
"strconv" "strconv"
"strings" "strings"
"testing" "testing"
"android/soong/android"
) )
func TestKotlin(t *testing.T) { func TestKotlin(t *testing.T) {
@@ -114,7 +115,7 @@ func TestKapt(t *testing.T) {
t.Run("", func(t *testing.T) { t.Run("", func(t *testing.T) {
ctx, _ := testJava(t, bp) ctx, _ := testJava(t, bp)
buildOS := android.BuildOs.String() buildOS := ctx.Config().BuildOS.String()
kapt := ctx.ModuleForTests("foo", "android_common").Rule("kapt") kapt := ctx.ModuleForTests("foo", "android_common").Rule("kapt")
kotlinc := ctx.ModuleForTests("foo", "android_common").Rule("kotlinc") kotlinc := ctx.ModuleForTests("foo", "android_common").Rule("kotlinc")
@@ -182,7 +183,7 @@ func TestKapt(t *testing.T) {
android.FixtureMergeEnv(env), android.FixtureMergeEnv(env),
).RunTestWithBp(t, bp) ).RunTestWithBp(t, bp)
buildOS := android.BuildOs.String() buildOS := result.Config.BuildOS.String()
kapt := result.ModuleForTests("foo", "android_common").Rule("kapt") kapt := result.ModuleForTests("foo", "android_common").Rule("kapt")
javac := result.ModuleForTests("foo", "android_common").Description("javac") javac := result.ModuleForTests("foo", "android_common").Description("javac")

View File

@@ -15,7 +15,6 @@
package java package java
import ( import (
"android/soong/android"
"testing" "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") javac := ctx.ModuleForTests("foo", "android_common").Rule("javac")
turbine := ctx.ModuleForTests("foo", "android_common").MaybeRule("turbine") 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") javac := ctx.ModuleForTests("foo", "android_common").Rule("javac")
turbine := ctx.ModuleForTests("foo", "android_common").MaybeRule("turbine") turbine := ctx.ModuleForTests("foo", "android_common").MaybeRule("turbine")

View File

@@ -83,6 +83,9 @@ type robolectricTest struct {
testConfig android.Path testConfig android.Path
data android.Paths data android.Paths
forceOSType android.OsType
forceArchType android.ArchType
} }
func (r *robolectricTest) TestSuites() []string { func (r *robolectricTest) TestSuites() []string {
@@ -115,6 +118,9 @@ func (r *robolectricTest) DepsMutator(ctx android.BottomUpMutatorContext) {
} }
func (r *robolectricTest) GenerateAndroidBuildActions(ctx android.ModuleContext) { 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.testConfig = tradefed.AutoGenRobolectricTestConfig(ctx, r.testProperties.Test_config,
r.testProperties.Test_config_template, r.testProperties.Test_suites, r.testProperties.Test_config_template, r.testProperties.Test_suites,
r.testProperties.Auto_gen_config) r.testProperties.Auto_gen_config)
@@ -345,7 +351,7 @@ func RobolectricTestFactory() android.Module {
func (r *robolectricTest) InstallBypassMake() bool { return true } func (r *robolectricTest) InstallBypassMake() bool { return true }
func (r *robolectricTest) InstallInTestcases() bool { return true } func (r *robolectricTest) InstallInTestcases() bool { return true }
func (r *robolectricTest) InstallForceOS() (*android.OsType, *android.ArchType) { func (r *robolectricTest) InstallForceOS() (*android.OsType, *android.ArchType) {
return &android.BuildOs, &android.BuildArch return &r.forceOSType, &r.forceArchType
} }
func robolectricRuntimesFactory() android.Module { func robolectricRuntimesFactory() android.Module {
@@ -366,6 +372,9 @@ type robolectricRuntimes struct {
props robolectricRuntimesProperties props robolectricRuntimesProperties
runtimes []android.InstallPath runtimes []android.InstallPath
forceOSType android.OsType
forceArchType android.ArchType
} }
func (r *robolectricRuntimes) TestSuites() []string { func (r *robolectricRuntimes) TestSuites() []string {
@@ -385,6 +394,9 @@ func (r *robolectricRuntimes) GenerateAndroidBuildActions(ctx android.ModuleCont
return return
} }
r.forceOSType = ctx.Config().BuildOS
r.forceArchType = ctx.Config().BuildArch
files := android.PathsForModuleSrc(ctx, r.props.Jars) files := android.PathsForModuleSrc(ctx, r.props.Jars)
androidAllDir := android.PathForModuleInstall(ctx, "android-all") 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) InstallBypassMake() bool { return true }
func (r *robolectricRuntimes) InstallInTestcases() bool { return true } func (r *robolectricRuntimes) InstallInTestcases() bool { return true }
func (r *robolectricRuntimes) InstallForceOS() (*android.OsType, *android.ArchType) { func (r *robolectricRuntimes) InstallForceOS() (*android.OsType, *android.ArchType) {
return &android.BuildOs, &android.BuildArch return &r.forceOSType, &r.forceArchType
} }

View File

@@ -255,9 +255,11 @@ func TestClasspath(t *testing.T) {
` + testcase.properties + ` ` + testcase.properties + `
}` }`
variant := "android_common" variant := func(result *android.TestResult) string {
if testcase.host == android.Host { if testcase.host == android.Host {
variant = android.BuildOs.String() + "_common" return result.Config.BuildOS.String() + "_common"
}
return "android_common"
} }
convertModulesToPaths := func(cp []string) []string { convertModulesToPaths := func(cp []string) []string {
@@ -312,7 +314,7 @@ func TestClasspath(t *testing.T) {
} }
checkClasspath := func(t *testing.T, result *android.TestResult, isJava8 bool) { 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") javac := foo.Rule("javac")
var deps []string var deps []string
@@ -376,7 +378,7 @@ func TestClasspath(t *testing.T) {
checkClasspath(t, result, true /* isJava8 */) checkClasspath(t, result, true /* isJava8 */)
if testcase.host != android.Host { 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.") 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 */) checkClasspath(t, result, false /* isJava8 */)
if testcase.host != android.Host { 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.") android.AssertStringDoesContain(t, "aidl command", aidl.RuleParams.Command, testcase.aidl+" -I.")
} }

View File

@@ -305,7 +305,7 @@ func (compiler *baseCompiler) compilerDeps(ctx DepsContext, deps Deps) Deps {
if !Bool(compiler.Properties.No_stdlibs) { if !Bool(compiler.Properties.No_stdlibs) {
for _, stdlib := range config.Stdlibs { for _, stdlib := range config.Stdlibs {
// If we're building for the primary arch of the build host, use the compiler's 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() stdlib = stdlib + "_" + ctx.toolchain().RustTriple()
} }
deps.Stdlibs = append(deps.Stdlibs, stdlib) deps.Stdlibs = append(deps.Stdlibs, stdlib)

View File

@@ -176,6 +176,8 @@ func TestProjectJsonBinary(t *testing.T) {
} }
func TestProjectJsonBindGen(t *testing.T) { func TestProjectJsonBindGen(t *testing.T) {
buildOS := android.TestConfig(t.TempDir(), nil, "", nil).BuildOS
bp := ` bp := `
rust_library { rust_library {
name: "libd", name: "libd",
@@ -214,9 +216,9 @@ func TestProjectJsonBindGen(t *testing.T) {
if strings.Contains(rootModule, "libbindings1") && !strings.Contains(rootModule, "android_arm64") { 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) 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", 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. // Check that libbindings1 does not depend on itself.
if strings.Contains(rootModule, "libbindings1") { if strings.Contains(rootModule, "libbindings1") {

View File

@@ -15,19 +15,21 @@
package sdk package sdk
import ( import (
"android/soong/android"
"log" "log"
"os" "os"
"runtime"
"testing" "testing"
"android/soong/android"
"github.com/google/blueprint/proptools" "github.com/google/blueprint/proptools"
) )
// Needed in an _test.go file in this package to ensure tests run correctly, particularly in IDE. // Needed in an _test.go file in this package to ensure tests run correctly, particularly in IDE.
func TestMain(m *testing.M) { 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. // 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) os.Exit(0)
} }

View File

@@ -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"} arches := []string{"android_arm64_armv8-a", buildOS + "_x86_64"}
for _, arch := range arches { for _, arch := range arches {
variant := ctx.ModuleForTests("foo", arch) 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) mod := ctx.ModuleForTests("foo", buildOS+"_x86_64").Module().(*ShTest)
if !mod.Host() { if !mod.Host() {
t.Errorf("host bit is not set for a sh_test_host module.") 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") variant := ctx.ModuleForTests("foo", buildOS+"_x86_64")
relocated := variant.Output("relocated/lib64/libbar.so") relocated := variant.Output("relocated/lib64/libbar.so")