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 adding arguments to Rules #1310

Merged
merged 1 commit into from
Aug 3, 2022
Merged

Conversation

illicitonion
Copy link
Contributor

What type of PR is this?

Feature

What package or component does this PR mostly affect?

rule

What does this PR do? Why is it needed?

Allow adding arguments to Rules

This allows supporting patterns like maybe, which take a
rule-to-instantiate as a positional argument.

@achew22
Copy link
Member

achew22 commented Jul 29, 2022

I think the code looks good, but I'm curious about where this would be used? Is it exclusively being used for the maybe macro? It is the only rule or macro in the entire ecosystem that I can think of that has an argument you don't explicitly invoke with kwargs.

One of the goals in my mind (I'm just some guy, so huge grain of salt) is that I want gazelle to generate "what I would have written." When combined with the fact that BUILD files are read a lot more than they are written, unnamed arguments in rules feels like it's going to impede understanding and clarity. Is this a situation where we should add special logic to make it only work for the maybe macro instead of everywhere? I could easily imagine a world where someone writes rules_foo and you just have to remember that the parameter ordering is name, srcs, deps, tags, testonly, visibility and that would be hard to interpret without looking up every time.

@illicitonion
Copy link
Contributor Author

I'm curious about where this would be used

Internally, we have a number of maybe-style macros which are used effectively as decorators; things like:

requires_network(
    java_test,
    name = "FooTest",
    ...
)

These end up following the maybe-like pattern of calling the first argument with some modification of the kwargs passed. In the above example, we set up some exec_properties and tags to control where the test may run when executing remotely, and whether it may be cached.

I agree that in general positional args aren't very clear, but for this particular pattern it seems pretty reasonable (and our users are already familiar with maybe :)).

@achew22
Copy link
Member

achew22 commented Jul 29, 2022

Out of curiosity, why is this superior to making a java_test_requires_networking macro, or making a java_test macro that has a requires_networking = True attribute? That's an extremely common pattern that I've seen through my codebases.

@illicitonion
Copy link
Contributor Author

Mostly orthogonality - the same reason http_archive doesn't have a maybe_http_archive or an unless_already_exists attribute. Aside from the dozens of off the shelf per-language test rules we'd need to create wrappers for (and possibly force to be used across many repositories owned by different teams), we have several individual teams who write their own test rules. Having to create so many macros, and duplicate the logic across all of them (or have to remember to call some library in each of them), is a lot more work, and makes it more likely that it gets missed for some test rule.

This is particularly bad where different teams write different rules; for instance, consider a team which maintains an execution environment - if they need to change how they tell the execution environment details (e.g. a different platform property), knowing that there's one place this is done, rather than needing to audit whether a bunch of rules are doing the right thing, simplifies things a lot.

rule/rule_test.go Show resolved Hide resolved
This allows supporting patterns like `maybe`, which take a
rule-to-instantiate as a positional argument.
@achew22 achew22 merged commit 2b30bc4 into bazelbuild:master Aug 3, 2022
@illicitonion illicitonion deleted the add-arg branch August 3, 2022 10:02
illicitonion added a commit to illicitonion/bazel-gazelle that referenced this pull request Aug 16, 2022
Since bazelbuild#1310 we can add
arguments to rules - this PR allows symbols to be loaded for these
arguments.
blico pushed a commit that referenced this pull request Aug 30, 2022
Since #1310 we can add
arguments to rules - this PR allows symbols to be loaded for these
arguments.
kreempuff added a commit to kreempuff/rules_unreal_engine that referenced this pull request Jan 31, 2023
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [bazel_gazelle](https://togithub.com/bazelbuild/bazel-gazelle) |
http_archive | minor | `v0.26.0` -> `v0.29.0` |

---

### Release Notes

<details>
<summary>bazelbuild/bazel-gazelle</summary>

###
[`v0.29.0`](https://togithub.com/bazelbuild/bazel-gazelle/releases/tag/v0.29.0)

[Compare
Source](https://togithub.com/bazelbuild/bazel-gazelle/compare/v0.28.0...v0.29.0)

#### What's Changed

- bzlmod: Update Publish to BCR app config by
[@&#8203;fmeum](https://togithub.com/fmeum) in
[bazelbuild/bazel-gazelle#1363
- Fix: Skip default_visibility extension logic if no BUILD.bazel file
present by [@&#8203;dnathe4th](https://togithub.com/dnathe4th) in
[bazelbuild/bazel-gazelle#1364
- fix updateStmt makeslice panic by
[@&#8203;pcj](https://togithub.com/pcj) in
[bazelbuild/bazel-gazelle#1371
- bzlmod: Add missing `strip_prefix` field to `source.template.json` by
[@&#8203;fmeum](https://togithub.com/fmeum) in
[bazelbuild/bazel-gazelle#1375
- feat: support common test args in `gazelle_generation_test` by
[@&#8203;cgrindel](https://togithub.com/cgrindel) in
[bazelbuild/bazel-gazelle#1377
- Make the new facts pacakge public by
[@&#8203;linzhp](https://togithub.com/linzhp) in
[bazelbuild/bazel-gazelle#1378
- fix: add timeout message for `gazelle_generation_test` by
[@&#8203;cgrindel](https://togithub.com/cgrindel) in
[bazelbuild/bazel-gazelle#1383
- bzlmod: Add missing repository metadata by
[@&#8203;fmeum](https://togithub.com/fmeum) in
[bazelbuild/bazel-gazelle#1387
- Replace `cfg = "host"` with `cfg = "exec"` by
[@&#8203;fmeum](https://togithub.com/fmeum) in
[bazelbuild/bazel-gazelle#1395
- upgrade rules_go to 0.37.0 by
[@&#8203;JamyDev](https://togithub.com/JamyDev) in
[bazelbuild/bazel-gazelle#1386
- Fix embed on windows by [@&#8203;st3veV](https://togithub.com/st3veV)
in
[bazelbuild/bazel-gazelle#1361
- Update bazel-skylib to 1.3.0. by
[@&#8203;benjaminp](https://togithub.com/benjaminp) in
[bazelbuild/bazel-gazelle#1367
- Fix Directives anchor by [@&#8203;jmthvt](https://togithub.com/jmthvt)
in
[bazelbuild/bazel-gazelle#1353
- Use `patch` from `@bazel_tools//tools/build_defs/repo` by
[@&#8203;tyler-french](https://togithub.com/tyler-french) in
[bazelbuild/bazel-gazelle#1381
- Add link to BenchSci's rules_nodejs_gazelle extension by
[@&#8203;ColinHeathman](https://togithub.com/ColinHeathman) in
[bazelbuild/bazel-gazelle#1369
- bzlmod: Skip Go modules available as Bazel modules by
[@&#8203;fmeum](https://togithub.com/fmeum) in
[bazelbuild/bazel-gazelle#1403
- repo: opportunistically populate RemoteCache from go.mod by
[@&#8203;jayconrod](https://togithub.com/jayconrod) in
[bazelbuild/bazel-gazelle#1396
- Fix Gazelle with `--incompatible_disallow_empty_glob` by
[@&#8203;fmeum](https://togithub.com/fmeum) in
[bazelbuild/bazel-gazelle#1405
- chore: remove experimental warning from bzlmod module by
[@&#8203;alexeagle](https://togithub.com/alexeagle) in
[bazelbuild/bazel-gazelle#1406
- chore: add Swift extension to language list by
[@&#8203;cgrindel](https://togithub.com/cgrindel) in
[bazelbuild/bazel-gazelle#1412
- Update everything for release prep, add releaser tool by
[@&#8203;dnathe4th](https://togithub.com/dnathe4th) in
[bazelbuild/bazel-gazelle#1373
- adding go version and std_package_list to releaser by
[@&#8203;linzhp](https://togithub.com/linzhp) in
[bazelbuild/bazel-gazelle#1415

#### New Contributors

- [@&#8203;damingerdai](https://togithub.com/damingerdai) made their
first contribution in
[bazelbuild/bazel-gazelle#1362
- [@&#8203;st3veV](https://togithub.com/st3veV) made their first
contribution in
[bazelbuild/bazel-gazelle#1361
- [@&#8203;benjaminp](https://togithub.com/benjaminp) made their first
contribution in
[bazelbuild/bazel-gazelle#1367
- [@&#8203;jmthvt](https://togithub.com/jmthvt) made their first
contribution in
[bazelbuild/bazel-gazelle#1353
- [@&#8203;ColinHeathman](https://togithub.com/ColinHeathman) made their
first contribution in
[bazelbuild/bazel-gazelle#1369

**Full Changelog**:
bazelbuild/bazel-gazelle@v0.28.0...v0.29.0

###
[`v0.28.0`](https://togithub.com/bazelbuild/bazel-gazelle/releases/tag/v0.28.0)

[Compare
Source](https://togithub.com/bazelbuild/bazel-gazelle/compare/v0.27.0...v0.28.0)

#### What's Changed

- language/proto: gen_known_imports creates structs instead of function
calls by [@&#8203;eric-skydio](https://togithub.com/eric-skydio) in
[bazelbuild/bazel-gazelle#1333
- Add DoneGeneratingRules language hook by
[@&#8203;illicitonion](https://togithub.com/illicitonion) in
[bazelbuild/bazel-gazelle#1325
- Allow configuring timeout of generation tests by
[@&#8203;illicitonion](https://togithub.com/illicitonion) in
[bazelbuild/bazel-gazelle#1324
- bug: Allow user-specified tags on gazelle rule by
[@&#8203;Helcaraxan](https://togithub.com/Helcaraxan) in
[bazelbuild/bazel-gazelle#1308
- Replace \_get_auth with Bazel's read_user_netrc by
[@&#8203;linzhp](https://togithub.com/linzhp) in
[bazelbuild/bazel-gazelle#1338
- language/go should consider default_visibility set by OtherGen
([#&#8203;783](https://togithub.com/bazelbuild/bazel-gazelle/issues/783))
by [@&#8203;dnathe4th](https://togithub.com/dnathe4th) in
[bazelbuild/bazel-gazelle#1341
- fix: pass `visibility` attribute for `gazelle` macro to resulting
`sh_binary` by [@&#8203;cgrindel](https://togithub.com/cgrindel) in
[bazelbuild/bazel-gazelle#1340
- Add additional bzlmod requirements to allow grpc protobufs to work by
[@&#8203;shs96c](https://togithub.com/shs96c) in
[bazelbuild/bazel-gazelle#1345
- bzlmod: Simplify go_grpc_library support by
[@&#8203;fmeum](https://togithub.com/fmeum) in
[bazelbuild/bazel-gazelle#1346
- bzlmod: Add support for custom `go_proto_library` compilers by
[@&#8203;fmeum](https://togithub.com/fmeum) in
[bazelbuild/bazel-gazelle#1348
- Add visibility extension to support recursive default_visibility
([#&#8203;783](https://togithub.com/bazelbuild/bazel-gazelle/issues/783))
by [@&#8203;dnathe4th](https://togithub.com/dnathe4th) in
[bazelbuild/bazel-gazelle#1343
- Make `gazelle_generation_test` respect out suffix when generating
golden files by [@&#8203;blorente](https://togithub.com/blorente) in
[bazelbuild/bazel-gazelle#1352
- Add size argument to `gazelle_generation_test` by
[@&#8203;charlesoconor](https://togithub.com/charlesoconor) in
[bazelbuild/bazel-gazelle#1351

#### New Contributors

- [@&#8203;eric-skydio](https://togithub.com/eric-skydio) made their
first contribution in
[bazelbuild/bazel-gazelle#1333
- [@&#8203;dnathe4th](https://togithub.com/dnathe4th) made their first
contribution in
[bazelbuild/bazel-gazelle#1341
- [@&#8203;cgrindel](https://togithub.com/cgrindel) made their first
contribution in
[bazelbuild/bazel-gazelle#1340
- [@&#8203;shs96c](https://togithub.com/shs96c) made their first
contribution in
[bazelbuild/bazel-gazelle#1345
- [@&#8203;blorente](https://togithub.com/blorente) made their first
contribution in
[bazelbuild/bazel-gazelle#1352
- [@&#8203;charlesoconor](https://togithub.com/charlesoconor) made their
first contribution in
[bazelbuild/bazel-gazelle#1351

**Full Changelog**:
bazelbuild/bazel-gazelle@v0.27.0...v0.28.0

###
[`v0.27.0`](https://togithub.com/bazelbuild/bazel-gazelle/releases/tag/v0.27.0)

[Compare
Source](https://togithub.com/bazelbuild/bazel-gazelle/compare/v0.26.0...v0.27.0)

#### What's Changed

- Use repo-relative labels everywhere by
[@&#8203;fmeum](https://togithub.com/fmeum) in
[bazelbuild/bazel-gazelle#1294
- Fix RST URL errors for rules_jvm by
[@&#8203;qaisjp](https://togithub.com/qaisjp) in
[bazelbuild/bazel-gazelle#1296
- bzlmod prototype by [@&#8203;fmeum](https://togithub.com/fmeum) in
[bazelbuild/bazel-gazelle#1266
- bzlmod: Do not create a repository with an invalid name by
[@&#8203;fmeum](https://togithub.com/fmeum) in
[bazelbuild/bazel-gazelle#1304
- language/go: Add support for //go:build tags by
[@&#8203;thempatel](https://togithub.com/thempatel) in
[bazelbuild/bazel-gazelle#1243
- Unwrap `go list -m -json` errors correctly by
[@&#8203;fmeum](https://togithub.com/fmeum) in
[bazelbuild/bazel-gazelle#1301
- Make one more label repo-relative by
[@&#8203;fmeum](https://togithub.com/fmeum) in
[bazelbuild/bazel-gazelle#1297
- bzlmod: Add go_deps.from_file by
[@&#8203;fmeum](https://togithub.com/fmeum) in
[bazelbuild/bazel-gazelle#1300
- language: add BaseLang by
[@&#8203;sluongng](https://togithub.com/sluongng) in
[bazelbuild/bazel-gazelle#1303
- Allow adding arguments to Rules by
[@&#8203;illicitonion](https://togithub.com/illicitonion) in
[bazelbuild/bazel-gazelle#1310
- Register and parse flags before calling Kinds/Loads by
[@&#8203;illicitonion](https://togithub.com/illicitonion) in
[bazelbuild/bazel-gazelle#1318
- SortMacro() should also sort the Loads by
[@&#8203;tyler-french](https://togithub.com/tyler-french) in
[bazelbuild/bazel-gazelle#1321
- bzlmod: Fix canonical label literal after Bazel change by
[@&#8203;fmeum](https://togithub.com/fmeum) in
[bazelbuild/bazel-gazelle#1322
- update-repos: don't add repositories declared with gazelle:repository…
by [@&#8203;tyler-french](https://togithub.com/tyler-french) in
[bazelbuild/bazel-gazelle#1326
- Look in call args for loadable symbols by
[@&#8203;illicitonion](https://togithub.com/illicitonion) in
[bazelbuild/bazel-gazelle#1317
- SortMacro() should also sort rules by Kind() by
[@&#8203;tyler-french](https://togithub.com/tyler-french) in
[bazelbuild/bazel-gazelle#1327
- bzlmod: Fix missing .format in go_deps by
[@&#8203;fmeum](https://togithub.com/fmeum) in
[bazelbuild/bazel-gazelle#1330
- bzlmod: Depend on rules_proto by
[@&#8203;fmeum](https://togithub.com/fmeum) in
[bazelbuild/bazel-gazelle#1331

#### New Contributors

- [@&#8203;qaisjp](https://togithub.com/qaisjp) made their first
contribution in
[bazelbuild/bazel-gazelle#1296

**Full Changelog**:
bazelbuild/bazel-gazelle@v0.26.0...v0.27.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://app.renovatebot.com/dashboard#github/kreempuff/rules_unreal_engine).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNC4xMTcuMSIsInVwZGF0ZWRJblZlciI6IjM0LjExNy4xIn0=-->
illicitonion added a commit to illicitonion/bazel-gazelle that referenced this pull request Jan 22, 2024
bazelbuild#1310 added support for
adding args from Gazelle, so you can express things like:

```
maybe(
    java_test,
    ...
)
```

But `map_kind` doesn't currently get applied to these args.

This PR adds that application.
illicitonion added a commit to illicitonion/bazel-gazelle that referenced this pull request Jan 22, 2024
bazelbuild#1310 added support for
adding args from Gazelle, so you can express things like:

```
maybe(
    java_test,
    ...
)
```

But `map_kind` doesn't currently get applied to these args.

This PR adds that application.
illicitonion added a commit to illicitonion/bazel-gazelle that referenced this pull request Jan 22, 2024
bazelbuild#1310 added support for
adding args from Gazelle, so you can express things like:

```
maybe(
    java_test,
    ...
)
```

But `map_kind` doesn't currently get applied to these args.

This PR adds that application.
illicitonion added a commit to illicitonion/bazel-gazelle that referenced this pull request Jan 25, 2024
bazelbuild#1310 added support for
adding args from Gazelle, so you can express things like:

```
maybe(
    java_test,
    ...
)
```

But `map_kind` doesn't currently get applied to these args.

This PR adds that application.
illicitonion added a commit to illicitonion/bazel-gazelle that referenced this pull request Apr 2, 2024
bazelbuild#1310 added support for
adding args from Gazelle, so you can express things like:

```
maybe(
    java_test,
    ...
)
```

But `map_kind` doesn't currently get applied to these args.

This PR adds that application.
fmeum pushed a commit to illicitonion/bazel-gazelle that referenced this pull request Apr 9, 2024
bazelbuild#1310 added support for
adding args from Gazelle, so you can express things like:

```
maybe(
    java_test,
    ...
)
```

But `map_kind` doesn't currently get applied to these args.

This PR adds that application.
fmeum pushed a commit that referenced this pull request Apr 9, 2024
* Apply map_kind to args as well as rule kinds

#1310 added support for
adding args from Gazelle, so you can express things like:

```
maybe(
    java_test,
    ...
)
```

But `map_kind` doesn't currently get applied to these args.

This PR adds that application.

* Panic -> Error

* Sort imports in testdata
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants