bazelbuild / bazelbuild/bazel

Allow declaring new private attributes when inheriting in a symbolic macro

Open
#25,055 0 comments 0 reactions 0 assignees View on GitHub
team-Loading-API type: feature request untriaged
Dominant language
Java
Stars
25.8k
Forks
4.6k
Avg merge
2d 18h
Merged PRs (30d)
75

Description

### Description of the feature request:

When defining a symbolic macro based on an existing rule or macro and using attribute inheritance, it's not possible to add a new attribute not present in the rule or macro being inherited.

Adding new attributes may be useful, particularly if they're private. For example, let's say I'm wrapping `java_test` to use my own test runner. I imagine the ideal way to provide my test runner to the macro is via a private atribute, similary to how we would do it if we were defining a rule:

```
my_test_wrapper = macro(
inherit_attrs = java_test,
attrs = {
... // block some attributes via None
"_test_runner": attr.label(
default = "//test-runner",
allow_single_file = True,
),
},
...
)

Error: no such attribute '_test_runner' in 'java_test' rule (did you mean 'use_testrunner'?)
```

While I can understand adding public attributes could not be desired, I think allowing private attributes can be very useful.

### Which category does this issue belong to?

Rules API

### What underlying problem are you trying to solve with this feature?

Creating more powerful macros.

### Which operating system are you running Bazel on?

WSL

### What is the output of `bazel info release`?

release 8.0.0

### If `bazel info release` returns `development version` or `(@non-git)`, tell us how you built Bazel.

_No response_

### What's the output of `git remote get-url origin; git rev-parse HEAD` ?

```text

```

### Have you found anything relevant by searching the web?

_No response_

### Any other information, logs, or outputs that you want to share?

_No response_

Contributor guide

Open the contributing guide

Research direction

The issue names no implementation files or tests. Start by locating Bazel's symbolic macro attribute-inheritance implementation and its tests, then verify the proposed private attribute case using a macro inheriting from java_test; done means a private new attribute is accepted while the existing inheritance behavior remains intact.

Written by the indexing model from the issue text.

Assessment

Domain
build-system
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.