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

Commit

Permalink
Fix import path prefixing issues
Browse files Browse the repository at this point in the history
...though, kinda not sure why that's correct.
  • Loading branch information
sdboyer committed Jun 21, 2016
1 parent db35020 commit f4d9d53
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
16 changes: 13 additions & 3 deletions analysis.go
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ func (t PackageTree) ExternalReach(main, tests bool) (map[string][]string, error
}

for _, imp := range imps {
if !strings.HasPrefix(filepath.Clean(imp), t.ImportRoot) {
if !checkPrefixSlash(filepath.Clean(imp), t.ImportRoot) {
w.ex[imp] = struct{}{}
} else {
if w2, seen := workmap[imp]; seen {
Expand All @@ -639,7 +639,8 @@ func (t PackageTree) ExternalReach(main, tests bool) (map[string][]string, error
return nil, nil
}

return wmToReach(workmap, t.ImportRoot)
//return wmToReach(workmap, t.ImportRoot)
return wmToReach(workmap, "") // TODO this passes tests, but doesn't seem right
}

func (t PackageTree) ListExternalImports(main, tests bool) ([]string, error) {
Expand All @@ -666,7 +667,7 @@ func (t PackageTree) ListExternalImports(main, tests bool) ([]string, error) {
}

for _, imp := range imps {
if !strings.HasPrefix(filepath.Clean(imp), t.ImportRoot) {
if !checkPrefixSlash(filepath.Clean(imp), t.ImportRoot) {
exm[imp] = struct{}{}
}
}
Expand All @@ -689,3 +690,12 @@ func (t PackageTree) ListExternalImports(main, tests bool) ([]string, error) {

return ex, nil
}

// checkPrefixSlash checks to see if the prefix is a prefix of the string as-is,
// and that it is either equal OR the prefix + / is still a prefix.
func checkPrefixSlash(s, prefix string) bool {
if !strings.HasPrefix(s, prefix) {
return false
}
return s == prefix || strings.HasPrefix(s, ensureTrailingSlash(prefix))
}
5 changes: 2 additions & 3 deletions solve_bimodal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package vsolver
import (
"fmt"
"path/filepath"
"strings"
)

// dsp - "depspec with packages"
Expand Down Expand Up @@ -424,7 +423,7 @@ func computeBimodalExternalMap(ds []depspec) map[pident]map[string][]string {
workmap := make(map[string]wm)

for _, pkg := range d.pkgs {
if !strings.HasPrefix(filepath.Clean(pkg.path), string(d.n)) {
if !checkPrefixSlash(filepath.Clean(pkg.path), string(d.n)) {
panic(fmt.Sprintf("pkg %s is not a child of %s, cannot be a part of that project", pkg.path, d.n))
}

Expand All @@ -434,7 +433,7 @@ func computeBimodalExternalMap(ds []depspec) map[pident]map[string][]string {
}

for _, imp := range pkg.imports {
if !strings.HasPrefix(filepath.Clean(imp), string(d.n)) {
if !checkPrefixSlash(filepath.Clean(imp), string(d.n)) {
// Easy case - if the import is not a child of the base
// project path, put it in the external map
w.ex[imp] = struct{}{}
Expand Down

0 comments on commit f4d9d53

Please sign in to comment.