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

Commit

Permalink
Allow project-level cycles involving root project
Browse files Browse the repository at this point in the history
Fixes #151.

♬ : Anna Kendrick / Cups (Pitch Perfect’s “When I’m Gone”)
  • Loading branch information
sdboyer committed Jan 24, 2017
1 parent 9b38990 commit 69f564a
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 20 deletions.
2 changes: 1 addition & 1 deletion bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ func (b *bridge) vtu(id ProjectIdentifier, v Version) versionTypeUnion {
// responsible for that code.
func (b *bridge) ListPackages(id ProjectIdentifier, v Version) (PackageTree, error) {
if b.s.rd.isRoot(id.ProjectRoot) {
panic("should never call ListPackages on root project")
return b.s.rd.rpt, nil
}

b.s.mtr.push("b-list-pkgs")
Expand Down
11 changes: 9 additions & 2 deletions rootdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,20 +141,27 @@ func (rd rootdata) combineConstraints() []workingConstraint {

// needVersionListFor indicates whether we need a version list for a given
// project root, based solely on general solver inputs (no constraint checking
// required). This will be true if any of the following conditions hold:
// required). Assuming the argument is not the root project itself, this will be
// true if any of the following conditions hold:
//
// - ChangeAll is on
// - The project is not in the lock
// - The project is in the lock, but is also in the list of projects to change
func (rd rootdata) needVersionsFor(pr ProjectRoot) bool {
if rd.isRoot(pr) {
return false
}

if rd.chngall {
return true
}

if _, has := rd.rlm[pr]; !has {
// not in the lock
return true
} else if _, has := rd.chng[pr]; has {
}

if _, has := rd.chng[pr]; has {
// in the lock, but marked for change
return true
}
Expand Down
14 changes: 2 additions & 12 deletions selection.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,7 @@ func (s *selection) getRequiredPackagesIn(id ProjectIdentifier) map[string]int {
uniq := make(map[string]int)
for _, dep := range s.deps[id.ProjectRoot] {
for _, pkg := range dep.dep.pl {
if count, has := uniq[pkg]; has {
count++
uniq[pkg] = count
} else {
uniq[pkg] = 1
}
uniq[pkg] = uniq[pkg] + 1
}
}

Expand All @@ -105,12 +100,7 @@ func (s *selection) getSelectedPackagesIn(id ProjectIdentifier) map[string]int {
for _, p := range s.projects {
if p.a.a.id.eq(id) {
for _, pkg := range p.a.pl {
if count, has := uniq[pkg]; has {
count++
uniq[pkg] = count
} else {
uniq[pkg] = 1
}
uniq[pkg] = uniq[pkg] + 1
}
}
}
Expand Down
7 changes: 3 additions & 4 deletions solve_bimodal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,16 +291,15 @@ var bimodalFixtures = map[string]bimodalFixture{
pkg("root", "a"),
),
dsp(mkDepspec("a 1.0.0"),
pkg("a"),
pkg("a", "b"),
pkg("a/foo"),
),
dsp(mkDepspec("b 1.0.0"),
pkg("b", "b/baz"),
pkg("b/baz", "a/foo"),
pkg("b", "a/foo"),
),
},
r: mksolution(
"a 1.0.0",
mklp("a 1.0.0", ".", "foo"),
"b 1.0.0",
),
},
Expand Down
7 changes: 6 additions & 1 deletion solver.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,6 @@ func (s *solver) solve() (map[atom]map[string]struct{}, error) {
func (s *solver) selectRoot() error {
s.mtr.push("select-root")
// Push the root project onto the queue.
// TODO(sdboyer) maybe it'd just be better to skip this?
awp := s.rd.rootAtom()
s.sel.pushSelection(awp, true)

Expand Down Expand Up @@ -1063,6 +1062,12 @@ func (s *solver) selectAtom(a atomWithPackages, pkgonly bool) {
}

for _, dep := range deps {
// Root can come back up here if there's a project-level cycle.
// Satisfiability checks have already ensured invariants are maintained,
// so we know we can just skip it here.
if s.rd.isRoot(dep.Ident.ProjectRoot) {
continue
}
// If this is dep isn't in the lock, do some prefetching. (If it is, we
// might be able to get away with zero network activity for it, so don't
// prefetch). This provides an opportunity for some parallelism wins, on
Expand Down

0 comments on commit 69f564a

Please sign in to comment.