1
0
mirror of https://github.com/golang/go synced 2024-11-22 09:54:40 -07:00

cmd/go: add -t flag to 'go get' to download test dependencies

Fixes #5126.

R=golang-dev, dsymonds, bradfitz, r, rsc, rogpeppe
CC=golang-dev
https://golang.org/cl/12566046
This commit is contained in:
Andrew Gerrand 2013-08-14 11:01:17 +10:00
parent 1a09d70e23
commit 5dde7ccecf
2 changed files with 23 additions and 5 deletions

View File

@ -236,7 +236,7 @@ Download and install packages and dependencies
Usage:
go get [-d] [-fix] [-u] [build flags] [packages]
go get [-d] [-fix] [-t] [-u] [build flags] [packages]
Get downloads and installs the packages named by the import paths,
along with their dependencies.
@ -247,6 +247,9 @@ it instructs get not to install the packages.
The -fix flag instructs get to run the fix tool on the downloaded packages
before resolving dependencies or building the code.
The -t flag instructs get to also download the packages required to build
the tests for the specified packages.
The -u flag instructs get to use the network to update the named packages
and their dependencies. By default, get uses the network to check out
missing packages but does not use it to look for updates to existing packages.

View File

@ -18,7 +18,7 @@ import (
)
var cmdGet = &Command{
UsageLine: "get [-d] [-fix] [-u] [build flags] [packages]",
UsageLine: "get [-d] [-fix] [-t] [-u] [build flags] [packages]",
Short: "download and install packages and dependencies",
Long: `
Get downloads and installs the packages named by the import paths,
@ -30,6 +30,9 @@ it instructs get not to install the packages.
The -fix flag instructs get to run the fix tool on the downloaded packages
before resolving dependencies or building the code.
The -t flag instructs get to also download the packages required to build
the tests for the specified packages.
The -u flag instructs get to use the network to update the named packages
and their dependencies. By default, get uses the network to check out
missing packages but does not use it to look for updates to existing packages.
@ -53,6 +56,7 @@ See also: go build, go install, go clean.
}
var getD = cmdGet.Flag.Bool("d", false, "")
var getT = cmdGet.Flag.Bool("t", false, "")
var getU = cmdGet.Flag.Bool("u", false, "")
var getFix = cmdGet.Flag.Bool("fix", false, "")
@ -65,7 +69,7 @@ func runGet(cmd *Command, args []string) {
// Phase 1. Download/update.
var stk importStack
for _, arg := range downloadPaths(args) {
download(arg, &stk)
download(arg, &stk, *getT)
}
exitIfErrors()
@ -137,7 +141,7 @@ var downloadRootCache = map[string]bool{}
// download runs the download half of the get command
// for the package named by the argument.
func download(arg string, stk *importStack) {
func download(arg string, stk *importStack, getTestDeps bool) {
p := loadPackage(arg, stk)
// There's nothing to do if this is a package in the standard library.
@ -216,7 +220,18 @@ func download(arg string, stk *importStack) {
// Process dependencies, now that we know what they are.
for _, dep := range p.deps {
download(dep.ImportPath, stk)
// Don't get test dependencies recursively.
download(dep.ImportPath, stk, false)
}
if getTestDeps {
// Process test dependencies when -t is specified.
// (Don't get test dependencies for test dependencies.)
for _, path := range p.TestImports {
download(path, stk, false)
}
for _, path := range p.XTestImports {
download(path, stk, false)
}
}
}
}