Skip to content

existing_rule and rule.outputs use different Starlark representations for attributes #2883

@dslomov

Description

@dslomov

(this issue originally reported by @alandonovan)

Observe the output of the program below:

$ cat t/BUILD
load(":inc.bzl", "r")

r(
    name = "myrule",
    src = "a",
)

print(type(native.existing_rule("myrule")["src"]))  # "string"

$ cat t/inc.bzl

def _implicit_outputs(src):
  return {"": "%s" % type(src)} # "Label"

def _implementation():
  pass

r = rule(
    outputs = _implicit_outputs,
    implementation = _implementation,
    attrs = {
        "src": attr.label(),
    },
)

$ blaze query t:*
WARNING: /google/src/cloud/adonovan/gbuild/google3/t/BUILD:8:1: string.
//t:Label
//t:myrule
//t:a
//t:BUILD

The existing_rule function converts a rule's attribute dictionary back into Skylark form. Similarly, the rule.outputs function converts some rule attributes into Skylark form. However, they use different conversion logic. For example, existing_rule converts labels to strings whereas rule.outputs preserves labels as labels.

This is confusing to users, since it requires twice as much documentation to specify (or would do, if either conversion were actually documented), and confusing to implementors, since it requires twice as much logic to implement.

They should use the same logic.

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-Rules-APIAPI for writing rules/aspects: providers, runfiles, actions, artifactstype: feature requestuntriaged

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions