-
Notifications
You must be signed in to change notification settings - Fork 1k
Add -gopath flag to init #497
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ import ( | |
"log" | ||
|
||
"github.com/golang/dep" | ||
fb "github.com/golang/dep/internal/feedback" | ||
"github.com/golang/dep/internal/gps" | ||
"github.com/pkg/errors" | ||
) | ||
|
@@ -125,18 +126,39 @@ 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 | ||
func (a *rootAnalyzer) FinalizeRootManifestAndLock(m *dep.Manifest, l *dep.Lock, ol dep.Lock) { | ||
a.removeTransitiveDependencies(m) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @carolynvs I used There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AFAIK only the importers may add a transitive or unused dep to the manifest, because they are just responsible for converting from the external config to dep's. In So unless someplace in the code else may be adding things to the manifest that may not belong, I don't think we need to call it again in |
||
|
||
// 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 { | ||
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When I split up the old What we have right here will only print either a using or a locking, but never both. Was that the intent? I expected that if we can deduce a constraint, that we could want to print the constraint and the locked project. If you agree, I think we need to add a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh! yeah, that's right. Didn't realize that got changed 😅 no need of the conditional else. |
||
} | ||
f.LogFeedback(a.ctx.Err) | ||
} | ||
} else { | ||
// 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) | ||
} | ||
} | ||
if !used { | ||
delete(m.Constraints, pr) | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Problem with this is that, since Should this be moved to init? or should we make at least rootAnalyzer aware of gopath flag? or maybe there's another way 🤔 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @darkowlzz I wrote out the workflow for init to help answer this question and decided to dump my notes, instead of just the one part that addresses the question. 😁
I believe that we can generalize the
Then we could have init keep a copy of the lock given to the solver, and pass it in as an additional argument to What do you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I remember we used to keep a copy of lock given to the solver and use the same to identify new constraints and projects, by comparing with new lock, at one point of time. I still have my dep fork at that point of time, copyLock 😊 So, yeah, a unified |
||
} | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
[[constraint]] | ||
name = "github.com/sdboyer/deptest" | ||
version = "1.0.0" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Previously, this used to be with a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yup, when init generates the manifest it should not write out the My preference is for the verbose output to print what's really going on and show the caret, but will leave that call to @sdboyer. If we do end up changing that, let's do it in a separate PR. |
||
|
||
[[constraint]] | ||
name = "github.com/sdboyer/deptestdos" | ||
version = "2.0.0" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Copyright 2017 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package foo | ||
|
||
import "github.com/sdboyer/deptest" | ||
|
||
func Foo() deptest.Foo { | ||
var y deptest.Foo | ||
|
||
return y | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright 2017 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/golang/notexist/foo" | ||
"github.com/sdboyer/deptestdos" | ||
) | ||
|
||
func main() { | ||
var x deptestdos.Bar | ||
y := foo.FooFunc() | ||
|
||
fmt.Println(x, y) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"commands": [ | ||
["init", "-no-examples"] | ||
], | ||
"gopath-initial": { | ||
"github.com/sdboyer/deptestdos": "a0196baa11ea047dd65037287451d36b861b00ea" | ||
}, | ||
"vendor-final": [ | ||
"github.com/sdboyer/deptest", | ||
"github.com/sdboyer/deptestdos" | ||
] | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since all this logic moved out of init.go into gopath_scanner.go, would you please rebase and move over your changes too? Sorry for the merge trouble!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's where the various bits are in gopath_scanner:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks :)