Skip to content

Commit

Permalink
Merge meta-PR to stabilize Gopkg metadata files
Browse files Browse the repository at this point in the history
  • Loading branch information
sdboyer committed May 27, 2017
2 parents 3e187c9 + ec6c4e8 commit 05c40eb
Show file tree
Hide file tree
Showing 86 changed files with 571 additions and 366 deletions.
8 changes: 4 additions & 4 deletions FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Please contribute to the FAQ! Found an explanation in an issue or pull request h
Summarize the question and quote the reply, linking back to the original comment.

* [What is the difference between Gopkg.toml (the "manifest") and Gopkg.lock (the "lock")?](#what-is-the-difference-between-gopkgtoml-the-manifest-and-gopkglock-the-lock)
* [When should I use dependencies, overrides or required in the manifest?](#when-should-i-use-dependencies-overrides-required-or-ignored-in-the-manifest)
* [When should I use `constraint`, `override` `required`, or `ignored` in the Gopkg.toml?](#when-should-i-use-constraint-override-required-or-ignored-in-gopkgtoml)
* [What is a direct or transitive dependency?](#what-is-a-direct-or-transitive-dependency)
* [Should I commit my vendor directory?](#should-i-commit-my-vendor-directory)
* [Why is it `dep ensure` instead of `dep install`?](#why-is-it-dep-ensure-instead-of-dep-install)
Expand All @@ -32,10 +32,10 @@ Summarize the question and quote the reply, linking back to the original comment
> This flexibility is important because it allows us to provide easy commands (e.g. `dep ensure -update`) that can manage an update process for you, within the constraints you specify, AND because it allows your project, when imported by someone else, to collaboratively specify the constraints for your own dependencies.
-[@sdboyer in #281](https://github.com/golang/dep/issues/281#issuecomment-284118314)

## When should I use dependencies, overrides, required, or ignored in the manifest?
## When should I use `constraint`, `override`, `required`, or `ignored` in `Gopkg.toml`?

* Use `dependencies` to constrain a [direct dependency](#what-is-a-direct-or-transitive-dependency) to a specific branch, version range, revision, or specify an alternate source such as a fork.
* Use `overrides` to constrain a [transitive dependency](#what-is-a-direct-or-transitive-dependency). See [How do I constrain a transitive dependency's version?](#how-do-i-constrain-a-transitive-dependencys-version) for more details on how overrides differ from dependencies. Overrides should be used cautiously, sparingly, and temporarily.
* Use `constraint` to constrain a [direct dependency](#what-is-a-direct-or-transitive-dependency) to a specific branch, version range, revision, or specify an alternate source such as a fork.
* Use `override` to constrain a [transitive dependency](#what-is-a-direct-or-transitive-dependency). See [How do I constrain a transitive dependency's version?](#how-do-i-constrain-a-transitive-dependencys-version) for more details on how overrides differ from dependencies. Overrides should be used cautiously, sparingly, and temporarily.
* Use `required` to explicitly add a dependency that is not imported directly or transitively, for example a development package used for code generation.
* Use `ignored` to ignore a package and any of that package's unique dependencies.

Expand Down
9 changes: 7 additions & 2 deletions Gopkg.lock

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

14 changes: 6 additions & 8 deletions Gopkg.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
required = ["github.com/Masterminds/semver"]

[[dependencies]]
[[constraint]]
branch = "2.x"
name = "github.com/Masterminds/semver"

[[dependencies]]
[[constraint]]
name = "github.com/Masterminds/vcs"
version = "^1.11.0"
version = "1.11.0"

[[dependencies]]
[[constraint]]
branch = "master"
name = "github.com/pelletier/go-toml"

[[dependencies]]
[[constraint]]
name = "github.com/pkg/errors"
version = ">=0.8.0, <1.0.0"
version = "0.8.0"
8 changes: 4 additions & 4 deletions cmd/dep/ensure.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func (cmd *ensureCommand) Run(ctx *dep.Ctx, args []string) error {
writeV = dep.VendorAlways
}

newLock := dep.LockFromInterface(solution)
newLock := dep.LockFromSolution(solution)
sw, err := dep.NewSafeWriter(nil, p.Lock, newLock, writeV)
if err != nil {
return err
Expand Down Expand Up @@ -205,14 +205,14 @@ func applyEnsureArgs(logger *log.Logger, args []string, overrides stringSlice, p
//
// TODO(sdboyer): for this case - or just in general - do we want to
// add project args to the requires list temporarily for this run?
if _, has := p.Manifest.Dependencies[pc.Ident.ProjectRoot]; !has {
if _, has := p.Manifest.Constraints[pc.Ident.ProjectRoot]; !has {
logger.Printf("dep: No constraint or alternate source specified for %q, omitting from manifest\n", pc.Ident.ProjectRoot)
}
// If it's already in the manifest, no need to log
continue
}

p.Manifest.Dependencies[pc.Ident.ProjectRoot] = gps.ProjectProperties{
p.Manifest.Constraints[pc.Ident.ProjectRoot] = gps.ProjectProperties{
Source: pc.Ident.Source,
Constraint: pc.Constraint,
}
Expand Down Expand Up @@ -329,7 +329,7 @@ func getProjectConstraint(arg string, sm gps.SourceManager) (gps.ProjectConstrai
// 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)
c, err := gps.NewSemverConstraintIC(s)
if err == nil {
return c
}
Expand Down
17 changes: 12 additions & 5 deletions cmd/dep/ensure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package main

import (
"reflect"
"testing"

"github.com/golang/dep/internal/gps"
Expand All @@ -13,7 +14,7 @@ import (
func TestDeduceConstraint(t *testing.T) {
t.Parallel()

sv, err := gps.NewSemverConstraint("v1.2.3")
sv, err := gps.NewSemverConstraintIC("v1.2.3")
if err != nil {
t.Fatal(err)
}
Expand All @@ -31,10 +32,16 @@ func TestDeduceConstraint(t *testing.T) {
"20120425195858-psty8c35ve2oej8t": gps.NewVersion("20120425195858-psty8c35ve2oej8t"),
}

for str, expected := range constraints {
c := deduceConstraint(str)
if c != expected {
t.Fatalf("expected: %#v, got %#v for %s", expected, c, str)
for str, want := range constraints {
got := deduceConstraint(str)

wantT := reflect.TypeOf(want)
gotT := reflect.TypeOf(got)
if wantT != gotT {
t.Errorf("expected type: %s, got %s, for input %s", wantT, gotT, str)
}
if got.String() != want.String() {
t.Errorf("expected value: %s, got %s for input %s", want, got, str)
}
}
}
11 changes: 5 additions & 6 deletions cmd/dep/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func (cmd *initCommand) Run(ctx *dep.Ctx, args []string) error {
return err
}
m := &dep.Manifest{
Dependencies: pd.constraints,
Constraints: pd.constraints,
}

// Make an initial lock from what knowledge we've collected about the
Expand Down Expand Up @@ -185,7 +185,7 @@ func (cmd *initCommand) Run(ctx *dep.Ctx, args []string) error {
handleAllTheFailuresOfTheWorld(err)
return err
}
l = dep.LockFromInterface(soln)
l = dep.LockFromSolution(soln)

// Iterate through the new projects in solved lock and add them to manifest
// if direct deps
Expand All @@ -201,7 +201,7 @@ func (cmd *initCommand) Run(ctx *dep.Ctx, args []string) error {
if newProject {
// If it's in notondisk, add to manifest, these are direct dependencies.
if _, ok := pd.notondisk[pr]; ok {
m.Dependencies[pr] = getProjectPropertiesFromVersion(x.Version())
m.Constraints[pr] = getProjectPropertiesFromVersion(x.Version())
}
}
}
Expand All @@ -213,7 +213,7 @@ func (cmd *initCommand) Run(ctx *dep.Ctx, args []string) error {
return errors.Wrap(err, "prepare solver")
}

l.Memo = s.HashInputs()
l.SolveMeta.InputsDigest = s.HashInputs()

// Pass timestamp (yyyyMMddHHmmss format) as suffix to backup name.
vendorbak, err := dep.BackupVendor(vpath, time.Now().Format("20060102150405"))
Expand Down Expand Up @@ -319,8 +319,7 @@ func getProjectPropertiesFromVersion(v gps.Version) gps.ProjectProperties {
case gps.IsBranch, gps.IsVersion:
pp.Constraint = v
case gps.IsSemver:
// TODO: remove "^" when https://github.com/golang/dep/issues/225 is ready.
c, err := gps.NewSemverConstraint("^" + v.String())
c, err := gps.NewSemverConstraintIC(v.String())
if err != nil {
panic(err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/dep/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestContains(t *testing.T) {
func TestGetProjectPropertiesFromVersion(t *testing.T) {
t.Parallel()

wantSemver, _ := gps.NewSemverConstraint("^v1.0.0")
wantSemver, _ := gps.NewSemverConstraintIC("v1.0.0")
cases := []struct {
version, want gps.Constraint
}{
Expand Down
4 changes: 2 additions & 2 deletions cmd/dep/prune.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ func (cmd *pruneCommand) Run(ctx *dep.Ctx, args []string) error {
return errors.Errorf("Gopkg.lock must exist for prune to know what files are safe to remove.")
}

if !bytes.Equal(s.HashInputs(), p.Lock.Memo) {
return errors.Errorf("lock hash doesn't match")
if !bytes.Equal(s.HashInputs(), p.Lock.SolveMeta.InputsDigest) {
return errors.Errorf("Gopkg.lock is out of sync the project; run dep ensure before pruning.")
}

var pruneLogger *log.Logger
Expand Down
10 changes: 5 additions & 5 deletions cmd/dep/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ func (cmd *removeCommand) Run(ctx *dep.Ctx, args []string) error {
}

var rm []gps.ProjectRoot
for pr := range p.Manifest.Dependencies {
for pr := range p.Manifest.Constraints {
if _, has := otherroots[pr]; !has {
delete(p.Manifest.Dependencies, pr)
delete(p.Manifest.Constraints, pr)
rm = append(rm, pr)
}
}
Expand Down Expand Up @@ -145,7 +145,7 @@ func (cmd *removeCommand) Run(ctx *dep.Ctx, args []string) error {
}
}

if _, indeps := p.Manifest.Dependencies[gps.ProjectRoot(arg)]; !indeps {
if _, indeps := p.Manifest.Constraints[gps.ProjectRoot(arg)]; !indeps {
return errors.Errorf("%q is not present in the manifest, cannot remove it", arg)
}

Expand All @@ -156,7 +156,7 @@ func (cmd *removeCommand) Run(ctx *dep.Ctx, args []string) error {
return errors.Errorf("not removing %q because it is imported by:\n\t%s (pass -force to override)", arg, strings.Join(pkgimport, "\n\t"))
}

delete(p.Manifest.Dependencies, gps.ProjectRoot(arg))
delete(p.Manifest.Constraints, gps.ProjectRoot(arg))
}
}

Expand All @@ -177,7 +177,7 @@ func (cmd *removeCommand) Run(ctx *dep.Ctx, args []string) error {
return err
}

newLock := dep.LockFromInterface(soln)
newLock := dep.LockFromSolution(soln)

sw, err := dep.NewSafeWriter(nil, p.Lock, newLock, dep.VendorOnChanged)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions cmd/dep/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ func runStatusAll(loggers *dep.Loggers, out outputter, p *dep.Project, sm gps.So
slp := p.Lock.Projects()
sort.Sort(dep.SortedLockedProjects(slp))

if bytes.Equal(s.HashInputs(), p.Lock.Memo) {
if bytes.Equal(s.HashInputs(), p.Lock.SolveMeta.InputsDigest) {
// If these are equal, we're guaranteed that the lock is a transitively
// complete picture of all deps. That eliminates the need for at least
// some checks.
Expand Down Expand Up @@ -331,7 +331,7 @@ func runStatusAll(loggers *dep.Loggers, out outputter, p *dep.Project, sm gps.So
// Only if we have a non-rev and non-plain version do/can we display
// anything wrt the version's updateability.
if bs.Version != nil && bs.Version.Type() != gps.IsVersion {
c, has := p.Manifest.Dependencies[proj.Ident().ProjectRoot]
c, has := p.Manifest.Constraints[proj.Ident().ProjectRoot]
if !has {
c.Constraint = gps.Any()
}
Expand Down

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

70 changes: 2 additions & 68 deletions cmd/dep/testdata/harness_tests/ensure/empty/case1/final/Gopkg.toml
Original file line number Diff line number Diff line change
@@ -1,70 +1,4 @@

## Gopkg.toml example (these lines may be deleted)

## "metadata" defines metadata about the project that could be used by other independent
## systems. The metadata defined here will be ignored by dep.
# [metadata]
# key1 = "value that convey data to other systems"
# system1-data = "value that is used by a system"
# system2-data = "value that is used by another system"

## "required" lists a set of packages (not projects) that must be included in
## Gopkg.lock. This list is merged with the set of packages imported by the current
## project. Use it when your project needs a package it doesn't explicitly import -
## including "main" packages.
# required = ["github.com/user/thing/cmd/thing"]

## "ignored" lists a set of packages (not projects) that are ignored when
## dep statically analyzes source code. Ignored packages can be in this project,
## or in a dependency.
# ignored = ["github.com/user/project/badpkg"]

## Dependencies define constraints on dependent projects. They are respected by
## dep whether coming from the Gopkg.toml of the current project or a dependency.
# [[dependencies]]
## Required: the root import path of the project being constrained.
# name = "github.com/user/project"
#
## Recommended: the version constraint to enforce for the project.
## Only one of "branch", "version" or "revision" can be specified.
# version = "1.0.0"
# branch = "master"
# revision = "abc123"
#
## Optional: an alternate location (URL or import path) for the project's source.
# source = "https://github.com/myfork/package.git"
#
## "metadata" defines metadata about the dependency or override that could be used
## by other independent systems. The metadata defined here will be ignored by dep.
# [metadata]
# key1 = "value that convey data to other systems"
# system1-data = "value that is used by a system"
# system2-data = "value that is used by another system"

## Overrides have the same structure as [[dependencies]], but supersede all
## [[dependencies]] declarations from all projects. Only the current project's
## [[overrides]] are applied.
##
## Overrides are a sledgehammer. Use them only as a last resort.
# [[overrides]]
## Required: the root import path of the project being constrained.
# name = "github.com/user/project"
#
## Optional: specifying a version constraint override will cause all other
## constraints on this project to be ignored; only the overridden constraint
## need be satisfied.
## Again, only one of "branch", "version" or "revision" can be specified.
# version = "1.0.0"
# branch = "master"
# revision = "abc123"
#
## Optional: specifying an alternate source location as an override will
## enforce that the alternate location is used for that project, regardless of
## what source location any dependent projects specify.
# source = "https://github.com/myfork/package.git"



[[dependencies]]
[[constraint]]
name = "github.com/sdboyer/deptest"
version = "^1.0.0"
version = "1.0.0"

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
@@ -1,3 +1,3 @@
[[dependencies]]
[[constraint]]
name = "github.com/sdboyer/deptest"
version = "~0.8.0"
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[[dependencies]]
[[constraint]]
name = "github.com/sdboyer/deptest"
version = "~0.8.0"

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

Loading

0 comments on commit 05c40eb

Please sign in to comment.