-
-
Notifications
You must be signed in to change notification settings - Fork 638
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
go: add tailor
support for go_package
, go_module
, and go_external_module
targets
#12406
Conversation
Introduce the `MaybeEmptySiblingAddresses` address spec to allow searching for addresses in a directory without a BUILD file or for which there are no targets in any of the BUILD files. It is similar in spirit to the already-existing `MaybeEmptyDescendantAddresses`. This PR is necessary for the Go tailor support in #12406. The inference for `go_external_module` attempts to find `go_module` targets along the tailor `search_paths`, but cannot use the `SiblingAddresses` address spec because directories at the top of the tree that may not have a BUILD file will cause `SiblingAddresses` to raise an exception. `SiblingAddresses` will now fail if it does not find any matching targets. [ci skip-rust] [ci skip-build-wheels]
f62adc7
to
12388c6
Compare
## Problem `./pants tailor` currently assumes that all targets on which it operates will have a `sources` field. As part of the Go plugin's tailor support in #12406, I would like `tailor` to infer `go_external_module` targets which do not have a `sources` field from the dependencies of `go_module` targets. Attempting to add a `GoExternalModule` target as a `PutativeTarget` caused invocation of `tailor` to raise an exception in `default_sources_for_target_type` because that function could not find a `sources` field. ## Solution Work-around the issue by teaching `tailor` to ignore the lack of a `sources` field if there are no owned sources or triggering sources for the `PutativeTarget`. The exception is now raised in `PutativeTarget.for_target_type` if there are any such sources. `default_sources_for_target_type` just returns an empty tuple if it could not find a `sources` field. This is just a work-around and is not intended as a longer term solution for `tailor` to support target types without `sources`. [ci skip-rust] [ci skip-build-wheels]
[ci skip-rust] [ci skip-build-wheels]
[ci skip-rust] [ci skip-build-wheels]
12388c6
to
d214197
Compare
I rebased the PR now that both blocking PRs have landed on |
ping on review |
[ci skip-rust] [ci skip-build-wheels]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Taking a look now, sorry for the delay. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! I am slightly confused about the sources
field on go_package
. I thought we were moving towards that target not having a sources
field but always owning the entire directory, since that is more idiomatic in Go? Is that future work? It will affect all this.
Yes, that change is coming in a future PR. |
This PR adds support for
./pants tailor
to the Go plugin:go_package
targets from the existence of*.go
files.go_module
targets from the presence ofgo.mod
files.go_external_module
targets based on resolving existinggo_module
targets for their module dependencies. These are written into a separateBUILD.godeps
file so it is easy to delete just the generatedgo_external_module
targets in order to re-run tailor to re-generate.Note: The inference for
go_external_module
targets is necessary because Pants does not currently support dynamic target injection from engine rules and we want to implement dependency inference betweengo_package
andgo_external_module
targets. Since plugins cannot dynamically creatego_external_module
targets, the short term solution is to require users to run./pants tailor
to create the appropriatego_external_module
targets. A future PR will implement dependency inference between these targets. This PR does not try to solve what we would want for this use case in the long term.