-
Notifications
You must be signed in to change notification settings - Fork 18.1k
cmd/go: documentation of go build
-o flag is misleading
#36784
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
Comments
go build
-o flag is misleadinggo build
-o flag is misleading
Emphasis mine:
(CC @jayconrod @matloob) |
The Could you describe the use-cases that led you to expect different behavior for these conditions? That might help us better tailor the documentation and/or behavior for those use-cases. |
It is just that the documentation and error message seems a bit inconsistent to me. However today I found a behavior that surprised me. In my Go projects I have a
I have to change the rule to This is consistent with how |
That probably should not be necessary. However, that is significantly different from the issue that you reported initially, which was that “an object is generated only if the |
Sorry, probably it was a _test.go file that contained an error and was ignored (as documented) by About the documentation, what do you think about changing
to
From some tests, go build never writes an object file to a directory; you have to specify a file.
Thanks. |
I would like the first clause of the sentence to be complete and accurate, since that is often the only part that folks read (especially when they're just skimming flag descriptions). So I think we need to keep “directory” in that first clause, rather than deferring it to the next sentence. |
I can't think of a good solution . If the But if the |
That property is intentional: the use-case in #14295 is to be able to build all of the binaries in a given project, without the restrictions of So, can we step up a level? What is the concrete problem that you're trying to address where the behavior of the |
The problem is the one I wrote in the issue title: documentation of Thanks. |
it's more than a documentation problem. if -o is a directory and one is building a non-main package, go build reports an error go build -o /tmp /Users/pjw/tools/internal/lsp go build -o /tmp/foo /Users/pjw/tools/internal/lsp |
https://go-review.googlesource.com/c/tools/+/246419/2 fixed a problem but introduced a new one, as go build treats -o directories differently depending on whether or not a main package is being built. (see golang/go#36784) This change explicitly constructs a temporary file for go build to use. Change-Id: I096748e9af5014428dab8a5aad703f062fe88d50 Reviewed-on: https://go-review.googlesource.com/c/tools/+/247899 Run-TryBot: Peter Weinberger <[email protected]> Reviewed-by: Pontus Leitzler <[email protected]> Reviewed-by: Rebecca Stambler <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
I run into this as well.
I usually spell out the file name. I was just feeling lazy today. Also, related, or not,
This time it is an executable, but it doesn't work. Reading this issue, I'm not sure what is the intended behavior. Maybe it is fine if this is intended. I just shouldn't be lazy... |
The current documentation is
It still incorrectly says that an object can be written to a directory. Unfortunately I can't think of a better way to express this without making the documentation harder to read. |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
Change https://golang.org/cl/312391 mentions this issue: |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
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.) |
The documentation of
go build
says:However an object is generated only if the
-o
flag specifies a file.To make things more confusing, when I have a non main package in the project root and a main package in a sub-directory,
go build -o file ./...
reports:The text was updated successfully, but these errors were encountered: