Factor in ID_LIKE variable and ARM variants when checking for overrides

This commit is contained in:
Arsen Musayelyan 2022-09-30 20:07:44 -07:00
parent 77c3ea7d56
commit 93d5ad9a53
4 changed files with 67 additions and 27 deletions

View File

@ -35,13 +35,13 @@ import (
_ "github.com/goreleaser/nfpm/v2/rpm" _ "github.com/goreleaser/nfpm/v2/rpm"
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
"golang.org/x/exp/slices" "golang.org/x/exp/slices"
"golang.org/x/sys/cpu"
"github.com/goreleaser/nfpm/v2" "github.com/goreleaser/nfpm/v2"
"github.com/goreleaser/nfpm/v2/files" "github.com/goreleaser/nfpm/v2/files"
"go.arsenm.dev/lure/distro" "go.arsenm.dev/lure/distro"
"go.arsenm.dev/lure/download" "go.arsenm.dev/lure/download"
"go.arsenm.dev/lure/internal/shutils" "go.arsenm.dev/lure/internal/shutils"
"go.arsenm.dev/lure/internal/cpu"
"go.arsenm.dev/lure/internal/shutils/decoder" "go.arsenm.dev/lure/internal/shutils/decoder"
"go.arsenm.dev/lure/manager" "go.arsenm.dev/lure/manager"
"mvdan.cc/sh/v3/expand" "mvdan.cc/sh/v3/expand"
@ -264,7 +264,7 @@ func buildPackage(ctx context.Context, script string, mgr manager.Manager) ([]st
} }
if pkgInfo.Arch == "arm" { if pkgInfo.Arch == "arm" {
pkgInfo.Arch = checkARMVariant() pkgInfo.Arch = cpu.ARMVariant()
} }
contents := []*files.Content{} contents := []*files.Content{}
@ -439,24 +439,6 @@ func setDirVars(ctx context.Context, runner *interp.Runner, srcdir, pkgdir strin
return runner.Run(ctx, fl) 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) { func setScripts(vars *BuildVars, info *nfpm.Info, scriptDir string) {
if vars.Scripts.PreInstall != "" { if vars.Scripts.PreInstall != "" {
info.Scripts.PreInstall = filepath.Join(scriptDir, vars.Scripts.PreInstall) info.Scripts.PreInstall = filepath.Join(scriptDir, vars.Scripts.PreInstall)

View File

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

26
internal/cpu/cpu.go Normal file
View File

@ -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"
}
}

View File

@ -28,6 +28,7 @@ import (
"github.com/mitchellh/mapstructure" "github.com/mitchellh/mapstructure"
"go.arsenm.dev/lure/distro" "go.arsenm.dev/lure/distro"
"go.arsenm.dev/lure/internal/cpu"
"golang.org/x/exp/slices" "golang.org/x/exp/slices"
"mvdan.cc/sh/v3/expand" "mvdan.cc/sh/v3/expand"
"mvdan.cc/sh/v3/interp" "mvdan.cc/sh/v3/interp"
@ -196,10 +197,33 @@ func (d *Decoder) genPossibleNames(name string) []string {
return []string{name} return []string{name}
} }
return []string{ architectures := []string{runtime.GOARCH}
fmt.Sprintf("%s_%s_%s", name, runtime.GOARCH, d.info.ID),
fmt.Sprintf("%s_%s", name, d.info.ID), if runtime.GOARCH == "arm" {
fmt.Sprintf("%s_%s", name, runtime.GOARCH), // More specific goes first
name, 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
} }