Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
dslomov opened this issue Apr 25, 2017 · 5 comments
Labels
P4 This is either out of scope or we don't have bandwidth to review a PR. (No assignee) stale Issues or PRs that are stale (no activity for 30 days) team-Rules-API API for writing rules/aspects: providers, runfiles, actions, artifacts type: feature request untriaged

Comments

@dslomov
Copy link
Contributor

dslomov commented Apr 25, 2017

(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.

@dslomov dslomov added category: extensibility > skylark P3 We're not considering working on this, but happy to review a PR. (No assignee) labels Apr 25, 2017
@dslomov dslomov added this to the 0.6 milestone Apr 25, 2017
@meisterT meisterT removed this from the 0.6 milestone May 12, 2020
@meisterT
Copy link
Member

closing in favor of #2884

@alandonovan
Copy link
Contributor

There are two separate problems here: this one is a problem with the design; the other one (#2884) is a problem with the documentation.

Please re-open this issue.

@meisterT meisterT reopened this May 15, 2020
@meisterT
Copy link
Member

Thanks for paying attention, re-opened.

@brandjon brandjon changed the title skylark: existing_rule and rule.outputs use different attr -> Skylark conversion logic existing_rule and rule.outputs use different Starlark representations for attributes Feb 15, 2021
@brandjon
Copy link
Member

Ideally existing_rule's attr types should be closely aligned with what you actually pass when instantiating a target. But to avoid ambiguity with respect to labels, we might have to use the Label type in existing_rule (and ensure that Label is valid as input to a target -- I forget offhand if that's the case).

If implicit outputs were to be redesigned, I'd want them to agree with existing_rules and the rest of the loading phase on the representation of attributes. But since we want to ditch implicit outputs, I'm less worried about that case. Regardless, the current design of implicit outputs doesn't inform what we should do for existing_rules very much.

@brandjon brandjon added P4 This is either out of scope or we don't have bandwidth to review a PR. (No assignee) team-Build-Language type: feature request and removed P3 We're not considering working on this, but happy to review a PR. (No assignee) team-Starlark type: documentation (cleanup) labels Feb 15, 2021
@brandjon brandjon added untriaged team-Rules-API API for writing rules/aspects: providers, runfiles, actions, artifacts and removed team-Build-Language labels Nov 4, 2022
@sgowroji sgowroji added the stale Issues or PRs that are stale (no activity for 30 days) label Feb 17, 2023
@sgowroji
Copy link
Member

Hi there! We're doing a clean up of old issues and will be closing this one. Please reopen (or ping me to reopen) if you’d like to discuss anything further. We’ll respond as soon as we have the bandwidth/resources to do so.

@sgowroji sgowroji closed this as not planned Won't fix, can't repro, duplicate, stale Feb 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P4 This is either out of scope or we don't have bandwidth to review a PR. (No assignee) stale Issues or PRs that are stale (no activity for 30 days) team-Rules-API API for writing rules/aspects: providers, runfiles, actions, artifacts type: feature request untriaged
Projects
None yet
Development

No branches or pull requests

6 participants