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

Commit

Permalink
Import glide config during dep init
Browse files Browse the repository at this point in the history
Use -skip-tools to bypass this behavior
  • Loading branch information
carolynvs committed May 2, 2017
1 parent 3951743 commit 931f258
Show file tree
Hide file tree
Showing 19 changed files with 624 additions and 83 deletions.
46 changes: 1 addition & 45 deletions cmd/dep/ensure.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@ package main

import (
"bytes"
"encoding/hex"
"flag"
"fmt"
"go/build"
"log"
"os"
"path/filepath"
"strconv"
"strings"

"github.com/golang/dep"
Expand Down Expand Up @@ -275,7 +273,7 @@ func getProjectConstraint(arg string, sm *gps.SourceMgr) (gps.ProjectConstraint,
parts := strings.SplitN(arg, "@", 2)
arg = parts[0]
versionStr = parts[1]
constraint.Constraint = deduceConstraint(parts[1])
constraint.Constraint = gps.DeduceConstraint(parts[1])
}
// TODO: What if there is no @, assume default branch (which may not be master) ?
// TODO: if we decide to keep equals.....
Expand Down Expand Up @@ -327,48 +325,6 @@ func getProjectConstraint(arg string, sm *gps.SourceMgr) (gps.ProjectConstraint,
return constraint, nil
}

// deduceConstraint tries to puzzle out what kind of version is given in a string -
// semver, a revision, or as a fallback, a plain tag
func deduceConstraint(s string) gps.Constraint {
// always semver if we can
c, err := gps.NewSemverConstraint(s)
if err == nil {
return c
}

slen := len(s)
if slen == 40 {
if _, err = hex.DecodeString(s); err == nil {
// Whether or not it's intended to be a SHA1 digest, this is a
// valid byte sequence for that, so go with Revision. This
// covers git and hg
return gps.Revision(s)
}
}
// Next, try for bzr, which has a three-component GUID separated by
// dashes. There should be two, but the email part could contain
// internal dashes
if strings.Count(s, "-") >= 2 {
// Work from the back to avoid potential confusion from the email
i3 := strings.LastIndex(s, "-")
// Skip if - is last char, otherwise this would panic on bounds err
if slen == i3+1 {
return gps.NewVersion(s)
}

i2 := strings.LastIndex(s[:i3], "-")
if _, err = strconv.ParseUint(s[i2+1:i3], 10, 64); err == nil {
// Getting this far means it'd pretty much be nuts if it's not a
// bzr rev, so don't bother parsing the email.
return gps.Revision(s)
}
}

// If not a plain SHA1 or bzr custom GUID, assume a plain version.
// TODO: if there is amgibuity here, then prompt the user?
return gps.NewVersion(s)
}

func checkErrors(m map[string]pkgtree.PackageOrErr) error {
noGoErrors, pkgErrors := 0, 0
for _, poe := range m {
Expand Down
38 changes: 0 additions & 38 deletions cmd/dep/ensure_test.go

This file was deleted.

23 changes: 23 additions & 0 deletions cmd/dep/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

"github.com/golang/dep"
"github.com/golang/dep/internal"
"github.com/golang/dep/internal/importer"
"github.com/pkg/errors"
"github.com/sdboyer/gps"
"github.com/sdboyer/gps/pkgtree"
Expand All @@ -33,6 +34,10 @@ versions available from the upstream source per the following algorithm:
- Default branch(es) (sorted lexicographically)
- Non-semver tags (sorted lexicographically)
If configuration files for other dependency management tools are found, they
are used to pre-populate the manifest and lock. Specify -skip-tools to disable
this behavior.
A Gopkg.toml file will be written with inferred version constraints for all
direct dependencies. Gopkg.lock will be written with precise versions, and
vendor/ will be populated with the precise versions written to Gopkg.lock.
Expand All @@ -46,10 +51,12 @@ func (cmd *initCommand) Hidden() bool { return false }

func (cmd *initCommand) Register(fs *flag.FlagSet) {
fs.BoolVar(&cmd.noExamples, "no-examples", false, "don't include example in Gopkg.toml")
fs.BoolVar(&cmd.skipTools, "skip-tools", false, "skip importing configuration from other dependency manager tools")
}

type initCommand struct {
noExamples bool
skipTools bool
}

func trimPathPrefix(p1, p2 string) string {
Expand Down Expand Up @@ -116,10 +123,26 @@ func (cmd *initCommand) Run(ctx *dep.Ctx, args []string) error {
if err != nil {
return err
}

m := &dep.Manifest{
Dependencies: pd.constraints,
}

if !cmd.skipTools {
ipd, err := importer.Import(root, cpr)
if err != nil {
return errors.Wrap(err, "Error importing dependency management configuration")
}

if ipd != nil {
m.Ignored = ipd.Ignored
for pr, c := range ipd.Dependencies {
internal.Vlogf("Importing dependency on %s: %s", pr, c)
m.Dependencies[pr] = c
}
}
}

// Make an initial lock from what knowledge we've collected about the
// versions on disk
l := &dep.Lock{
Expand Down
20 changes: 20 additions & 0 deletions cmd/dep/testdata/harness_tests/init/glide1/final/Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions cmd/dep/testdata/harness_tests/init/glide1/final/Gopkg.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
ignored = ["github.com/sdboyer/dep-test","github.com/golang/notexist/samples"]

[[dependencies]]
branch = "master"
name = "github.com/golang/lint"

[[dependencies]]
branch = "master"
name = "github.com/sdboyer/deptest"
source = "https://github.com/carolynvs/deptest.git"

[[dependencies]]
name = "github.com/sdboyer/deptestdos"
version = "v2.0.0"
14 changes: 14 additions & 0 deletions cmd/dep/testdata/harness_tests/init/glide1/initial/glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions cmd/dep/testdata/harness_tests/init/glide1/initial/glide.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package: github.com/golang/notexist
homepage: http://example.com
license: MIT
owners:
- name: Sam Boyer
email: sdboyer@example.com
homepage: http://sdboyer.io
ignore:
- github.com/sdboyer/dep-test
excludeDirs:
- samples
import:
- package: github.com/sdboyer/deptest
repo: https://github.com/carolynvs/deptest.git
vcs: git
version: master
- package: github.com/sdboyer/deptestdos
version: v2.0.0
testImport:
- package: github.com/golang/lint
17 changes: 17 additions & 0 deletions cmd/dep/testdata/harness_tests/init/glide1/initial/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// 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/dep-test"
"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
}
13 changes: 13 additions & 0 deletions cmd/dep/testdata/harness_tests/init/glide1/testcase.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"commands": [
["init", "-no-examples"]
],
"gopath-initial": {
"github.com/golang/lint": "cb00e5669539f047b2f4c53a421a01b0c8e172c6",
"github.com/sdboyer/deptest": "3f4c3bea144e112a69bbe5d8d01c1b09a544253f"
},
"vendor-final": [
"github.com/sdboyer/deptest",
"github.com/sdboyer/deptestdos"
]
}
Loading

0 comments on commit 931f258

Please sign in to comment.