]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.cc] cmd/go: fix expansion of 'std', add 'cmd'
authorRuss Cox <rsc@golang.org>
Sun, 22 Feb 2015 17:41:32 +0000 (12:41 -0500)
committerRuss Cox <rsc@golang.org>
Mon, 23 Feb 2015 15:13:17 +0000 (15:13 +0000)
The wildcard 'std' is defined in documentation to be all the packages
in the Go standard library. It has also historically matched commands
in the main repo, but as we implement core commands in Go, that
becomes problematic. We need a wildcard that means just the library,
and since 'std' is already documented to have that definition, make it so.

Add a new wildcard 'cmd' for the commands in the main repo ($GOROOT).
Commands that want both can say 'std cmd' (or 'cmd std') to get the
effect of the old 'std'.

Update make.bash etc to say both std and cmd most of the time.

Exception: in race.bash, do not install race-enabled versions of
the actual commands. This avoids trying to write binaries while
using them, but more importantly it avoids enabling the race
detector and its associated memory overhead for the already
memory-hungry compilers.

Change-Id: I26bb06cb13b636dfbe71a015ee0babeb270a0275
Reviewed-on: https://go-review.googlesource.com/5550
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
src/cmd/go/help.go
src/cmd/go/main.go
src/cmd/go/test.bash
src/make.bash
src/make.bat
src/make.rc
src/race.bash
src/race.bat
src/run.bash
src/run.bat
src/run.rc

index c590fdb37fe80665050428af053040b8fd56a62c..2ab0353589c581b123f5747ad421a88e7051100d 100644 (file)
@@ -59,6 +59,9 @@ system.
 - "std" is like all but expands to just the packages in the standard
 Go library.
 
+- "cmd" expands to the Go repository's commands and their
+internal libraries.
+
 An import path is a pattern if it includes one or more "..." wildcards,
 each of which can match any string, including the empty string and
 strings containing slashes.  Such a pattern expands to all package
index d5e86395a2cfdc6cb7b369f0cd3e441b3d0382e2..d7e522bd5a7cffb263d3beae49d0321e2d9cfdb8 100644 (file)
@@ -311,7 +311,7 @@ func importPathsNoDotExpansion(args []string) []string {
                } else {
                        a = path.Clean(a)
                }
