Skip to content

Commit

Permalink
Adds -tags support
Browse files Browse the repository at this point in the history
This commit is a patch based on tools#117
that adds support for -tags to godep.

It is REQUIRED in order to save the deps for a different platform on
your dev machine; in our case it is to save off the heroku deps
in addition to our application deps in order to pull in and build the
goose migration tool remotely and have it available on heroku.
  • Loading branch information
Zachery Moneypenny committed Jan 15, 2015
1 parent 0baa7ea commit a496565
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
11 changes: 10 additions & 1 deletion pkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,19 @@ type Package struct {
// Unlike the go tool, an empty argument list is treated as
// an empty list; "." must be given explicitly if desired.
func LoadPackages(name ...string) (a []*Package, err error) {
args := []string{"list", "-e", "-json"}
return runListCommand(args, name...)
}

func LoadPackagesWithTags(tags string, name ...string) (a []*Package, err error) {
args := []string{"list", "-e", "-json", "-tags", tags}
return runListCommand(args, name...)
}

func runListCommand(args []string, name ...string) (a []*Package, err error) {
if len(name) == 0 {
return nil, nil
}
args := []string{"list", "-e", "-json"}
cmd := exec.Command("go", append(args, name...)...)
r, err := cmd.StdoutPipe()
if err != nil {
Expand Down
14 changes: 12 additions & 2 deletions save.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
)

var cmdSave = &Command{
Usage: "save [-r] [packages]",
Usage: "save [-r] [-tags=\"\"] [packages]",
Short: "list and copy dependencies into Godeps",
Long: `
Save writes a list of the dependencies of the named packages along
Expand Down Expand Up @@ -46,6 +46,9 @@ 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.
if -tags="<BUILD TAGS>" is given, the dependencies will be generated
with the specified build tags.
For more about specifying packages, see 'go help packages'.
`,
Run: runSave,
Expand All @@ -54,11 +57,13 @@ For more about specifying packages, see 'go help packages'.
var (
saveCopy = true
saveR = false
tags = ""
)

func init() {
cmdSave.Flag.BoolVar(&saveCopy, "copy", true, "copy source code")
cmdSave.Flag.BoolVar(&saveR, "r", false, "rewrite import paths")
cmdSave.Flag.StringVar(&tags, "tags", "", "build tags")
}

func runSave(cmd *Command, args []string) {
Expand Down Expand Up @@ -96,7 +101,12 @@ func save(pkgs []string) error {
} else {
pkgs = []string{"."}
}
a, err := LoadPackages(pkgs...)
var a []*Package
if len(tags) > 0 {
a, err = LoadPackagesWithTags(tags, pkgs...)
} else {
a, err = LoadPackages(pkgs...)
}
if err != nil {
return err
}
Expand Down

0 comments on commit a496565

Please sign in to comment.