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 4 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
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,153 @@ | ||
// 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 { | ||
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...") | ||
|
||
packages, err := v.loadVndrFile(dir) | ||
if err != nil { | ||
return nil, nil, errors.Wrapf(err, "unable to load vndr file") | ||
} | ||
|
||
manifest := &dep.Manifest{ | ||
Constraints: make(gps.ProjectConstraints), | ||
} | ||
lock := &dep.Lock{} | ||
|
||
for _, pkg := range 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) | ||
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 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. |
||
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 | ||
} | ||
|
||
func (v *vndrImporter) loadVndrFile(dir string) ([]vndrPackage, error) { | ||
v.logger.Printf("Converting from vendor.conf...") | ||
|
||
f, err := os.Open(vndrFile(dir)) | ||
if err != nil { | ||
return nil, errors.Wrapf(err, "Unable to open %s", vndrFile(dir)) | ||
} | ||
defer f.Close() | ||
|
||
var packages []vndrPackage | ||
scanner := bufio.NewScanner(f) | ||
for scanner.Scan() { | ||
pkg, err := parseVndrLine(scanner.Text()) | ||
if err != nil { | ||
return nil, errors.Wrapf(err, "unable to parse line") | ||
} | ||
if pkg == nil { | ||
// Could be an empty line or one which is just a comment | ||
continue | ||
} | ||
packages = append(packages, *pkg) | ||
} | ||
|
||
if scanner.Err() != nil { | ||
return nil, errors.Wrapf(err, "unable to read %s", vndrFile(dir)) | ||
} | ||
|
||
return packages, nil | ||
} | ||
|
||
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 | ||
} | ||
|
||
type vndrPackage struct { | ||
importPath string | ||
revision string | ||
repository string | ||
} |
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.
Note to self: If #952 is merged first, we should use the constructor
dep.NewManifest
.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.
The race is on! 🏁