Skip to content

Commit

Permalink
fix(nfpm): termux platform (#4812)
Browse files Browse the repository at this point in the history
closes #4810 
closes  #4809

---------

Co-authored-by: rsteube <rsteube@users.noreply.github.com>
  • Loading branch information
caarlos0 and rsteube committed Apr 28, 2024
1 parent c052ccc commit bf31227
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 12 deletions.
26 changes: 18 additions & 8 deletions internal/pipe/nfpm/nfpm.go
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
}
Expand All @@ -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
}
}
Expand Down Expand Up @@ -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
Expand Down
20 changes: 16 additions & 4 deletions internal/pipe/nfpm/nfpm_test.go
Expand Up @@ -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
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions www/docs/customization/nfpm.md
Expand Up @@ -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

Expand Down

0 comments on commit bf31227

Please sign in to comment.