From ed9644fc3954d6852c725e2efd062fb46c0786a7 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Tue, 30 Apr 2013 17:04:58 -0400 Subject: [PATCH] cmd/go: undo CL 8119049 Manual undo due to later changes in doc/go1.1.html; cmd/go/test.bash still passes. Rationale, from CL 8119049 review log: This makes the 'go run' command different from every other command. For example, 'go test' does not mean 'go test *.go'. If we were going to handle the no arguments case in 'go run', I would hope that it would scan the current directory to find a package just like 'go build' or 'go test' would, and then it would require that package to be 'package main', and then it would run that package. This would make it match 'go test' and 'go build' and 'go install' and so on. It would mean that if you are working on a command in a directory that is 'go install'able, then 'go run' will run the binary for you. The current CL does not accomplish that when build constraints or file name constraints are involved. For example, if I am working on a program like: $ ls main.go main_386.s main_arm.s main_amd64.s $ Then 'go run' will fail here because the .s files are ignored. If instead I am working on a program like: $ ls main.go main_386.go main_arm.go main_amd64.go $ then 'go run' will fail because too many files are included. I would like to see this command implemented so that it is compatible with the other go subcommands. Since it is too late to do that for Go 1.1, I would like to see this CL reverted, to preserve the option to do it better later. R=golang-dev, iant, r CC=golang-dev https://golang.org/cl/8797049 --- src/cmd/go/doc.go | 2 +- src/cmd/go/run.go | 16 ++-------------- 2 files changed, 3 insertions(+), 15 deletions(-) diff --git a/src/cmd/go/doc.go b/src/cmd/go/doc.go index d7fca806270..df82ab45b0d 100644 --- a/src/cmd/go/doc.go +++ b/src/cmd/go/doc.go @@ -367,7 +367,7 @@ Compile and run Go program Usage: - go run [build flags] [gofiles...] [arguments...] + go run [build flags] gofiles... [arguments...] Run compiles and runs the main package comprising the named Go source files. If no files are named, it compiles and runs all non-test Go source files. diff --git a/src/cmd/go/run.go b/src/cmd/go/run.go index d8ba4dbddd8..91bdc1be2a4 100644 --- a/src/cmd/go/run.go +++ b/src/cmd/go/run.go @@ -8,12 +8,11 @@ import ( "fmt" "os" "os/exec" - "path/filepath" "strings" ) var cmdRun = &Command{ - UsageLine: "run [build flags] [gofiles...] [arguments...]", + UsageLine: "run [build flags] gofiles... [arguments...]", Short: "compile and run Go program", Long: ` Run compiles and runs the main package comprising the named Go source files. @@ -46,18 +45,7 @@ func runRun(cmd *Command, args []string) { } files, cmdArgs := args[:i], args[i:] if len(files) == 0 { - allFiles, err := filepath.Glob("*.go") - if err != nil { - fatalf("go run: %s", err) - } - for _, file := range allFiles { - if !strings.HasSuffix(file, "_test.go") { - files = append(files, file) - } - } - if len(files) == 0 { - fatalf("go run: no go files found") - } + fatalf("go run: no go files listed") } for _, file := range files { if strings.HasSuffix(file, "_test.go") {