]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: first piece of tool rearrangement
authorRob Pike <r@golang.org>
Sun, 29 Jan 2012 17:19:05 +0000 (09:19 -0800)
committerRob Pike <r@golang.org>
Sun, 29 Jan 2012 17:19:05 +0000 (09:19 -0800)
1) create go-tool dir in make.bash
2) clean up stale binaries in make.bash
3) add 'tool' command to go
4) convert goyacc->yacc as a first test tool
Since goyacc stands alone, it's a safe trial.

R=rsc
CC=golang-dev
https://golang.org/cl/5576061

26 files changed:
src/Make.tool [new file with mode: 0644]
src/buildscript/darwin_386.sh
src/buildscript/darwin_amd64.sh
src/buildscript/freebsd_386.sh
src/buildscript/freebsd_amd64.sh
src/buildscript/linux_386.sh
src/buildscript/linux_amd64.sh
src/buildscript/linux_arm.sh
src/buildscript/netbsd_386.sh
src/buildscript/netbsd_amd64.sh
src/buildscript/openbsd_386.sh
src/buildscript/openbsd_amd64.sh
src/buildscript/plan9_386.sh
src/buildscript/windows_386.sh
src/buildscript/windows_amd64.sh
src/cmd/Makefile
src/cmd/go/Makefile
src/cmd/go/main.go
src/cmd/go/tool.go [new file with mode: 0644]
src/cmd/yacc/Makefile [moved from src/cmd/goyacc/Makefile with 74% similarity]
src/cmd/yacc/doc.go [moved from src/cmd/goyacc/doc.go with 82% similarity]
src/cmd/yacc/units.txt [moved from src/cmd/goyacc/units.txt with 100% similarity]
src/cmd/yacc/units.y [moved from src/cmd/goyacc/units.y with 98% similarity]
src/cmd/yacc/yacc.go [moved from src/cmd/goyacc/goyacc.go with 99% similarity]
src/make.bash
src/pkg/Makefile

diff --git a/src/Make.tool b/src/Make.tool
new file mode 100644 (file)
index 0000000..fdbb4dd
--- /dev/null
@@ -0,0 +1,49 @@
+# Copyright 2009 The Go Authors.  All rights reserved.
+# Use of this source code is governed by a BSD-style
+# license that can be found in the LICENSE file.
+
+ifeq ($(GOOS),windows)
+TARG:=$(TARG).exe
+endif
+
+# Tools always go into $GOROOT/bin/go-tool
+TOOLDIR=$(QUOTED_GOROOT)/bin/go-tool
+
+all: $(TARG)
+
+include $(QUOTED_GOROOT)/src/Make.common
+
+PREREQ+=$(patsubst %,%.make,$(DEPS))
+
+$(TARG): _go_.$O
+       $(LD) $(LDIMPORTS) -o $@ _go_.$O
+
+_go_.$O: $(GOFILES) $(PREREQ)
+       $(GC) $(GCFLAGS) $(GCIMPORTS) -o $@ $(GOFILES)
+
+install: $(TOOLDIR)/$(TARG)
+
+$(TOOLDIR)/$(TARG): $(TARG)
+       mkdir -p $(TOOLDIR) && cp -f $(TARG) $(TOOLDIR)
+
+CLEANFILES+=$(TARG) _test _testmain.go test.out build.out
+
+nuke: clean
+       rm -f $(TOOLDIR)/$(TARG)
+
+# for gotest
+testpackage: _test/main.a
+
+testpackage-clean:
+       rm -f _test/main.a _gotest_.$O
+
+_test/main.a: _gotest_.$O
+       @mkdir -p _test
+       rm -f $@
+       gopack grc $@ _gotest_.$O
+
+_gotest_.$O: $(GOFILES) $(GOTESTFILES)
+       $(GC) $(GCFLAGS) $(GCIMPORTS) -o $@ $(GOFILES) $(GOTESTFILES)
+
+importpath:
+       echo main
index 73897ba41851bcfc639ef04b5dfb150ebaed7336..38feafd06342997ee7d1b808a6c374af5a426d46 100755 (executable)
@@ -491,7 +491,7 @@ cp "$WORK"/text/template.a "$GOROOT"/pkg/darwin_386/text/template.a
 
 mkdir -p "$WORK"/cmd/go/_obj/
 cd "$GOROOT"/src/cmd/go
