Skip to content

cmd/go: inconsistency when go build -o is a file or directory #37379

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
perillo opened this issue Feb 22, 2020 · 4 comments
Closed

cmd/go: inconsistency when go build -o is a file or directory #37379

perillo opened this issue Feb 22, 2020 · 4 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@perillo
Copy link
Contributor

perillo commented Feb 22, 2020

What version of Go are you using (go version)?

$ go version
go version go1.14rc1 linux/amd64

Does this issue reproduce with the latest release?

Yes.

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN="/home/manlio/.local/bin"
GOCACHE="/home/manlio/.cache/go-build"
GOENV="/home/manlio/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/manlio/.local/lib/go:/home/manlio/src/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/manlio/sdk/go1.14rc1"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/manlio/sdk/go1.14rc1/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build934357574=/tmp/go-build -gno-record-gcc-switches"
GOROOT/bin/go version: go version go1.14rc1 linux/amd64
GOROOT/bin/go tool compile -V: compile version go1.14rc1
uname -sr: Linux 5.5.4-arch1-1
/usr/lib/libc.so.6: GNU C Library (GNU libc) stable release version 2.31.
gdb --version: GNU gdb (GDB) 9.1

What did you do?

go build -o path behave differently when path is a file or directory.

As an example, go build -o file ./pkg, will build an executable if pkg is a main package or an archive otherwise.

On the other hand, go build -o dir ./..., will build all the main packages, saving the files in the build directory, using the last segment of the importpath as the name. This is done even if two executable happen to have the same name, without any notice.

For consistency, go build -o dir ./... should save the archive files in the build directory, when processing non main packages, using the same algorithm used for main packages.

I suspect that building an archive file is here only for compatibility reason.

@perillo perillo changed the title cmd/go: incosistency when go build -o is a file or directory cmd/go: inconsistency when go build -o is a file or directory Feb 22, 2020
@bcmills
Copy link
Contributor

bcmills commented Feb 26, 2020

CC @jayconrod @matloob

@bcmills
Copy link
Contributor

bcmills commented Feb 26, 2020

This is done even if two executable happen to have the same name, without any notice.

That seems like an independent bug. File it as a separate issue?

@bcmills
Copy link
Contributor

bcmills commented Feb 26, 2020

For consistency, go build -o dir ./... should save the archive files in the build directory, when processing non main packages, using the same algorithm used for main packages.

I don't think I understand what you mean. Do you expect go build to write archive files into dir, or to build the archive files but not copy them in?

More generally (and following #36784 (comment)): what is the concrete problem that you're trying to address where the current behavior of the -o flag is causing trouble?

@bcmills bcmills added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. labels Feb 26, 2020
@bcmills bcmills added this to the Unplanned milestone Feb 26, 2020
@gopherbot
Copy link
Contributor

Timed out in state WaitingForInfo. Closing.

(I am just a bot, though. Please speak up if this is a mistake or you have the requested information.)

@golang golang locked and limited conversation to collaborators Mar 26, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

3 participants