From a7c6b14cbfea1e29e19c0c4a837462ec88afbe6c Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Mon, 22 Aug 2022 09:29:55 -0300 Subject: [PATCH] feat: termux.deb (#3333) termux support, built from #3258 : minor code changes support for 386 as well docs tests closes #3118 closes #3258 Signed-off-by: Carlos A Becker Co-authored-by: rsteube --- internal/pipe/nfpm/nfpm.go | 32 ++++++++++++++++++++++++++++++-- internal/pipe/nfpm/nfpm_test.go | 12 +++++++++--- www/docs/customization/nfpm.md | 8 ++++++++ 3 files changed, 47 insertions(+), 5 deletions(-) diff --git a/internal/pipe/nfpm/nfpm.go b/internal/pipe/nfpm/nfpm.go index c1e3f6eb0ea..7cf2a0824c2 100644 --- a/internal/pipe/nfpm/nfpm.go +++ b/internal/pipe/nfpm/nfpm.go @@ -121,11 +121,39 @@ 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 + 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) if err != nil { return err @@ -138,7 +166,7 @@ func create(ctx *context.Context, fpm config.NFPM, format string, binaries []*ar "PackageName": fpm.PackageName, }) - binDir, err := t.Apply(fpm.Bindir) + binDir, err := t.Apply(bindDir) if err != nil { return err } @@ -326,7 +354,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.", "", 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 8200a07942e..1ec3830fa8b 100644 --- a/www/docs/customization/nfpm.md +++ b/www/docs/customization/nfpm.md @@ -66,6 +66,7 @@ nfpms: - apk - deb - rpm + - termux.deb # Packages your package depends on. (overridable) dependencies: @@ -378,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 +