Make FirstTarget treat HostCross separately from Host

Use Target.Os and Target.HostCross as the key in FirstTarget so that
it returns a separate target for host and host cross architectures.
This is useful when host and host cross are both linux_musl, but
host cross is an independenct architecture like arm64.

Bug: 236052820
Test: cross compile linux_musl-arm64
Change-Id: If75790001afe9d0f9d4d8166f207847851812297
This commit is contained in:
Colin Cross
2022-07-19 14:41:11 -07:00
parent 1b3d5f836c
commit c5d7ad6b68

View File

@@ -1843,20 +1843,23 @@ func getCommonTargets(targets []Target) []Target {
}
// FirstTarget takes a list of Targets and a list of multilib values and returns a list of Targets
// that contains zero or one Target for each OsType, selecting the one that matches the earliest
// filter.
// that contains zero or one Target for each OsType and HostCross, selecting the one that matches
// the earliest filter.
func FirstTarget(targets []Target, filters ...string) []Target {
// find the first target from each OS
var ret []Target
hasHost := false
set := make(map[OsType]bool)
type osHostCross struct {
os OsType
hostCross bool
}
set := make(map[osHostCross]bool)
for _, filter := range filters {
buildTargets := filterMultilibTargets(targets, filter)
for _, t := range buildTargets {
if _, found := set[t.Os]; !found {
hasHost = hasHost || (t.Os.Class == Host)
set[t.Os] = true
key := osHostCross{t.Os, t.HostCross}
if _, found := set[key]; !found {
set[key] = true
ret = append(ret, t)
}
}