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

#907 Warn when an importer cannot preserve a constraint #1013

Closed
wants to merge 82 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
84b3567
HashFromNode and VerifyDepTree
karrick Jul 15, 2017
ae2c30e
added package declarations at top of all test go files
karrick Aug 5, 2017
1a76ff6
refactor based on feedback from @sdboyer
karrick Aug 7, 2017
66fe4eb
writes NULL byte after writing to hash
karrick Aug 7, 2017
5c97180
added copywrite notification for dummy files
karrick Aug 7, 2017
546d65f
test scaffolding dirs and files have meaningful names
karrick Aug 7, 2017
f1d5d85
use filepath function to locate testdata_digest directory
karrick Aug 7, 2017
b6d16e1
convert CRLF to LF when hashing file contents
karrick Aug 8, 2017
9a7209d
added copywrite notification for digest{,_test}.go
karrick Aug 8, 2017
581e51a
fixes `gosimple $PKGS` lint suggestion
karrick Aug 8, 2017
a298630
lineEndingReader is more simplified than lineEndingWriterTo
karrick Aug 8, 2017
f0b532d
bug fixes and better testing for lineEndingReader
karrick Aug 8, 2017
911fda4
TestScaffolding prints testdata_digest directory
karrick Aug 8, 2017
ecbbf03
pathnames returned as keys to VerifyDepTree normalized with filepath.…
karrick Aug 8, 2017
0f7b419
continue printing VerifyDepTree response
karrick Aug 8, 2017
443fcd3
comments and some logic changes
karrick Aug 8, 2017
8575040
normalize pathnames as keys for expected digests map
karrick Aug 9, 2017
541b3f8
no longer dumps status output during testing
karrick Aug 9, 2017
0a01713
no longer dumps status output during testing
karrick Aug 9, 2017
8a0c365
two loop solution
karrick Aug 12, 2017
cba6ebe
O(n) loop for CRLF -> LF translation in lineEndingReader
karrick Aug 12, 2017
59a1046
typos
karrick Aug 12, 2017
c5be3d8
NotInLock loop more easy to read
karrick Aug 13, 2017
87959d0
DigestFromPathname -> DigestFromDirectory
karrick Aug 13, 2017
29b1709
sets element in backing array to nil after popping off queue
karrick Aug 13, 2017
17e7c9d
comments updated
karrick Aug 13, 2017
0df696c
code cleanup and documentation updates
karrick Aug 13, 2017
394b995
fix(status): print verbose messages
darkowlzz Aug 14, 2017
f02d479
VerifyDepTree reports all NotInLock file system nodes
karrick Aug 14, 2017
b7081bd
#907 is this sane?
Aug 14, 2017
5e17e7e
Make the CI happy (er)
Aug 14, 2017
e9ff6b2
additional test cases
karrick Aug 15, 2017
fbe5d64
VerifyDepTree test displays actual hash values when got status does n…
karrick Aug 15, 2017
48cd664
DirWalk
karrick Aug 15, 2017
845c95e
repeatedly uses io.CopyBuffer with pre-allocated buffer
karrick Aug 15, 2017
9a883e8
DigestFromDirectory uses DirWalk
karrick Aug 15, 2017
a252c36
public type has properly formatted documentation
karrick Aug 15, 2017
83ad7c6
DigestFromDirectory handles Lstat error from DirWalk
karrick Aug 15, 2017
a9bb8cd
removed constant no longer being used
karrick Aug 15, 2017
53e80dc
Merge pull request #1009 from darkowlzz/status-verbose
darkowlzz Aug 16, 2017
33bebd6
use gps.Any()
Aug 16, 2017
87bf819
internal/gps: parallelize WriteDepTree
ibrasho Aug 16, 2017
2e1f284
Merge pull request #1021 from ibrasho-forks/parallelize-WriteDepTree
sdboyer Aug 17, 2017
2097d86
Merge pull request #959 from karrick/master
sdboyer Aug 17, 2017
f88c233
dep: add NewManifest
ibrasho Aug 7, 2017
184949a
gps: source cache: interface tweaks and implementation optimizations
jmank88 Aug 17, 2017
b4373a7
Guard against errs in stripVendor WalkFunc
sdboyer Aug 17, 2017
8f928b1
Accommodate error channel size properly
sdboyer Aug 17, 2017
b4ff96f
Fix remove-before-visit bug
sdboyer Aug 17, 2017
151b3c8
Fix remove-before-visit for Windows, too
sdboyer Aug 17, 2017
ee6fcfc
Merge pull request #1023 from jmank88/source_cache
sdboyer Aug 17, 2017
1720318
Comment on issues before starting work
carolynvs Aug 17, 2017
d30b1cf
Merge pull request #1029 from carolynvs/lick-cookies
sdboyer Aug 17, 2017
8c85179
Drop unnecessary err check at start of walker
sdboyer Aug 17, 2017
6ca8a48
Merge pull request #1026 from sdboyer/nil-info-walk
sdboyer Aug 17, 2017
4d53b51
status: adding counts to verbose output
jmank88 Aug 18, 2017
1ea0fdc
init: more verbose logging
jmank88 Aug 19, 2017
1bef80e
Merge pull request #1038 from jmank88/init_verbose
carolynvs Aug 19, 2017
d895a66
ensure: tweaks to align no-vendor behavior and verbose/dry-run loggin…
jmank88 Aug 21, 2017
edc545f
Merge pull request #1037 from jmank88/verbose_status
jmank88 Aug 21, 2017
ae5c000
Merge pull request #1019 from ibrasho-forks/add-Manifest-constructor
darkowlzz Aug 22, 2017
a917880
internal/fs: fix os.Chmod on Windows with long paths (#925)
ibrasho Aug 22, 2017
1f6d6bb
cmd/dep: make checkErrors more lenient (#997)
ibrasho Aug 22, 2017
915565a
cmd/dep: fix vndr importpath validation
carolynvs Aug 24, 2017
7c04369
Add support importing from govend (#1040)
RaviTezu Aug 24, 2017
d877bdb
Merge pull request #1056 from carolynvs/vndr-validation
carolynvs Aug 24, 2017
baf53e5
Fixes #1046 Adds Unimplemented to unimplemented flags
adamo57 Aug 24, 2017
9e91480
#907 is this sane?
Aug 14, 2017
f920210
Make the CI happy (er)
Aug 14, 2017
2560cbd
use gps.Any()
Aug 16, 2017
244d01f
Merge branch 'WIP-issue-907' of github.com:djosephsen/dep into WIP-is…
Aug 24, 2017
aa81dc0
Document generating graph visualizations
markwest1 Aug 24, 2017
c26c5b9
Merge pull request #1050 from markwest1/I975
carolynvs Aug 24, 2017
2e93170
Added newline
adamo57 Aug 24, 2017
0981b2c
Removed build error
adamo57 Aug 24, 2017
cb99496
Merge pull request #1057 from adamo57/master
darkowlzz Aug 25, 2017
d9ac5a3
add testdata/{vndr,govend} in CODEOWNERS
darkowlzz Aug 25, 2017
f134697
Merge pull request #1062 from golang/vndr-govend-codeowners
carolynvs Aug 25, 2017
230f35f
Revert "use gps.Any()"
Aug 25, 2017
6d41041
use gps.Any()
Aug 16, 2017
948031c
use gps.Any()
Aug 25, 2017
40eb6ee
fix the return from buildProjectConstraint()
Aug 25, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
/cmd/dep/*_importer* @carolynvs
/cmd/dep/testdata/glide @carolynvs
/cmd/dep/testdata/godep @carolynvs
/cmd/dep/testdata/vndr @carolynvs
/cmd/dep/testdata/govend @carolynvs
/cmd/dep/testdata/harness_tests/init @carolynvs
/cmd/dep/testdata/init** @carolynvs
/analyzer* @carolynvs
Expand Down
4 changes: 4 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ The gophers there will answer or ask you to file an issue if you've tripped over

## Contributing code

Let us know if you are interested in working on an issue by leaving a comment
on the issue in GitHub. This helps avoid multiple people unknowingly
working on the same issue.

Please read the [Contribution Guidelines](https://golang.org/doc/contribute.html)
before sending patches.

Expand Down
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,26 @@ This happens when a new import is added. Run `dep ensure` to install the missing

As `dep status` suggests, run `dep ensure` to update your lockfile. Then run `dep status` again, and the lock mismatch should go away.

### Visualizing dependencies

Generate a visual representation of the dependency tree by piping the output of `dep status -dot` to [graphviz](http://www.graphviz.org/).
#### Linux
```
$ sudo apt-get install graphviz
$ dep status -dot | dot -T png | display
```
#### MacOS
```
$ brew install graphviz
$ dep status -dot | dot -T png | open -f -a /Applications/Preview.app
```
#### Windows
```
> choco install graphviz.portable
> dep status -dot | dot -T png -o status.png; start status.png
```
<p align="center"><img src="docs/img/StatusGraph.png"></p>

### Updating dependencies

Updating brings the version of a dependency in `Gopkg.lock` and `vendor/` to the latest version allowed by the constraints in `Gopkg.toml`.
Expand Down
85 changes: 54 additions & 31 deletions cmd/dep/ensure.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,12 @@ func (cmd *ensureCommand) Run(ctx *dep.Ctx, args []string) error {
return errors.Wrap(err, "ensure ListPackage for project")
}

if err := checkErrors(params.RootPackageTree.Packages); err != nil {
return err
if fatal, err := checkErrors(params.RootPackageTree.Packages); err != nil {
if fatal {
return err
} else if ctx.Verbose {
ctx.Out.Println(err)
}
}

if cmd.add {
Expand Down Expand Up @@ -223,15 +227,15 @@ func (cmd *ensureCommand) runDefault(ctx *dep.Ctx, args []string, p *dep.Project

if p.Lock != nil && bytes.Equal(p.Lock.InputHash(), solver.HashInputs()) {
// Memo matches, so there's probably nothing to do.
if ctx.Verbose {
ctx.Out.Printf("%s was already in sync with imports and %s\n", dep.LockName, dep.ManifestName)
}

if cmd.noVendor {
// The user said not to touch vendor/, so definitely nothing to do.
return nil
}

if ctx.Verbose {
ctx.Out.Printf("%s was already in sync with imports and %s, recreating vendor/ directory", dep.LockName, dep.ManifestName)
}

// TODO(sdboyer) The desired behavior at this point is to determine
// whether it's necessary to write out vendor, or if it's already
// consistent with the lock. However, we haven't yet determined what
Expand All @@ -244,8 +248,7 @@ func (cmd *ensureCommand) runDefault(ctx *dep.Ctx, args []string, p *dep.Project
}

if cmd.dryRun {
ctx.Out.Printf("Would have populated vendor/ directory from %s", dep.LockName)
return nil
return sw.PrintPreparedActions(ctx.Out, ctx.Verbose)
}

logger := ctx.Err
Expand All @@ -261,12 +264,16 @@ func (cmd *ensureCommand) runDefault(ctx *dep.Ctx, args []string, p *dep.Project
return errors.Wrap(err, "ensure Solve()")
}

sw, err := dep.NewSafeWriter(nil, p.Lock, dep.LockFromSolution(solution), dep.VendorOnChanged)
vendorBehavior := dep.VendorOnChanged
if cmd.noVendor {
vendorBehavior = dep.VendorNever
}
sw, err := dep.NewSafeWriter(nil, p.Lock, dep.LockFromSolution(solution), vendorBehavior)
if err != nil {
return err
}
if cmd.dryRun {
return sw.PrintPreparedActions(ctx.Out)
return sw.PrintPreparedActions(ctx.Out, ctx.Verbose)
}

logger := ctx.Err
Expand All @@ -292,14 +299,7 @@ func (cmd *ensureCommand) runVendorOnly(ctx *dep.Ctx, args []string, p *dep.Proj
}

if cmd.dryRun {
ctx.Out.Printf("Would have populated vendor/ directory from %s", dep.LockName)
if ctx.Verbose {
err := sw.PrintPreparedActions(ctx.Err)
if err != nil {
return errors.WithMessage(err, "prepared actions")
}
}
return nil
return sw.PrintPreparedActions(ctx.Out, ctx.Verbose)
}

logger := ctx.Err
Expand Down Expand Up @@ -394,7 +394,7 @@ func (cmd *ensureCommand) runUpdate(ctx *dep.Ctx, args []string, p *dep.Project,
return err
}
if cmd.dryRun {
return sw.PrintPreparedActions(ctx.Out)
return sw.PrintPreparedActions(ctx.Out, ctx.Verbose)
}

logger := ctx.Err
Expand Down Expand Up @@ -603,9 +603,8 @@ func (cmd *ensureCommand) runAdd(ctx *dep.Ctx, args []string, p *dep.Project, sm

// Prep post-actions and feedback from adds.
var reqlist []string
appender := &dep.Manifest{
Constraints: make(gps.ProjectConstraints),
}
appender := dep.NewManifest()

for pr, instr := range addInstructions {
for path := range instr.ephReq {
reqlist = append(reqlist, path)
Expand Down Expand Up @@ -648,7 +647,7 @@ func (cmd *ensureCommand) runAdd(ctx *dep.Ctx, args []string, p *dep.Project, sm
}

if cmd.dryRun {
return sw.PrintPreparedActions(ctx.Out)
return sw.PrintPreparedActions(ctx.Out, ctx.Verbose)
}

logger := ctx.Err
Expand Down Expand Up @@ -748,10 +747,10 @@ func getProjectConstraint(arg string, sm gps.SourceManager) (gps.ProjectConstrai
return gps.ProjectConstraint{Ident: pi, Constraint: c}, arg, nil
}

func checkErrors(m map[string]pkgtree.PackageOrErr) error {
func checkErrors(m map[string]pkgtree.PackageOrErr) (fatal bool, err error) {
var (
buildErrors []string
noGoErrors int
noGoErrors int
pkgtreeErrors = make(pkgtreeErrs, 0, len(m))
)

for _, poe := range m {
Expand All @@ -760,18 +759,42 @@ func checkErrors(m map[string]pkgtree.PackageOrErr) error {
case *build.NoGoError:
noGoErrors++
default:
buildErrors = append(buildErrors, poe.Err.Error())
pkgtreeErrors = append(pkgtreeErrors, poe.Err)
}
}
}

// If pkgtree was empty or all dirs lacked any Go code, return an error.
if len(m) == 0 || len(m) == noGoErrors {
return errors.New("all dirs lacked any go code")
return true, errors.New("no dirs contained any Go code")
}

if len(buildErrors) > 0 {
return errors.Errorf("Found %d errors:\n\n%s", len(buildErrors), strings.Join(buildErrors, "\n"))
// If all dirs contained build errors, return an error.
if len(m) == len(pkgtreeErrors) {
return true, errors.New("all dirs contained build errors")
}

return nil
// If all directories either had no Go files or caused a build error, return an error.
if len(m) == len(pkgtreeErrors)+noGoErrors {
return true, pkgtreeErrors
}

// If m contained some errors, return a warning with those errors.
if len(pkgtreeErrors) > 0 {
return false, pkgtreeErrors
}

return false, nil
}

type pkgtreeErrs []error

func (e pkgtreeErrs) Error() string {
errs := make([]string, 0, len(e))

for _, err := range e {
errs = append(errs, err.Error())
}

return fmt.Sprintf("found %d errors in the package tree:\n%s", len(e), strings.Join(errs, "\n"))
}
50 changes: 39 additions & 11 deletions cmd/dep/ensure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,21 @@ func TestInvalidEnsureFlagCombinations(t *testing.T) {
func TestCheckErrors(t *testing.T) {
tt := []struct {
name string
hasErrs bool
fatal bool
pkgOrErrMap map[string]pkgtree.PackageOrErr
}{
{
name: "noErrors",
hasErrs: false,
name: "noErrors",
fatal: false,
pkgOrErrMap: map[string]pkgtree.PackageOrErr{
"mypkg": {
P: pkgtree.Package{},
},
},
},
{
name: "hasErrors",
hasErrs: true,
name: "hasErrors",
fatal: true,
pkgOrErrMap: map[string]pkgtree.PackageOrErr{
"github.com/me/pkg": {
Err: &build.NoGoError{},
Expand All @@ -81,8 +81,8 @@ func TestCheckErrors(t *testing.T) {
},
},
{
name: "onlyGoErrors",
hasErrs: false,
name: "onlyGoErrors",
fatal: false,
pkgOrErrMap: map[string]pkgtree.PackageOrErr{
"github.com/me/pkg": {
Err: &build.NoGoError{},
Expand All @@ -93,20 +93,48 @@ func TestCheckErrors(t *testing.T) {
},
},
{
name: "allGoErrors",
hasErrs: true,
name: "onlyBuildErrors",
fatal: false,
pkgOrErrMap: map[string]pkgtree.PackageOrErr{
"github.com/me/pkg": {
Err: &build.NoGoError{},
},
"github.com/someone/pkg": {
P: pkgtree.Package{},
},
},
},
{
name: "allGoErrors",
fatal: true,
pkgOrErrMap: map[string]pkgtree.PackageOrErr{
"github.com/me/pkg": {
Err: &build.NoGoError{},
},
},
},
{
name: "allMixedErrors",
fatal: true,
pkgOrErrMap: map[string]pkgtree.PackageOrErr{
"github.com/me/pkg": {
Err: &build.NoGoError{},
},
"github.com/someone/pkg": {
Err: errors.New("code is busted"),
},
},
},
}

for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {
if hasErrs := checkErrors(tc.pkgOrErrMap) != nil; hasErrs != tc.hasErrs {
t.Fail()
fatal, err := checkErrors(tc.pkgOrErrMap)
if tc.fatal != fatal {
t.Fatalf("expected fatal flag to be %T, got %T", tc.fatal, fatal)
}
if err == nil && fatal {
t.Fatal("unexpected fatal flag value while err is nil")
}
})
}
Expand Down
7 changes: 3 additions & 4 deletions cmd/dep/glide_importer.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,7 @@ func (g *glideImporter) convert(pr gps.ProjectRoot) (*dep.Manifest, *dep.Lock, e
task.WriteString("...")
g.logger.Println(task)

manifest := &dep.Manifest{
Constraints: make(gps.ProjectConstraints),
}
manifest := dep.NewManifest()

for _, pkg := range append(g.yaml.Imports, g.yaml.TestImports...) {
pc, err := g.buildProjectConstraint(pkg)
Expand Down Expand Up @@ -204,7 +202,8 @@ func (g *glideImporter) buildProjectConstraint(pkg glidePackage) (pc gps.Project
}
pc.Constraint, err = g.sm.InferConstraint(pkg.Reference, pc.Ident)
if err != nil {
return
g.logger.Printf("Unable to interpret revision specifier '%s' for package %s: %s", pkg.Name, pc.Ident, err.Error())
pc.Constraint = gps.Any()
}

if g.verbose {
Expand Down
7 changes: 3 additions & 4 deletions cmd/dep/godep_importer.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,7 @@ func (g *godepImporter) load(projectDir string) error {
func (g *godepImporter) convert(pr gps.ProjectRoot) (*dep.Manifest, *dep.Lock, error) {
g.logger.Println("Converting from Godeps.json ...")

manifest := &dep.Manifest{
Constraints: make(gps.ProjectConstraints),
}
manifest := dep.NewManifest()
lock := &dep.Lock{}

for _, pkg := range g.json.Imports {
Expand Down Expand Up @@ -160,7 +158,8 @@ func (g *godepImporter) buildProjectConstraint(pkg godepPackage) (pc gps.Project
pc.Ident = gps.ProjectIdentifier{ProjectRoot: gps.ProjectRoot(pkg.ImportPath)}
pc.Constraint, err = g.sm.InferConstraint(pkg.Comment, pc.Ident)
if err != nil {
return
g.logger.Printf("Unable to interpret revision specifier '%s' for package %s: %s", pkg.ImportPath, pc.Ident, err.Error())
pc.Constraint = gps.Any()
}

f := fb.NewConstraintFeedback(pc, fb.DepTypeImported)
Expand Down
5 changes: 0 additions & 5 deletions cmd/dep/godep_importer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ func TestGodepConfig_Convert(t *testing.T) {
},
},
convertTestCase: &convertTestCase{

projectRoot: gps.ProjectRoot("github.com/sdboyer/deptest"),
wantConstraint: "^1.12.0-12-g2fd980e",
wantLockCount: 1,
Expand All @@ -70,7 +69,6 @@ func TestGodepConfig_Convert(t *testing.T) {
},
},
convertTestCase: &convertTestCase{

projectRoot: gps.ProjectRoot("github.com/sdboyer/deptest"),
wantConstraint: "^1.0.0",
wantRevision: gps.Revision("ff2948a2ac8f538c4ecd55962e919d1e13e74baf"),
Expand All @@ -83,7 +81,6 @@ func TestGodepConfig_Convert(t *testing.T) {
Imports: []godepPackage{{ImportPath: ""}},
},
convertTestCase: &convertTestCase{

wantConvertErr: true,
},
},
Expand All @@ -96,7 +93,6 @@ func TestGodepConfig_Convert(t *testing.T) {
},
},
convertTestCase: &convertTestCase{

wantConvertErr: true,
},
},
Expand All @@ -116,7 +112,6 @@ func TestGodepConfig_Convert(t *testing.T) {
},
},
convertTestCase: &convertTestCase{

projectRoot: gps.ProjectRoot("github.com/sdboyer/deptest"),
wantLockCount: 1,
wantConstraint: "^1.0.0",
Expand Down
Loading