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

Add importer for govendor #815

Merged
merged 6 commits into from
Nov 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# v0.3.3 (Unreleased)

NEW FEATURES:
* Add support for importing from [govendor](https://github.com/kardianos/govendor)
based projects (#815).

BUG FIXES:

* Releases targeting Windows now have a `.exe` suffix (#1291).
Expand Down
2 changes: 1 addition & 1 deletion cmd/dep/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ specified, use the current directory.
When configuration for another dependency management tool is detected, it is
imported into the initial manifest and lock. Use the -skip-tools flag to
disable this behavior. The following external tools are supported:
glide, godep, vndr, govend, gb, gvt.
glide, godep, vndr, govend, gb, gvt, govendor.

Any dependencies that are not constrained by external configuration use the
GOPATH analysis below.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Import govendor config in vendor dir.

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,5 @@
ignored = ["github.com/golang/notexist/samples*","github.com/sdboyer/dep-test*"]

[[constraint]]
name = "github.com/sdboyer/deptestdos"
version = "2.0.0"
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)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright 2016 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 samples

import dt "github.com/carolynvs/go-dep-test"

func Sample1() int {
var x = dt.Thing
return x
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"comment": "",
"ignore": "test github.com/sdboyer/dep-test samples/",
"package": [
{
"checksumSHA1": "4R6TQcq0/gI/I2kKeUunuO/pEec=",
"path": "github.com/sdboyer/deptest",
"revision": "3f4c3bea144e112a69bbe5d8d01c1b09a544253f",
"revisionTime": "2017-02-22T03:31:47Z"
},
{
"checksumSHA1": "96YwrJjpE07ENey/eDWWnCWKQOw=",
"path": "github.com/sdboyer/deptestdos",
"revision": "5c607206be5decd28e6263ffffdcee067266015e",
"revisionTime": "2017-02-22T03:34:58Z",
"version": "v2",
"versionExact": "v2.0.0"
}
],
"rootPath": "github.com/golang/notexist"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"commands": [
["init", "-no-examples", "-gopath"]
],
"error-expected": "",
"gopath-initial": {
"github.com/sdboyer/deptest": "3f4c3bea144e112a69bbe5d8d01c1b09a544253f",
"github.com/sdboyer/deptestdos": "5c607206be5decd28e6263ffffdcee067266015e"
},
"vendor-final": [
"github.com/sdboyer/deptest",
"github.com/sdboyer/deptestdos"
]
}
2 changes: 1 addition & 1 deletion docs/FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ about what's going on.
During `dep init` configuration from other dependency managers is detected
and imported, unless `-skip-tools` is specified.

The following tools are supported: `glide`, `godep`, `vndr`, `govend`, `gb` and `gvt`.
The following tools are supported: `glide`, `godep`, `vndr`, `govend`, `gb`, `gvt` and `govendor`.

See [#186](https://github.com/golang/dep/issues/186#issuecomment-306363441) for
how to add support for another tool.
Expand Down
37 changes: 20 additions & 17 deletions internal/importers/base/importer.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package base

import (
"log"
"strings"

"github.com/golang/dep"
"github.com/golang/dep/gps"
Expand All @@ -16,28 +17,27 @@ import (
// Importer provides a common implementation for importing from other
// dependency managers.
type Importer struct {
sm gps.SourceManager

Logger *log.Logger
Verbose bool
Manifest *dep.Manifest
Lock *dep.Lock
SourceManager gps.SourceManager
Logger *log.Logger
Verbose bool
Manifest *dep.Manifest
Lock *dep.Lock
}

// NewImporter creates a new Importer for embedding in an importer.
func NewImporter(logger *log.Logger, verbose bool, sm gps.SourceManager) *Importer {
return &Importer{
Logger: logger,
Verbose: verbose,
Manifest: dep.NewManifest(),
Lock: &dep.Lock{},
sm: sm,
Logger: logger,
Verbose: verbose,
Manifest: dep.NewManifest(),
Lock: &dep.Lock{},
SourceManager: sm,
}
}

// isTag determines if the specified value is a tag (plain or semver).
func (i *Importer) isTag(pi gps.ProjectIdentifier, value string) (bool, gps.Version, error) {
versions, err := i.sm.ListVersions(pi)
versions, err := i.SourceManager.ListVersions(pi)
if err != nil {
return false, nil, errors.Wrapf(err, "unable to list versions for %s(%s)", pi.ProjectRoot, pi.Source)
}
Expand All @@ -61,7 +61,7 @@ func (i *Importer) isTag(pi gps.ProjectIdentifier, value string) (bool, gps.Vers
// manifest, then finally the revision.
func (i *Importer) lookupVersionForLockedProject(pi gps.ProjectIdentifier, c gps.Constraint, rev gps.Revision) (gps.Version, error) {
// Find the version that goes with this revision, if any
versions, err := i.sm.ListVersions(pi)
versions, err := i.SourceManager.ListVersions(pi)
if err != nil {
return rev, errors.Wrapf(err, "Unable to lookup the version represented by %s in %s(%s). Falling back to locking the revision only.", rev, pi.ProjectRoot, pi.Source)
}
Expand Down Expand Up @@ -130,7 +130,7 @@ func (i *Importer) loadPackages(packages []ImportedPackage) ([]importedProject,

projects := make(map[gps.ProjectRoot]*importedProject, len(packages))
for _, pkg := range packages {
pr, err := i.sm.DeduceProjectRoot(pkg.Name)
pr, err := i.SourceManager.DeduceProjectRoot(pkg.Name)
if err != nil {
return nil, errors.Wrapf(err, "Cannot determine the project root for %s", pkg.Name)
}
Expand Down Expand Up @@ -188,6 +188,9 @@ func (i *Importer) ImportPackages(packages []ImportedPackage, defaultConstraintF
source = ""
} else if isDefault {
source = ""
} else if strings.Contains(source, "/vendor/") {
i.Logger.Printf(" Ignoring imported source %s for %s because vendored sources aren't supported", source, prj.Root)
source = ""
}
}

Expand All @@ -198,7 +201,7 @@ func (i *Importer) ImportPackages(packages []ImportedPackage, defaultConstraintF
},
}

pc.Constraint, err = i.sm.InferConstraint(prj.ConstraintHint, pc.Ident)
pc.Constraint, err = i.SourceManager.InferConstraint(prj.ConstraintHint, pc.Ident)
if err != nil {
pc.Constraint = gps.Any()
}
Expand Down Expand Up @@ -306,12 +309,12 @@ func (i *Importer) convertToConstraint(v gps.Version) gps.Constraint {
func (i *Importer) isDefaultSource(projectRoot gps.ProjectRoot, sourceURL string) (bool, error) {
// this condition is mainly for gopkg.in imports,
// as some importers specify the repository url as https://gopkg.in/...,
// but sm.SourceURLsForPath() returns https://github.com/... urls for gopkg.in
// but SourceManager.SourceURLsForPath() returns https://github.com/... urls for gopkg.in
if sourceURL == "https://"+string(projectRoot) {
return true, nil
}

sourceURLs, err := i.sm.SourceURLsForPath(string(projectRoot))
sourceURLs, err := i.SourceManager.SourceURLsForPath(string(projectRoot))
if err != nil {
return false, err
}
Expand Down
15 changes: 14 additions & 1 deletion internal/importers/base/importer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ func TestBaseImporter_ImportProjects(t *testing.T) {
},
},
},
"ignoring default source": {
"ignore default source": {
importertest.TestCase{
WantConstraint: "*",
WantSourceRepo: "",
Expand All @@ -394,6 +394,19 @@ func TestBaseImporter_ImportProjects(t *testing.T) {
},
},
},
"ignore vendored source": {
importertest.TestCase{
WantConstraint: "*",
WantSourceRepo: "",
WantWarning: "vendored sources aren't supported",
},
[]ImportedPackage{
{
Name: importertest.Project,
Source: "example.com/vendor/" + importertest.Project,
},
},
},
}

for name, tc := range testcases {
Expand Down
Loading