1
0
mirror of https://github.com/golang/go synced 2024-11-25 00:37:57 -07:00

cmd/go: add -v flag to build and install

The -v flag prints the names of packages as they are built/installed.

Use -v in make.bash/run.bash to avoid a silent pause during
the build while Go code is being compiled.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/5532055
This commit is contained in:
Russ Cox 2012-01-09 16:44:01 -08:00
parent b8615a0931
commit 146a703cd1
5 changed files with 19 additions and 9 deletions

View File

@ -28,7 +28,7 @@ func init() {
} }
var cmdBuild = &Command{ var cmdBuild = &Command{
UsageLine: "build [-a] [-n] [-x] [-o output] [importpath... | gofiles...]", UsageLine: "build [-a] [-n] [-v] [-x] [-o output] [importpath... | gofiles...]",
Short: "compile packages and dependencies", Short: "compile packages and dependencies",
Long: ` Long: `
Build compiles the packages named by the import paths, Build compiles the packages named by the import paths,
@ -44,6 +44,7 @@ serving only as a check that the packages can be built.
The -a flag forces rebuilding of packages that are already up-to-date. The -a flag forces rebuilding of packages that are already up-to-date.
The -n flag prints the commands but does not run them. The -n flag prints the commands but does not run them.
The -v flag prints the names of packages as they are compiled.
The -x flag prints the commands. The -x flag prints the commands.
The -o flag specifies the output file name. The -o flag specifies the output file name.
It is an error to use -o when the command line specifies multiple packages. It is an error to use -o when the command line specifies multiple packages.
@ -56,12 +57,13 @@ See also: go install, go get, go clean.
var buildA = cmdBuild.Flag.Bool("a", false, "") var buildA = cmdBuild.Flag.Bool("a", false, "")
var buildN = cmdBuild.Flag.Bool("n", false, "") var buildN = cmdBuild.Flag.Bool("n", false, "")
var buildV = cmdBuild.Flag.Bool("v", false, "")
var buildX = cmdBuild.Flag.Bool("x", false, "") var buildX = cmdBuild.Flag.Bool("x", false, "")
var buildO = cmdBuild.Flag.String("o", "", "output file") var buildO = cmdBuild.Flag.String("o", "", "output file")
func runBuild(cmd *Command, args []string) { func runBuild(cmd *Command, args []string) {
var b builder var b builder
b.init(*buildA, *buildN, *buildX) b.init(*buildA, *buildN, *buildV, *buildX)
var pkgs []*Package var pkgs []*Package
if len(args) > 0 && strings.HasSuffix(args[0], ".go") { if len(args) > 0 && strings.HasSuffix(args[0], ".go") {
@ -95,7 +97,7 @@ func runBuild(cmd *Command, args []string) {
} }
var cmdInstall = &Command{ var cmdInstall = &Command{
UsageLine: "install [-a] [-n] [-x] [importpath...]", UsageLine: "install [-a] [-n] [-v] [-x] [importpath...]",
Short: "compile and install packages and dependencies", Short: "compile and install packages and dependencies",
Long: ` Long: `
Install compiles and installs the packages named by the import paths, Install compiles and installs the packages named by the import paths,
@ -103,6 +105,7 @@ along with their dependencies.
The -a flag forces reinstallation of packages that are already up-to-date. The -a flag forces reinstallation of packages that are already up-to-date.
The -n flag prints the commands but does not run them. The -n flag prints the commands but does not run them.
The -v flag prints the names of packages as they are compiled.
The -x flag prints the commands. The -x flag prints the commands.
For more about import paths, see 'go help importpath'. For more about import paths, see 'go help importpath'.
@ -113,11 +116,12 @@ See also: go build, go get, go clean.
var installA = cmdInstall.Flag.Bool("a", false, "") var installA = cmdInstall.Flag.Bool("a", false, "")
var installN = cmdInstall.Flag.Bool("n", false, "") var installN = cmdInstall.Flag.Bool("n", false, "")
var installV = cmdInstall.Flag.Bool("v", false, "")
var installX = cmdInstall.Flag.Bool("x", false, "") var installX = cmdInstall.Flag.Bool("x", false, "")
func runInstall(cmd *Command, args []string) { func runInstall(cmd *Command, args []string) {
var b builder var b builder
b.init(*installA, *installN, *installX) b.init(*installA, *installN, *installV, *installX)
a := &action{} a := &action{}
for _, p := range packages(args) { for _, p := range packages(args) {
a.deps = append(a.deps, b.action(modeInstall, modeInstall, p)) a.deps = append(a.deps, b.action(modeInstall, modeInstall, p))
@ -132,6 +136,7 @@ type builder struct {
work string // the temporary work directory (ends in filepath.Separator) work string // the temporary work directory (ends in filepath.Separator)
aflag bool // the -a flag aflag bool // the -a flag
nflag bool // the -n flag nflag bool // the -n flag
vflag bool // the -v flag
xflag bool // the -x flag xflag bool // the -x flag
arch string // e.g., "6" arch string // e.g., "6"
goroot string // the $GOROOT goroot string // the $GOROOT
@ -190,10 +195,11 @@ const (
modeInstall modeInstall
) )
func (b *builder) init(aflag, nflag, xflag bool) { func (b *builder) init(aflag, nflag, vflag, xflag bool) {
var err error var err error
b.aflag = aflag b.aflag = aflag
b.nflag = nflag b.nflag = nflag
b.vflag = vflag
b.xflag = xflag b.xflag = xflag
b.actionCache = make(map[cacheKey]*action) b.actionCache = make(map[cacheKey]*action)
b.mkdirCache = make(map[string]bool) b.mkdirCache = make(map[string]bool)
@ -456,6 +462,10 @@ func (b *builder) build(a *action) error {
fmt.Printf("\n#\n# %s\n#\n\n", a.p.ImportPath) fmt.Printf("\n#\n# %s\n#\n\n", a.p.ImportPath)
} }
if b.vflag {
fmt.Fprintf(os.Stderr, "%s\n", a.p.ImportPath)
}
// make build directory // make build directory
obj := a.objdir obj := a.objdir
if err := b.mkdir(obj); err != nil { if err := b.mkdir(obj); err != nil {

View File

@ -31,7 +31,7 @@ var runX = cmdRun.Flag.Bool("x", false, "")
func runRun(cmd *Command, args []string) { func runRun(cmd *Command, args []string) {
var b builder var b builder
b.init(*runA, *runN, *runX) b.init(*runA, *runN, false, *runX)
files, args := splitArgs(args) files, args := splitArgs(args)
p := goFilesPackage(files, "") p := goFilesPackage(files, "")
p.target = "" // must build - not up to date p.target = "" // must build - not up to date

View File

@ -220,7 +220,7 @@ func runTest(cmd *Command, args []string) {
} }
var b builder var b builder
b.init(false, false, testX) b.init(false, false, false, testX)
var builds, runs []*action var builds, runs []*action

View File

@ -96,7 +96,7 @@ if $USE_GO_TOOL; then
./buildscript_${GOOS}_$GOARCH.sh ./buildscript_${GOOS}_$GOARCH.sh
echo '# Building Go code.' echo '# Building Go code.'
go install -a std go install -a -v std
else else
echo; echo; echo %%%% making pkg %%%%; echo echo; echo; echo %%%% making pkg %%%%; echo
gomake -C pkg install gomake -C pkg install

View File

@ -34,7 +34,7 @@ if $rebuild; then
if $USE_GO_TOOL; then if $USE_GO_TOOL; then
echo echo
echo '# Package builds' echo '# Package builds'
time go install -a std time go install -a -v std
else else
(xcd pkg (xcd pkg
gomake clean gomake clean