https://pantsbuild.org/ logo
#plugins
Title
# plugins
g

gorgeous-winter-99296

03/18/2023, 4:39 PM
Is there a way to have "anonymous" targets? I'm working on replicating
FROM scratch
in my container backend. I did a very rough impl like this:
Copy code
oci_empty_image(name="empty")

file(name="numbers", source="numbers.csv")

oci_image_build(
   name="data",
   base=[":empty"], 
   packages=[":numbers"],
)
But the extra targtet is a bit unnecessary, so I'm trying to condense it a bit. What I'd want is something that's still explicit, maybe
base=[empty()]
or similar. I know I can solve this with strings and manual shenanigans - but that would end up needing handling in a bunch of places, and breaks things like
pants dependees
. If it's a target my fieldsets all just "work" (using a dummy scalar field as a marker, admittedly). Any thoughts/prior art? 🙂
This is the neatest I've gotten...
Copy code
base=[f':{oci_empty_image(name="empty").name}']
Which is... icky.
It also creates lots of empty pointless base image targets... I'd want all of them to alias to the same "global target" if they can't be anonymous. It makes no sense for these to be addressable apart from as a marker for the "empty base".
f

fast-nail-55400

03/18/2023, 9:30 PM
You can use the "synthetic targets" union to let your plugin create such targets. You can even then have dependency inference infer that target if base is not specified.
(assuming you wanted to solve this with targets)
g

gorgeous-winter-99296

03/18/2023, 11:21 PM
BOOM that's it. I'll still need it explicitly for 2.14, but that's fine.
Thanks a lot!
f

fast-nail-55400

03/19/2023, 10:02 AM
another way would be to have a data model inside your plugin code that is created from targets but which are not targets themselves. Then you could supply that "base image" model whenever
base
is not set in a target. For example, in the Go plugin, the various targets are converted to
BuildGoPackageTargetRequest
which is a DAG of package build requests without any reference to targets including build requests for SDK packages (which are not represented as targets).
g

gorgeous-winter-99296

03/19/2023, 10:29 AM
Yeah; that'd work. But I really do want it to be explicit - forgetting to config the base shouldn't lead to broken images 🙂
3 Views