Skip to content
This repository has been archived by the owner on Feb 3, 2018. It is now read-only.

Commit

Permalink
wip!
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladimir Varankin committed Mar 11, 2017
1 parent 5826765 commit 17dd765
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 17 deletions.
14 changes: 14 additions & 0 deletions analysis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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], ".")
}
12 changes: 6 additions & 6 deletions pkgtree/pkgtree.go
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions pkgtree/pkgtree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion pkgtree/reachmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}{}
Expand Down
6 changes: 3 additions & 3 deletions rootdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ 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 {
rm, _ := rd.rpt.ToReachMap(true, true, false, rd.ig)
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)
}
}
Expand Down Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion solve_basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
14 changes: 13 additions & 1 deletion solve_bimodal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"path/filepath"
"strings"

"github.com/sdboyer/gps/pkgtree"
)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion solve_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
2 changes: 1 addition & 1 deletion solver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 17dd765

Please sign in to comment.