-8g -o "$WORK"/cmd/go/_obj/_go_.8 -p cmd/go -I "$WORK" ./bootstrap.go ./build.go ./fix.go ./fmt.go ./get.go ./help.go ./list.go ./main.go ./pkg.go ./run.go ./test.go ./testflag.go ./vcs.go ./version.go ./vet.go
+8g -o "$WORK"/cmd/go/_obj/_go_.8 -p cmd/go -I "$WORK" ./bootstrap.go ./build.go ./fix.go ./fmt.go ./get.go ./help.go ./list.go ./main.go ./pkg.go ./run.go ./test.go ./testflag.go ./tool.go ./vcs.go ./version.go ./vet.go
 gopack grc "$WORK"/cmd/go.a "$WORK"/cmd/go/_obj/_go_.8
 8l -o "$WORK"/cmd/go/_obj/a.out -L "$WORK" "$WORK"/cmd/go.a
 mkdir -p "$GOBIN"/
index b0cab57404172bc334966d8a1a82a8313bd3bc45..200279dba9b2bfef1d62f1c44c759ff32a9b1bf1 100755 (executable)
@@ -490,7 +490,7 @@ cp "$WORK"/text/template.a "$GOROOT"/pkg/darwin_amd64/text/template.a
 
 mkdir -p "$WORK"/cmd/go/_obj/
 cd "$GOROOT"/src/cmd/go
-6g -o "$WORK"/cmd/go/_obj/_go_.6 -p cmd/go -I "$WORK" ./bootstrap.go ./build.go ./fix.go ./fmt.go ./get.go ./help.go ./list.go ./main.go ./pkg.go ./run.go ./test.go ./testflag.go ./vcs.go ./version.go ./vet.go
+6g -o "$WORK"/cmd/go/_obj/_go_.6 -p cmd/go -I "$WORK" ./bootstrap.go ./build.go ./fix.go ./fmt.go ./get.go ./help.go ./list.go ./main.go ./pkg.go ./run.go ./test.go ./testflag.go ./tool.go ./vcs.go ./version.go ./vet.go
 gopack grc "$WORK"/cmd/go.a "$WORK"/cmd/go/_obj/_go_.6
 6l -o "$WORK"/cmd/go/_obj/a.out -L "$WORK" "$WORK"/cmd/go.a
 mkdir -p "$GOBIN"/
index 0c24e12c5a70fad2559c27903c57818d2a6cafe9..85e2af8baca513a070c576b52c90cffe985c85b4 100755 (executable)
@@ -491,7 +491,7 @@ cp "$WORK"/text/template.a "$GOROOT"/pkg/freebsd_386/text/template.a
 
 mkdir -p "$WORK"/cmd/go/_obj/
 cd "$GOROOT"/src/cmd/go
-8g -o "$WORK"/cmd/go/_obj/_go_.8 -p cmd/go -I "$WORK" ./bootstrap.go ./build.go ./fix.go ./fmt.go ./get.go ./help.go ./list.go ./main.go ./pkg.go ./run.go ./test.go ./testflag.go ./vcs.go ./version.go ./vet.go
+8g -o "$WORK"/cmd/go/_obj/_go_.8 -p cmd/go -I "$WORK" ./bootstrap.go ./build.go ./fix.go ./fmt.go ./get.go ./help.go ./list.go ./main.go ./pkg.go ./run.go ./test.go ./testflag.go ./tool.go ./vcs.go ./version.go ./vet.go
 gopack grc "$WORK"/cmd/go.a "$WORK"/cmd/go/_obj/_go_.8
 8l -o "$WORK"/cmd/go/_obj/a.out -L "$WORK" "$WORK"/cmd/go.a
 mkdir -p "$GOBIN"/
index 0a645cca207647ce672fa9c2aea8873c62f64b32..50c44b882e51a1f8a9a4d057e4468e5cc0e5adb0 100755 (executable)
@@ -490,7 +490,7 @@ cp "$WORK"/text/template.a "$GOROOT"/pkg/freebsd_amd64/text/template.a
 
 mkdir -p "$WORK"/cmd/go/_obj/
 cd "$GOROOT"/src/cmd/go
