Skip to content

Commit

Permalink
feat: termux.deb (#3333)
Browse files Browse the repository at this point in the history
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 <caarlos0@users.noreply.github.com>
Co-authored-by: rsteube <rsteube@users.noreply.github.com>
  • Loading branch information
caarlos0 and rsteube committed Aug 22, 2022
1 parent 3729f1e commit a7c6b14
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 5 deletions.
32 changes: 30 additions & 2 deletions internal/pipe/nfpm/nfpm.go
Expand Up @@ -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
Expand All @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
12 changes: 9 additions & 3 deletions internal/pipe/nfpm/nfpm_test.go
Expand Up @@ -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 }}",
Expand Down Expand Up @@ -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)
Expand All @@ -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",
Expand All @@ -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")
Expand Down
8 changes: 8 additions & 0 deletions www/docs/customization/nfpm.md
Expand Up @@ -66,6 +66,7 @@ nfpms:
- apk
- deb
- rpm
- termux.deb

# Packages your package depends on. (overridable)
dependencies:
Expand Down Expand Up @@ -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

0 comments on commit a7c6b14

Please sign in to comment.