From 17dd765eff8485803460ea172088a63decc354c9 Mon Sep 17 00:00:00 2001 From: Vladimir Varankin Date: Sun, 12 Mar 2017 01:59:04 +0300 Subject: [PATCH] wip! --- analysis.go | 14 ++++++++++++++ pkgtree/pkgtree.go | 12 ++++++------ pkgtree/pkgtree_test.go | 6 +++--- pkgtree/reachmap.go | 2 +- rootdata.go | 6 +++--- solve_basic_test.go | 2 +- solve_bimodal_test.go | 14 +++++++++++++- solve_test.go | 2 +- solver.go | 2 +- 9 files changed, 43 insertions(+), 17 deletions(-) diff --git a/analysis.go b/analysis.go index 1f4087a..2b66dbe 100644 --- a/analysis.go +++ b/analysis.go @@ -20,3 +20,17 @@ func init() { archListString := "386 amd64 amd64p32 arm armbe arm64 arm64be ppc64 ppc64le mips mipsle mips64 mips64le mips64p32 mips64p32le ppc s390 s390x sparc sparc64" archList = strings.Split(archListString, " ") } + +// Stored as a var so that tests can swap it out. Ugh globals, ugh. +var isStdLib = doIsStdLib + +// This was lovingly lifted from src/cmd/go/pkg.go in Go's code +// (isStandardImportPath). +func doIsStdLib(path string) bool { + i := strings.Index(path, "/") + if i < 0 { + i = len(path) + } + + return !strings.Contains(path[:i], ".") +} diff --git a/pkgtree/pkgtree.go b/pkgtree/pkgtree.go index e214b70..f85154a 100644 --- a/pkgtree/pkgtree.go +++ b/pkgtree/pkgtree.go @@ -15,7 +15,7 @@ import ( ) // Stored as a var so that tests can swap it out. Ugh globals, ugh. -var IsStdLib = doIsStdLib +var isStdLib = doIsStdLib // This was lovingly lifted from src/cmd/go/pkg.go in Go's code // (isStandardImportPath). @@ -736,11 +736,11 @@ func wmToReach(workmap map[string]wm, backprop bool) (ReachMap, map[string]*ErrP // FIXME(sdboyer) we need an improved model that allows us to // accurately reject real import cycles. return true - // grey means an import cycle; guaranteed badness right here. You'd - // hope we never encounter it in a dependency (really? you published - // that code?), but we have to defend against it. - //colors[pkg] = black - //poison(append(path, pkg)) // poison self and parents + // grey means an import cycle; guaranteed badness right here. You'd + // hope we never encounter it in a dependency (really? you published + // that code?), but we have to defend against it. + //colors[pkg] = black + //poison(append(path, pkg)) // poison self and parents case black: // black means we're revisiting a package that was already diff --git a/pkgtree/pkgtree_test.go b/pkgtree/pkgtree_test.go index c30824f..0547770 100644 --- a/pkgtree/pkgtree_test.go +++ b/pkgtree/pkgtree_test.go @@ -1737,13 +1737,13 @@ func TestFlattenReachMap(t *testing.T) { // turning off stdlib should cut most things, but we need to override the // function - IsStdLib = doIsStdLib + isStdLib = doIsStdLib name = "no stdlib" stdlib = false except("encoding/binary", "go/parser", "hash", "net/http", "os", "sort") validate() - // Restore stdlib func override - IsStdLib = func(path string) bool { + // restore stdlib func override + isStdLib = func(path string) bool { return false } diff --git a/pkgtree/reachmap.go b/pkgtree/reachmap.go index ba66de7..f17968a 100644 --- a/pkgtree/reachmap.go +++ b/pkgtree/reachmap.go @@ -51,7 +51,7 @@ func (rm ReachMap) flatten(filter func(string) bool, stdlib bool) []string { for pkg, ie := range rm { if filter(pkg) { for _, ex := range ie.External { - if !stdlib && IsStdLib(ex) { + if !stdlib && isStdLib(ex) { continue } exm[ex] = struct{}{} diff --git a/rootdata.go b/rootdata.go index 18b8c15..28d2304 100644 --- a/rootdata.go +++ b/rootdata.go @@ -43,7 +43,7 @@ type rootdata struct { rpt pkgtree.PackageTree } -// rootImportList returns a list of the unique imports from the root data. +// externalImportList returns a list of the unique imports from the root data. // Ignores and requires are taken into consideration, stdlib is excluded, and // errors within the local set of package are not backpropagated. func (rd rootdata) externalImportList() []string { @@ -51,7 +51,7 @@ func (rd rootdata) externalImportList() []string { all := rm.Flatten(false) reach := make([]string, 0, len(all)) for _, r := range all { - if !pkgtree.IsStdLib(r) { + if !isStdLib(r) { reach = append(reach, r) } } @@ -113,7 +113,7 @@ func (rd rootdata) getApplicableConstraints() []workingConstraint { // Walk all dep import paths we have to consider and mark the corresponding // wc entry in the trie, if any for _, im := range rd.externalImportList() { - if pkgtree.IsStdLib(im) { + if isStdLib(im) { continue } diff --git a/solve_basic_test.go b/solve_basic_test.go index 3d74779..6dcd0fd 100644 --- a/solve_basic_test.go +++ b/solve_basic_test.go @@ -1351,7 +1351,7 @@ func init() { } // reachMaps contain externalReach()-type data for a given depspec fixture's -// universe of proejcts, packages, and versions. +// universe of projects, packages, and versions. type reachMap map[pident]map[string][]string type depspecSourceManager struct { diff --git a/solve_bimodal_test.go b/solve_bimodal_test.go index bf6f563..ce70e51 100644 --- a/solve_bimodal_test.go +++ b/solve_bimodal_test.go @@ -4,6 +4,7 @@ import ( "fmt" "path/filepath" "strings" + "github.com/sdboyer/gps/pkgtree" ) @@ -1003,7 +1004,7 @@ type tpkg struct { type bimodalFixture struct { // name of this fixture datum n string - // bimodal project. first is always treated as root project + // bimodal project; first is always treated as root project ds []depspec // results; map of name/version pairs r map[ProjectIdentifier]LockedProject @@ -1197,3 +1198,14 @@ func computeBimodalExternalMap(ds []depspec) map[pident]map[string][]string { return rm } + +// eqOrSlashedPrefix checks to see if the prefix is either equal to the string, +// or that it is a prefix and the next char in the string is "/". +func eqOrSlashedPrefix(s, prefix string) bool { + if !strings.HasPrefix(s, prefix) { + return false + } + + prflen, pathlen := len(prefix), len(s) + return prflen == pathlen || strings.Index(s[prflen:], "/") == 0 +} diff --git a/solve_test.go b/solve_test.go index 41be907..bd3cbbf 100644 --- a/solve_test.go +++ b/solve_test.go @@ -46,7 +46,7 @@ func overrideMkBridge() { // sets the isStdLib func to always return false, otherwise it would identify // pretty much all of our fixtures as being stdlib and skip everything func overrideIsStdLib() { - pkgtree.IsStdLib = func(path string) bool { + isStdLib = func(path string) bool { return false } } diff --git a/solver.go b/solver.go index 55a177e..32de419 100644 --- a/solver.go +++ b/solver.go @@ -580,7 +580,7 @@ func (s *solver) intersectConstraintsWithImports(deps []workingConstraint, reach dmap := make(map[ProjectRoot]completeDep) for _, rp := range reach { // If it's a stdlib-shaped package, skip it. - if pkgtree.IsStdLib(rp) { + if isStdLib(rp) { continue }