I'm writing a backend that works with the `package...
# plugins
p
I'm writing a backend that works with the
package
goal to package 4 distinct target types. To do this, I need to implement a
PackageFieldSet
. Essentially, I need all the fields on the target, which means I need a
FieldSet
that lists all of the fields on the target. I'm debating between making a
FieldSet
for each target that lists everything, or creating a single
FieldSet
that lists the few fields that are common between the 4 distinct target types. But, I'm not sure what the value of having a
FieldSet
is. From the docs:
A
FieldSet
is a way to specify which Fields your rule needs to use in a typed way that is understood by the engine.
Normally, your rule should simply use
tgt.get()
and
tgt.has_field()
instead of a
FieldSet
. However, for several of the Common plugin tasks, you will instead need to create a
FieldSet
so that the combination of fields you use can be represented by a type understood by the engine.
https://www.pantsbuild.org/v2.17/docs/rules-api-and-target-api#fieldsets What is the value of listing all of the fields in the
FieldSet
? Could I list a bare minimum set in the
FieldSet
, get the original target, and then access the fields on the original target? Why does the engine need the types on the
FieldSet
for packaging? Something to do with caching?
e
At a broad brush, a target in a build file will generally collect more metadata than most goals / rules need; so the field set lets a rule say exactly what it needs - for caching granularity purposes as you guessed.
Basically, a target collects all metadata you need to associate with a file for whatever purpose (for targets with sources). A rule does not care about targets (or need not), it just cares about the metadata it cares about.
Hopefully that makes sense. Basically the odd duck here is target generally since we already have typed fields, save for sources, which could be typed but aren't currently. If they were, most need for targets sub-types internally would probably go away.
p
Ah. I can see the distinction for targets with sources. That makes sense.