From 2a7c14ddce4d4c126e72035a821c42229a357a86 Mon Sep 17 00:00:00 2001 From: rsteube Date: Wed, 27 Jul 2022 19:58:42 +0200 Subject: [PATCH 1/2] nfpm: added termux --- internal/pipe/nfpm/nfpm.go | 20 ++++++++++++++++++-- www/docs/customization/nfpm.md | 2 ++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/internal/pipe/nfpm/nfpm.go b/internal/pipe/nfpm/nfpm.go index 38b68a5bd82..0e87e810f4e 100644 --- a/internal/pipe/nfpm/nfpm.go +++ b/internal/pipe/nfpm/nfpm.go @@ -126,6 +126,18 @@ func create(ctx *context.Context, fpm config.NFPM, format string, binaries []*ar infoArch := binaries[0].Goarch + binaries[0].Goarm + binaries[0].Gomips // key used for the ConventionalFileName et al arch := infoArch + binaries[0].Goamd64 // unique arch key + if format == "termux.deb" { + if arch == "386" { + return nil // skip arch + } + replacer := strings.NewReplacer( + "amd64", "x86_64", + "arm64", "aarch64", + ) + infoArch = replacer.Replace(infoArch) + arch = replacer.Replace(arch) + } + overridden, err := mergeOverrides(fpm, format) if err != nil { return err @@ -138,7 +150,11 @@ func create(ctx *context.Context, fpm config.NFPM, format string, binaries []*ar "PackageName": fpm.PackageName, }) - binDir, err := t.Apply(fpm.Bindir) + patchedBindir := fpm.Bindir + if format == "termux.deb" { + patchedBindir = "/data/data/com.termux/files" + patchedBindir + } + binDir, err := t.Apply(patchedBindir) if err != nil { return err } @@ -324,7 +340,7 @@ func create(ctx *context.Context, fpm config.NFPM, format string, binaries []*ar info.Deb.Signature = nfpm.DebSignature{} } - packager, err := nfpm.Get(format) + packager, err := nfpm.Get(strings.Replace(format, "termux.deb", "deb", 1)) if err != nil { return err } diff --git a/www/docs/customization/nfpm.md b/www/docs/customization/nfpm.md index dc1b0d43795..8497f5c415c 100644 --- a/www/docs/customization/nfpm.md +++ b/www/docs/customization/nfpm.md @@ -66,6 +66,8 @@ nfpms: - apk - deb - rpm + # same as deb but with altered bindir and arch for termux + - termux.deb # Packages your package depends on. dependencies: From f59f82742d166d0e6f36e9eba351f036f6cab338 Mon Sep 17 00:00:00 2001 From: Carlos A Becker Date: Sun, 21 Aug 2022 22:10:54 -0300 Subject: [PATCH 2/2] feat: termux.deb Signed-off-by: Carlos A Becker --- internal/pipe/nfpm/nfpm.go | 30 +++++++++++++++++++++--------- internal/pipe/nfpm/nfpm_test.go | 12 +++++++++--- www/docs/customization/nfpm.md | 8 +++++++- 3 files changed, 37 insertions(+), 13 deletions(-) diff --git a/internal/pipe/nfpm/nfpm.go b/internal/pipe/nfpm/nfpm.go index 71833d037a6..7cf2a0824c2 100644 --- a/internal/pipe/nfpm/nfpm.go +++ b/internal/pipe/nfpm/nfpm.go @@ -121,21 +121,37 @@ func mergeOverrides(fpm config.NFPM, format string) (*config.NFPMOverridables, e return &overridden, nil } +const termuxFormat = "termux.deb" + +func isSupportedTermuxArch(arch string) bool { + for _, a := range []string{"amd64", "arm64", "386"} { + if strings.HasPrefix(arch, a) { + return true + } + } + return false +} + func create(ctx *context.Context, fpm config.NFPM, format string, binaries []*artifact.Artifact) error { // TODO: improve mips handling on nfpm infoArch := binaries[0].Goarch + binaries[0].Goarm + binaries[0].Gomips // key used for the ConventionalFileName et al arch := infoArch + binaries[0].Goamd64 // unique arch key - if format == "termux.deb" { - if arch == "386" { - return nil // skip arch + bindDir := fpm.Bindir + if format == termuxFormat { + if !isSupportedTermuxArch(arch) { + log.Debugf("skipping termux.deb for %s as its not supported by termux", arch) + return nil } + replacer := strings.NewReplacer( + "386", "i686", "amd64", "x86_64", "arm64", "aarch64", ) infoArch = replacer.Replace(infoArch) arch = replacer.Replace(arch) + bindDir = filepath.Join("/data/data/com.termux/files", bindDir) } overridden, err := mergeOverrides(fpm, format) @@ -150,11 +166,7 @@ func create(ctx *context.Context, fpm config.NFPM, format string, binaries []*ar "PackageName": fpm.PackageName, }) - patchedBindir := fpm.Bindir - if format == "termux.deb" { - patchedBindir = "/data/data/com.termux/files" + patchedBindir - } - binDir, err := t.Apply(patchedBindir) + binDir, err := t.Apply(bindDir) if err != nil { return err } @@ -342,7 +354,7 @@ func create(ctx *context.Context, fpm config.NFPM, format string, binaries []*ar info.Deb.Signature = nfpm.DebSignature{} } - packager, err := nfpm.Get(strings.Replace(format, "termux.deb", "deb", 1)) + packager, err := nfpm.Get(strings.Replace(format, "termux.", "", 1)) if err != nil { return err } diff --git a/internal/pipe/nfpm/nfpm_test.go b/internal/pipe/nfpm/nfpm_test.go index 9cc22a24c4c..cdae7aab5d7 100644 --- a/internal/pipe/nfpm/nfpm_test.go +++ b/internal/pipe/nfpm/nfpm_test.go @@ -92,7 +92,7 @@ func TestRunPipe(t *testing.T) { ID: "someid", Bindir: "/usr/bin", Builds: []string{"default"}, - Formats: []string{"deb", "rpm", "apk"}, + Formats: []string{"deb", "rpm", "apk", "termux.deb"}, Section: "somesection", Priority: "standard", Description: "Some description with {{ .Env.DESC }}", @@ -220,7 +220,7 @@ func TestRunPipe(t *testing.T) { } require.NoError(t, Pipe{}.Run(ctx)) packages := ctx.Artifacts.Filter(artifact.ByType(artifact.LinuxPackage)).List() - require.Len(t, packages, 30) + require.Len(t, packages, 36) for _, pkg := range packages { format := pkg.Format() require.NotEmpty(t, format) @@ -245,6 +245,12 @@ func TestRunPipe(t *testing.T) { "./testdata/testfile-" + pkg.Goarch + pkg.Goamd64 + pkg.Goarm + pkg.Gomips + ".txt", binPath, }, sources(artifact.ExtraOr(*pkg, extraFiles, files.Contents{}))) + + bin := "/usr/bin/subdir/" + if format == termuxFormat { + bin = filepath.Join("/data/data/com.termux/files", bin) + } + bin = filepath.Join(bin, "mybin") require.ElementsMatch(t, []string{ "/var/log/foobar", "/usr/share/testfile.txt", @@ -254,7 +260,7 @@ func TestRunPipe(t *testing.T) { "/etc/nope2.conf", "/etc/nope3_mybin.conf", "/etc/folder", - "/usr/bin/subdir/mybin", + bin, }, destinations(artifact.ExtraOr(*pkg, extraFiles, files.Contents{}))) } require.Len(t, ctx.Config.NFPMs[0].Contents, 8, "should not modify the config file list") diff --git a/www/docs/customization/nfpm.md b/www/docs/customization/nfpm.md index c957009dd7a..1ec3830fa8b 100644 --- a/www/docs/customization/nfpm.md +++ b/www/docs/customization/nfpm.md @@ -66,7 +66,6 @@ nfpms: - apk - deb - rpm - # same as deb but with altered bindir and arch for termux - termux.deb # Packages your package depends on. (overridable) @@ -380,3 +379,10 @@ nfpms: !!! info Fields marked with "overridable" can be overriden for any format. + +## A note about Termux + +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 +