Skip to content
This repository has been archived by the owner on Sep 9, 2020. It is now read-only.

Commit

Permalink
Generalize FinalizeManifestAndLock
Browse files Browse the repository at this point in the history
- Removes gopathScanner's FinalizeManifestAndLock() and its usage.
- Adds using RemoveTransitiveDependencies() to remove unused
constraints.
- Changes rootAnalyzer's FinalizeManifestAndLock to log feedback for new
constraints and locked projects only.
  • Loading branch information
darkowlzz committed Jun 17, 2017
1 parent b674913 commit d56d41b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 53 deletions.
21 changes: 0 additions & 21 deletions cmd/dep/gopath_scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,27 +134,6 @@ func (g *gopathScanner) overlay(rootM *dep.Manifest, rootL *dep.Lock) {
}
}

func (g *gopathScanner) FinalizeRootManifestAndLock(m *dep.Manifest, l *dep.Lock) {
// Iterate through the new projects in solved lock and add them to manifest
// if direct deps and log feedback for all the new projects.
for _, x := range l.Projects() {
pr := x.Ident().ProjectRoot
newProject := true
// Check if it's a new project, not in the old lock
for _, y := range g.origL.Projects() {
if pr == y.Ident().ProjectRoot {
newProject = false
}
}
if newProject {
// If it's in notondisk, add to manifest, these are direct dependencies.
if _, ok := g.pd.notondisk[pr]; ok {
m.Constraints[pr] = getProjectPropertiesFromVersion(x.Version())
}
}
}
}

func trimPathPrefix(p1, p2 string) string {
if fs.HasFilepathPrefix(p1, p2) {
return p1[len(p2):]
Expand Down
7 changes: 3 additions & 4 deletions cmd/dep/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ func (cmd *initCommand) Run(ctx *dep.Ctx, args []string) error {
}

rootAnalyzer.skipTools = true // Don't import external config during solve for now
copyLock := *p.Lock // Copy lock before solving. Use this to separate new lock projects from solved lock

params := gps.SolveParameters{
RootDir: root,
Expand All @@ -174,10 +175,8 @@ func (cmd *initCommand) Run(ctx *dep.Ctx, args []string) error {
}
p.Lock = dep.LockFromSolution(soln)

rootAnalyzer.FinalizeRootManifestAndLock(p.Manifest, p.Lock)
if cmd.gopath {
gs.FinalizeRootManifestAndLock(p.Manifest, p.Lock)
}
rootAnalyzer.RemoveTransitiveDependencies(p.Manifest)
rootAnalyzer.FinalizeRootManifestAndLock(p.Manifest, p.Lock, copyLock)

// Run gps.Prepare with appropriate constraint solutions from solve run
// to generate the final lock memo.
Expand Down
55 changes: 27 additions & 28 deletions cmd/dep/root_analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (a *rootAnalyzer) importManifestAndLock(dir string, pr gps.ProjectRoot, sup
if err != nil {
return nil, nil, err
}
a.removeTransitiveDependencies(m)
a.RemoveTransitiveDependencies(m)
return m, l, err
}
}
Expand All @@ -91,7 +91,7 @@ func (a *rootAnalyzer) importManifestAndLock(dir string, pr gps.ProjectRoot, sup
return emptyManifest, nil, nil
}

func (a *rootAnalyzer) removeTransitiveDependencies(m *dep.Manifest) {
func (a *rootAnalyzer) RemoveTransitiveDependencies(m *dep.Manifest) {
for pr := range m.Constraints {
if _, isDirect := a.directDeps[string(pr)]; !isDirect {
delete(m.Constraints, pr)
Expand Down Expand Up @@ -126,39 +126,38 @@ func (a *rootAnalyzer) DeriveManifestAndLock(dir string, pr gps.ProjectRoot) (gp
return gps.SimpleManifest{}, nil, nil
}

func (a *rootAnalyzer) FinalizeRootManifestAndLock(m *dep.Manifest, l *dep.Lock) {
// Remove dependencies from the manifest that aren't used
for pr := range m.Constraints {
var used bool
for _, y := range l.Projects() {
if pr == y.Ident().ProjectRoot {
used = true
break
}
}
if !used {
delete(m.Constraints, pr)
}
}
// Pick the direct dependencies from the solution lock and add to manifest.
// This is done to fill up the manifest constraints with the dependencies
// solved over the network.
func (a *rootAnalyzer) FinalizeRootManifestAndLock(m *dep.Manifest, l *dep.Lock, ol dep.Lock) {
// Iterate through the new projects in solved lock and add them to manifest
// if they are direct deps and log feedback for all the new projects.
for _, y := range l.Projects() {
var f *fb.ConstraintFeedback
pr := y.Ident().ProjectRoot
// New constraints: in new lock and dir dep but not in manifest
if _, ok := a.directDeps[string(pr)]; ok {
pp := getProjectPropertiesFromVersion(y.Version())
if pp.Constraint != nil {
m.Constraints[pr] = pp
pc := gps.ProjectConstraint{Ident: y.Ident(), Constraint: pp.Constraint}
f = fb.NewConstraintFeedback(pc, fb.DepTypeDirect)
} else {
f = fb.NewLockedProjectFeedback(y, fb.DepTypeDirect)
if _, ok := m.Constraints[pr]; !ok {
pp := getProjectPropertiesFromVersion(y.Version())
if pp.Constraint != nil {
m.Constraints[pr] = pp
pc := gps.ProjectConstraint{Ident: y.Ident(), Constraint: pp.Constraint}
f = fb.NewConstraintFeedback(pc, fb.DepTypeDirect)
} else {
f = fb.NewLockedProjectFeedback(y, fb.DepTypeDirect)
}
f.LogFeedback(a.ctx.Err)
}
} else {
f = fb.NewLockedProjectFeedback(y, fb.DepTypeTransitive)
// New locked projects: in new lock but not in old lock
newProject := true
for _, opl := range ol.Projects() {
if pr == opl.Ident().ProjectRoot {
newProject = false
}
}
if newProject {
f = fb.NewLockedProjectFeedback(y, fb.DepTypeTransitive)
f.LogFeedback(a.ctx.Err)
}
}
f.LogFeedback(a.ctx.Err)
}
}

Expand Down

0 comments on commit d56d41b

Please sign in to comment.