From 9524bb8a26d3915e84a4df956d2ec064e836c4a3 Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Wed, 24 May 2023 02:34:03 +0000 Subject: [PATCH] fix: mips softfloat/hardfloat handling --- deb/deb.go | 7 ------- nfpm.go | 6 ++++++ nfpm_test.go | 22 ++++++++++++++++++++++ rpm/rpm.go | 7 ------- 4 files changed, 28 insertions(+), 14 deletions(-) diff --git a/deb/deb.go b/deb/deb.go index f814945d..d139841f 100644 --- a/deb/deb.go +++ b/deb/deb.go @@ -51,13 +51,6 @@ func ensureValidArch(info *nfpm.Info) *nfpm.Info { info.Arch = info.Deb.Arch } else if arch, ok := archToDebian[info.Arch]; ok { info.Arch = arch - } else { - for k, v := range archToDebian { - if strings.HasPrefix(info.Arch, k) { - info.Arch = v - break - } - } } return info diff --git a/nfpm.go b/nfpm.go index b1410f8e..372164bd 100644 --- a/nfpm.go +++ b/nfpm.go @@ -479,6 +479,12 @@ func WithDefaults(info *Info) *Info { if info.Arch == "" { info.Arch = "amd64" } + if strings.HasPrefix(info.Arch, "mips") { + info.Arch = strings.NewReplacer( + "softfloat", "", + "hardfloat", "", + ).Replace(info.Arch) + } if info.Version == "" { info.Version = "v0.0.0-rc0" } diff --git a/nfpm_test.go b/nfpm_test.go index 24a75495..aa5274fb 100644 --- a/nfpm_test.go +++ b/nfpm_test.go @@ -119,6 +119,28 @@ func TestDefaults(t *testing.T) { }, }, *got) }) + t.Run("mips softfloat", func(t *testing.T) { + makeinfo := func() nfpm.Info { + return nfpm.Info{ + Platform: "linux", + Arch: "mips64softfloat", + } + } + info := makeinfo() + nfpm.WithDefaults(&info) + require.Equal(t, "mips64", info.Arch) + }) + t.Run("mips softfloat", func(t *testing.T) { + makeinfo := func() nfpm.Info { + return nfpm.Info{ + Platform: "linux", + Arch: "mips64hardfloat", + } + } + info := makeinfo() + nfpm.WithDefaults(&info) + require.Equal(t, "mips64", info.Arch) + }) } func TestPrepareForPackager(t *testing.T) { diff --git a/rpm/rpm.go b/rpm/rpm.go index fc1da8d9..0d3fa4d4 100644 --- a/rpm/rpm.go +++ b/rpm/rpm.go @@ -75,13 +75,6 @@ func ensureValidArch(info *nfpm.Info) *nfpm.Info { info.Arch = info.RPM.Arch } else if arch, ok := archToRPM[info.Arch]; ok { info.Arch = arch - } else { - for k, v := range archToRPM { - if strings.HasPrefix(info.Arch, k) { - info.Arch = v - break - } - } } return info