From 8cf0cb3a0aec11dab4d219ade4176024ab8900e9 Mon Sep 17 00:00:00 2001 From: Chongyi Zheng Date: Sun, 3 Nov 2024 20:40:53 -0500 Subject: [PATCH] Support normalizing any arm64/v9.x variants Signed-off-by: Chongyi Zheng Signed-off-by: Samuel Karp --- compare_test.go | 24 ++++++++++++++++++++++++ database.go | 22 +++++++++++++++------- 2 files changed, 39 insertions(+), 7 deletions(-) diff --git a/compare_test.go b/compare_test.go index c514bf0..ef5c2a1 100644 --- a/compare_test.go +++ b/compare_test.go @@ -479,6 +479,30 @@ func TestOnlyStrict(t *testing.T) { }, }, }, + { + platform: "linux/arm64/v9.5", + matches: map[bool][]string{ + true: { + "linux/arm64/v9.5", + }, + false: { + "linux/arm", + "linux/arm/v5", + "linux/arm/v6", + "linux/arm/v7", + "linux/arm/v8", + "linux/amd64", + "linux/arm/v4", + "linux/arm64/v8", + "linux/arm64/v8.1", + "linux/arm64/v9", + "linux/arm64/v9.1", + "linux/arm64/v9.4", + "windows/amd64", + "windows/arm", + }, + }, + }, { platform: "linux/arm64/v9", matches: map[bool][]string{ diff --git a/database.go b/database.go index 113bbab..4c7c669 100644 --- a/database.go +++ b/database.go @@ -86,14 +86,22 @@ func normalizeArch(arch, variant string) (string, string) { } case "aarch64", "arm64": arch = "arm64" - switch variant { - case "8", "v8", "8.0", "v8.0": + majorVariant, minorVariant, hasMinor := strings.Cut(variant, ".") + majorVariant = strings.TrimPrefix(majorVariant, "v") + if minorVariant == "0" { + minorVariant = "" + hasMinor = false + } + + if (majorVariant == "" || majorVariant == "8") && !hasMinor { + // normalize v8 to empty string variant = "" - case "9", "9.0", "v9.0": - variant = "v9" - case "8.1", "8.2", "8.3", "8.4", "8.5", "8.6", "8.7", "8.8", "8.9", - "9.1", "9.2", "9.3", "9.4", "9.5": - variant = "v" + variant + } else { + // otherwise to v8.x or v9 or v9.x + variant = "v" + majorVariant + if hasMinor { + variant = variant + "." + minorVariant + } } case "armhf": arch = "arm"