-               if a == "all" || a == "std" {
+               if a == "all" || a == "std" || a == "cmd" {
                        out = append(out, allPackages(a)...)
                        continue
                }
@@ -478,8 +478,8 @@ func treeCanMatchPattern(pattern string) func(name string) bool {
 
 // allPackages returns all the packages that can be found
 // under the $GOPATH directories and $GOROOT matching pattern.
-// The pattern is either "all" (all packages), "std" (standard packages)
-// or a path including "...".
+// The pattern is either "all" (all packages), "std" (standard packages),
+// "cmd" (standard commands), or a path including "...".
 func allPackages(pattern string) []string {
        pkgs := matchPackages(pattern)
        if len(pkgs) == 0 {
@@ -491,7 +491,7 @@ func allPackages(pattern string) []string {
 func matchPackages(pattern string) []string {
        match := func(string) bool { return true }
        treeCanMatch := func(string) bool { return true }
-       if pattern != "all" && pattern != "std" {
+       if pattern != "all" && pattern != "std" && pattern != "cmd" {
                match = matchPattern(pattern)
                treeCanMatch = treeCanMatchPattern(pattern)
        }
@@ -504,47 +504,16 @@ func matchPackages(pattern string) []string {
        }
        var pkgs []string
 
-       // Commands
-       cmd := filepath.Join(goroot, "src/cmd") + string(filepath.Separator)
-       filepath.Walk(cmd, func(path string, fi os.FileInfo, err error) error {
-               if err != nil || !fi.IsDir() || path == cmd {
-                       return nil
-               }
-               name := path[len(cmd):]
-               if !treeCanMatch(name) {
-                       return filepath.SkipDir
-               }
-               // Commands are all in cmd/, not in subdirectories.
-               if strings.Contains(name, string(filepath.Separator)) {
-                       return filepath.SkipDir
-               }
-
-               // We use, e.g., cmd/gofmt as the pseudo import path for gofmt.
-               name = "cmd/" + name
-               if have[name] {
-                       return nil
-               }
-               have[name] = true
-               if !match(name) {
-                       return nil
-               }
-               _, err = buildContext.ImportDir(path, 0)
-               if err != nil {
-                       if _, noGo := err.(*build.NoGoError); !noGo {
-                               log.Print(err)
-                       }
-                       return nil
-               }
-               pkgs = append(pkgs, name)
-               return nil
-       })
-
        for _, src := range buildContext.SrcDirs() {
                if pattern == "std" && src != gorootSrc {
                        continue
                }
                src = filepath.Clean(src) + string(filepath.Separator)
-               filepath.Walk(src, func(path string, fi os.FileInfo, err error) error {
+               root := src
+               if pattern == "cmd" {
+                       root += "cmd" + string(filepath.Separator)
+               }
+               filepath.Walk(root, func(path string, fi os.FileInfo, err error) error {
                        if err != nil || !fi.IsDir() || path == src {
                                return nil
                        }
@@ -556,7 +525,10 @@ func matchPackages(pattern string) []string {
                        }
 
                        name := filepath.ToSlash(path[len(src):])
-                       if pattern == "std" && strings.Contains(name, ".") {
+                       if pattern == "std" && (strings.Contains(name, ".") || name == "cmd") {
+                               // The name "std" is only the standard library.
+                               // If the name has a dot, assume it's a domain name for go get,
+                               // and if the name is cmd, it's the root of the command tree.
                                return filepath.SkipDir
                        }
                        if !treeCanMatch(name) {
index e0f066f186dbd0db07e86edc519df446bfd74014..25d3c66665f3e36ce162cebc9465f4a1d2870688 100755 (executable)
@@ -510,8 +510,7 @@ if [ $(./testgo test fmt fmt fmt fmt fmt | wc -l) -ne 1 ] ; then
     ok=false
 fi
 
-# ensure that output of 'go list' is consistent between runs
-TEST go list is consistent
+TEST go list has a consistent order
 ./testgo list std > test_std.list || ok=false
 if ! ./testgo list std | cmp -s test_std.list - ; then
        echo "go list std ordering is inconsistent"
@@ -519,6 +518,18 @@ if ! ./testgo list std | cmp -s test_std.list - ; then
 fi
 rm -f test_std.list
 
+TEST go list std does not include commands
+if ./testgo list std | grep cmd/; then
+       echo "go list std shows commands"
+       ok=false
+fi
+
+TEST go list cmd only shows commands
+if ./testgo list cmd | grep -v 'cmd/'; then
+       echo "go list cmd shows non-commands"
+       ok=false
+fi
+
 # issue 4096. Validate the output of unsuccessful go install foo/quxx 
 TEST unsuccessful go install should mention missing package
 if [ $(./testgo install 'foo/quxx' 2>&1 | grep -c 'cannot find package "foo/quxx" in any of') -ne 1 ] ; then
index 215fedd6eefaf45a5512f29830d2373eda89e924..365664303e1eaa0fee26a179d1b552d027d0dbe5 100755 (executable)
@@ -153,12 +153,12 @@ if [ "$GOHOSTARCH" != "$GOARCH" -o "$GOHOSTOS" != "$GOOS" ]; then
        # CC_FOR_TARGET is recorded as the default compiler for the go tool. When building for the host, however,
        # use the host compiler, CC, from `cmd/dist/dist env` instead.
        CC=$CC GOOS=$GOHOSTOS GOARCH=$GOHOSTARCH \
-               "$GOTOOLDIR"/go_bootstrap install -gcflags "$GO_GCFLAGS" -ldflags "$GO_LDFLAGS" -v std
+               "$GOTOOLDIR"/go_bootstrap install -gcflags "$GO_GCFLAGS" -ldflags "$GO_LDFLAGS" -v std cmd
        echo
 fi
 
 echo "##### Building packages and commands for $GOOS/$GOARCH."
-CC=$CC_FOR_TARGET "$GOTOOLDIR"/go_bootstrap install $GO_FLAGS -gcflags "$GO_GCFLAGS" -ldflags "$GO_LDFLAGS" -v std
+CC=$CC_FOR_TARGET "$GOTOOLDIR"/go_bootstrap install $GO_FLAGS -gcflags "$GO_GCFLAGS" -ldflags "$GO_LDFLAGS" -v std cmd
 echo
 
 rm -f "$GOTOOLDIR"/go_bootstrap
index ba3469e69e08832134a2f97160bbf8d870276b81..70569551e5828d83aefa25371dc929c56dbe0741 100644 (file)
@@ -88,14 +88,14 @@ echo ##### Building tools for local system. %GOHOSTOS%/%GOHOSTARCH%
 setlocal
 set GOOS=%GOHOSTOS%
 set GOARCH=%GOHOSTARCH%
-"%GOTOOLDIR%\go_bootstrap" install -gcflags "%GO_GCFLAGS%" -ldflags "%GO_LDFLAGS%" -v std
+"%GOTOOLDIR%\go_bootstrap" install -gcflags "%GO_GCFLAGS%" -ldflags "%GO_LDFLAGS%" -v std cmd
 endlocal
 if errorlevel 1 goto fail
 echo.
 
 :mainbuild
 echo ##### Building packages and commands.
-"%GOTOOLDIR%\go_bootstrap" install -gcflags "%GO_GCFLAGS%" -ldflags "%GO_LDFLAGS%" -a -v std
+"%GOTOOLDIR%\go_bootstrap" install -gcflags "%GO_GCFLAGS%" -ldflags "%GO_LDFLAGS%" -a -v std cmd
 if errorlevel 1 goto fail
 del "%GOTOOLDIR%\go_bootstrap.exe"
 echo.
index f4302739f7e5ae14d8ac0d7d482ac6cc52dd8670..46ab35bcbc2db7a2033dc3fcbdb0e0889f8b700f 100755 (executable)
@@ -84,12 +84,12 @@ if(~ $sysname vx32)
 if(! ~ $GOHOSTARCH $GOARCH || ! ~ $GOHOSTOS $GOOS){
        echo '# Building packages and commands for host,' $GOHOSTOS/$GOHOSTARCH^.
        GOOS=$GOHOSTOS GOARCH=$GOHOSTARCH \
-               $GOTOOLDIR/go_bootstrap install -gcflags $"GO_GCFLAGS -ldflags $"GO_LDFLAGS -v $pflag std
+               $GOTOOLDIR/go_bootstrap install -gcflags $"GO_GCFLAGS -ldflags $"GO_LDFLAGS -v $pflag std cmd
        echo
 }
 
 echo '# Building packages and commands for' $GOOS/$GOARCH^.
-$GOTOOLDIR/go_bootstrap install -gcflags $"GO_GCFLAGS -ldflags $"GO_LDFLAGS -v $pflag std
+$GOTOOLDIR/go_bootstrap install -gcflags $"GO_GCFLAGS -ldflags $"GO_LDFLAGS -v $pflag std cmd
 echo
 
 rm -f $GOTOOLDIR/go_bootstrap
index 6225840168834d2fa16c56841f5c1c2d20e00f86..b305c8f970ebd4cf577b71070ff60277ffd68b46 100755 (executable)
@@ -40,8 +40,6 @@ if [ ! -f make.bash ]; then
        exit 1
 fi
 . ./make.bash --no-banner
-# golang.org/issue/5537 - we must build a race enabled cmd/cgo before trying to use it.
-go install -race cmd/cgo
 go install -race std
 
 # we must unset GOROOT_FINAL before tests, because runtime/debug requires
index 027c475640193db104e94fbaaba33b3552a3e569..1ab019c25a575385516b81553d5349ccdb1453c6 100644 (file)
@@ -30,9 +30,6 @@ goto fail
 :continue
 call make.bat --no-banner --no-local
 if %GOBUILDFAIL%==1 goto end
-:: golang.org/issue/5537 - we must build a race enabled cmd/cgo before trying to use it.
-echo # go install -race cmd/cgo
-go install -race cmd/cgo
 echo # go install -race std
 go install -race std
 if errorlevel 1 goto fail
index bb1424c50443690d1b66ab4f7e14f3a07f7723ff..4177124e1bcdd33176df40277039a378ca08a558 100755 (executable)
@@ -38,7 +38,7 @@ if [ "$1" == "--no-rebuild" ]; then
        shift
 else
        echo '##### Building packages and commands.'
-       time go install -a -v std
+       time go install -a -v std cmd
        echo
 fi
 
@@ -56,7 +56,7 @@ timeout_scale=1
 [ "$GOARCH" == "arm" ] && timeout_scale=3
 
 echo '##### Testing packages.'
-time go test std -short -timeout=$(expr 120 \* $timeout_scale)s -gcflags "$GO_GCFLAGS"
+time go test std cmd -short -timeout=$(expr 120 \* $timeout_scale)s -gcflags "$GO_GCFLAGS"
 echo
 
 # We set GOMAXPROCS=2 in addition to -cpu=1,2,4 in order to test runtime bootstrap code,
index 7586ab5f18c4acd9e27ec851024b9c37374bd0b1..4b7637563badda45b0f2f625dba1d185856cb75e 100644 (file)
@@ -20,7 +20,7 @@ rem TODO avoid rebuild if possible
 
 if x%1==x--no-rebuild goto norebuild
 echo ##### Building packages and commands.
-go install -a -v std
+go install -a -v std cmd
 if errorlevel 1 goto fail
 echo.
 :norebuild
@@ -38,7 +38,7 @@ del env.bat
 echo.
 
 echo ##### Testing packages.
-go test std -short -timeout=120s
+go test std cmd -short -timeout=120s
 if errorlevel 1 goto fail
 echo.
 
index 8d2ce38a0e790fc38cca6e358d4b5278440c571c..1c92f0389c24ed7e3ee9b1dcecf5db53608f707b 100755 (executable)
@@ -19,7 +19,7 @@ if not {
        if(~ $sysname vx32)
                pflag = (-p 1)
        echo '# Building packages and commands.'
-       time go install -a -v $pflag std
+       time go install -a -v $pflag std cmd
        echo
 }
 
@@ -29,7 +29,7 @@ if not {
 GOROOT_FINAL = ()
 
 echo '# Testing packages.'
-time go test std -short -timeout 240s
+time go test std cmd -short -timeout 240s
 echo
 
 # Temporary GCE builder hack until Plan 9 on GCE is fast enough.