Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
x/tools/go/packages: clarify behavior when given zero patterns #28767
I've ported a few tools over from a mix of https://github.com/kisielk/gotool and
Until today, when I happened to notice that running
I presume it's fair enough if
Options that come to mind, in order of personal preference:
If we go with the doc fix route, I'd suggest including the string
By that light, I think that it should treat no packages as the same as
I agree there is a problem here. The tricky thing is that the underlying build systems vary in their treatment of an empty argument list. The go tool treats [ ] as ["."], but Blaze and Bazel treat [ ] as an empty request: a no-op. Furthermore "." is not a valid argument to Bazel; the closest concept is ":all", but users would not conventionally expect [ ] to mean [":all"].
If we follow the principle outlined in the docs ("the conventions of the underlying build system") then the interpretation of [ ] may vary, which is fine for interactive command-line users who know the conventions of their build system. If an application driving packages.Load needs a way to say "all the packages in the current directory", then perhaps we should add another special query (like name=..., file=...), but I have not yet come across the need.
I think we should leave this up to the driver but call out explicitly in the docs to Load that an empty pattern list is driver defined behavior, because it might surprise some people, and programmatic uses that are trying to avoid driver defined behavior need to know to avoid this case.
referenced this issue
Nov 13, 2018
This was fixed by https://go-review.googlesource.com/c/tools/+/155898