-6g -o "$WORK"/cmd/go/_obj/_go_.6 -p cmd/go -I "$WORK" ./bootstrap.go ./build.go ./fix.go ./fmt.go ./get.go ./help.go ./list.go ./main.go ./pkg.go ./run.go ./test.go ./testflag.go ./vcs.go ./version.go ./vet.go
+6g -o "$WORK"/cmd/go/_obj/_go_.6 -p cmd/go -I "$WORK" ./bootstrap.go ./build.go ./fix.go ./fmt.go ./get.go ./help.go ./list.go ./main.go ./pkg.go ./run.go ./test.go ./testflag.go ./tool.go ./vcs.go ./version.go ./vet.go
 gopack grc "$WORK"/cmd/go.a "$WORK"/cmd/go/_obj/_go_.6
 6l -o "$WORK"/cmd/go/_obj/a.out -L "$WORK" "$WORK"/cmd/go.a
 mkdir -p "$GOBIN"/
index 246f17b06183cf3a196b2b6aec7b2110788bfe39..7cdc5eb7c8785b16669e7743ae3b9507ed96fa83 100755 (executable)
@@ -491,7 +491,7 @@ cp "$WORK"/text/template.a "$GOROOT"/pkg/linux_386/text/template.a
 
 mkdir -p "$WORK"/cmd/go/_obj/
 cd "$GOROOT"/src/cmd/go
-8g -o "$WORK"/cmd/go/_obj/_go_.8 -p cmd/go -I "$WORK" ./bootstrap.go ./build.go ./fix.go ./fmt.go ./get.go ./help.go ./list.go ./main.go ./pkg.go ./run.go ./test.go ./testflag.go ./vcs.go ./version.go ./vet.go
+8g -o "$WORK"/cmd/go/_obj/_go_.8 -p cmd/go -I "$WORK" ./bootstrap.go ./build.go ./fix.go ./fmt.go ./get.go ./help.go ./list.go ./main.go ./pkg.go ./run.go ./test.go ./testflag.go ./tool.go ./vcs.go ./version.go ./vet.go
 gopack grc "$WORK"/cmd/go.a "$WORK"/cmd/go/_obj/_go_.8
 8l -o "$WORK"/cmd/go/_obj/a.out -L "$WORK" "$WORK"/cmd/go.a
 mkdir -p "$GOBIN"/
index 1c1ff21a904946fb812579ae965ee83871f9a677..9b0591825218ec2b2dda07514d16108a319343cd 100755 (executable)
@@ -490,7 +490,7 @@ cp "$WORK"/text/template.a "$GOROOT"/pkg/linux_amd64/text/template.a
 
 mkdir -p "$WORK"/cmd/go/_obj/
 cd "$GOROOT"/src/cmd/go
-6g -o "$WORK"/cmd/go/_obj/_go_.6 -p cmd/go -I "$WORK" ./bootstrap.go ./build.go ./fix.go ./fmt.go ./get.go ./help.go ./list.go ./main.go ./pkg.go ./run.go ./test.go ./testflag.go ./vcs.go ./version.go ./vet.go
+6g -o "$WORK"/cmd/go/_obj/_go_.6 -p cmd/go -I "$WORK" ./bootstrap.go ./build.go ./fix.go ./fmt.go ./get.go ./help.go ./list.go ./main.go ./pkg.go ./run.go ./test.go ./testflag.go ./tool.go ./vcs.go ./version.go ./vet.go
 gopack grc "$WORK"/cmd/go.a "$WORK"/cmd/go/_obj/_go_.6
 6l -o "$WORK"/cmd/go/_obj/a.out -L "$WORK" "$WORK"/cmd/go.a
 mkdir -p "$GOBIN"/
index d2e1a7a100d3ce0f11dbdffe64545d932f2f71d6..7113ef376c0da09462e35bea5603ffafa8a1d364 100755 (executable)
@@ -494,7 +494,7 @@ cp "$WORK"/text/template.a "$GOROOT"/pkg/linux_arm/text/template.a
 
 mkdir -p "$WORK"/cmd/go/_obj/
 cd "$GOROOT"/src/cmd/go
-5g -o "$WORK"/cmd/go/_obj/_go_.5 -p cmd/go -I "$WORK" ./bootstrap.go ./build.go ./fix.go ./fmt.go ./get.go ./help.go ./list.go ./main.go ./pkg.go ./run.go ./test.go ./testflag.go ./vcs.go ./version.go ./vet.go
+5g -o "$WORK"/cmd/go/_obj/_go_.5 -p cmd/go -I "$WORK" ./bootstrap.go ./build.go ./fix.go ./fmt.go ./get.go ./help.go ./list.go ./main.go ./pkg.go ./run.go ./test.go ./testflag.go ./tool.go ./vcs.go ./version.go ./vet.go
 gopack grc "$WORK"/cmd/go.a "$WORK"/cmd/go/_obj/_go_.5
 5l -o "$WORK"/cmd/go/_obj/a.out -L "$WORK" "$WORK"/cmd/go.a
 mkdir -p "$GOBIN"/
index fcf847571b0a21ae19e9d5520a98ec5b525a9c43..6fbe215a844f96d016f8c63979c2b1cb30406abf 100755 (executable)
@@ -491,7 +491,7 @@ cp "$WORK"/text/template.a "$GOROOT"/pkg/netbsd_386/text/template.a
 
 mkdir -p "$WORK"/cmd/go/_obj/
 cd "$GOROOT"/src/cmd/go
-8g -o "$WORK"/cmd/go/_obj/_go_.8 -p cmd/go -I "$WORK" ./bootstrap.go ./build.go ./fix.go ./fmt.go ./get.go ./help.go ./list.go ./main.go ./pkg.go ./run.go ./test.go ./testflag.go ./vcs.go ./version.go ./vet.go
+8g -o "$WORK"/cmd/go/_obj/_go_.8 -p cmd/go -I "$WORK" ./bootstrap.go ./build.go ./fix.go ./fmt.go ./get.go ./help.go ./list.go ./main.go ./pkg.go ./run.go ./test.go ./testflag.go ./tool.go ./vcs.go ./version.go ./vet.go
 gopack grc "$WORK"/cmd/go.a "$WORK"/cmd/go/_obj/_go_.8
 8l -o "$WORK"/cmd/go/_obj/a.out -L "$WORK" "$WORK"/cmd/go.a
 mkdir -p "$GOBIN"/
index 8ad1a154366711f04ce0c2dacaac3ea41e5f5b3e..9b0db555f459261597cf0fdefc2e0aaaefabb2d7 100755 (executable)
@@ -490,7 +490,7 @@ cp "$WORK"/text/template.a "$GOROOT"/pkg/netbsd_amd64/text/template.a
 
 mkdir -p "$WORK"/cmd/go/_obj/
 cd "$GOROOT"/src/cmd/go
-6g -o "$WORK"/cmd/go/_obj/_go_.6 -p cmd/go -I "$WORK" ./bootstrap.go ./build.go ./fix.go ./fmt.go ./get.go ./help.go ./list.go ./main.go ./pkg.go ./run.go ./test.go ./testflag.go ./vcs.go ./version.go ./vet.go
+6g -o "$WORK"/cmd/go/_obj/_go_.6 -p cmd/go -I "$WORK" ./bootstrap.go ./build.go ./fix.go ./fmt.go ./get.go ./help.go ./list.go ./main.go ./pkg.go ./run.go ./test.go ./testflag.go ./tool.go ./vcs.go ./version.go ./vet.go
 gopack grc "$WORK"/cmd/go.a "$WORK"/cmd/go/_obj/_go_.6
 6l -o "$WORK"/cmd/go/_obj/a.out -L "$WORK" "$WORK"/cmd/go.a
 mkdir -p "$GOBIN"/
index f80e1e0acb77e7f11cbac50864e2c5017a0a3e67..192c436612902db926c6bbf584bc0bf88f967480 100755 (executable)
@@ -491,7 +491,7 @@ cp "$WORK"/text/template.a "$GOROOT"/pkg/openbsd_386/text/template.a
 
 mkdir -p "$WORK"/cmd/go/_obj/
 cd "$GOROOT"/src/cmd/go
-8g -o "$WORK"/cmd/go/_obj/_go_.8 -p cmd/go -I "$WORK" ./bootstrap.go ./build.go ./fix.go ./fmt.go ./get.go ./help.go ./list.go ./main.go ./pkg.go ./run.go ./test.go ./testflag.go ./vcs.go ./version.go ./vet.go
+8g -o "$WORK"/cmd/go/_obj/_go_.8 -p cmd/go -I "$WORK" ./bootstrap.go ./build.go ./fix.go ./fmt.go ./get.go ./help.go ./list.go ./main.go ./pkg.go ./run.go ./test.go ./testflag.go ./tool.go ./vcs.go ./version.go ./vet.go
 gopack grc "$WORK"/cmd/go.a "$WORK"/cmd/go/_obj/_go_.8
 8l -o "$WORK"/cmd/go/_obj/a.out -L "$WORK" "$WORK"/cmd/go.a
 mkdir -p "$GOBIN"/
index 257eecc96e23c7a5b5ddfde5fc22b0e3acc83bf6..77979c3221938d851ae5535c13ac5202fe3d2eab 100755 (executable)
@@ -490,7 +490,7 @@ cp "$WORK"/text/template.a "$GOROOT"/pkg/openbsd_amd64/text/template.a
 
 mkdir -p "$WORK"/cmd/go/_obj/
 cd "$GOROOT"/src/cmd/go
-6g -o "$WORK"/cmd/go/_obj/_go_.6 -p cmd/go -I "$WORK" ./bootstrap.go ./build.go ./fix.go ./fmt.go ./get.go ./help.go ./list.go ./main.go ./pkg.go ./run.go ./test.go ./testflag.go ./vcs.go ./version.go ./vet.go
+6g -o "$WORK"/cmd/go/_obj/_go_.6 -p cmd/go -I "$WORK" ./bootstrap.go ./build.go ./fix.go ./fmt.go ./get.go ./help.go ./list.go ./main.go ./pkg.go ./run.go ./test.go ./testflag.go ./tool.go ./vcs.go ./version.go ./vet.go
 gopack grc "$WORK"/cmd/go.a "$WORK"/cmd/go/_obj/_go_.6
 6l -o "$WORK"/cmd/go/_obj/a.out -L "$WORK" "$WORK"/cmd/go.a
 mkdir -p "$GOBIN"/
index 9e3303ed8283c250b07c2d6cda5edc5aa2b01731..bf454e493c256d341aaf12c0bcdc7fbdd456521b 100755 (executable)
@@ -491,7 +491,7 @@ cp "$WORK"/text/template.a "$GOROOT"/pkg/plan9_386/text/template.a
 
 mkdir -p "$WORK"/cmd/go/_obj/
 cd "$GOROOT"/src/cmd/go
-8g -o "$WORK"/cmd/go/_obj/_go_.8 -p cmd/go -I "$WORK" ./bootstrap.go ./build.go ./fix.go ./fmt.go ./get.go ./help.go ./list.go ./main.go ./pkg.go ./run.go ./test.go ./testflag.go ./vcs.go ./version.go ./vet.go
+8g -o "$WORK"/cmd/go/_obj/_go_.8 -p cmd/go -I "$WORK" ./bootstrap.go ./build.go ./fix.go ./fmt.go ./get.go ./help.go ./list.go ./main.go ./pkg.go ./run.go ./test.go ./testflag.go ./tool.go ./vcs.go ./version.go ./vet.go
 gopack grc "$WORK"/cmd/go.a "$WORK"/cmd/go/_obj/_go_.8
 8l -o "$WORK"/cmd/go/_obj/a.out -L "$WORK" "$WORK"/cmd/go.a
 mkdir -p "$GOBIN"/
index 789d5b67ff4f6f6881c14bfc1516818d1633343b..dc1f305b319ca79909bc86b55ca5cd97c24ed7cc 100755 (executable)
@@ -493,7 +493,7 @@ cp "$WORK"/text/template.a "$GOROOT"/pkg/windows_386/text/template.a
 
 mkdir -p "$WORK"/cmd/go/_obj/
 cd "$GOROOT"/src/cmd/go
-8g -o "$WORK"/cmd/go/_obj/_go_.8 -p cmd/go -I "$WORK" ./bootstrap.go ./build.go ./fix.go ./fmt.go ./get.go ./help.go ./list.go ./main.go ./pkg.go ./run.go ./test.go ./testflag.go ./vcs.go ./version.go ./vet.go
+8g -o "$WORK"/cmd/go/_obj/_go_.8 -p cmd/go -I "$WORK" ./bootstrap.go ./build.go ./fix.go ./fmt.go ./get.go ./help.go ./list.go ./main.go ./pkg.go ./run.go ./test.go ./testflag.go ./tool.go ./vcs.go ./version.go ./vet.go
 gopack grc "$WORK"/cmd/go.a "$WORK"/cmd/go/_obj/_go_.8
 8l -o "$WORK"/cmd/go/_obj/a.out.exe -L "$WORK" "$WORK"/cmd/go.a
 mkdir -p "$GOBIN"/
index 0026c1e08641288926ed06dd784aa9a06946ff70..11487786f22fc6416639eeb76cc3acccde31a68e 100755 (executable)
@@ -492,7 +492,7 @@ cp "$WORK"/text/template.a "$GOROOT"/pkg/windows_amd64/text/template.a
 
 mkdir -p "$WORK"/cmd/go/_obj/
 cd "$GOROOT"/src/cmd/go
-6g -o "$WORK"/cmd/go/_obj/_go_.6 -p cmd/go -I "$WORK" ./bootstrap.go ./build.go ./fix.go ./fmt.go ./get.go ./help.go ./list.go ./main.go ./pkg.go ./run.go ./test.go ./testflag.go ./vcs.go ./version.go ./vet.go
+6g -o "$WORK"/cmd/go/_obj/_go_.6 -p cmd/go -I "$WORK" ./bootstrap.go ./build.go ./fix.go ./fmt.go ./get.go ./help.go ./list.go ./main.go ./pkg.go ./run.go ./test.go ./testflag.go ./tool.go ./vcs.go ./version.go ./vet.go
 gopack grc "$WORK"/cmd/go.a "$WORK"/cmd/go/_obj/_go_.6
 6l -o "$WORK"/cmd/go/_obj/a.out.exe -L "$WORK" "$WORK"/cmd/go.a
 mkdir -p "$GOBIN"/
index ee82b8311677f2ba0e7eae3d57f9b1afb2690b57..089739d05afaaf3333750765c24c4b3786ea824c 100644 (file)
@@ -42,7 +42,7 @@ CLEANDIRS=\
        gofmt\
        goinstall\
        gotest\
-       goyacc\
+       yacc\
 
 install: $(patsubst %,%.install,$(DIRS))
 clean: $(patsubst %,%.clean,$(CLEANDIRS))
index 295a14498cf2c27dda7a421310c5d3d8cdd4dc1b..3e19d2e3dc8550af24d16e47c0ea6b806ee512bc 100644 (file)
@@ -18,6 +18,7 @@ GOFILES=\
        run.go\
        test.go\
        testflag.go\
+       tool.go\
        version.go\
        vet.go\
        vcs.go\
index ca3b1188a678671128dd2c606349b5b1fc4a0e02..b69c66d3eb908acd3b549ce3da115f2475b501f0 100644 (file)
@@ -75,6 +75,7 @@ var commands = []*Command{
        cmdList,
        cmdRun,
        cmdTest,
+       cmdTool,
        cmdVersion,
        cmdVet,
 
diff --git a/src/cmd/go/tool.go b/src/cmd/go/tool.go
new file mode 100644 (file)
index 0000000..24ed78b
--- /dev/null
@@ -0,0 +1,100 @@
+// Copyright 2011 The Go Authors.  All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+import (
+       "fmt"
+       "go/build"
+       "os"
+       "os/exec"
+       "sort"
+       "strings"
+)
+
+var cmdTool = &Command{
+       Run:       runTool,
+       UsageLine: "tool command [args...]",
+       Short:     "run specified go tool",
+       Long: `
+Tool runs the go tool command identified by the arguments.
+With no arguments it prints the list of known tools.
+
+For more about each tool command, see 'go tool command -h'.
+`,
+}
+
+var (
+       toolGoos       = build.DefaultContext.GOOS
+       toolIsWindows  = toolGoos == "windows"
+       toolBinToolDir = build.Path[0].BinDir() + "/go-tool"
+)
+
+const toolWindowsExtension = ".exe"
+
+func runTool(cmd *Command, args []string) {
+       if len(args) == 0 {
+               listTools()
+               return
+       }
+       tool := args[0]
+       // The tool name must be lower-case letters and numbers.
+       for _, c := range tool {
+               switch {
+               case 'a' <= c && c <= 'z', '0' <= c && c <= '9':
+               default:
+                       fmt.Fprintf(os.Stderr, "go tool: bad tool name %q\n", tool)
+                       exitStatus = 2
+                       return
+               }
+       }
+       toolPath := toolBinToolDir + "/" + tool
+       if toolIsWindows {
+               toolPath += toolWindowsExtension
+       }
+       // Give a nice message if there is no tool with that name.
+       if _, err := os.Stat(toolPath); err != nil {
+               fmt.Fprintf(os.Stderr, "go tool: no such tool %q\n", tool)
+               exitStatus = 3
+               return
+       }
+       toolCmd := &exec.Cmd{
+               Path:   toolPath,
+               Args:   args,
+               Stdout: os.Stdout,
+               Stderr: os.Stderr,
+       }
+       err := toolCmd.Run()
+       if err != nil {
+               fmt.Fprintf(os.Stderr, "go tool %s failed: %s\n", tool, err)
+               exitStatus = 1
+               return
+       }
+}
+
+// listTools prints a list of the available tools in the go-tools directory.
+func listTools() {
+       toolDir, err := os.Open(toolBinToolDir)
+       if err != nil {
+               fmt.Fprintf(os.Stderr, "go tool: no tool directory: %s\n", err)
+               exitStatus = 2
+               return
+       }
+       names, err := toolDir.Readdirnames(-1)
+       if err != nil {
+               fmt.Fprintf(os.Stderr, "go tool: can't read directory: %s\n", err)
+               exitStatus = 2
+               return
+       }
+       sort.StringSlice(names).Sort()
+       for _, name := range names {
+               // Unify presentation by going to lower case.
+               name = strings.ToLower(name)
+               // If it's windows, don't show the .exe suffix.
+               if toolIsWindows && strings.HasSuffix(name, toolWindowsExtension) {
+                       name = name[:len(name)-len(toolWindowsExtension)]
+               }
+               fmt.Println(name)
+       }
+}
similarity index 74%
rename from src/cmd/goyacc/Makefile
rename to src/cmd/yacc/Makefile
index a616e853485b3373ed12a6e076c6c0368d5adba5..6ce9d54fbec403cea57e7340369b307443711b9d 100644 (file)
@@ -4,14 +4,14 @@
 
 include ../../Make.inc
 
-TARG=goyacc
+TARG=yacc
 GOFILES=\
-       goyacc.go\
+       yacc.go\
 
-include ../../Make.cmd
+include ../../Make.tool
 
-units: goyacc units.y
-       ./goyacc -p units_ units.y
+units: yacc units.y
+       ./yacc -p units_ units.y
        $(GC) $(GCFLAGS) $(GCIMPORTS) y.go
        $(LD) -o units y.$O
 
similarity index 82%
rename from src/cmd/goyacc/doc.go
rename to src/cmd/yacc/doc.go
index 5dd6abe693bb2ffa1d7512f00b97d7befbb6d672..9874a2ae2e1606ae20e003aac82bb9ebcb3c5b0d 100644 (file)
@@ -4,7 +4,8 @@
 
 /*
 
-Goyacc is a version of yacc for Go.
+Yacc is a version of yacc for Go. It is run with the command
+       go tool yacc args...
 It is written in Go and generates parsers written in Go.
 
 It is largely transliterated from the Inferno version written in Limbo
@@ -13,7 +14,8 @@ written in C and documented at
 
        http://plan9.bell-labs.com/magic/man2html/1/yacc
 
-Yacc adepts will have no trouble adapting to this form of the tool.
+Adepts of the original yacc will have no trouble adapting to this
+form of the tool.
 
 The file units.y in this directory is a yacc grammar for a version of
 the Unix tool units, also written in Go and largely transliterated
@@ -37,9 +39,9 @@ which holds the yyLexer passed to Parse.
 
 Multiple grammars compiled into a single program should be placed in
 distinct packages.  If that is impossible, the "-p prefix" flag to
-goyacc sets the prefix, by default yy, that begins the names of
+yacc sets the prefix, by default yy, that begins the names of
 symbols, including types, the parser, and the lexer, generated and
-referenced by goyacc's generated code.  Setting it to distinct values
+referenced by yacc's generated code.  Setting it to distinct values
 allows multiple grammars to be placed in a single package.
 
 */
similarity index 98%
rename from src/cmd/goyacc/units.y
rename to src/cmd/yacc/units.y
index 3833486ad0776906c6103ed71b31a7b36530d291..f10cb7c7dcb3e1e45257de8ca28d02a999daa221 100644 (file)
@@ -7,17 +7,17 @@
 // See http://plan9.bell-labs.com/plan9/license.html
 
 // Generate parser with prefix "units_":
-//     goyacc -p "units_"
+//     go tool yacc -p "units_"
 
 %{
 
 // units.y
-// example of a goyacc program
+// example of a Go yacc program
 // usage is
-//     goyacc -p "units_" units.y (produces y.go)
+//     go tool yacc -p "units_" units.y (produces y.go)
 //     6g y.go
 //     6l y.6
-//     ./6.out $GOROOT/src/cmd/goyacc/units
+//     ./6.out $GOROOT/src/cmd/yacc/units
 //     you have: c
 //     you want: furlongs/fortnight
 //             * 1.8026178e+12
@@ -288,7 +288,7 @@ func main() {
 
        flag.Parse()
 
-       file = os.Getenv("GOROOT") + "/src/cmd/goyacc/units.txt"
+       file = os.Getenv("GOROOT") + "/src/cmd/yacc/units.txt"
        if flag.NArg() > 0 {
                file = flag.Arg(0)
        }
similarity index 99%
rename from src/cmd/goyacc/goyacc.go
rename to src/cmd/yacc/yacc.go
index e1b99bed2bd41b26cf0ac5c713341a373f59d95a..c91a72123ebd4d9d6779257f06d10514daac3ec2 100644 (file)
@@ -2933,7 +2933,7 @@ func chcopy(q string) string {
 }
 
 func usage() {
-       fmt.Fprintf(stderr, "usage: goyacc [-o output] [-v parsetable] input\n")
+       fmt.Fprintf(stderr, "usage: yacc [-o output] [-v parsetable] input\n")
        exit(1)
 }
 
index 34708b5063e2ce48634faa8879c99b10c63782b3..aeaa181090063ff9207c13c3c169d67412d200ad 100755 (executable)
@@ -22,11 +22,21 @@ if ld --version 2>&1 | grep 'gold.* 2\.20' >/dev/null; then
 fi
 
 # Create target directories
-if [ "$GOBIN" = "$GOROOT/bin" ]; then
-       mkdir -p "$GOROOT/bin"
-fi
+mkdir -p "$GOROOT/bin/go-tool"
 mkdir -p "$GOROOT/pkg"
 
+# Remove old, pre-go-tool binaries.
+rm -f "$GOROOT"/bin/[568][acgl]
+rm -f "$GOROOT"/bin/{6cov,6nm,cgo,ebnflint,goapi,gofix,goinstall,gomake,gopack,gopprof,gotest,gotype,govet,goyacc,hgpatch,quietgcc}
+
+# If GOBIN is set and it has a Go compiler, it must also be cleaned.
+if [ -n "GOBIN" ]; then
+       if [ -x "$GOBIN"/5g -o -x "$GOBIN"/6g -o -x "$GOBIN"/8g ]; then
+               rm -f "$GOBIN"/[568][acgl]
+               rm -f "$GOBIN"/{6cov,6nm,cgo,ebnflint,goapi,gofix,goinstall,gomake,gopack,gopprof,gotest,gotype,govet,goyacc,hgpatch,quietgcc}
+       fi
+fi
+
 GOROOT_FINAL=${GOROOT_FINAL:-$GOROOT}
 
 MAKEFLAGS=${MAKEFLAGS:-"-j4"}
index 4638558803531ccdeb382c714bdde0f31b1de746..6ffa527da259b173fd6c203342b0ac1d743982e6 100644 (file)
@@ -161,7 +161,7 @@ DIRS=\
        ../cmd/goinstall\
        ../cmd/gotest\
        ../cmd/govet\
-       ../cmd/goyacc\
+       ../cmd/yacc\
 
 ifeq ($(GOOS),linux)
 DIRS+=\
@@ -194,7 +194,7 @@ NOTEST+=\
        ../cmd/cgo\
        ../cmd/godoc\
        ../cmd/gotest\
-       ../cmd/goyacc\
+       ../cmd/yacc\
 
 NOBENCH+=\