<#18067 Expressive target declarations in BUILD fi...
# github-notifications
q
#18067 Expressive target declarations in BUILD files New discussion created by kaos This idea is a bit on the wild side, but I think it may have potential.. It serves two main purposes: a) Flexibility in field values and meta field values b) Target-lookups from within BUILD files. So, here's a rough straw-man sketch of this idea:
Copy code
# some/BUILD

@python_sources
def some_name():
    # Function calls in the target body provides field values.
    
    # Set description and tags
    description("foo bar")
    tags("this", "and", "that")

    # Optional dependencies based on if `src/foo:bar` is tagged with `foo`
    # The `target[ADDR]` syntax requests a single target with ADDR
    if "foo" in target["src/foo:bar"].tags:
        dependencies("quux", "qorgi")

    # Append additional tags from all targets in `src/proj/lib::`
    # The `targets[SPEC]` syntax requests all targets for the `SPEC`.
    for t in targets["src/proj/lib::"]:
        # `self` allows access to the field values currently being defined in this target body.
        tags(*self.tags, *t.tags)
The idea being that this syntax would be fully compatible with the regular syntax, and only used for cases where the extra flexibility is needed. Also, this is just sci-fi day-dreaming on my part--not something that I'm actually in need of today. Declaring the field values as function calls, allows attaching additional information to the field values in a natural way. Also the arguments to the method itself may be used for oob pragma style information/control what-not.
Copy code
@target 
def example(pragma="declaration"):
  field(value, meta=data, additional=info)
pantsbuild/pants