Commit 71d83b72 authored by Rob Pike's avatar Rob Pike

cmd/go: add go tools to rearrangement

fix, vet
yacc is also fixed (it was wrong before)
All that's left is the commands used during compilation
This looks like a huge CL, but it's almost all file renames.
The action is in cmd/go/pkg.go, the Makefiles, and .../doc.go.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/5595044
parent 108961b2
......@@ -38,10 +38,11 @@ CLEANDIRS=\
8l\
cgo\
godoc\
gofix\
fix\
gofmt\
goinstall\
gotest\
vet\
yacc\
install: $(patsubst %,%.install,$(DIRS))
......
......@@ -44,7 +44,7 @@ GOFILES=\
url.go\
xmlapi.go\
include ../../Make.cmd
include ../../Make.tool
test:
gotest
......
......@@ -3,34 +3,34 @@
// license that can be found in the LICENSE file.
/*
Gofix finds Go programs that use old APIs and rewrites them to use
newer ones. After you update to a new Go release, gofix helps make
Fix finds Go programs that use old APIs and rewrites them to use
newer ones. After you update to a new Go release, fix helps make
the necessary changes to your programs.
Usage:
gofix [-r name,...] [path ...]
go tool fix [-r name,...] [path ...]
Without an explicit path, gofix reads standard input and writes the
Without an explicit path, fix reads standard input and writes the
result to standard output.
If the named path is a file, gofix rewrites the named files in place.
If the named path is a directory, gofix rewrites all .go files in that
directory tree. When gofix rewrites a file, it prints a line to standard
If the named path is a file, fix rewrites the named files in place.
If the named path is a directory, fix rewrites all .go files in that
directory tree. When fix rewrites a file, it prints a line to standard
error giving the name of the file and the rewrite applied.
If the -diff flag is set, no files are rewritten. Instead gofix prints
If the -diff flag is set, no files are rewritten. Instead fix prints
the differences a rewrite would introduce.
The -r flag restricts the set of rewrites considered to those in the
named list. By default gofix considers all known rewrites. Gofix's
rewrites are idempotent, so that it is safe to apply gofix to updated
named list. By default fix considers all known rewrites. Fix's
rewrites are idempotent, so that it is safe to apply fix to updated
or partially updated code even without using the -r flag.
Gofix prints the full list of fixes it can apply in its help output;
to see them, run gofix -?.
Fix prints the full list of fixes it can apply in its help output;
to see them, run go tool fix -?.
Gofix does not make backup copies of the files that it edits.
Fix does not make backup copies of the files that it edits.
Instead, use a version control system's ``diff'' functionality to inspect
the changes that gofix makes before committing them.
the changes that fix makes before committing them.
*/
package documentation
......@@ -36,11 +36,11 @@ var allowed, force map[string]bool
var doDiff = flag.Bool("diff", false, "display diffs instead of rewriting files")
// enable for debugging gofix failures
// enable for debugging fix failures
const debug = false // display incorrectly reformatted source and exit
func usage() {
fmt.Fprintf(os.Stderr, "usage: gofix [-diff] [-r fixname,...] [-force fixname,...] [path ...]\n")
fmt.Fprintf(os.Stderr, "usage: go tool fix [-diff] [-r fixname,...] [-force fixname,...] [path ...]\n")
flag.PrintDefaults()
fmt.Fprintf(os.Stderr, "\nAvailable rewrites are:\n")
sort.Sort(byName(fixes))
......@@ -244,14 +244,14 @@ func isGoFile(f os.FileInfo) bool {
}
func diff(b1, b2 []byte) (data []byte, err error) {
f1, err := ioutil.TempFile("", "gofix")
f1, err := ioutil.TempFile("", "go-fix")
if err != nil {
return nil, err
}
defer os.Remove(f1.Name())
defer f1.Close()
f2, err := ioutil.TempFile("", "gofix")
f2, err := ioutil.TempFile("", "go-fix")
if err != nil {
return nil, err
}
......
......@@ -87,8 +87,8 @@ http://codereview.appspot.com/4433066
// x.(*reflect.MapValue).Elem(v) becomes x.MapIndex(v).
// In general, reflectFn needs to know the type of the receiver expression.
// In most cases (and in all the cases in the Go source tree), the toy
// type checker in typecheck.go provides enough information for gofix
// to make the rewrite. If gofix misses a rewrite, the code that is left over
// type checker in typecheck.go provides enough information for fix
// to make the rewrite. If fix misses a rewrite, the code that is left over
// will not compile, so it will be noticed immediately.
func reflectFn(f *ast.File) bool {
......
......@@ -9,12 +9,12 @@ var cmdFix = &Command{
UsageLine: "fix [importpath...]",
Short: "run gofix on packages",
Long: `
Fix runs the gofix command on the packages named by the import paths.
Fix runs the Go fix command on the packages named by the import paths.
For more about gofix, see 'godoc gofix'.
For more about fix, see 'godoc fix'.
For more about import paths, see 'go help importpath'.
To run gofix with specific options, run gofix itself.
To run fix with specific options, run 'go tool fix'.
See also: go fmt, go vet.
`,
......
......@@ -224,6 +224,14 @@ Loop:
return string(b)
}
// isGoTool is the list of directories for Go programs that are installed in
// $GOROOT/bin/go-tool.
var isGoTool = map[string]bool{
"cmd/fix": true,
"cmd/vet": true,
"cmd/yacc": true,
}
func scanPackage(ctxt *build.Context, t *build.Tree, arg, importPath, dir string, stk *importStack) *Package {
// Read the files in the directory to learn the structure
// of the package.
......@@ -262,7 +270,11 @@ func scanPackage(ctxt *build.Context, t *build.Tree, arg, importPath, dir string
if info.Package == "main" {
_, elem := filepath.Split(importPath)
p.target = filepath.Join(t.BinDir(), elem)
if t.Goroot && isGoTool[p.ImportPath] {
p.target = filepath.Join(t.Path, "bin/go-tool", elem)
} else {
p.target = filepath.Join(t.BinDir(), elem)
}
if ctxt.GOOS == "windows" {
p.target += ".exe"
}
......
......@@ -9,12 +9,12 @@ var cmdVet = &Command{
UsageLine: "vet [importpath...]",
Short: "run govet on packages",
Long: `
Vet runs the govet command on the packages named by the import paths.
Vet runs the Go vet command on the packages named by the import paths.
For more about govet, see 'godoc govet'.
For more about vet, see 'godoc vet'.
For more about import paths, see 'go help importpath'.
To run govet with specific options, run govet itself.
To run govet with specific options, run 'go tool vet'.
See also: go fmt, go fix.
`,
......
......@@ -4,14 +4,14 @@
include ../../Make.inc
TARG=govet
TARG=vet
GOFILES=\
govet.go\
main.go\
method.go\
print.go\
structtag.go\
include ../../Make.cmd
include ../../Make.tool
test testshort: $(TARG)
../../../test/errchk $(TARG) -printfuncs='Warn:1,Warnf:1' print.go
......@@ -4,7 +4,7 @@
/*
Govet does simple checking of Go source code.
Vet does simple checking of Go source code.
It checks for simple errors in calls to functions named
Print Printf Println
......@@ -13,13 +13,13 @@ It checks for simple errors in calls to functions named
Error Errorf
Fatal Fatalf
If the function name ends with an 'f', the function is assumed to take
a format descriptor string in the manner of fmt.Printf. If not, govet
a format descriptor string in the manner of fmt.Printf. If not, vet
complains about arguments that look like format descriptor strings.
Usage:
govet [flag] [file.go ...]
govet [flag] [directory ...] # Scan all .go files under directory, recursively
go tool vet [flag] [file.go ...]
go tool vet [flag] [directory ...] # Scan all .go files under directory, recursively
The flags are:
-v
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Govet is a simple checker for static errors in Go source code.
// Vet is a simple checker for static errors in Go source code.
// See doc.go for more information.
package main
......@@ -120,7 +120,7 @@ func walkDir(root string) {
// error formats the error to standard error, adding program
// identification and a newline
func errorf(format string, args ...interface{}) {
fmt.Fprintf(os.Stderr, "govet: "+format+"\n", args...)
fmt.Fprintf(os.Stderr, "vet: "+format+"\n", args...)
setExit(2)
}
......
......@@ -23,7 +23,7 @@ type MethodSig struct {
// checks are dynamic, such methods would not cause a compile error
// if they have the wrong signature: instead the dynamic check would
// fail, sometimes mysteriously. If a method is found with a name listed
// here but not the input/output types listed here, govet complains.
// here but not the input/output types listed here, vet complains.
//
// A few of the canonical methods have very common names.
// For example, a type might implement a Scan method that
......
......@@ -156,7 +156,7 @@ const (
)
// printVerbs identifies which flags are known to printf for each verb.
// TODO: A type that implements Formatter may do what it wants, and govet
// TODO: A type that implements Formatter may do what it wants, and vet
// will complain incorrectly.
var printVerbs = []printVerb{
// '-' is a width modifier, always valid.
......
......@@ -156,11 +156,11 @@ DIRS=\
unicode/utf8\
../cmd/cgo\
../cmd/godoc\
../cmd/gofix\
../cmd/fix\
../cmd/gofmt\
../cmd/goinstall\
../cmd/gotest\
../cmd/govet\
../cmd/vet\
../cmd/yacc\
ifeq ($(GOOS),linux)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment