]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: add -t flag to 'go get' to download test dependencies
authorAndrew Gerrand <adg@golang.org>
Wed, 14 Aug 2013 01:01:17 +0000 (11:01 +1000)
committerAndrew Gerrand <adg@golang.org>
Wed, 14 Aug 2013 01:01:17 +0000 (11:01 +1000)
Fixes #5126.

R=golang-dev, dsymonds, bradfitz, r, rsc, rogpeppe
CC=golang-dev
https://golang.org/cl/12566046

src/cmd/go/doc.go
src/cmd/go/get.go

index 85aebe24e965e66bd7fe95a6f04c4cf9b8b50680..bb885701801a03920c10409f9752f47d90530637 100644 (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.
index f9a1cfce463dbe543d8192ddaea157e126f2e476..83244b2531d1f177587311f28d84ba29a9031511 100644 (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)
+                       }
                }
        }
 }