This repository has been archived by the owner on Sep 9, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1k
Add importer for github.com/LK4D4/vndr #978
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8da26b1
Add vndr importer
spenczar 29b8f33
Add vndr importer integration test
spenczar cbb749f
Add check of manifest and lock contents
spenczar d9b5e54
Add tests of parsing vndr lines
spenczar f5bf006
Add integration test case for vndr
spenczar 4b0d599
Merge branch 'master' into vndr_importer
spenczar 65c6d98
Use table of tests for vndr importer
spenczar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
cmd/dep/testdata/harness_tests/init/vndr/case1/final/Gopkg.lock
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
4 changes: 4 additions & 0 deletions
4
cmd/dep/testdata/harness_tests/init/vndr/case1/final/Gopkg.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
[[constraint]] | ||
name = "github.com/sdboyer/deptestdos" | ||
version = "2.0.0" |
16 changes: 16 additions & 0 deletions
16
cmd/dep/testdata/harness_tests/init/vndr/case1/initial/main.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// 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/sdboyer/deptestdos" | ||
) | ||
|
||
func main() { | ||
var x deptestdos.Bar | ||
fmt.Println(x) | ||
} |
3 changes: 3 additions & 0 deletions
3
cmd/dep/testdata/harness_tests/init/vndr/case1/initial/vendor.conf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Comment on its own line | ||
github.com/sdboyer/deptest 3f4c3bea144e112a69bbe5d8d01c1b09a544253f https://github.com/sdboyer/deptest.git | ||
github.com/sdboyer/deptestdos v2.0.0 |
13 changes: 13 additions & 0 deletions
13
cmd/dep/testdata/harness_tests/init/vndr/case1/testcase.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"commands": [ | ||
["init", "-no-examples"] | ||
], | ||
"error-expected": "", | ||
"gopath-initial": { | ||
"github.com/sdboyer/deptest": "3f4c3bea144e112a69bbe5d8d01c1b09a544253f" | ||
}, | ||
"vendor-final": [ | ||
"github.com/sdboyer/deptest", | ||
"github.com/sdboyer/deptestdos" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Detected vndr configuration file... | ||
Converting from vendor.conf... | ||
Using 3f4c3bea144e112a69bbe5d8d01c1b09a544253f as initial hint for imported dep github.com/sdboyer/deptest | ||
Trying v0.8.1 (3f4c3be) as initial lock for imported dep github.com/sdboyer/deptest | ||
Using ^2.0.0 as initial constraint for imported dep github.com/sdboyer/deptestdos | ||
Trying * (v2.0.0) as initial lock for imported dep github.com/sdboyer/deptestdos |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
github.com/sdboyer/deptest 3f4c3bea144e112a69bbe5d8d01c1b09a544253f https://github.com/sdboyer/deptest.git # trailing comment | ||
# line comment | ||
|
||
github.com/sdboyer/deptestdos v2.0.0 # trailing comment |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
// 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 ( | ||
"bufio" | ||
"log" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
|
||
"github.com/golang/dep" | ||
fb "github.com/golang/dep/internal/feedback" | ||
"github.com/golang/dep/internal/gps" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
func vndrFile(dir string) string { | ||
return filepath.Join(dir, "vendor.conf") | ||
} | ||
|
||
type vndrImporter struct { | ||
packages []vndrPackage | ||
|
||
logger *log.Logger | ||
verbose bool | ||
sm gps.SourceManager | ||
} | ||
|
||
func newVndrImporter(log *log.Logger, verbose bool, sm gps.SourceManager) *vndrImporter { | ||
return &vndrImporter{ | ||
logger: log, | ||
verbose: verbose, | ||
sm: sm, | ||
} | ||
} | ||
|
||
func (v *vndrImporter) Name() string { return "vndr" } | ||
|
||
func (v *vndrImporter) HasDepMetadata(dir string) bool { | ||
_, err := os.Stat(vndrFile(dir)) | ||
return err == nil | ||
} | ||
|
||
func (v *vndrImporter) Import(dir string, pr gps.ProjectRoot) (*dep.Manifest, *dep.Lock, error) { | ||
v.logger.Println("Detected vndr configuration file...") | ||
|
||
err := v.loadVndrFile(dir) | ||
if err != nil { | ||
return nil, nil, errors.Wrapf(err, "unable to load vndr file") | ||
} | ||
|
||
return v.convert(pr) | ||
} | ||
|
||
func (v *vndrImporter) loadVndrFile(dir string) error { | ||
v.logger.Printf("Converting from vendor.conf...") | ||
|
||
f, err := os.Open(vndrFile(dir)) | ||
if err != nil { | ||
return errors.Wrapf(err, "Unable to open %s", vndrFile(dir)) | ||
} | ||
defer f.Close() | ||
|
||
scanner := bufio.NewScanner(f) | ||
for scanner.Scan() { | ||
pkg, err := parseVndrLine(scanner.Text()) | ||
if err != nil { | ||
return errors.Wrapf(err, "unable to parse line") | ||
} | ||
if pkg == nil { | ||
// Could be an empty line or one which is just a comment | ||
continue | ||
} | ||
v.packages = append(v.packages, *pkg) | ||
} | ||
|
||
if scanner.Err() != nil { | ||
return errors.Wrapf(err, "unable to read %s", vndrFile(dir)) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (v *vndrImporter) convert(pr gps.ProjectRoot) (*dep.Manifest, *dep.Lock, error) { | ||
var ( | ||
manifest = &dep.Manifest{ | ||
Constraints: make(gps.ProjectConstraints), | ||
} | ||
lock = &dep.Lock{} | ||
err error | ||
) | ||
|
||
for _, pkg := range v.packages { | ||
pc := gps.ProjectConstraint{ | ||
Ident: gps.ProjectIdentifier{ | ||
ProjectRoot: gps.ProjectRoot(pkg.importPath), | ||
Source: pkg.repository, | ||
}, | ||
} | ||
pc.Constraint, err = v.sm.InferConstraint(pkg.revision, pc.Ident) | ||
if err != nil { | ||
return nil, nil, errors.Wrapf(err, "Unable to interpret revision specifier '%s' for package %s", pkg.importPath, pkg.revision) | ||
} | ||
|
||
manifest.Constraints[pc.Ident.ProjectRoot] = gps.ProjectProperties{ | ||
Source: pc.Ident.Source, | ||
Constraint: pc.Constraint, | ||
} | ||
fb.NewConstraintFeedback(pc, fb.DepTypeImported).LogFeedback(v.logger) | ||
|
||
revision := gps.Revision(pkg.revision) | ||
version, err := lookupVersionForLockedProject(pc.Ident, pc.Constraint, revision, v.sm) | ||
if err != nil { | ||
v.logger.Println(err.Error()) | ||
} | ||
|
||
lp := gps.NewLockedProject(pc.Ident, version, nil) | ||
|
||
lock.P = append(lock.P, lp) | ||
fb.NewLockedProjectFeedback(lp, fb.DepTypeImported).LogFeedback(v.logger) | ||
} | ||
|
||
return manifest, lock, nil | ||
} | ||
|
||
type vndrPackage struct { | ||
importPath string | ||
revision string | ||
repository string | ||
} | ||
|
||
func parseVndrLine(line string) (*vndrPackage, error) { | ||
commentIdx := strings.Index(line, "#") | ||
if commentIdx >= 0 { | ||
line = line[:commentIdx] | ||
} | ||
line = strings.TrimSpace(line) | ||
|
||
if line == "" { | ||
return nil, nil | ||
} | ||
|
||
parts := strings.Fields(line) | ||
|
||
if !(len(parts) == 2 || len(parts) == 3) { | ||
return nil, errors.Errorf("invalid config format: %q", line) | ||
} | ||
|
||
pkg := &vndrPackage{ | ||
importPath: parts[0], | ||
revision: parts[1], | ||
} | ||
if len(parts) == 3 { | ||
pkg.repository = parts[2] | ||
} | ||
|
||
return pkg, nil | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I know that moby uses short git hashes, which is a bit of a problem. I think it would be easiest to have that be a separate issue, so I created #987 to address that part.