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

Support macros/rules packed within bazel struct #1524

Merged
merged 2 commits into from
May 11, 2023

Conversation

birunts
Copy link
Contributor

@birunts birunts commented May 4, 2023

What type of PR is this?
Feature

What package or component does this PR mostly affect?
cmd/gazelle

What does this PR do? Why is it needed?
Bazel allows to pack rules or macros within a struct, e.g. convenience interfaces for select()
(see https://github.com/bazelbuild/bazel-skylib/blob/main/lib/selects.bzl)

Changes adds support for macros/rules packed within bazel struct.

Load statements are not able to insert struct symbols. This is needed in case some macros are packaged into a struct like selects.config_setting_group
(see https://github.com/bazelbuild/bazel-skylib/blob/main/lib/selects.bzl#L245).

Any would like to generate selects.config_setting_group rule with rule.LoadInfo:

{
	Name: "@bazel_skylib//lib:selects.bzl",
	Symbols: []string{
		"selects",
	},
},

needs a load statement in BUILD.bazel of:

# GOOD
load("@bazel_skylib//lib:selects.bzl", "selects")

but NOT

# WRONG
load("@bazel_skylib//lib:selects.bzl", "selects.config_setting_group")

Which issues(s) does this PR fix?
Fixes #1523

Other notes for review

@birunts birunts force-pushed the struct_rules branch 2 times, most recently from c2b442a to 188f5f9 Compare May 5, 2023 13:34
Copy link
Member

@fmeum fmeum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks solid, just left a single comment.

birunts added 2 commits May 11, 2023 07:52
This change adds test for handling macros/rules
which are packed into the struct e.g.:
  `selects.config_setting_group`
Bazel allows to pack rules or macros within a struct,
e.g. convenience interfaces for `select()`
(see https://github.com/bazelbuild/bazel-skylib/blob/main/lib/selects.bzl)

Currently Gazelle is not able to recognize of rules which consist of:
`struct_name.rule_name` e.g. `selects.config_setting_group`.
When such rule is present inside BUILD.bazel file, parsing is not
able to recognize it and is simply ignored like it was never present.
Thus merging mechanizm won't work for it and duplicated rule will
be created (assuming thus rule was creaded before).

All above highly prevents of using and creating such rules
like `selects.config_setting_group`.

This change adds support for recognizing macros packed within
struct correctly.
Copy link
Member

@fmeum fmeum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks solid, just left a single comment.

@fmeum fmeum merged commit 55532d5 into bazel-contrib:master May 11, 2023
@birunts birunts deleted the struct_rules branch May 18, 2023 12:41
renovate bot referenced this pull request in kreempuff/rules_unreal_engine May 27, 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.30.0` -> `v0.31.0` |

---

### ⚠ Dependency Lookup Warnings ⚠

Warnings were logged while processing this repo. Please check the
Dependency Dashboard for more information.

---

### Release Notes

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

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

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

#### What's Changed

- feat: allow passing GIT_CONFIG_COUNT and it's related configs by
[@&#8203;manuelnaranjo](https://togithub.com/manuelnaranjo) in
[https://github.com/bazelbuild/bazel-gazelle/pull/1462](https://togithub.com/bazelbuild/bazel-gazelle/pull/1462)
- feat(bzlmod): add `module_override` tag to allow patching in go_deps
by [@&#8203;tyler-french](https://togithub.com/tyler-french) in
[https://github.com/bazelbuild/bazel-gazelle/pull/1500](https://togithub.com/bazelbuild/bazel-gazelle/pull/1500)
- fix typo `build_proto_file_mode` in message by
[@&#8203;tyler-french](https://togithub.com/tyler-french) in
[https://github.com/bazelbuild/bazel-gazelle/pull/1504](https://togithub.com/bazelbuild/bazel-gazelle/pull/1504)
- fix: support running within a dir named workspace by
[@&#8203;jbedard](https://togithub.com/jbedard) in
[https://github.com/bazelbuild/bazel-gazelle/pull/1498](https://togithub.com/bazelbuild/bazel-gazelle/pull/1498)
- fix: check for gazelle command before adding -repo_config flag by
[@&#8203;cgrindel](https://togithub.com/cgrindel) in
[https://github.com/bazelbuild/bazel-gazelle/pull/1501](https://togithub.com/bazelbuild/bazel-gazelle/pull/1501)
- language/go: Infer prefix from go.mod by
[@&#8203;fmeum](https://togithub.com/fmeum) in
[https://github.com/bazelbuild/bazel-gazelle/pull/1497](https://togithub.com/bazelbuild/bazel-gazelle/pull/1497)
- don't overwrite directives by
[@&#8203;tyler-french](https://togithub.com/tyler-french) in
[https://github.com/bazelbuild/bazel-gazelle/pull/1503](https://togithub.com/bazelbuild/bazel-gazelle/pull/1503)
- Support Bzlmod for gazelle itself by
[@&#8203;fmeum](https://togithub.com/fmeum) in
[https://github.com/bazelbuild/bazel-gazelle/pull/1509](https://togithub.com/bazelbuild/bazel-gazelle/pull/1509)
- language/go: Add windows arm64 as a known platform. by
[@&#8203;connyay](https://togithub.com/connyay) in
[https://github.com/bazelbuild/bazel-gazelle/pull/1507](https://togithub.com/bazelbuild/bazel-gazelle/pull/1507)
- Adding lifecycle manager by
[@&#8203;linzhp](https://togithub.com/linzhp) in
[https://github.com/bazelbuild/bazel-gazelle/pull/1475](https://togithub.com/bazelbuild/bazel-gazelle/pull/1475)
- Disable protobuf generation for more modules by
[@&#8203;seh](https://togithub.com/seh) in
[https://github.com/bazelbuild/bazel-gazelle/pull/1514](https://togithub.com/bazelbuild/bazel-gazelle/pull/1514)
- Support '~' in label repo by
[@&#8203;mark-thm](https://togithub.com/mark-thm) in
[https://github.com/bazelbuild/bazel-gazelle/pull/1518](https://togithub.com/bazelbuild/bazel-gazelle/pull/1518)
- language/go: Handle `unix` build tag. by
[@&#8203;connyay](https://togithub.com/connyay) in
[https://github.com/bazelbuild/bazel-gazelle/pull/1512](https://togithub.com/bazelbuild/bazel-gazelle/pull/1512)
- Pass data arg through to sh_binary if defined by
[@&#8203;Preston4tw](https://togithub.com/Preston4tw) in
[https://github.com/bazelbuild/bazel-gazelle/pull/1483](https://togithub.com/bazelbuild/bazel-gazelle/pull/1483)
- remove circular override hack by
[@&#8203;tyler-french](https://togithub.com/tyler-french) in
[https://github.com/bazelbuild/bazel-gazelle/pull/1515](https://togithub.com/bazelbuild/bazel-gazelle/pull/1515)
- Add major version suffix download example by
[@&#8203;kriswuollett](https://togithub.com/kriswuollett) in
[https://github.com/bazelbuild/bazel-gazelle/pull/1453](https://togithub.com/bazelbuild/bazel-gazelle/pull/1453)
- Relax parsing of labels by
[@&#8203;purkhusid](https://togithub.com/purkhusid) in
[https://github.com/bazelbuild/bazel-gazelle/pull/1508](https://togithub.com/bazelbuild/bazel-gazelle/pull/1508)
- bzlmod: Add `build_file_generation` to `gazelle_override` by
[@&#8203;fmeum](https://togithub.com/fmeum) in
[https://github.com/bazelbuild/bazel-gazelle/pull/1522](https://togithub.com/bazelbuild/bazel-gazelle/pull/1522)
- Fix incremental build of to bootstrap Gazelle by
[@&#8203;fmeum](https://togithub.com/fmeum) in
[https://github.com/bazelbuild/bazel-gazelle/pull/1529](https://togithub.com/bazelbuild/bazel-gazelle/pull/1529)
- Support macros/rules packed within bazel `struct` by
[@&#8203;birunts](https://togithub.com/birunts) in
[https://github.com/bazelbuild/bazel-gazelle/pull/1524](https://togithub.com/bazelbuild/bazel-gazelle/pull/1524)
- Prefer non-proto over proto deps in external repos by
[@&#8203;fmeum](https://togithub.com/fmeum) in
[https://github.com/bazelbuild/bazel-gazelle/pull/1537](https://togithub.com/bazelbuild/bazel-gazelle/pull/1537)
- bzlmod: Return `extension_metadata` to automate `use_repo` fixes by
[@&#8203;fmeum](https://togithub.com/fmeum) in
[https://github.com/bazelbuild/bazel-gazelle/pull/1511](https://togithub.com/bazelbuild/bazel-gazelle/pull/1511)
- Fix `go:embed` failing to add `embedsrcs` for subdirectories named
build by [@&#8203;sgavinio](https://togithub.com/sgavinio) in
[https://github.com/bazelbuild/bazel-gazelle/pull/1539](https://togithub.com/bazelbuild/bazel-gazelle/pull/1539)
- Remove support for godep and dep by
[@&#8203;sluongng](https://togithub.com/sluongng) in
[https://github.com/bazelbuild/bazel-gazelle/pull/1541](https://togithub.com/bazelbuild/bazel-gazelle/pull/1541)
- Avoid putting -repo_config after directories by
[@&#8203;linzhp](https://togithub.com/linzhp) in
[https://github.com/bazelbuild/bazel-gazelle/pull/1544](https://togithub.com/bazelbuild/bazel-gazelle/pull/1544)
- Dropping -args by [@&#8203;linzhp](https://togithub.com/linzhp) in
[https://github.com/bazelbuild/bazel-gazelle/pull/1546](https://togithub.com/bazelbuild/bazel-gazelle/pull/1546)

#### New Contributors

- [@&#8203;connyay](https://togithub.com/connyay) made their first
contribution in
[https://github.com/bazelbuild/bazel-gazelle/pull/1507](https://togithub.com/bazelbuild/bazel-gazelle/pull/1507)
- [@&#8203;mark-thm](https://togithub.com/mark-thm) made their first
contribution in
[https://github.com/bazelbuild/bazel-gazelle/pull/1518](https://togithub.com/bazelbuild/bazel-gazelle/pull/1518)
- [@&#8203;Preston4tw](https://togithub.com/Preston4tw) made their first
contribution in
[https://github.com/bazelbuild/bazel-gazelle/pull/1483](https://togithub.com/bazelbuild/bazel-gazelle/pull/1483)
- [@&#8203;kriswuollett](https://togithub.com/kriswuollett) made their
first contribution in
[https://github.com/bazelbuild/bazel-gazelle/pull/1453](https://togithub.com/bazelbuild/bazel-gazelle/pull/1453)
- [@&#8203;purkhusid](https://togithub.com/purkhusid) made their first
contribution in
[https://github.com/bazelbuild/bazel-gazelle/pull/1508](https://togithub.com/bazelbuild/bazel-gazelle/pull/1508)
- [@&#8203;birunts](https://togithub.com/birunts) made their first
contribution in
[https://github.com/bazelbuild/bazel-gazelle/pull/1524](https://togithub.com/bazelbuild/bazel-gazelle/pull/1524)
- [@&#8203;sgavinio](https://togithub.com/sgavinio) made their first
contribution in
[https://github.com/bazelbuild/bazel-gazelle/pull/1539](https://togithub.com/bazelbuild/bazel-gazelle/pull/1539)

**Full Changelog**:
bazel-contrib/bazel-gazelle@v0.30.0...v0.31.0

</details>

---

### Configuration

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

🚦 **Automerge**: Enabled.

♻ **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:eyJjcmVhdGVkSW5WZXIiOiIzNS4xMDIuNCIsInVwZGF0ZWRJblZlciI6IjM1LjEwMi40IiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9-->
renovate bot referenced this pull request in cgrindel/bazel-starlib May 27, 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.30.0` -> `v0.31.0` |

---

### Release Notes

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

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

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

#### What's Changed

- feat: allow passing GIT_CONFIG_COUNT and it's related configs by
[@&#8203;manuelnaranjo](https://togithub.com/manuelnaranjo) in
[https://github.com/bazelbuild/bazel-gazelle/pull/1462](https://togithub.com/bazelbuild/bazel-gazelle/pull/1462)
- feat(bzlmod): add `module_override` tag to allow patching in go_deps
by [@&#8203;tyler-french](https://togithub.com/tyler-french) in
[https://github.com/bazelbuild/bazel-gazelle/pull/1500](https://togithub.com/bazelbuild/bazel-gazelle/pull/1500)
- fix typo `build_proto_file_mode` in message by
[@&#8203;tyler-french](https://togithub.com/tyler-french) in
[https://github.com/bazelbuild/bazel-gazelle/pull/1504](https://togithub.com/bazelbuild/bazel-gazelle/pull/1504)
- fix: support running within a dir named workspace by
[@&#8203;jbedard](https://togithub.com/jbedard) in
[https://github.com/bazelbuild/bazel-gazelle/pull/1498](https://togithub.com/bazelbuild/bazel-gazelle/pull/1498)
- fix: check for gazelle command before adding -repo_config flag by
[@&#8203;cgrindel](https://togithub.com/cgrindel) in
[https://github.com/bazelbuild/bazel-gazelle/pull/1501](https://togithub.com/bazelbuild/bazel-gazelle/pull/1501)
- language/go: Infer prefix from go.mod by
[@&#8203;fmeum](https://togithub.com/fmeum) in
[https://github.com/bazelbuild/bazel-gazelle/pull/1497](https://togithub.com/bazelbuild/bazel-gazelle/pull/1497)
- don't overwrite directives by
[@&#8203;tyler-french](https://togithub.com/tyler-french) in
[https://github.com/bazelbuild/bazel-gazelle/pull/1503](https://togithub.com/bazelbuild/bazel-gazelle/pull/1503)
- Support Bzlmod for gazelle itself by
[@&#8203;fmeum](https://togithub.com/fmeum) in
[https://github.com/bazelbuild/bazel-gazelle/pull/1509](https://togithub.com/bazelbuild/bazel-gazelle/pull/1509)
- language/go: Add windows arm64 as a known platform. by
[@&#8203;connyay](https://togithub.com/connyay) in
[https://github.com/bazelbuild/bazel-gazelle/pull/1507](https://togithub.com/bazelbuild/bazel-gazelle/pull/1507)
- Adding lifecycle manager by
[@&#8203;linzhp](https://togithub.com/linzhp) in
[https://github.com/bazelbuild/bazel-gazelle/pull/1475](https://togithub.com/bazelbuild/bazel-gazelle/pull/1475)
- Disable protobuf generation for more modules by
[@&#8203;seh](https://togithub.com/seh) in
[https://github.com/bazelbuild/bazel-gazelle/pull/1514](https://togithub.com/bazelbuild/bazel-gazelle/pull/1514)
- Support '~' in label repo by
[@&#8203;mark-thm](https://togithub.com/mark-thm) in
[https://github.com/bazelbuild/bazel-gazelle/pull/1518](https://togithub.com/bazelbuild/bazel-gazelle/pull/1518)
- language/go: Handle `unix` build tag. by
[@&#8203;connyay](https://togithub.com/connyay) in
[https://github.com/bazelbuild/bazel-gazelle/pull/1512](https://togithub.com/bazelbuild/bazel-gazelle/pull/1512)
- Pass data arg through to sh_binary if defined by
[@&#8203;Preston4tw](https://togithub.com/Preston4tw) in
[https://github.com/bazelbuild/bazel-gazelle/pull/1483](https://togithub.com/bazelbuild/bazel-gazelle/pull/1483)
- remove circular override hack by
[@&#8203;tyler-french](https://togithub.com/tyler-french) in
[https://github.com/bazelbuild/bazel-gazelle/pull/1515](https://togithub.com/bazelbuild/bazel-gazelle/pull/1515)
- Add major version suffix download example by
[@&#8203;kriswuollett](https://togithub.com/kriswuollett) in
[https://github.com/bazelbuild/bazel-gazelle/pull/1453](https://togithub.com/bazelbuild/bazel-gazelle/pull/1453)
- Relax parsing of labels by
[@&#8203;purkhusid](https://togithub.com/purkhusid) in
[https://github.com/bazelbuild/bazel-gazelle/pull/1508](https://togithub.com/bazelbuild/bazel-gazelle/pull/1508)
- bzlmod: Add `build_file_generation` to `gazelle_override` by
[@&#8203;fmeum](https://togithub.com/fmeum) in
[https://github.com/bazelbuild/bazel-gazelle/pull/1522](https://togithub.com/bazelbuild/bazel-gazelle/pull/1522)
- Fix incremental build of to bootstrap Gazelle by
[@&#8203;fmeum](https://togithub.com/fmeum) in
[https://github.com/bazelbuild/bazel-gazelle/pull/1529](https://togithub.com/bazelbuild/bazel-gazelle/pull/1529)
- Support macros/rules packed within bazel `struct` by
[@&#8203;birunts](https://togithub.com/birunts) in
[https://github.com/bazelbuild/bazel-gazelle/pull/1524](https://togithub.com/bazelbuild/bazel-gazelle/pull/1524)
- Prefer non-proto over proto deps in external repos by
[@&#8203;fmeum](https://togithub.com/fmeum) in
[https://github.com/bazelbuild/bazel-gazelle/pull/1537](https://togithub.com/bazelbuild/bazel-gazelle/pull/1537)
- bzlmod: Return `extension_metadata` to automate `use_repo` fixes by
[@&#8203;fmeum](https://togithub.com/fmeum) in
[https://github.com/bazelbuild/bazel-gazelle/pull/1511](https://togithub.com/bazelbuild/bazel-gazelle/pull/1511)
- Fix `go:embed` failing to add `embedsrcs` for subdirectories named
build by [@&#8203;sgavinio](https://togithub.com/sgavinio) in
[https://github.com/bazelbuild/bazel-gazelle/pull/1539](https://togithub.com/bazelbuild/bazel-gazelle/pull/1539)
- Remove support for godep and dep by
[@&#8203;sluongng](https://togithub.com/sluongng) in
[https://github.com/bazelbuild/bazel-gazelle/pull/1541](https://togithub.com/bazelbuild/bazel-gazelle/pull/1541)
- Avoid putting -repo_config after directories by
[@&#8203;linzhp](https://togithub.com/linzhp) in
[https://github.com/bazelbuild/bazel-gazelle/pull/1544](https://togithub.com/bazelbuild/bazel-gazelle/pull/1544)
- Dropping -args by [@&#8203;linzhp](https://togithub.com/linzhp) in
[https://github.com/bazelbuild/bazel-gazelle/pull/1546](https://togithub.com/bazelbuild/bazel-gazelle/pull/1546)

#### New Contributors

- [@&#8203;connyay](https://togithub.com/connyay) made their first
contribution in
[https://github.com/bazelbuild/bazel-gazelle/pull/1507](https://togithub.com/bazelbuild/bazel-gazelle/pull/1507)
- [@&#8203;mark-thm](https://togithub.com/mark-thm) made their first
contribution in
[https://github.com/bazelbuild/bazel-gazelle/pull/1518](https://togithub.com/bazelbuild/bazel-gazelle/pull/1518)
- [@&#8203;Preston4tw](https://togithub.com/Preston4tw) made their first
contribution in
[https://github.com/bazelbuild/bazel-gazelle/pull/1483](https://togithub.com/bazelbuild/bazel-gazelle/pull/1483)
- [@&#8203;kriswuollett](https://togithub.com/kriswuollett) made their
first contribution in
[https://github.com/bazelbuild/bazel-gazelle/pull/1453](https://togithub.com/bazelbuild/bazel-gazelle/pull/1453)
- [@&#8203;purkhusid](https://togithub.com/purkhusid) made their first
contribution in
[https://github.com/bazelbuild/bazel-gazelle/pull/1508](https://togithub.com/bazelbuild/bazel-gazelle/pull/1508)
- [@&#8203;birunts](https://togithub.com/birunts) made their first
contribution in
[https://github.com/bazelbuild/bazel-gazelle/pull/1524](https://togithub.com/bazelbuild/bazel-gazelle/pull/1524)
- [@&#8203;sgavinio](https://togithub.com/sgavinio) made their first
contribution in
[https://github.com/bazelbuild/bazel-gazelle/pull/1539](https://togithub.com/bazelbuild/bazel-gazelle/pull/1539)

**Full Changelog**:
bazel-contrib/bazel-gazelle@v0.30.0...v0.31.0

</details>

---

### Configuration

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

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR is behind base branch, 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/cgrindel/bazel-starlib).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNS4xMDIuNCIsInVwZGF0ZWRJblZlciI6IjM1LjEwMi40IiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
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.

support macros/rules packed within bazel struct
2 participants