//
// The -o flag forces build to write the resulting executable or object
// to the named output file or directory, instead of the default behavior described
-// in the last two paragraphs. If the named output is a directory that exists,
-// then any resulting executables will be written to that directory.
+// in the last two paragraphs. If the named output is an existing directory or
+// ends with a slash or backslash, then any resulting executables
+// will be written to that directory.
//
// The -i flag installs the packages that are dependencies of the target.
//
The -o flag forces build to write the resulting executable or object
to the named output file or directory, instead of the default behavior described
-in the last two paragraphs. If the named output is a directory that exists,
-then any resulting executables will be written to that directory.
+in the last two paragraphs. If the named output is an existing directory or
+ends with a slash or backslash, then any resulting executables
+will be written to that directory.
The -i flag installs the packages that are dependencies of the target.
}
if cfg.BuildO != "" {
- // If the -o name exists and is a directory, then
+ // If the -o name exists and is a directory or
+ // ends with a slash or backslash, then
// write all main packages to that directory.
// Otherwise require only a single package be built.
- if fi, err := os.Stat(cfg.BuildO); err == nil && fi.IsDir() {
+ if fi, err := os.Stat(cfg.BuildO); (err == nil && fi.IsDir()) ||
+ strings.HasSuffix(cfg.BuildO, "/") ||
+ strings.HasSuffix(cfg.BuildO, string(os.PathSeparator)) {
if !explicitO {
base.Fatalf("go build: build output %q already exists and is a directory", cfg.BuildO)
}
exists -exec myprog
! exists myprogr.exe
+! exists bin
+go build -o bin/x x.go
+exists -exec bin/x
+rm bin
+
+! exists bin
+go build -o bin/ x.go
+exists -exec bin/x$GOEXE
+rm bin
+
+[windows] ! exists bin
+[windows] go build -o bin\x x.go
+[windows] exists -exec bin\x
+[windows] rm bin
+
+[windows] ! exists bin
+[windows] go build -o bin\ x.go
+[windows] exists -exec bin\x.exe
+[windows] rm bin
+
+! exists bin
+mkdir bin
+go build -o bin x.go
+exists -exec bin/x$GOEXE
+rm bin
+
go build p.go
! exists p
! exists p.a