Factor in ID_LIKE variable and ARM variants when checking for overrides

master
Arsen Musayelyan 2 months ago
parent 77c3ea7d56
commit 93d5ad9a53

@ -35,13 +35,13 @@ import (
_ "github.com/goreleaser/nfpm/v2/rpm"
"github.com/urfave/cli/v2"
"golang.org/x/exp/slices"
"golang.org/x/sys/cpu"
"github.com/goreleaser/nfpm/v2"
"github.com/goreleaser/nfpm/v2/files"
"go.arsenm.dev/lure/distro"
"go.arsenm.dev/lure/download"
"go.arsenm.dev/lure/internal/shutils"
"go.arsenm.dev/lure/internal/cpu"
"go.arsenm.dev/lure/internal/shutils/decoder"
"go.arsenm.dev/lure/manager"
"mvdan.cc/sh/v3/expand"
@ -264,7 +264,7 @@ func buildPackage(ctx context.Context, script string, mgr manager.Manager) ([]st
}
if pkgInfo.Arch == "arm" {
pkgInfo.Arch = checkARMVariant()
pkgInfo.Arch = cpu.ARMVariant()
}
contents := []*files.Content{}
@ -439,24 +439,6 @@ func setDirVars(ctx context.Context, runner *interp.Runner, srcdir, pkgdir strin
return runner.Run(ctx, fl)
}
// checkARMVariant checks which variant of ARM lure is running
// on, by using the same detection method as Go itself
func checkARMVariant() string {
armEnv := os.Getenv("LURE_ARM_VARIANT")
// ensure value has "arm" prefix, such as arm5 or arm6
if strings.HasPrefix(armEnv, "arm") {
return armEnv
}
if cpu.ARM.HasVFPv3 {
return "arm7"
} else if cpu.ARM.HasVFP {
return "arm6"
} else {
return "arm5"
}
}
func setScripts(vars *BuildVars, info *nfpm.Info, scriptDir string) {
if vars.Scripts.PreInstall != "" {
info.Scripts.PreInstall = filepath.Join(scriptDir, vars.Scripts.PreInstall)

@ -22,6 +22,7 @@ import (
"context"
"errors"
"os"
"strings"
"go.arsenm.dev/lure/internal/shutils"
"mvdan.cc/sh/v3/expand"
@ -35,6 +36,7 @@ type OSRelease struct {
Name string
PrettyName string
ID string
Like []string
BuildID string
ANSIColor string
HomeURL string
@ -80,7 +82,7 @@ func ParseOSRelease(ctx context.Context) (*OSRelease, error) {
return nil, ErrParse
}
return &OSRelease{
out := &OSRelease{
Name: runner.Vars["NAME"].Str,
PrettyName: runner.Vars["PRETTY_NAME"].Str,
ID: runner.Vars["ID"].Str,
@ -91,5 +93,11 @@ func ParseOSRelease(ctx context.Context) (*OSRelease, error) {
SupportURL: runner.Vars["SUPPORT_URL"].Str,
BugReportURL: runner.Vars["BUG_REPORT_URL"].Str,
Logo: runner.Vars["LOGO"].Str,
}, nil
}
if runner.Vars["ID_LIKE"].IsSet() {
out.Like = strings.Split(runner.Vars["ID_LIKE"].Str, " ")
}
return out, nil
}

@ -0,0 +1,26 @@
package cpu
import (
"os"
"strings"
"golang.org/x/sys/cpu"
)
// ARMVariant checks which variant of ARM lure is running
// on, by using the same detection method as Go itself
func ARMVariant() string {
armEnv := os.Getenv("LURE_ARM_VARIANT")
// ensure value has "arm" prefix, such as arm5 or arm6
if strings.HasPrefix(armEnv, "arm") {
return armEnv
}
if cpu.ARM.HasVFPv3 {
return "arm7"
} else if cpu.ARM.HasVFP {
return "arm6"
} else {
return "arm5"
}
}

@ -28,6 +28,7 @@ import (
"github.com/mitchellh/mapstructure"
"go.arsenm.dev/lure/distro"
"go.arsenm.dev/lure/internal/cpu"
"golang.org/x/exp/slices"
"mvdan.cc/sh/v3/expand"
"mvdan.cc/sh/v3/interp"
@ -196,10 +197,33 @@ func (d *Decoder) genPossibleNames(name string) []string {
return []string{name}
}
return []string{
fmt.Sprintf("%s_%s_%s", name, runtime.GOARCH, d.info.ID),
fmt.Sprintf("%s_%s", name, d.info.ID),
fmt.Sprintf("%s_%s", name, runtime.GOARCH),
name,
architectures := []string{runtime.GOARCH}
if runtime.GOARCH == "arm" {
// More specific goes first
architectures[0] = cpu.ARMVariant()
architectures = append(architectures, "arm")
}
distros := []string{d.info.ID}
distros = append(distros, d.info.Like...)
var out []string
for _, arch := range architectures {
for _, distro := range distros {
out = append(
out,
fmt.Sprintf("%s_%s_%s", name, arch, distro),
fmt.Sprintf("%s_%s", name, distro),
)
}
out = append(out, fmt.Sprintf("%s_%s", name, arch))
}
out = append(out, name)
for index, item := range out {
out[index] = strings.ReplaceAll(item, "-", "_")
}
return out
}

Loading…
Cancel
Save