Mark deps explicitly added with `//go get` as direct
What type of PR is this?
Feature
What does this PR do? Why is it needed?
When running go get example.com/[email protected], the module example.com/foo will be added to go.mod with an // indirect comment, just like its transitive dependencies. This results in go_deps not being able to distinguish this explicitly requested new dep from other indirect deps that shouldn't be imported by the root module. Running go mod tidy or go get without arguments is required to have the comment removed after adding a reference to the new module in code.
This change makes it so that bazel run @rules_go//go get example.com/[email protected] marks the requested module as a direct dependency. This realizes https://github.com/golang/go/issues/68593 in our custom wrapper, thus making this command the only one needed to add a new module dependency and have it work with a subsequent Bazel build (assuming that also updates the BUILD files with Gazelle). This matches the behavior of gopls when adding a new dependency.
I am not sure if we should diverge from the official go get behavior. The workflow we recommends in Uber is to add a (potentially dummy) import to the code before running go mod tidy. This makes sure that people don't add new deps to the repo without using it
I am not sure if we should diverge from the official go get behavior. The workflow we recommends in Uber is to add a (potentially dummy) import to the code before running go mod tidy. This makes sure that people don't add new deps to the repo without using it
I also don't like this deviation (especially now that the Go issue has been closed), but note that we are already deviating in an aspect that's arguably worse: If you go get a dep, start to use it in code and then go build ./..., this will pass. If you bazel run @rules_go//go get a dep, start to use it in code and then bazel build //... (including running Gazelle), you will get an error due to the dep not having been added as explicit.