Is there a way to have "anonymous" targets? I'm wo...
# plugins
g
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
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
BOOM that's it. I'll still need it explicitly for 2.14, but that's fine.
Thanks a lot!
f
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
Yeah; that'd work. But I really do want it to be explicit - forgetting to config the base shouldn't lead to broken images 🙂