Skip to content

Commit

Permalink
Allow import cycles to avoid xtest import problems
Browse files Browse the repository at this point in the history
Because xtests (package *_test) can import the package they cohabit a
directory with, but ExternalReach() merges normal and test imports
together (and ListPackages() merges test and xtest imports into test
imports), it's possible for it to appear like there's an import cycle,
even though there isn't one in code that would actually compile
together.

The proper solution to this requires refactoring to allow multiple
packages to exist per directory. That's a major undertaking, and really
should only be attempted as part of sdboyer/gps#99. So, this is a quick fix in the
meantime.
  • Loading branch information
sdboyer committed Jan 20, 2017
1 parent 5cc9f45 commit 1598fae
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions analysis.go
Original file line number Diff line number Diff line change
Expand Up @@ -690,14 +690,17 @@ func wmToReach(workmap map[string]wm, basedir string) map[string][]string {
return true

case grey:
// Import cycles can arise in healthy situations through xtests, so
// allow them for now.
//
// 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.
//
// FIXME handle import cycles by dropping everything involved. (i
// think we need to compute SCC, then drop *all* of them?)
colors[pkg] = black
poison(append(path, pkg)) // poison self and parents
//colors[pkg] = black
//poison(append(path, pkg)) // poison self and parents

case black:
// black means we're done with the package. If it has an entry in
Expand All @@ -724,9 +727,6 @@ func wmToReach(workmap map[string]wm, basedir string) map[string][]string {
default:
panic(fmt.Sprintf("invalid color marker %v for %s", colors[pkg], pkg))
}

// shouldn't ever hit this
return false
}

// Run the depth-first exploration.
Expand Down

0 comments on commit 1598fae

Please sign in to comment.