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

Commit 6ace212

Browse files
committed
Generalize FinalizeManifestAndLock
- 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.
1 parent b674913 commit 6ace212

File tree

3 files changed

+30
-52
lines changed

3 files changed

+30
-52
lines changed

cmd/dep/gopath_scanner.go

-21
Original file line numberDiff line numberDiff line change
@@ -134,27 +134,6 @@ func (g *gopathScanner) overlay(rootM *dep.Manifest, rootL *dep.Lock) {
134134
}
135135
}
136136

137-
func (g *gopathScanner) FinalizeRootManifestAndLock(m *dep.Manifest, l *dep.Lock) {
138-
// Iterate through the new projects in solved lock and add them to manifest
139-
// if direct deps and log feedback for all the new projects.
140-
for _, x := range l.Projects() {
141-
pr := x.Ident().ProjectRoot
142-
newProject := true
143-
// Check if it's a new project, not in the old lock
144-
for _, y := range g.origL.Projects() {
145-
if pr == y.Ident().ProjectRoot {
146-
newProject = false
147-
}
148-
}
149-
if newProject {
150-
// If it's in notondisk, add to manifest, these are direct dependencies.
151-
if _, ok := g.pd.notondisk[pr]; ok {
152-
m.Constraints[pr] = getProjectPropertiesFromVersion(x.Version())
153-
}
154-
}
155-
}
156-
}
157-
158137
func trimPathPrefix(p1, p2 string) string {
159138
if fs.HasFilepathPrefix(p1, p2) {
160139
return p1[len(p2):]

cmd/dep/init.go

+3-5
Original file line numberDiff line numberDiff line change
@@ -140,15 +140,16 @@ func (cmd *initCommand) Run(ctx *dep.Ctx, args []string) error {
140140
return err
141141
}
142142

143-
gs := newGopathScanner(ctx, directDeps, sm)
144143
if cmd.gopath {
144+
gs := newGopathScanner(ctx, directDeps, sm)
145145
err = gs.InitializeRootManifestAndLock(p.Manifest, p.Lock)
146146
if err != nil {
147147
return err
148148
}
149149
}
150150

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

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

177-
rootAnalyzer.FinalizeRootManifestAndLock(p.Manifest, p.Lock)
178-
if cmd.gopath {
179-
gs.FinalizeRootManifestAndLock(p.Manifest, p.Lock)
180-
}
178+
rootAnalyzer.FinalizeRootManifestAndLock(p.Manifest, p.Lock, copyLock)
181179

182180
// Run gps.Prepare with appropriate constraint solutions from solve run
183181
// to generate the final lock memo.

cmd/dep/root_analyzer.go

+27-26
Original file line numberDiff line numberDiff line change
@@ -126,39 +126,40 @@ func (a *rootAnalyzer) DeriveManifestAndLock(dir string, pr gps.ProjectRoot) (gp
126126
return gps.SimpleManifest{}, nil, nil
127127
}
128128

129-
func (a *rootAnalyzer) FinalizeRootManifestAndLock(m *dep.Manifest, l *dep.Lock) {
130-
// Remove dependencies from the manifest that aren't used
131-
for pr := range m.Constraints {
132-
var used bool
133-
for _, y := range l.Projects() {
134-
if pr == y.Ident().ProjectRoot {
135-
used = true
136-
break
137-
}
138-
}
139-
if !used {
140-
delete(m.Constraints, pr)
141-
}
142-
}
143-
// Pick the direct dependencies from the solution lock and add to manifest.
144-
// This is done to fill up the manifest constraints with the dependencies
145-
// solved over the network.
129+
func (a *rootAnalyzer) FinalizeRootManifestAndLock(m *dep.Manifest, l *dep.Lock, ol dep.Lock) {
130+
// Iterate through the new projects in solved lock and add them to manifest
131+
// if they are direct deps and log feedback for all the new projects.
132+
a.removeTransitiveDependencies(m)
133+
146134
for _, y := range l.Projects() {
147135
var f *fb.ConstraintFeedback
148136
pr := y.Ident().ProjectRoot
137+
// New constraints: in new lock and dir dep but not in manifest
149138
if _, ok := a.directDeps[string(pr)]; ok {
150-
pp := getProjectPropertiesFromVersion(y.Version())
151-
if pp.Constraint != nil {
152-
m.Constraints[pr] = pp
153-
pc := gps.ProjectConstraint{Ident: y.Ident(), Constraint: pp.Constraint}
154-
f = fb.NewConstraintFeedback(pc, fb.DepTypeDirect)
155-
} else {
156-
f = fb.NewLockedProjectFeedback(y, fb.DepTypeDirect)
139+
if _, ok := m.Constraints[pr]; !ok {
140+
pp := getProjectPropertiesFromVersion(y.Version())
141+
if pp.Constraint != nil {
142+
m.Constraints[pr] = pp
143+
pc := gps.ProjectConstraint{Ident: y.Ident(), Constraint: pp.Constraint}
144+
f = fb.NewConstraintFeedback(pc, fb.DepTypeDirect)
145+
} else {
146+
f = fb.NewLockedProjectFeedback(y, fb.DepTypeDirect)
147+
}
148+
f.LogFeedback(a.ctx.Err)
157149
}
158150
} else {
159-
f = fb.NewLockedProjectFeedback(y, fb.DepTypeTransitive)
151+
// New locked projects: in new lock but not in old lock
152+
newProject := true
153+
for _, opl := range ol.Projects() {
154+
if pr == opl.Ident().ProjectRoot {
155+
newProject = false
156+
}
157+
}
158+
if newProject {
159+
f = fb.NewLockedProjectFeedback(y, fb.DepTypeTransitive)
160+
f.LogFeedback(a.ctx.Err)
161+
}
160162
}
161-
f.LogFeedback(a.ctx.Err)
162163
}
163164
}
164165

0 commit comments

Comments
 (0)