1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-03-19 20:57:53 +02:00

fix(nfpm): termux platform (#4812)

closes #4810 
closes  #4809

---------

Co-authored-by: rsteube <rsteube@users.noreply.github.com>
This commit is contained in:
Carlos Alexandro Becker 2024-04-28 20:20:53 -03:00 committed by GitHub
parent c052ccc691
commit bf31227b4e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 35 additions and 12 deletions

View File

@ -103,6 +103,7 @@ func doRun(ctx *context.Context, fpm config.NFPM) error {
artifact.Or( artifact.Or(
artifact.ByGoos("linux"), artifact.ByGoos("linux"),
artifact.ByGoos("ios"), artifact.ByGoos("ios"),
artifact.ByGoos("android"),
), ),
} }
if len(fpm.Builds) > 0 { if len(fpm.Builds) > 0 {
@ -144,9 +145,12 @@ func mergeOverrides(fpm config.NFPM, format string) (*config.NFPMOverridables, e
const termuxFormat = "termux.deb" const termuxFormat = "termux.deb"
func isSupportedTermuxArch(arch string) bool { func isSupportedTermuxArch(goos, goarch string) bool {
for _, a := range []string{"amd64", "arm64", "386"} { if goos != "android" {
if strings.HasPrefix(arch, a) { return false
}
for _, arch := range []string{"amd64", "arm64", "386"} {
if strings.HasPrefix(goarch, arch) {
return true return true
} }
} }
@ -155,12 +159,12 @@ func isSupportedTermuxArch(arch string) bool {
// arch officially only supports x86_64. // arch officially only supports x86_64.
// however, there are unofficial ports for 686, arm64, and armv7 // however, there are unofficial ports for 686, arm64, and armv7
func isSupportedArchlinuxArch(arch, arm string) bool { func isSupportedArchlinuxArch(goarch, goarm string) bool {
if arch == "arm" && arm == "7" { if goarch == "arm" && goarm == "7" {
return true return true
} }
for _, a := range []string{"amd64", "arm64", "386"} { for _, arch := range []string{"amd64", "arm64", "386"} {
if strings.HasPrefix(arch, a) { if strings.HasPrefix(goarch, arch) {
return true return true
} }
} }
@ -194,19 +198,25 @@ func create(ctx *context.Context, fpm config.NFPM, format string, artifacts []*a
return nil return nil
} }
case termuxFormat: 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) log.Debugf("skipping termux.deb for %s as its not supported by termux", arch)
return nil return nil
} }
infoArch = termuxArchReplacer.Replace(infoArch) infoArch = termuxArchReplacer.Replace(infoArch)
arch = termuxArchReplacer.Replace(arch) arch = termuxArchReplacer.Replace(arch)
infoPlatform = "linux"
fpm.Bindir = termuxPrefixedDir(fpm.Bindir) fpm.Bindir = termuxPrefixedDir(fpm.Bindir)
fpm.Libdirs.Header = termuxPrefixedDir(fpm.Libdirs.Header) fpm.Libdirs.Header = termuxPrefixedDir(fpm.Libdirs.Header)
fpm.Libdirs.CArchive = termuxPrefixedDir(fpm.Libdirs.CArchive) fpm.Libdirs.CArchive = termuxPrefixedDir(fpm.Libdirs.CArchive)
fpm.Libdirs.CShared = termuxPrefixedDir(fpm.Libdirs.CShared) 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) overridden, err := mergeOverrides(fpm, format)
if err != nil { if err != nil {
return err return err

View File

@ -196,7 +196,7 @@ func TestRunPipe(t *testing.T) {
}, },
}, },
}, testctx.WithVersion("1.0.0"), testctx.WithCurrentTag("v1.0.0")) }, 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"} { for _, goarch := range []string{"amd64", "386", "arm64", "arm", "mips"} {
if goos == "ios" && goarch != "arm64" { if goos == "ios" && goarch != "arm64" {
continue 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) 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, "foo_1.0.0_ios_arm64-10-20"+ext, pkg.Name)
} }
require.Equal(t, "someid", pkg.ID()) 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")) }, 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"} { for _, goarch := range []string{"amd64", "386"} {
ctx.Artifacts.Add(&artifact.Artifact{ ctx.Artifacts.Add(&artifact.Artifact{
Name: "mybin", 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{ ctx.Artifacts.Add(&artifact.Artifact{
Name: "mybin", Name: "mybin",
Goos: "linux", Goos: "linux",

View File

@ -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 a different `bindir` (prefixed with `/data/data/com.termux/files/`)
- it uses slightly different architecture names than Debian - it uses slightly different architecture names than Debian
- it will only package binaries built for Android
## Conventional file names, Debian, and ARMv6 ## Conventional file names, Debian, and ARMv6