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

Commit

Permalink
Merge branch 'master' of https://github.com/golang/dep into dot_output
Browse files Browse the repository at this point in the history
  • Loading branch information
Rhymond committed Mar 10, 2017
2 parents 3ff1f50 + 70f818a commit 4275dd0
Show file tree
Hide file tree
Showing 91 changed files with 1,386 additions and 612 deletions.
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Dep is an open source project.

It is the work of hundreds of contributors. We appreciate your help!

Keep an eye on the [Roadmap](https://github.com/golang/dep/wiki/Roadmap) for a summary of where the project is, and where we're headed.

## Filing issues

Expand Down
10 changes: 3 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,12 @@ Linux: [![Build Status](https://travis-ci.org/golang/dep.svg?branch=master)](htt

Dep is a prototype dependency management tool. It requires Go 1.7 or newer to compile.

### Dep is NOT an official tool. It is not (yet) blessed by the Go team.

It IS, however, the consensus effort of most of the Go community, and being integrated into the `go` toolchain is the goal.

We're working on a roadmap with more details.
`dep` is NOT an official tool. Yet. Check out the [Roadmap](https://github.com/golang/dep/wiki/Roadmap)!

## Current status

**Pre-alpha**.
Lots of functionality is knowingly missing or broken.
**Alpha**.
Functionality is known to be broken, missing or incomplete. Command and file format changes are still planned.
The repository is open to solicit feedback and contributions from the community.
Please see below for feedback and contribution guidelines.

Expand Down
130 changes: 0 additions & 130 deletions cmd/dep/ensure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,98 +7,9 @@ package main
import (
"testing"

"github.com/golang/dep/test"
"github.com/sdboyer/gps"
)

func TestEnsureOverrides(t *testing.T) {
test.NeedsExternalNetwork(t)
test.NeedsGit(t)

h := test.NewHelper(t)
defer h.Cleanup()

h.TempDir("src")
h.Setenv("GOPATH", h.Path("."))

h.TempCopy("src/thing/thing.go", "ensure/overrides_main.go")
h.Cd(h.Path("src/thing"))

h.Run("init")
h.Run("ensure", "-override", "github.com/carolynvs/go-dep-test@0.1.1")

goldenManifest := "ensure/overrides_manifest.golden.json"
wantManifest := h.GetTestFileString(goldenManifest)
gotManifest := h.ReadManifest()
if gotManifest != wantManifest {
if *test.UpdateGolden {
if err := h.WriteTestFile(goldenManifest, string(gotManifest)); err != nil {
t.Fatal(err)
}
} else {
t.Fatalf("expected %s, got %s", wantManifest, gotManifest)
}
}

goldenLock := "ensure/overrides_lock.golden.json"
wantLock := h.GetTestFileString(goldenLock)
gotLock := h.ReadLock()
if gotLock != wantLock {
if *test.UpdateGolden {
if err := h.WriteTestFile(goldenLock, string(gotLock)); err != nil {
t.Fatal(err)
}
} else {
t.Fatalf("expected %s, got %s", wantLock, gotLock)
}
}
}

func TestEnsureEmptyRepoNoArgs(t *testing.T) {
test.NeedsExternalNetwork(t)
test.NeedsGit(t)

h := test.NewHelper(t)
defer h.Cleanup()

h.TempDir("src")
h.Setenv("GOPATH", h.Path("."))
h.TempCopy("src/thing/thing.go", "ensure/bare_main.go")
h.Cd(h.Path("src/thing"))

h.Run("init")
h.Run("ensure")

// make sure vendor exists
h.MustExist(h.Path("src/thing/vendor/github.com/jimmysmith95/fixed-version"))

goldenManifest := "ensure/bare_manifest.golden.json"
wantManifest := h.GetTestFileString(goldenManifest)
gotManifest := h.ReadManifest()
if gotManifest != wantManifest {
if *test.UpdateGolden {
if err := h.WriteTestFile(goldenManifest, string(gotManifest)); err != nil {
t.Fatal(err)
}
} else {
t.Fatalf("expected %s, got %s", wantManifest, gotManifest)
}
}

goldenLock := "ensure/bare_lock.golden.json"
wantLock := h.GetTestFileString(goldenLock)
gotLock := h.ReadLock()
if gotLock != wantLock {
if *test.UpdateGolden {
if err := h.WriteTestFile(goldenLock, string(gotLock)); err != nil {
t.Fatal(err)
}
} else {
t.Fatalf("expected %s, got %s", wantLock, gotLock)
}
}
}

func TestDeduceConstraint(t *testing.T) {
sv, err := gps.NewSemverConstraint("v1.2.3")
if err != nil {
Expand All @@ -125,44 +36,3 @@ func TestDeduceConstraint(t *testing.T) {
}
}
}

func TestEnsureUpdate(t *testing.T) {
test.NeedsExternalNetwork(t)
test.NeedsGit(t)

h := test.NewHelper(t)
defer h.Cleanup()

// Setup up a test project
h.TempDir("src")
h.Setenv("GOPATH", h.Path("."))
h.TempCopy("src/thing/main.go", "ensure/update_main.go")
origManifest := "ensure/update_manifest.json"
h.TempCopy("src/thing/manifest.json", origManifest)
origLock := "ensure/update_lock.json"
h.TempCopy("src/thing/lock.json", origLock)
h.Cd(h.Path("src/thing"))

h.Run("ensure", "-update", "github.com/carolynvs/go-dep-test")

// Verify that the manifest wasn't modified by -update
wantManifest := h.GetTestFileString(origManifest)
gotManifest := h.ReadManifest()
if gotManifest != wantManifest {
t.Fatalf("The manifest should not be modified during an update. Expected %s, got %s", origManifest, gotManifest)
}

// Verify the lock matches the expected golden file
goldenLock := "ensure/update_lock.golden.json"
wantLock := h.GetTestFileString(goldenLock)
gotLock := h.ReadLock()
if gotLock != wantLock {
if *test.UpdateGolden {
if err := h.WriteTestFile(goldenLock, string(gotLock)); err != nil {
t.Fatal(err)
}
} else {
t.Fatalf("expected %s, got %s", wantLock, gotLock)
}
}
}
131 changes: 62 additions & 69 deletions cmd/dep/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ func isStdLib(path string) bool {
// TODO solve failures can be really creative - we need to be similarly creative
// in handling them and informing the user appropriately
func handleAllTheFailuresOfTheWorld(err error) {
fmt.Printf("solve error: %s", err)
fmt.Printf("solve error: %s\n", err)
}

func writeFile(path string, in json.Marshaler) error {
Expand Down Expand Up @@ -238,8 +238,6 @@ type projectData struct {
}

func getProjectData(ctx *dep.Ctx, pkgT gps.PackageTree, cpr string, sm *gps.SourceMgr) (projectData, error) {
vlogf("Building dependency graph...")

constraints := make(gps.ProjectConstraints)
dependencies := make(map[gps.ProjectRoot][]string)
packages := make(map[string]bool)
Expand All @@ -254,59 +252,48 @@ func getProjectData(ctx *dep.Ctx, pkgT gps.PackageTree, cpr string, sm *gps.Sour
fmt.Fprintf(os.Stderr, "%s %s\n", message, pr)
}

for _, v := range pkgT.Packages {
// TODO: Some errors maybe should not be skipped ;-)
if v.Err != nil {
vlogf("%v", v.Err)
continue
}
vlogf("Package %q, analyzing...", v.P.ImportPath)

for _, ip := range v.P.Imports {
if isStdLib(ip) {
continue
}
if hasImportPathPrefix(ip, cpr) {
// Don't analyze imports from the current project.
continue
}
pr, err := sm.DeduceProjectRoot(ip)
if err != nil {
return projectData{}, errors.Wrap(err, "sm.DeduceProjectRoot") // TODO: Skip and report ?
}
rm, _ := pkgT.ToReachMap(true, true, false, nil)
if len(rm) == 0 {
return projectData{}, nil
}

packages[ip] = true
if _, ok := dependencies[pr]; ok {
if !contains(dependencies[pr], ip) {
dependencies[pr] = append(dependencies[pr], ip)
}
vlogf("Building dependency graph...")
// Exclude stdlib imports from the list returned from Flatten().
const omitStdlib = false
for _, ip := range rm.Flatten(omitStdlib) {
pr, err := sm.DeduceProjectRoot(ip)
if err != nil {
return projectData{}, errors.Wrap(err, "sm.DeduceProjectRoot") // TODO: Skip and report ?
}

continue
}
go syncDep(pr, sm)
packages[ip] = true
if _, has := dependencies[pr]; has {
dependencies[pr] = append(dependencies[pr], ip)
continue
}
go syncDep(pr, sm)

vlogf("Package %q has import %q, analyzing...", v.P.ImportPath, ip)
vlogf("Found import of %q, analyzing...", ip)

dependencies[pr] = []string{ip}
v, err := ctx.VersionInWorkspace(pr)
if err != nil {
notondisk[pr] = true
vlogf("Could not determine version for %q, omitting from generated manifest", pr)
continue
}

ondisk[pr] = v
pp := gps.ProjectProperties{}
switch v.Type() {
case gps.IsBranch, gps.IsVersion, gps.IsRevision:
pp.Constraint = v
case gps.IsSemver:
c, _ := gps.NewSemverConstraint("^" + v.String())
pp.Constraint = c
}
dependencies[pr] = []string{ip}
v, err := ctx.VersionInWorkspace(pr)
if err != nil {
notondisk[pr] = true
vlogf("Could not determine version for %q, omitting from generated manifest", pr)
continue
}

constraints[pr] = pp
ondisk[pr] = v
pp := gps.ProjectProperties{}
switch v.Type() {
case gps.IsBranch, gps.IsVersion, gps.IsRevision:
pp.Constraint = v
case gps.IsSemver:
c, _ := gps.NewSemverConstraint("^" + v.String())
pp.Constraint = c
}

constraints[pr] = pp
}

vlogf("Analyzing transitive imports...")
Expand Down Expand Up @@ -350,13 +337,31 @@ func getProjectData(ctx *dep.Ctx, pkgT gps.PackageTree, cpr string, sm *gps.Sour
// project is not present in the workspace, and so we need to
// solve to deal with this dep.
r := filepath.Join(ctx.GOPATH, "src", string(pr))
_, err := os.Lstat(r)
if os.IsNotExist(err) {
fi, err := os.Stat(r)
if os.IsNotExist(err) || !fi.IsDir() {
colors[pkg] = black
notondisk[pr] = true
return nil
}

// We know the project is on disk; the question is whether we're
// first seeing it here, in the transitive exploration, or if it
// was found in the initial pass on direct imports. We know it's
// the former if there's no entry for it in the ondisk map.
if _, in := ondisk[pr]; !in {
v, err := ctx.VersionInWorkspace(pr)
if err != nil {
// Even if we know it's on disk, errors are still
// possible when trying to deduce version. If we
// encounter such an error, just treat the project as
// not being on disk; the solver will work it out.
colors[pkg] = black
notondisk[pr] = true
return nil
}
ondisk[pr] = v
}

ptree, err = gps.ListPackages(r, string(pr))
if err != nil {
// Any error here other than an a nonexistent dir (which
Expand Down Expand Up @@ -386,28 +391,15 @@ func getProjectData(ctx *dep.Ctx, pkgT gps.PackageTree, cpr string, sm *gps.Sour
return nil
}

if _, ok := dependencies[pr]; ok {
if !contains(dependencies[pr], pkg) {
dependencies[pr] = append(dependencies[pr], pkg)
if deps, has := dependencies[pr]; has {
if !contains(deps, pkg) {
dependencies[pr] = append(deps, pkg)
}
} else {
dependencies[pr] = []string{pkg}
go syncDep(pr, sm)
}

// project must be on disk at this point; question is
// whether we're first seeing it here, in the transitive
// exploration, or if it arose in the direct dep parts
if _, in := ondisk[pr]; !in {
v, err := ctx.VersionInWorkspace(pr)
if err != nil {
colors[pkg] = black
notondisk[pr] = true
return nil
}
ondisk[pr] = v
}

// recurse
for _, rpkg := range reached.External {
if isStdLib(rpkg) {
Expand All @@ -416,13 +408,14 @@ func getProjectData(ctx *dep.Ctx, pkgT gps.PackageTree, cpr string, sm *gps.Sour

err := dft(rpkg)
if err != nil {
// Bubble up any errors we encounter
return err
}
}

colors[pkg] = black
case grey:
return fmt.Errorf("Import cycle detected on %s", pkg)
return errors.Errorf("Import cycle detected on %s", pkg)
}
return nil
}
Expand Down
Loading

0 comments on commit 4275dd0

Please sign in to comment.