Skip to content

Commit

Permalink
Replace gopkgbuild with go-srcinfo (Jguer#528)
Browse files Browse the repository at this point in the history
* Prefer vercmp over gopkgbuild

* Replace gopkgbuild with go-srcinfo
  • Loading branch information
Morganamilo authored and Jguer committed Jul 16, 2018
1 parent b1fb1b9 commit d6b8623
Show file tree
Hide file tree
Showing 16 changed files with 791 additions and 1,318 deletions.
14 changes: 7 additions & 7 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@

[[constraint]]
branch = "master"
name = "github.com/mikkeloscar/gopkgbuild"
name = "github.com/Morganamilo/go-srcinfo"
1 change: 0 additions & 1 deletion depCheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"sync"

alpm "github.com/jguer/go-alpm"
// gopkg "github.com/mikkeloscar/gopkgbuild"
)

func (dp *depPool) checkInnerConflict(name string, conflict string, conflicts mapStringSet) {
Expand Down
26 changes: 11 additions & 15 deletions install.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
"strconv"
"strings"

gosrc "github.com/Morganamilo/go-srcinfo"
alpm "github.com/jguer/go-alpm"
rpc "github.com/mikkeloscar/aur"
gopkg "github.com/mikkeloscar/gopkgbuild"
)

// Install handles package installs
Expand All @@ -25,7 +25,7 @@ func install(parser *arguments) error {
warnings := &aurWarnings{}

removeMake := false
srcinfosStale := make(map[string]*gopkg.PKGBUILD)
srcinfosStale := make(map[string]*gosrc.Srcinfo)

//remotenames: names of all non repo packages on the system
_, _, localNames, remoteNames, err := filterPackages()
Expand Down Expand Up @@ -407,7 +407,7 @@ func install(parser *arguments) error {
return nil
}

func getIncompatible(pkgs []*rpc.Pkg, srcinfos map[string]*gopkg.PKGBUILD, bases map[string][]*rpc.Pkg) (stringSet, error) {
func getIncompatible(pkgs []*rpc.Pkg, srcinfos map[string]*gosrc.Srcinfo, bases map[string][]*rpc.Pkg) (stringSet, error) {
incompatible := make(stringSet)
alpmArch, err := alpmHandle.Arch()
if err != nil {
Expand Down Expand Up @@ -711,14 +711,14 @@ func editPkgBuilds(pkgs []*rpc.Pkg, bases map[string][]*rpc.Pkg) error {
return nil
}

func parseSRCINFOFiles(pkgs []*rpc.Pkg, srcinfos map[string]*gopkg.PKGBUILD, bases map[string][]*rpc.Pkg) error {
func parseSRCINFOFiles(pkgs []*rpc.Pkg, srcinfos map[string]*gosrc.Srcinfo, bases map[string][]*rpc.Pkg) error {
for k, pkg := range pkgs {
dir := filepath.Join(config.BuildDir, pkg.PackageBase)

str := bold(cyan("::") + " Parsing SRCINFO (%d/%d): %s\n")
fmt.Printf(str, k+1, len(pkgs), cyan(formatPkgbase(pkg, bases)))

pkgbuild, err := gopkg.ParseSRCINFO(filepath.Join(dir, ".SRCINFO"))
pkgbuild, err := gosrc.ParseFile(filepath.Join(dir, ".SRCINFO"))
if err != nil {
return fmt.Errorf("%s: %s", pkg.Name, err)
}
Expand All @@ -729,14 +729,14 @@ func parseSRCINFOFiles(pkgs []*rpc.Pkg, srcinfos map[string]*gopkg.PKGBUILD, bas
return nil
}

func tryParsesrcinfosFile(pkgs []*rpc.Pkg, srcinfos map[string]*gopkg.PKGBUILD, bases map[string][]*rpc.Pkg) {
func tryParsesrcinfosFile(pkgs []*rpc.Pkg, srcinfos map[string]*gosrc.Srcinfo, bases map[string][]*rpc.Pkg) {
for k, pkg := range pkgs {
dir := filepath.Join(config.BuildDir, pkg.PackageBase)

str := bold(cyan("::") + " Parsing SRCINFO (%d/%d): %s\n")
fmt.Printf(str, k+1, len(pkgs), cyan(formatPkgbase(pkg, bases)))

pkgbuild, err := gopkg.ParseSRCINFO(filepath.Join(dir, ".SRCINFO"))
pkgbuild, err := gosrc.ParseFile(filepath.Join(dir, ".SRCINFO"))
if err != nil {
fmt.Printf("cannot parse %s skipping: %s\n", pkg.Name, err)
continue
Expand All @@ -752,15 +752,11 @@ func pkgBuildsToSkip(pkgs []*rpc.Pkg, targets stringSet) stringSet {
for _, pkg := range pkgs {
if config.ReDownload == "no" || (config.ReDownload == "yes" && !targets.get(pkg.Name)) {
dir := filepath.Join(config.BuildDir, pkg.PackageBase, ".SRCINFO")
pkgbuild, err := gopkg.ParseSRCINFO(dir)
pkgbuild, err := gosrc.ParseFile(dir)

if err == nil {
versionRPC, errR := gopkg.NewCompleteVersion(pkg.Version)
versionPKG, errP := gopkg.NewCompleteVersion(pkgbuild.Version())
if errP == nil && errR == nil {
if !versionRPC.Newer(versionPKG) {
toSkip.set(pkg.PackageBase)
}
if alpm.VerCmp(pkgbuild.Version(), pkg.Version) > 0 {
toSkip.set(pkg.PackageBase)
}
}
}
Expand Down Expand Up @@ -833,7 +829,7 @@ func downloadPkgBuildsSources(pkgs []*rpc.Pkg, bases map[string][]*rpc.Pkg, inco
return
}

func buildInstallPkgBuilds(dp *depPool, do *depOrder, srcinfos map[string]*gopkg.PKGBUILD, parser *arguments, incompatible stringSet, conflicts mapStringSet) error {
func buildInstallPkgBuilds(dp *depPool, do *depOrder, srcinfos map[string]*gosrc.Srcinfo, parser *arguments, incompatible stringSet, conflicts mapStringSet) error {
for _, pkg := range do.Aur {
dir := filepath.Join(config.BuildDir, pkg.PackageBase)
built := true
Expand Down
6 changes: 3 additions & 3 deletions keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"os/exec"
"strings"

gosrc "github.com/Morganamilo/go-srcinfo"
rpc "github.com/mikkeloscar/aur"
gopkg "github.com/mikkeloscar/gopkgbuild"
)

// pgpKeySet maps a PGP key with a list of PKGBUILDs that require it.
Expand Down Expand Up @@ -41,7 +41,7 @@ func (set pgpKeySet) get(key string) bool {

// checkPgpKeys iterates through the keys listed in the PKGBUILDs and if needed,
// asks the user whether yay should try to import them.
func checkPgpKeys(pkgs []*rpc.Pkg, bases map[string][]*rpc.Pkg, srcinfos map[string]*gopkg.PKGBUILD) error {
func checkPgpKeys(pkgs []*rpc.Pkg, bases map[string][]*rpc.Pkg, srcinfos map[string]*gosrc.Srcinfo) error {
// Let's check the keys individually, and then we can offer to import
// the problematic ones.
problematic := make(pgpKeySet)
Expand All @@ -51,7 +51,7 @@ func checkPgpKeys(pkgs []*rpc.Pkg, bases map[string][]*rpc.Pkg, srcinfos map[str
for _, pkg := range pkgs {
srcinfo := srcinfos[pkg.PackageBase]

for _, key := range srcinfo.Validpgpkeys {
for _, key := range srcinfo.ValidPGPKeys {
// If key already marked as problematic, indicate the current
// PKGBUILD requires it.
if problematic.get(key) {
Expand Down
26 changes: 17 additions & 9 deletions keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"regexp"
"testing"

gosrc "github.com/Morganamilo/go-srcinfo"
rpc "github.com/mikkeloscar/aur"
gopkg "github.com/mikkeloscar/gopkgbuild"
)

const (
Expand Down Expand Up @@ -124,6 +124,14 @@ func TestImportKeys(t *testing.T) {
}
}

func makeSrcinfo(pkgbase string, pgpkeys ...string) *gosrc.Srcinfo {
srcinfo := gosrc.Srcinfo{}
srcinfo.Pkgbase = pkgbase
srcinfo.ValidPGPKeys = pgpkeys

return &srcinfo
}

func TestCheckPgpKeys(t *testing.T) {
keyringDir, err := ioutil.TempDir("/tmp", "yay-test-keyring")
if err != nil {
Expand All @@ -139,15 +147,15 @@ func TestCheckPgpKeys(t *testing.T) {

casetests := []struct {
pkgs []*rpc.Pkg
srcinfos map[string]*gopkg.PKGBUILD
srcinfos map[string]*gosrc.Srcinfo
bases map[string][]*rpc.Pkg
wantError bool
}{
// cower: single package, one valid key not yet in the keyring.
// 487EACC08557AD082088DABA1EB2638FF56C0C53: Dave Reisner.
{
pkgs: []*rpc.Pkg{newPkg("cower")},
srcinfos: map[string]*gopkg.PKGBUILD{"cower": {Pkgbase: "cower", Validpgpkeys: []string{"487EACC08557AD082088DABA1EB2638FF56C0C53"}}},
srcinfos: map[string]*gosrc.Srcinfo{"cower": makeSrcinfo("cower", "487EACC08557AD082088DABA1EB2638FF56C0C53")},
bases: map[string][]*rpc.Pkg{"cower": {newPkg("cower")}},
wantError: false,
},
Expand All @@ -156,15 +164,15 @@ func TestCheckPgpKeys(t *testing.T) {
// B6C8F98282B944E3B0D5C2530FC3042E345AD05D: Hans Wennborg.
{
pkgs: []*rpc.Pkg{newPkg("libc++")},
srcinfos: map[string]*gopkg.PKGBUILD{"libc++": {Pkgbase: "libc++", Validpgpkeys: []string{"11E521D646982372EB577A1F8F0871F202119294", "B6C8F98282B944E3B0D5C2530FC3042E345AD05D"}}},
srcinfos: map[string]*gosrc.Srcinfo{"libc++": makeSrcinfo("libc++", "11E521D646982372EB577A1F8F0871F202119294", "B6C8F98282B944E3B0D5C2530FC3042E345AD05D")},
bases: map[string][]*rpc.Pkg{"libc++": {newPkg("libc++")}},
wantError: false,
},
// Two dummy packages requiring the same key.
// ABAF11C65A2970B130ABE3C479BE3E4300411886: Linus Torvalds.
{
pkgs: []*rpc.Pkg{newPkg("dummy-1"), newPkg("dummy-2")},
srcinfos: map[string]*gopkg.PKGBUILD{"dummy-1": {Pkgbase: "dummy-1", Validpgpkeys: []string{"ABAF11C65A2970B130ABE3C479BE3E4300411886"}}, "dummy-2": {Pkgbase: "dummy-2", Validpgpkeys: []string{"ABAF11C65A2970B130ABE3C479BE3E4300411886"}}},
srcinfos: map[string]*gosrc.Srcinfo{"dummy-1": makeSrcinfo("dummy-1", "ABAF11C65A2970B130ABE3C479BE3E4300411886"), "dummy-2": makeSrcinfo("dummy-2", "ABAF11C65A2970B130ABE3C479BE3E4300411886")},
bases: map[string][]*rpc.Pkg{"dummy-1": {newPkg("dummy-1")}, "dummy-2": {newPkg("dummy-2")}},
wantError: false,
},
Expand All @@ -174,29 +182,29 @@ func TestCheckPgpKeys(t *testing.T) {
// C52048C0C0748FEE227D47A2702353E0F7E48EDB: Thomas Dickey.
{
pkgs: []*rpc.Pkg{newPkg("dummy-3")},
srcinfos: map[string]*gopkg.PKGBUILD{"dummy-3": {Pkgbase: "dummy-3", Validpgpkeys: []string{"11E521D646982372EB577A1F8F0871F202119294", "C52048C0C0748FEE227D47A2702353E0F7E48EDB"}}},
srcinfos: map[string]*gosrc.Srcinfo{"dummy-3": makeSrcinfo("dummy-3", "11E521D646982372EB577A1F8F0871F202119294", "C52048C0C0748FEE227D47A2702353E0F7E48EDB")},
bases: map[string][]*rpc.Pkg{"dummy-3": {newPkg("dummy-3")}},
wantError: false,
},
// Two dummy packages with existing keys.
{
pkgs: []*rpc.Pkg{newPkg("dummy-4"), newPkg("dummy-5")},
srcinfos: map[string]*gopkg.PKGBUILD{"dummy-4": {Pkgbase: "dummy-4", Validpgpkeys: []string{"11E521D646982372EB577A1F8F0871F202119294"}}, "dummy-5": {Pkgbase: "dummy-5", Validpgpkeys: []string{"C52048C0C0748FEE227D47A2702353E0F7E48EDB"}}},
srcinfos: map[string]*gosrc.Srcinfo{"dummy-4": makeSrcinfo("dummy-4", "11E521D646982372EB577A1F8F0871F202119294"), "dummy-5": makeSrcinfo("dummy-5", "C52048C0C0748FEE227D47A2702353E0F7E48EDB")},
bases: map[string][]*rpc.Pkg{"dummy-4": {newPkg("dummy-4")}, "dummy-5": {newPkg("dummy-5")}},
wantError: false,
},
// Dummy package with invalid key, should fail.
{
pkgs: []*rpc.Pkg{newPkg("dummy-7")},
srcinfos: map[string]*gopkg.PKGBUILD{"dummy-7": {Pkgbase: "dummy-7", Validpgpkeys: []string{"THIS-SHOULD-FAIL"}}},
srcinfos: map[string]*gosrc.Srcinfo{"dummy-7": makeSrcinfo("dummy-7", "THIS-SHOULD-FAIL")},
bases: map[string][]*rpc.Pkg{"dummy-7": {newPkg("dummy-7")}},
wantError: true,
},
// Dummy package with both an invalid an another valid key, should fail.
// A314827C4E4250A204CE6E13284FC34C8E4B1A25: Thomas Bächler.
{
pkgs: []*rpc.Pkg{newPkg("dummy-8")},
srcinfos: map[string]*gopkg.PKGBUILD{"dummy-8": {Pkgbase: "dummy-8", Validpgpkeys: []string{"A314827C4E4250A204CE6E13284FC34C8E4B1A25", "THIS-SHOULD-FAIL"}}},
srcinfos: map[string]*gosrc.Srcinfo{"dummy-8": makeSrcinfo("dummy-8", "A314827C4E4250A204CE6E13284FC34C8E4B1A25", "THIS-SHOULD-FAIL")},
bases: map[string][]*rpc.Pkg{"dummy-8": {newPkg("dummy-8")}},
wantError: true,
},
Expand Down
76 changes: 30 additions & 46 deletions upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (

alpm "github.com/jguer/go-alpm"
rpc "github.com/mikkeloscar/aur"
pkgb "github.com/mikkeloscar/gopkgbuild"
)

// upgrade type describes a system upgrade.
Expand Down Expand Up @@ -63,63 +62,48 @@ func (u upSlice) Less(i, j int) bool {

}

func getVersionDiff(oldVersion, newversion string) (left, right string) {
old, errOld := pkgb.NewCompleteVersion(oldVersion)
new, errNew := pkgb.NewCompleteVersion(newversion)

if errOld != nil {
left = red("Invalid Version")
}
if errNew != nil {
right = red("Invalid Version")
func getVersionDiff(oldVersion, newVersion string) (left, right string) {
if oldVersion == newVersion {
return oldVersion, newVersion
}

if errOld == nil && errNew == nil {
oldVersion := old.String()
newVersion := new.String()

if oldVersion == newVersion {
return oldVersion, newVersion
}

diffPosition := 0
diffPosition := 0

checkWords := func(str string, index int, words ...string) bool {
for _, word := range words {
wordLength := len(word)
nextIndex := index + 1
if (index < len(str)-wordLength) &&
(str[nextIndex:(nextIndex+wordLength)] == word) {
return true
}
checkWords := func(str string, index int, words ...string) bool {
for _, word := range words {
wordLength := len(word)
nextIndex := index + 1
if (index < len(str)-wordLength) &&
(str[nextIndex:(nextIndex+wordLength)] == word) {
return true
}
return false
}
return false
}

for index, char := range oldVersion {
charIsSpecial := !(unicode.IsLetter(char) || unicode.IsNumber(char))
for index, char := range oldVersion {
charIsSpecial := !(unicode.IsLetter(char) || unicode.IsNumber(char))

if (index >= len(newVersion)) || (char != rune(newVersion[index])) {
if charIsSpecial {
diffPosition = index
}
break
if (index >= len(newVersion)) || (char != rune(newVersion[index])) {
if charIsSpecial {
diffPosition = index
}
break
}

if charIsSpecial ||
(((index == len(oldVersion)-1) || (index == len(newVersion)-1)) &&
((len(oldVersion) != len(newVersion)) ||
(oldVersion[index] == newVersion[index]))) ||
checkWords(oldVersion, index, "rc", "pre", "alpha", "beta") {
diffPosition = index + 1
}
if charIsSpecial ||
(((index == len(oldVersion)-1) || (index == len(newVersion)-1)) &&
((len(oldVersion) != len(newVersion)) ||
(oldVersion[index] == newVersion[index]))) ||
checkWords(oldVersion, index, "rc", "pre", "alpha", "beta") {
diffPosition = index + 1
}
}

samePart := oldVersion[0:diffPosition]
samePart := oldVersion[0:diffPosition]

left = samePart + red(oldVersion[diffPosition:])
right = samePart + green(newVersion[diffPosition:])
}
left = samePart + red(oldVersion[diffPosition:])
right = samePart + green(newVersion[diffPosition:])

return
}
Expand Down
8 changes: 4 additions & 4 deletions vcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"strings"
"time"

gosrc "github.com/Morganamilo/go-srcinfo"
rpc "github.com/mikkeloscar/aur"
gopkg "github.com/mikkeloscar/gopkgbuild"
)

// Info contains the last commit sha of a repo
Expand All @@ -25,7 +25,7 @@ type shaInfo struct {
// createDevelDB forces yay to create a DB of the existing development packages
func createDevelDB() error {
infoMap := make(map[string]*rpc.Pkg)
srcinfosStale := make(map[string]*gopkg.PKGBUILD)
srcinfosStale := make(map[string]*gosrc.Srcinfo)

_, _, _, remoteNames, err := filterPackages()
if err != nil {
Expand Down Expand Up @@ -103,15 +103,15 @@ func parseSource(source string) (url string, branch string, protocols []string)
return
}

func updateVCSData(pkgName string, sources []string) {
func updateVCSData(pkgName string, sources []gosrc.ArchString) {
if savedInfo == nil {
savedInfo = make(vcsInfo)
}

info := make(shaInfos)

for _, source := range sources {
url, branch, protocols := parseSource(source)
url, branch, protocols := parseSource(source.Value)
if url == "" || branch == "" {
continue
}
Expand Down
Loading

0 comments on commit d6b8623

Please sign in to comment.