Skip to content
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: go list -json should provide an option to set the context to UseAllFiles=true #30504

Closed
nim-nim opened this issue Mar 1, 2019 · 5 comments

Comments

@nim-nim
Copy link

nim-nim commented Mar 1, 2019

go version go1.12 linux/amd64

When preparing a codebase for use on different architectures, for reuse in projects that will set (or not) specific build constrains, you do not want go list to filter its output based on the system the preparation steps occurs on. go list should have a mode that is independent of the system it runs on (at most, perhaps, restricting the output to a specific OS).

@mvdan
Copy link
Member

mvdan commented Mar 1, 2019

go list loads packages, sometimes with type information; for example via flags like -export. To properly typecheck or build a package, it's necessary to only load the files for a specific GOOS/GOARCH pair. How would this work?

If you want to list all Go files, you should load all Go files within certain directories, not load entire packages. A package doesn't necessarily include all Go files in a directory, by its own definition.

@ianlancetaylor ianlancetaylor changed the title go list -json should provide an option to set the context to UseAllFiles=true cmd/go: go list -json should provide an option to set the context to UseAllFiles=true Mar 1, 2019
@ianlancetaylor
Copy link
Contributor

Can't you use the IgnoredGoFiles field for this?

@nim-nim
Copy link
Author

nim-nim commented Mar 1, 2019

I think I haven't tried it yet because
UseAllFiles bool // use files regardless of +build lines, file names
describes my need, while
IgnoredGoFiles []string // .go source files ignored due to build constraints
is less clear, and probably ignore then de-ignore is too weird for my brain.

Also IgnoredGoFiles seems .go specific, while UseAllFiles is nicely generic.

But if you tell me that's the exact same end-result, sure, I will do it that way.

@jayconrod
Copy link
Contributor

I think IgnoredGoFiles is what you want. That will contain .go files that would have been in GoFiles had UseAllFiles been set.

I don't think go list can necessarily implement UseAllFiles the same way go/build does in any case. go list loads a dependency graph of packages, and that graph may be significantly altered if build constraints are ignored. For example, you could end up with dependency cycle errors when no dependency cycle exists on any specific platform.

@nim-nim
Copy link
Author

nim-nim commented Mar 1, 2019

Ok, thanks for the clarification. I'll try this. Hopefully, it won't hit a corner case no one though of yet.

@nim-nim nim-nim closed this as completed Mar 1, 2019
@golang golang locked and limited conversation to collaborators Feb 29, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants