Skip to content
This repository was archived by the owner on Feb 26, 2019. It is now read-only.

Respect the GO15VENDOREXPERIMENT env variable #244

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 8 additions & 1 deletion rewrite.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,14 @@ func rewriteGoFile(name, qual string, paths []string) error {
// sep is the signature set of path elements that
// precede the original path of an imported package
// in a rewritten import path.
const sep = "/Godeps/_workspace/src/"
var sep = "/Godeps/_workspace/src/"
var VendorExperiment = os.Getenv("GO15VENDOREXPERIMENT") == "1"

func init() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest the signature defaultSep(experiment bool) string for this.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. I likened it to flag handling, which is done elsewhere in init functions.

Are you suggesting that init should call defaultSep(VendorExperiment) to set sep or that everywhere sep is currently used it should be replaced with defaultSep(VendorExperiment) ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm suggesting the first, e.g. var sep = defaultSep(VendorExperiment).

Flags are defined in init functions only because they have to to avoid a cycle. (Try changing it to var saveR = cmdSave.Flag.Bool(...) to see what happens.)

if VendorExperiment {
sep = "/vendor/"
}
}

// unqualify returns the part of importPath after the last
// occurrence of the signature path elements
Expand Down
18 changes: 13 additions & 5 deletions save.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ with the exact source control revision of each dependency, and copies
their source code into a subdirectory.

The list is written to Godeps/Godeps.json, and source code for all
dependencies is copied into Godeps/_workspace.
dependencies is copied into either Godeps/_workspace or, if the vendor
experiment it turned on, vendor.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/it/is/


The dependency list is a JSON document with the following structure:

Expand All @@ -44,7 +45,8 @@ Any dependencies already present in the list will be left unchanged.
To update a dependency to a newer revision, use 'godep update'.

If -r is given, import statements will be rewritten to refer
directly to the copied source code.
directly to the copied source code. This is not compatible with the
vendor experiment.

For more about specifying packages, see 'go help packages'.
`,
Expand All @@ -62,6 +64,10 @@ func init() {
}

func runSave(cmd *Command, args []string) {
if VendorExperiment && saveR {
log.Println("flag -r is incompatible with the vendoring experiment")
cmd.UsageExit()
}
if !saveCopy {
log.Println("flag unsupported: -copy=false")
cmd.UsageExit()
Expand Down Expand Up @@ -145,8 +151,7 @@ func save(pkgs []string) error {
// ignores this directory when traversing packages
// starting at the project's root. For example,
// godep go list ./...
workspace := filepath.Join("Godeps", "_workspace")
srcdir := filepath.Join(workspace, "src")
srcdir := filepath.FromSlash(strings.Trim(sep, "/"))
rem := subDeps(gold.Deps, gnew.Deps)
add := subDeps(gnew.Deps, gold.Deps)
err = removeSrc(srcdir, rem)
Expand All @@ -157,7 +162,10 @@ func save(pkgs []string) error {
if err != nil {
return err
}
writeVCSIgnore(workspace)
if !VendorExperiment {
f, _ := filepath.Split(srcdir)
writeVCSIgnore(f)
}
var rewritePaths []string
if saveR {
for _, dep := range gnew.Deps {
Expand Down