Skip to content

Implicit outputs feature is underdocumented #2882

@dslomov

Description

@dslomov

(originally reported by @alandonovan)
The documentation at
https://bazel.build/versions/master/docs/skylark/lib/globals.html#parameters-22 is vague. It should answer the following questions:

  • What are valid attribute types in %{attr}?
  • How is each type of attribute converted to a string by %{attr}?
  • What happens if the attribute is a sequence, such as %{deps}?
  • What happens if multiple sequence attributes appear in the same template?
  • What's the typical significance of the dict key?

Peeking at the implementation, the answers appear to be:

  • Only strings and lists of strings.
  • strings are unchanged; lists of strings are expanded elementwise
  • "%{x}-%{y}" produces the cross product of lists x and y
  • if the cross product is greater than 1, it's an error.
    if it's empty, there are no implicit outputs.
    otherwise the sole member of the cross product is used.

All this begs the question: what's the point of the cross-product logic if the resulting set has at most one element?

Also: why is it that the 'implicit outputs' function has access to whichever attributes it wants through its parameters AND returns a dict of templates "%{name}-%{srcs}.x" that are then subject to further attribute expansion? It seems redundant.

There are not one but three ad-hoc conversion processes here:

  1. existing_rule
  2. the mechanism that converts rule attributes into arguments to the rule.outputs function
  3. the attributesValue function that converts a rule and a %{foo} pattern to a list of strings.

Ideally there would be one (clearly documented) conversion from attributes to Skylark values to replace #1 and #2. #3 would be replaced by an extremely simple conversion such as "%s" recursively applied to each Skylark value. Anything else---dirname, basename; removal of files extensions, etc) should be done by writing Skylark logic.

Users do not have to write output functions very often. It is better to make them explicit than concise, and doing so lets you simplify the implementation and the spec.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P4This is either out of scope or we don't have bandwidth to review a PR. (No assignee)staleIssues or PRs that are stale (no activity for 30 days)team-DocumentationDocumentation improvements that cannot be directly linked to other team labelsteam-Rules-APIAPI for writing rules/aspects: providers, runfiles, actions, artifactstype: documentation (cleanup)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions