Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: termux.deb #3333

Merged
merged 3 commits into from Aug 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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