Create function for getting canonical CPU architecture
ci/woodpecker/push/woodpecker Pipeline was successful
Details
ci/woodpecker/push/woodpecker Pipeline was successful
Details
This commit is contained in:
parent
4e71a5c35c
commit
7164aac0b4
21
build.go
21
build.go
|
@ -329,7 +329,7 @@ func buildPackage(ctx context.Context, script string, mgr manager.Manager) ([]st
|
||||||
pkgInfo := &nfpm.Info{
|
pkgInfo := &nfpm.Info{
|
||||||
Name: vars.Name,
|
Name: vars.Name,
|
||||||
Description: vars.Description,
|
Description: vars.Description,
|
||||||
Arch: runtime.GOARCH,
|
Arch: cpu.Arch(),
|
||||||
Version: vars.Version,
|
Version: vars.Version,
|
||||||
Release: strconv.Itoa(vars.Release),
|
Release: strconv.Itoa(vars.Release),
|
||||||
Homepage: vars.Homepage,
|
Homepage: vars.Homepage,
|
||||||
|
@ -353,10 +353,6 @@ func buildPackage(ctx context.Context, script string, mgr manager.Manager) ([]st
|
||||||
pkgInfo.Arch = "all"
|
pkgInfo.Arch = "all"
|
||||||
}
|
}
|
||||||
|
|
||||||
if pkgInfo.Arch == "arm" {
|
|
||||||
pkgInfo.Arch = cpu.ARMVariant()
|
|
||||||
}
|
|
||||||
|
|
||||||
contents := []*files.Content{}
|
contents := []*files.Content{}
|
||||||
filepath.Walk(pkgdir, func(path string, fi os.FileInfo, err error) error {
|
filepath.Walk(pkgdir, func(path string, fi os.FileInfo, err error) error {
|
||||||
trimmed := strings.TrimPrefix(path, pkgdir)
|
trimmed := strings.TrimPrefix(path, pkgdir)
|
||||||
|
@ -479,11 +475,6 @@ func buildPackage(ctx context.Context, script string, mgr manager.Manager) ([]st
|
||||||
func genBuildEnv(info *distro.OSRelease) []string {
|
func genBuildEnv(info *distro.OSRelease) []string {
|
||||||
env := os.Environ()
|
env := os.Environ()
|
||||||
|
|
||||||
arch := runtime.GOARCH
|
|
||||||
if arch == "arm" {
|
|
||||||
arch = cpu.ARMVariant()
|
|
||||||
}
|
|
||||||
|
|
||||||
env = append(
|
env = append(
|
||||||
env,
|
env,
|
||||||
"DISTRO_NAME="+info.Name,
|
"DISTRO_NAME="+info.Name,
|
||||||
|
@ -492,7 +483,7 @@ func genBuildEnv(info *distro.OSRelease) []string {
|
||||||
"DISTRO_VERSION_ID="+info.VersionID,
|
"DISTRO_VERSION_ID="+info.VersionID,
|
||||||
"DISTRO_ID_LIKE="+strings.Join(info.Like, " "),
|
"DISTRO_ID_LIKE="+strings.Join(info.Like, " "),
|
||||||
|
|
||||||
"ARCH="+arch,
|
"ARCH="+cpu.Arch(),
|
||||||
"NCPU="+strconv.Itoa(runtime.NumCPU()),
|
"NCPU="+strconv.Itoa(runtime.NumCPU()),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -621,17 +612,11 @@ func archMatches(architectures []string) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
arch := runtime.GOARCH
|
|
||||||
|
|
||||||
if arch == "arm" {
|
|
||||||
arch = cpu.ARMVariant()
|
|
||||||
}
|
|
||||||
|
|
||||||
if slices.Contains(architectures, "arm") {
|
if slices.Contains(architectures, "arm") {
|
||||||
architectures = append(architectures, cpu.ARMVariant())
|
architectures = append(architectures, cpu.ARMVariant())
|
||||||
}
|
}
|
||||||
|
|
||||||
return slices.Contains(architectures, arch)
|
return slices.Contains(architectures, cpu.Arch())
|
||||||
}
|
}
|
||||||
|
|
||||||
func setVersion(ctx context.Context, r *interp.Runner, to string) error {
|
func setVersion(ctx context.Context, r *interp.Runner, to string) error {
|
||||||
|
|
|
@ -20,6 +20,7 @@ package cpu
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"golang.org/x/sys/cpu"
|
"golang.org/x/sys/cpu"
|
||||||
|
@ -42,3 +43,11 @@ func ARMVariant() string {
|
||||||
return "arm5"
|
return "arm5"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Arch() string {
|
||||||
|
arch := runtime.GOARCH
|
||||||
|
if arch == "arm" {
|
||||||
|
arch = ARMVariant()
|
||||||
|
}
|
||||||
|
return arch
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue