--- /dev/null
+# 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
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"/
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"/
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"/
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"/
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"/
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"/
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"/
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"/
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"/
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"/
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"/
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"/
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"/
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"/
gofmt\
goinstall\
gotest\
- goyacc\
+ yacc\
install: $(patsubst %,%.install,$(DIRS))
clean: $(patsubst %,%.clean,$(CLEANDIRS))
run.go\
test.go\
testflag.go\
+ tool.go\
version.go\
vet.go\
vcs.go\
cmdList,
cmdRun,
cmdTest,
+ cmdTool,
cmdVersion,
cmdVet,
--- /dev/null
+// 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)
+ }
+}
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
/*
-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
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
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.
*/
// 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
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)
}
}
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)
}
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"}
../cmd/goinstall\
../cmd/gotest\
../cmd/govet\
- ../cmd/goyacc\
+ ../cmd/yacc\
ifeq ($(GOOS),linux)
DIRS+=\
../cmd/cgo\
../cmd/godoc\
../cmd/gotest\
- ../cmd/goyacc\
+ ../cmd/yacc\
NOBENCH+=\