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
Target generators should not depend on generated targets? #13118
Comments
|
One nuance with the idea that generated targets should depend on their target generator: that will require adding something like #12953 so that the If we don't fix that, then we'd pull in all the sibling files even if they're not needed. Example: thanks to this proposal, the That is, we do want to express the dependency relationship between the generator and generated. But we don't want it to be a traditional dependency where we resolve the |
Arguably a generator target should not have a |
Precisely, that's what #12953 is about. I think I agree. Thanks! |
If this were the case, it would never make sense for the generated targets to depend on the generator, right? There would be no point. Given that, I'm not sure that inverting dependencies from "generator -> generated" to "generated -> generator" makes sense. If there is an alternative implementation of aliases that allows you to depend on all of the files (generated) in a target (generator) without the target depending on them, then maybe it would make sense. But that doesn't seem to be where #13086 is trending. |
Well, it can also still have sources (e.g., |
Exactly. I think it depends on how the target generator works. For For For Maybe there's a better word than "generating sources", like "triggering sources". |
Or adopted_sources? (As they'd be orphan without the generated target "adopting" them) |
Ah ha! A user just pointed out that
That's happening because it's the old context-aware object factory API, and we used different semantics in 2.0 when adding "file targets" (now called generated targets). I continue to think that a generated target depending on its generator is conceptually sound. Re the alias mechanism, I have an idea for how we can refactor the implementation so that we decouple the alias from how we set dependencies. |
This is majorly confusing me with trying to achieve the CLI semantics at https://docs.google.com/document/d/1WWQM-X6kHoSCKwItqf61NiKFWNSlpnTC5QNu3ul9RDk/edit#. Specifically, it confuses me because of this: pants/src/python/pants/backend/go/util_rules/build_pkg.py Lines 278 to 288 in ca35723
We are using dependency inference so that each generated Go package target depends automatically on its owning But, at the same time that we add the dependency on the We need to figure that dependency relationship out, I believe it is blocking fixing the CLI specs. Either we stop adding a dep from generated targets on their |
While I agree that this sounds like it needs to change, I really don't see how it blocks So yea, let's fix this. But |
…f `sources: list[str]` (#14082) To minimize behavior changes while implementing #14075, we want to make sure that `--changed-since=HEAD --changed-dependees=direct` will still claim that all generated `python_requirement` targets are impacted if the `requirements.txt` changed. This would happen naturally if a generated target depended on its target generator: #13118. But that will require a lot more design work and is a big change we're not ready to make. So we can work around this by still having `_python_requirements_file` even with target generators. But before doing that, we should change to `source: str` to actually represent the expected API of the target. Because this is a private API, we make a breaking change. [ci skip-rust] [ci skip-build-wheels]
This is messing up codegen for Go. We currently have pants/src/python/pants/backend/go/util_rules/build_pkg_target.py Lines 194 to 205 in b00b846
Which means that if you depend on I actually no longer think my original proposal is relevant here....even if we fix Instead, I think the only solution is to do what we do what do already do for pants/src/python/pants/backend/python/target_types.py Lines 1066 to 1074 in b00b846
We would rename this to something like |
…er` (#14727) Closes #13118 and #12953. Really that first ticket was about getting `--changed-since` to work properly for generated targets that depend on the contents of a source file like `go.mod` or `requirements.txt`. (Note that this is different than `python_sources` -> `python_source` etc, which don't actually consume the contents of their `sources` during generation.) I originally hypothesized that to do that we would need to stop having target generators depend on generated targets. But that was a red herring. Instead, the simplest solution is to lean into the fix we've used for Python since #9307: generate a distinct target type to "own" the generating sources. Then add a dependency on that target to all the other generated targets. This gives us the exact semantics we want! It's not the most elegant solution—e.g. boilerplate for rule authors—but it solves a real problem well. [ci skip-rust] [ci skip-build-wheels]
(Relates to #13086, but this is a more focused question.)
Currently, a target generator depends on all of its generated targets:
pants/src/python/pants/engine/internals/graph.py
Lines 879 to 886 in 1d23bcc
This was added in #10511 so that target generators can be used as an alias to their generated targets, that you can use the generator as a CLI spec and in
dependencies
field as shorthand for everything generated.But if you disregard that alias use case, it does not make sense for a target generator to depend on a generated target. The role should be reversed, that a generated target depends on its generator.
Concrete example: in Go, a
go_mod
target generates_go_external_package
and (soon)_go_internal_package
targets. When you change the filego.mod
orgo.sum
, it would make sense for./pants --changed-since=HEAD --changed-dependees=transitive
to include all the generated targets - but it won't, because generated targets do not depend on their target generator.It would be problematic if the generator and the generated cyclically depended on each other. Beyond this introducing cycles, it would break
TransitiveTargets
such that a generated target would depend on all its sibling generated targets.From first principles, conceptually, why would a target generator depend on what it generates? That doesn't make intuitive sense to me.
Rather, I believe we modeled it this way to facilitate the alias mechanism of #13086. That suggests it's a leaky implementation detail of the alias mechanism, and we should consider how better to model this.
The text was updated successfully, but these errors were encountered: