From bf31227b4eb975f87b995719d3b152f4d9b2f993 Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Sun, 28 Apr 2024 20:20:53 -0300 Subject: [PATCH] fix(nfpm): termux platform (#4812) closes #4810 closes #4809 --------- Co-authored-by: rsteube --- internal/pipe/nfpm/nfpm.go | 26 ++++++++++++++++++-------- internal/pipe/nfpm/nfpm_test.go | 20 ++++++++++++++++---- www/docs/customization/nfpm.md | 1 + 3 files changed, 35 insertions(+), 12 deletions(-) diff --git a/internal/pipe/nfpm/nfpm.go b/internal/pipe/nfpm/nfpm.go index 62fbcf4cd2a..e7f2459eb8b 100644 --- a/internal/pipe/nfpm/nfpm.go +++ b/internal/pipe/nfpm/nfpm.go @@ -103,6 +103,7 @@ func doRun(ctx *context.Context, fpm config.NFPM) error { artifact.Or( artifact.ByGoos("linux"), artifact.ByGoos("ios"), + artifact.ByGoos("android"), ), } if len(fpm.Builds) > 0 { @@ -144,9 +145,12 @@ func mergeOverrides(fpm config.NFPM, format string) (*config.NFPMOverridables, e const termuxFormat = "termux.deb" -func isSupportedTermuxArch(arch string) bool { - for _, a := range []string{"amd64", "arm64", "386"} { - if strings.HasPrefix(arch, a) { +func isSupportedTermuxArch(goos, goarch string) bool { + if goos != "android" { + return false + } + for _, arch := range []string{"amd64", "arm64", "386"} { + if strings.HasPrefix(goarch, arch) { return true } } @@ -155,12 +159,12 @@ func isSupportedTermuxArch(arch string) bool { // arch officially only supports x86_64. // however, there are unofficial ports for 686, arm64, and armv7 -func isSupportedArchlinuxArch(arch, arm string) bool { - if arch == "arm" && arm == "7" { +func isSupportedArchlinuxArch(goarch, goarm string) bool { + if goarch == "arm" && goarm == "7" { return true } - for _, a := range []string{"amd64", "arm64", "386"} { - if strings.HasPrefix(arch, a) { + for _, arch := range []string{"amd64", "arm64", "386"} { + if strings.HasPrefix(goarch, arch) { return true } } @@ -194,19 +198,25 @@ func create(ctx *context.Context, fpm config.NFPM, format string, artifacts []*a return nil } case termuxFormat: - if !isSupportedTermuxArch(artifacts[0].Goarch) { + if !isSupportedTermuxArch(artifacts[0].Goos, artifacts[0].Goarch) { log.Debugf("skipping termux.deb for %s as its not supported by termux", arch) return nil } infoArch = termuxArchReplacer.Replace(infoArch) arch = termuxArchReplacer.Replace(arch) + infoPlatform = "linux" fpm.Bindir = termuxPrefixedDir(fpm.Bindir) fpm.Libdirs.Header = termuxPrefixedDir(fpm.Libdirs.Header) fpm.Libdirs.CArchive = termuxPrefixedDir(fpm.Libdirs.CArchive) fpm.Libdirs.CShared = termuxPrefixedDir(fpm.Libdirs.CShared) } + if artifacts[0].Goos == "android" && format != termuxFormat { + log.Debugf("skipping android packaging as its not supported by %s", format) + return nil + } + overridden, err := mergeOverrides(fpm, format) if err != nil { return err diff --git a/internal/pipe/nfpm/nfpm_test.go b/internal/pipe/nfpm/nfpm_test.go index b9dd2ec3d96..5fbc0221d61 100644 --- a/internal/pipe/nfpm/nfpm_test.go +++ b/internal/pipe/nfpm/nfpm_test.go @@ -196,7 +196,7 @@ func TestRunPipe(t *testing.T) { }, }, }, testctx.WithVersion("1.0.0"), testctx.WithCurrentTag("v1.0.0")) - for _, goos := range []string{"linux", "darwin", "ios"} { + for _, goos := range []string{"linux", "darwin", "ios", "android"} { for _, goarch := range []string{"amd64", "386", "arm64", "arm", "mips"} { if goos == "ios" && goarch != "arm64" { continue @@ -415,9 +415,12 @@ func TestRunPipe(t *testing.T) { } } - if pkg.Goos == "linux" { + switch pkg.Goos { + case "linux": require.Equal(t, "foo_1.0.0_linux_"+arch+"-10-20"+ext, pkg.Name) - } else { + case "android": + require.Equal(t, "foo_1.0.0_android_"+arch+"-10-20"+ext, pkg.Name) + default: require.Equal(t, "foo_1.0.0_ios_arm64-10-20"+ext, pkg.Name) } require.Equal(t, "someid", pkg.ID()) @@ -961,7 +964,7 @@ func TestDebSpecificConfig(t *testing.T) { }, }, }, testctx.WithVersion("1.0.0"), testctx.WithCurrentTag("v1.0.0")) - for _, goos := range []string{"linux", "darwin"} { + for _, goos := range []string{"linux", "darwin", "android"} { for _, goarch := range []string{"amd64", "386"} { ctx.Artifacts.Add(&artifact.Artifact{ Name: "mybin", @@ -1619,6 +1622,15 @@ func TestTemplateExt(t *testing.T) { }, }, }) + ctx.Artifacts.Add(&artifact.Artifact{ + Name: "mybin", + Goos: "android", + Goarch: "amd64", + Type: artifact.Binary, + Extra: map[string]interface{}{ + artifact.ExtraID: "default", + }, + }) ctx.Artifacts.Add(&artifact.Artifact{ Name: "mybin", Goos: "linux", diff --git a/www/docs/customization/nfpm.md b/www/docs/customization/nfpm.md index 9bb92980eda..0ed5106838f 100644 --- a/www/docs/customization/nfpm.md +++ b/www/docs/customization/nfpm.md @@ -498,6 +498,7 @@ Termux is the same format as `deb`, the differences are: - it uses a different `bindir` (prefixed with `/data/data/com.termux/files/`) - it uses slightly different architecture names than Debian +- it will only package binaries built for Android ## Conventional file names, Debian, and ARMv6