mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-05-18 00:47:48 +08:00
Merge pull request #2717 from crazy-max/fix-ls-notrunc
ls: ensure deterministic output for truncated platforms
This commit is contained in:
commit
d353f5f6ba
@ -308,6 +308,12 @@ func (tp truncatedPlatforms) String() string {
|
|||||||
var out []string
|
var out []string
|
||||||
var count int
|
var count int
|
||||||
|
|
||||||
|
var keys []string
|
||||||
|
for k := range tp.res {
|
||||||
|
keys = append(keys, k)
|
||||||
|
}
|
||||||
|
sort.Strings(keys)
|
||||||
|
|
||||||
seen := make(map[string]struct{})
|
seen := make(map[string]struct{})
|
||||||
for _, mpf := range truncMajorPlatforms {
|
for _, mpf := range truncMajorPlatforms {
|
||||||
if tpf, ok := tp.res[mpf]; ok {
|
if tpf, ok := tp.res[mpf]; ok {
|
||||||
@ -333,19 +339,19 @@ func (tp truncatedPlatforms) String() string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for mpf, pf := range tp.res {
|
for _, mpf := range keys {
|
||||||
if len(out) >= tp.max {
|
if len(out) >= tp.max {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
if _, ok := seen[mpf]; ok {
|
if _, ok := seen[mpf]; ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if len(pf) == 1 {
|
if len(tp.res[mpf]) == 1 {
|
||||||
out = append(out, fmt.Sprintf("%s", pf[0]))
|
out = append(out, fmt.Sprintf("%s", tp.res[mpf][0]))
|
||||||
count++
|
count++
|
||||||
} else {
|
} else {
|
||||||
hasPreferredPlatform := false
|
hasPreferredPlatform := false
|
||||||
for _, pf := range pf {
|
for _, pf := range tp.res[mpf] {
|
||||||
if strings.HasSuffix(pf, "*") {
|
if strings.HasSuffix(pf, "*") {
|
||||||
hasPreferredPlatform = true
|
hasPreferredPlatform = true
|
||||||
break
|
break
|
||||||
@ -355,8 +361,8 @@ func (tp truncatedPlatforms) String() string {
|
|||||||
if hasPreferredPlatform {
|
if hasPreferredPlatform {
|
||||||
mainpf += "*"
|
mainpf += "*"
|
||||||
}
|
}
|
||||||
out = append(out, fmt.Sprintf("%s (+%d)", mainpf, len(pf)))
|
out = append(out, fmt.Sprintf("%s (+%d)", mainpf, len(tp.res[mpf])))
|
||||||
count += len(pf)
|
count += len(tp.res[mpf])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user