Merge "Improve clarity of arch decoding."

This commit is contained in:
Liz Kammer
2022-03-02 15:44:26 +00:00
committed by Gerrit Code Review
2 changed files with 65 additions and 36 deletions

View File

@@ -1518,23 +1518,32 @@ func decodeTargetProductVariables(config *config) (map[OsType][]Target, error) {
targets := make(map[OsType][]Target) targets := make(map[OsType][]Target)
var targetErr error var targetErr error
addTarget := func(os OsType, archName string, archVariant, cpuVariant *string, abi []string, type targetConfig struct {
nativeBridgeEnabled NativeBridgeSupport, nativeBridgeHostArchName *string, os OsType
nativeBridgeRelativePath *string) { archName string
archVariant *string
cpuVariant *string
abi []string
nativeBridgeEnabled NativeBridgeSupport
nativeBridgeHostArchName *string
nativeBridgeRelativePath *string
}
addTarget := func(target targetConfig) {
if targetErr != nil { if targetErr != nil {
return return
} }
arch, err := decodeArch(os, archName, archVariant, cpuVariant, abi) arch, err := decodeArch(target.os, target.archName, target.archVariant, target.cpuVariant, target.abi)
if err != nil { if err != nil {
targetErr = err targetErr = err
return return
} }
nativeBridgeRelativePathStr := String(nativeBridgeRelativePath) nativeBridgeRelativePathStr := String(target.nativeBridgeRelativePath)
nativeBridgeHostArchNameStr := String(nativeBridgeHostArchName) nativeBridgeHostArchNameStr := String(target.nativeBridgeHostArchName)
// Use guest arch as relative install path by default // Use guest arch as relative install path by default
if nativeBridgeEnabled && nativeBridgeRelativePathStr == "" { if target.nativeBridgeEnabled && nativeBridgeRelativePathStr == "" {
nativeBridgeRelativePathStr = arch.ArchType.String() nativeBridgeRelativePathStr = arch.ArchType.String()
} }
@@ -1542,11 +1551,11 @@ func decodeTargetProductVariables(config *config) (map[OsType][]Target, error) {
// the currently configured build machine (either because the OS is different or because of // the currently configured build machine (either because the OS is different or because of
// the unsupported arch) // the unsupported arch)
hostCross := false hostCross := false
if os.Class == Host { if target.os.Class == Host {
var osSupported bool var osSupported bool
if os == config.BuildOS { if target.os == config.BuildOS {
osSupported = true osSupported = true
} else if config.BuildOS.Linux() && os.Linux() { } else if config.BuildOS.Linux() && target.os.Linux() {
// LinuxBionic and Linux are compatible // LinuxBionic and Linux are compatible
osSupported = true osSupported = true
} else { } else {
@@ -1568,11 +1577,11 @@ func decodeTargetProductVariables(config *config) (map[OsType][]Target, error) {
} }
} }
targets[os] = append(targets[os], targets[target.os] = append(targets[target.os],
Target{ Target{
Os: os, Os: target.os,
Arch: arch, Arch: arch,
NativeBridge: nativeBridgeEnabled, NativeBridge: target.nativeBridgeEnabled,
NativeBridgeHostArchName: nativeBridgeHostArchNameStr, NativeBridgeHostArchName: nativeBridgeHostArchNameStr,
NativeBridgeRelativePath: nativeBridgeRelativePathStr, NativeBridgeRelativePath: nativeBridgeRelativePathStr,
HostCross: hostCross, HostCross: hostCross,
@@ -1584,11 +1593,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(config.BuildOS, *variables.HostArch, nil, nil, nil, NativeBridgeDisabled, nil, nil) addTarget(targetConfig{os: config.BuildOS, archName: *variables.HostArch, nativeBridgeEnabled: NativeBridgeDisabled})
// An optional secondary host target. // An optional secondary host target.
if variables.HostSecondaryArch != nil && *variables.HostSecondaryArch != "" { if variables.HostSecondaryArch != nil && *variables.HostSecondaryArch != "" {
addTarget(config.BuildOS, *variables.HostSecondaryArch, nil, nil, nil, NativeBridgeDisabled, nil, nil) addTarget(targetConfig{os: config.BuildOS, archName: *variables.HostSecondaryArch, nativeBridgeEnabled: NativeBridgeDisabled})
} }
// Optional cross-compiled host targets, generally Windows. // Optional cross-compiled host targets, generally Windows.
@@ -1603,45 +1612,65 @@ func decodeTargetProductVariables(config *config) (map[OsType][]Target, error) {
} }
// The primary cross-compiled host target. // The primary cross-compiled host target.
addTarget(crossHostOs, *variables.CrossHostArch, nil, nil, nil, NativeBridgeDisabled, nil, nil) addTarget(targetConfig{os: crossHostOs, archName: *variables.CrossHostArch, nativeBridgeEnabled: NativeBridgeDisabled})
// An optional secondary cross-compiled host target. // An optional secondary cross-compiled host target.
if variables.CrossHostSecondaryArch != nil && *variables.CrossHostSecondaryArch != "" { if variables.CrossHostSecondaryArch != nil && *variables.CrossHostSecondaryArch != "" {
addTarget(crossHostOs, *variables.CrossHostSecondaryArch, nil, nil, nil, NativeBridgeDisabled, nil, nil) addTarget(targetConfig{os: crossHostOs, archName: *variables.CrossHostSecondaryArch, nativeBridgeEnabled: NativeBridgeDisabled})
} }
} }
// Optional device targets // Optional device targets
if variables.DeviceArch != nil && *variables.DeviceArch != "" { if variables.DeviceArch != nil && *variables.DeviceArch != "" {
// The primary device target. // The primary device target.
addTarget(Android, *variables.DeviceArch, variables.DeviceArchVariant, addTarget(targetConfig{
variables.DeviceCpuVariant, variables.DeviceAbi, NativeBridgeDisabled, nil, nil) os: Android,
archName: *variables.DeviceArch,
archVariant: variables.DeviceArchVariant,
cpuVariant: variables.DeviceCpuVariant,
abi: variables.DeviceAbi,
nativeBridgeEnabled: NativeBridgeDisabled,
})
// An optional secondary device target. // An optional secondary device target.
if variables.DeviceSecondaryArch != nil && *variables.DeviceSecondaryArch != "" { if variables.DeviceSecondaryArch != nil && *variables.DeviceSecondaryArch != "" {
addTarget(Android, *variables.DeviceSecondaryArch, addTarget(targetConfig{
variables.DeviceSecondaryArchVariant, variables.DeviceSecondaryCpuVariant, os: Android,
variables.DeviceSecondaryAbi, NativeBridgeDisabled, nil, nil) archName: *variables.DeviceSecondaryArch,
archVariant: variables.DeviceSecondaryArchVariant,
cpuVariant: variables.DeviceSecondaryCpuVariant,
abi: variables.DeviceSecondaryAbi,
nativeBridgeEnabled: NativeBridgeDisabled,
})
} }
// An optional NativeBridge device target. // An optional NativeBridge device target.
if variables.NativeBridgeArch != nil && *variables.NativeBridgeArch != "" { if variables.NativeBridgeArch != nil && *variables.NativeBridgeArch != "" {
addTarget(Android, *variables.NativeBridgeArch, addTarget(targetConfig{
variables.NativeBridgeArchVariant, variables.NativeBridgeCpuVariant, os: Android,
variables.NativeBridgeAbi, NativeBridgeEnabled, variables.DeviceArch, archName: *variables.NativeBridgeArch,
variables.NativeBridgeRelativePath) archVariant: variables.NativeBridgeArchVariant,
cpuVariant: variables.NativeBridgeCpuVariant,
abi: variables.NativeBridgeAbi,
nativeBridgeEnabled: NativeBridgeEnabled,
nativeBridgeHostArchName: variables.DeviceArch,
nativeBridgeRelativePath: variables.NativeBridgeRelativePath,
})
} }
// An optional secondary NativeBridge device target. // An optional secondary NativeBridge device target.
if variables.DeviceSecondaryArch != nil && *variables.DeviceSecondaryArch != "" && if variables.DeviceSecondaryArch != nil && *variables.DeviceSecondaryArch != "" &&
variables.NativeBridgeSecondaryArch != nil && *variables.NativeBridgeSecondaryArch != "" { variables.NativeBridgeSecondaryArch != nil && *variables.NativeBridgeSecondaryArch != "" {
addTarget(Android, *variables.NativeBridgeSecondaryArch, addTarget(targetConfig{
variables.NativeBridgeSecondaryArchVariant, os: Android,
variables.NativeBridgeSecondaryCpuVariant, archName: *variables.NativeBridgeSecondaryArch,
variables.NativeBridgeSecondaryAbi, archVariant: variables.NativeBridgeSecondaryArchVariant,
NativeBridgeEnabled, cpuVariant: variables.NativeBridgeSecondaryCpuVariant,
variables.DeviceSecondaryArch, abi: variables.NativeBridgeSecondaryAbi,
variables.NativeBridgeSecondaryRelativePath) nativeBridgeEnabled: NativeBridgeEnabled,
nativeBridgeHostArchName: variables.DeviceSecondaryArch,
nativeBridgeRelativePath: variables.NativeBridgeSecondaryRelativePath,
})
} }
} }
@@ -1701,11 +1730,11 @@ func getAmlAbisConfig() []archConfig {
} }
// decodeArchSettings converts a list of archConfigs into a list of Targets for the given OsType. // decodeArchSettings converts a list of archConfigs into a list of Targets for the given OsType.
func decodeArchSettings(os OsType, archConfigs []archConfig) ([]Target, error) { func decodeAndroidArchSettings(archConfigs []archConfig) ([]Target, error) {
var ret []Target var ret []Target
for _, config := range archConfigs { for _, config := range archConfigs {
arch, err := decodeArch(os, config.arch, &config.archVariant, arch, err := decodeArch(Android, config.arch, &config.archVariant,
&config.cpuVariant, config.abi) &config.cpuVariant, config.abi)
if err != nil { if err != nil {
return nil, err return nil, err

View File

@@ -520,7 +520,7 @@ func NewConfig(moduleListFile string, runGoTests bool, outDir, soongOutDir strin
} }
if archConfig != nil { if archConfig != nil {
androidTargets, err := decodeArchSettings(Android, archConfig) androidTargets, err := decodeAndroidArchSettings(archConfig)
if err != nil { if err != nil {
return Config{}, err return Config{}, err
} }