Skip to content

Commit

Permalink
Add support for multiple 'Architecture' values
Browse files Browse the repository at this point in the history
This allows architecture to be multivalued. On x86-64 machines, this
could be something like:
    Architecture = x86-64-v3 x86-64

We use the first specified Architecture value in mirrorlist $arch
variable replacement, as this is backwards-compatible and sane.

More info:
https://git.archlinux.org/pacman.git/commit/?id=3179db108a83104d9de6d1d607f55f8118e92160

Signed-off-by: x1b6e6 <ftdabcde@gmail.com>
  • Loading branch information
x1b6e6 authored and Jguer committed May 4, 2021
1 parent 29f4c43 commit de113b8
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 16 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ module github.com/Jguer/yay/v10

require (
github.com/Jguer/go-alpm v0.0.0-20200405152916-a3feea4322e9 // indirect
github.com/Jguer/go-alpm/v2 v2.0.2
github.com/Morganamilo/go-pacmanconf v0.0.0-20180910220353-9c5265e1b14f
github.com/Jguer/go-alpm/v2 v2.0.3-0.20210503120603-1e8b5ec6f821
github.com/Morganamilo/go-pacmanconf v0.0.0-20210502114700-cff030e927a5
github.com/Morganamilo/go-srcinfo v1.0.0
github.com/bradleyjkemp/cupaloy v2.3.0+incompatible
github.com/davecgh/go-spew v1.1.1 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
github.com/Jguer/go-alpm v0.0.0-20200405152916-a3feea4322e9 h1:lLQSUe6iRdtFrP0zkDV7n8I8XKSxRHQTEU1KRh4IOLg=
github.com/Jguer/go-alpm v0.0.0-20200405152916-a3feea4322e9/go.mod h1:D5SUcIS9Yiz/L8cjRzq/992eERnx6ugYmGlc4e7xdus=
github.com/Jguer/go-alpm/v2 v2.0.2 h1:BbF/6dg2tXISEJiCtxlX6J/TCSoB/g+31bCfEiH9D0c=
github.com/Jguer/go-alpm/v2 v2.0.2/go.mod h1:zU4iKCtNkDARfj5BrKJXYAQ5nIjtZbySfa0paboSmTQ=
github.com/Morganamilo/go-pacmanconf v0.0.0-20180910220353-9c5265e1b14f h1:ptFKynTV1p8JCzqk81NcMj0DV0Xle+PdKxfHjPbdIOU=
github.com/Morganamilo/go-pacmanconf v0.0.0-20180910220353-9c5265e1b14f/go.mod h1:Hk55m330jNiwxRodIlMCvw5iEyoRUCIY64W1p9D+tHc=
github.com/Jguer/go-alpm/v2 v2.0.3-0.20210503120603-1e8b5ec6f821 h1:ds4SK2NSSFF3f/jOUL7liQ2N6Ug7UQzFdAvWcj44Y2s=
github.com/Jguer/go-alpm/v2 v2.0.3-0.20210503120603-1e8b5ec6f821/go.mod h1:zU4iKCtNkDARfj5BrKJXYAQ5nIjtZbySfa0paboSmTQ=
github.com/Morganamilo/go-pacmanconf v0.0.0-20210502114700-cff030e927a5 h1:TMscPjkb1ThXN32LuFY5bEYIcXZx3YlwzhS1GxNpn/c=
github.com/Morganamilo/go-pacmanconf v0.0.0-20210502114700-cff030e927a5/go.mod h1:Hk55m330jNiwxRodIlMCvw5iEyoRUCIY64W1p9D+tHc=
github.com/Morganamilo/go-srcinfo v1.0.0 h1:Wh4nEF+HJWo+29hnxM18Q2hi+DUf0GejS13+Wg+dzmI=
github.com/Morganamilo/go-srcinfo v1.0.0/go.mod h1:MP6VGY1NNpVUmYIEgoM9acix95KQqIRyqQ0hCLsyYUY=
github.com/bradleyjkemp/cupaloy v2.3.0+incompatible h1:UafIjBvWQmS9i/xRg+CamMrnLTKNzo+bdmT/oH34c2Y=
Expand Down
18 changes: 16 additions & 2 deletions install.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,18 +443,32 @@ func earlyRefresh(cmdArgs *settings.Arguments) error {
return config.Runtime.CmdRunner.Show(passToPacman(arguments))
}

func alpmArchIsSupported(alpmArch []string, arch string) bool {
if arch == "any" {
return true
}

for _, a := range alpmArch {
if a == arch {
return true
}
}

return false
}

func getIncompatible(bases []dep.Base, srcinfos map[string]*gosrc.Srcinfo, dbExecutor db.Executor) (stringset.StringSet, error) {
incompatible := make(stringset.StringSet)
basesMap := make(map[string]dep.Base)
alpmArch, err := dbExecutor.AlpmArch()
alpmArch, err := dbExecutor.AlpmArchitectures()
if err != nil {
return nil, err
}

nextpkg:
for _, base := range bases {
for _, arch := range srcinfos[base.Pkgbase()].Arch {
if arch == "any" || arch == alpmArch {
if alpmArchIsSupported(alpmArch, arch) {
continue nextpkg
}
}
Expand Down
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ func initAlpm(cmdArgs *settings.Arguments, pacmanConfigPath string) (*pacmanconf
pacmanConf.DBPath = dbPath
}

if arch, _, exists := cmdArgs.GetArg("arch"); exists {
pacmanConf.Architecture = arch
if arch := cmdArgs.GetArgs("arch"); arch != nil {
pacmanConf.Architecture = append(pacmanConf.Architecture, arch...)
}

if ignoreArray := cmdArgs.GetArgs("ignore"); ignoreArray != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/db/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type Upgrade struct {
}

type Executor interface {
AlpmArch() (string, error)
AlpmArchitectures() ([]string, error)
BiggestPackages() []IPackage
Cleanup()
IsCorrectVersionInstalled(string, string) bool
Expand Down
6 changes: 1 addition & 5 deletions pkg/db/ialpm/alpm.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func configureAlpm(pacmanConf *pacmanconf.Config, alpmHandle *alpm.Handle) error
return err
}

if err := alpmHandle.SetArch(pacmanConf.Architecture); err != nil {
if err := alpmSetArchitecture(alpmHandle, pacmanConf.Architecture); err != nil {
return err
}

Expand Down Expand Up @@ -442,10 +442,6 @@ func (ae *AlpmExecutor) RepoUpgrades(enableDowngrade bool) ([]db.Upgrade, error)
return slice, nil
}

func (ae *AlpmExecutor) AlpmArch() (string, error) {
return ae.handle.Arch()
}

func (ae *AlpmExecutor) BiggestPackages() []alpm.IPackage {
localPackages := []alpm.IPackage{}
_ = ae.localDB.PkgCache().SortBySize().ForEach(func(pkg alpm.IPackage) error {
Expand Down
17 changes: 17 additions & 0 deletions pkg/db/ialpm/alpm_five.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// +build !six

package ialpm

import (
alpm "github.com/Jguer/go-alpm/v2"
)

func alpmSetArchitecture(alpmHandle *alpm.Handle, arch []string) error {
return alpmHandle.SetArch(arch[0])
}

func (ae *AlpmExecutor) AlpmArchitectures() ([]string, error) {
arch, err := ae.handle.Arch()

return []string{arch}, err
}
17 changes: 17 additions & 0 deletions pkg/db/ialpm/alpm_six.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// +build six

package ialpm

import (
alpm "github.com/Jguer/go-alpm/v2"
)

func alpmSetArchitecture(alpmHandle *alpm.Handle, arch []string) error {
return alpmHandle.SetArchitectures(arch)
}

func (ae *AlpmExecutor) AlpmArchitectures() ([]string, error) {
architectures, err := ae.handle.GetArchitectures()

return architectures.Slice(), err
}

0 comments on commit de113b8

Please sign in to comment.