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

Allow private attributes as outputs template placeholders #4366

Closed
mboes opened this issue Dec 29, 2017 · 5 comments
Closed

Allow private attributes as outputs template placeholders #4366

mboes opened this issue Dec 29, 2017 · 5 comments
Labels
P4 This is either out of scope or we don't have bandwidth to review a PR. (No assignee) type: feature request

Comments

@mboes
Copy link
Contributor

mboes commented Dec 29, 2017

Description of the feature request:

Consider the following rule:

my_rule = rule(
  _my_rule_impl,
  outputs = {
    "conf": "%{name}-%{_version}.conf",
  },
  attrs = { ..., "_version": attr.string(default = "1.0.0") },
)

This definition doesn't work. It fails with:

For attribute 'conf' in outputs: Invalid placeholder(s) in template

The reason is that _version is a private attribute. But citing private attributes in outputs sounds legit to me, since the spec of the outputs is a property of rule that itself has a private attribute. I could work around this problem using declare_file etc, so it sounds to me like an arbitrary limitation that private variables can't be cited in the outputs template.

Environment info

  • Bazel version (output of bazel info release): release 0.9.0- (@non-git)

Have you found anything relevant by searching the web?

No relevant GitHub issues that I could find, except possibly #2467.

mboes added a commit to tweag/rules_haskell that referenced this issue Dec 29, 2017
@hlopko hlopko added category: extensibility > skylark P3 We're not considering working on this, but happy to review a PR. (No assignee) type: feature request labels Jan 2, 2018
@brandjon
Copy link
Member

brandjon commented Mar 5, 2018

This happens because private attributes are internally name-mangled to make them (almost) inaccessible to users in BUILD files. Perversely, you can actually use them in templates if you access them as %{$version} instead of %{_version}. I don't recommend relying on that behavior as we'll surely want to break it (eventually) and use %{_version} instead.

@laurentlb
Copy link
Contributor

Recommendation is to avoid outputs = {...} and instead create the files with ctx.actions.declare_file. This is much more flexible.

@laurentlb laurentlb added P4 This is either out of scope or we don't have bandwidth to review a PR. (No assignee) team-Starlark and removed P3 We're not considering working on this, but happy to review a PR. (No assignee) category: extensibility > skylark labels Nov 21, 2018
@laurentlb
Copy link
Contributor

cc @c-parsons

@ittaiz
Copy link
Member

ittaiz commented Nov 21, 2018 via email

@c-parsons
Copy link
Contributor

The document heading for #6241 covers reasons for an imminent deprecation of rule()'s outputs parameter, and links to some best practices.

As such, I think we can close this issue. (Feel free to comment /discuss within #6241 or its document, though!)

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) type: feature request
Projects
None yet
Development

No branches or pull requests

6 participants