-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
cmd/go: build -o dir ./... should build (and discard) non main packages #37378
Comments
A similar problem is that when there are no main packages,
It is questionable if this is the right thing to do, but I think it is incovenient. |
I think at least building the matching packages makes sense, although it would make the use-case in #14295 arbitrarily slower in some cases. Jay, Michael: any thoughts? |
No strong opinion, but I think we should keep the current behavior.
If the intent is to check whether packages build, there are a few ways to do that, most precisely |
|
Because of the other bug you observed: we are failing to detect collisions when building multiple executables with the same binary name. |
Hmm... The obvious workaround is to run |
I asked why because, on the same module with several main packages and several non main packages,
but Both |
@jayconrod I have read again the documentation of
I'm not sure to understand why to explicitly add Now, without the
To reduce build time, it is always possible to use |
It's a special case. If the I think I misunderstood the reason for its existence though. I've always used it to test whether packages build without writing them anywhere. However, it's not documented. It looks like it was added as a fix for #16811, where So nevermind, let's not rely on (Sorry for the slow response, I typed this a few hours ago, but GitHub comments were down) |
Thinking about this some more. In most repos that mix And, for the few cases that do matter, users can always select only the I think it makes sense for the |
I just found recently that, if I'm correct, in order to discard the build artifacts a simple The current code is in cmd/go/internal/work/build.go: // Special case -o /dev/null by not writing at all.
if cfg.BuildO == os.DevNull {
cfg.BuildO = ""
} However, if it is possible to simply set
|
See also #36784. |
Sorry, this of course don't discard the generation of the executable file, in the case of a main package. |
I wrote a patch to make The main change is that when the The default behavior when the
I'm not sure how There is another subtle change. explicitO := len(cfg.BuildO) > 0
// ...
if cfg.BuildO != "" {
if is-a-directory {
if !explicitO {
base.Fatalf("go build: build output %q already exists and is a directory", cfg.BuildO)
} I think the Thanks. |
Change https://golang.org/cl/312391 mentions this issue: |
Unfortunately, making I still agree that it would make sense for |
I modified the CL to keep the existing behavior when the This change still causes a test to fail:
The current implementation reports I have not updated the documentation, but probably there is no need to explicitly say that when Thanks. |
I updated the test:
I don't like how the test is done. The test just need to verify that the |
@bcmills, when you have time can you review https://golang.org/cl/312391? Thanks. |
@jayconrod had some concerns about building non-main packages, so I would prefer to wait until he is back to review as well, or perhaps @matloob and I can perhaps review once we're in a more stable state for #36460 heading into the freeze. |
Thinking about it, what happens to the non-main packages object files? Will |
Yes, (But, again, I suspect that in most repos containing |
As a test, I compared the time required to check if all packages can be built and to write the executables, using the current $ go clean -cache
$ time godevel build -o /dev/null ./... && godevel build -o build/ $(go list -f '{{if eq .Name "main"}}{{.ImportPath}}{{end}}' ./...)
godevel build -o /dev/null $(go list ./...) 35.32s user 3.15s system 341% cpu 11.282 total $ go clean -cache
$ time godevel build -o build/ ./...
godevel build -o build/ ./... 33.02s user 2.87s system 350% cpu 10.243 total So, the difference is minimal, but still I think that |
This seems a better alternative for checking that all packages can be built and writing all executables to a go build -o /dev/null ./... && (go build -o build ./... 2>/dev/null || true) |
with #69290 go build ./... && go build -o bin ./... should be very fast. |
@seankhliao #69290 was restricted to only do caching for |
ah... I didn't notice |
Yeah we didn't communicate it loudly when we changed it. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I have a module, with a main package in the module root directory and another package in a subdirectory.
A
.go
file in the nested package has a syntax error.I ran the following commands
What did you expect to see?
Both commands to report an error
What did you see instead?
Only the first command reports the syntax error.
The text was updated successfully, but these errors were encountered: