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

Env Var Expansion and Cleanup #23

Merged
merged 1 commit into from
Oct 27, 2023

Conversation

CauhxMilloy
Copy link
Contributor

TemplateVariableInfo provides a mechanism for custom make variable expansion.

string_flag() contains a simple (pre-built) way to generate flags. This be used with config_setting() and can be set via commandline (without --define). TemplateVariableInfo support was added to string_flag() in bazelbuild/bazel-skylib#440.

Many other Bazel target rules support make variable expansion on many attributes (e.g. env). This PR adds support for TemplateVariableInfo (e.g. via string_flag() or other custom rule) to bats bazel test rules on the env attribute.

Changes:

  • Adding call to ctx.expand_make_variables() in _bats_test_impl().
    • This is done in addition to (after) expansion for $(location ...).
  • Updating :hello_world_test (which tests env attribute usage) to also test flag-driven envs.
  • Adding @bazel_skylib to workspace.
    • Only used to declare/reference string_flag() in tests/BUILD.bazel.
    • While this could have been simply covered by a custom rule (to return a TemplateVariableInfo) in a test-specific .bzl file, it seemed better to just use the common (external/pre-existing) rule.
    • Refenced via git_repository() (instead of http_archive()) as the necessary changes are not yet in a tag/release.
    • Only affects tests, and thus does not cause any extra transitive dependencies on libraries that use this project.
  • Misc other changes:
    • Updating bats-support and bats-assert rules to use glob().
      • Supports newer versions, which separated out contents into multiple .bash files.
      • More flexible than naming exact file names.
    • Replacing attribute dict update() call with dict concat operator |.
    • Renaming some test cases in hello_world.bats.

See https://bazel.build/rules/lib/providers/TemplateVariableInfo, https://bazel.build/docs/configurable-attributes, https://bazel.build/reference/be/general#config_setting, https://bazel.build/extending/config#defining-build-settings

`TemplateVariableInfo` provides a mechanism for custom make variable expansion.

`string_flag()` contains a simple (pre-built) way to generate flags.
This be used with `config_setting()` and can be set via commandline (without `--define`).
`TemplateVariableInfo` support was added to `string_flag()` in bazelbuild/bazel-skylib#440.

Many other Bazel target rules support make variable expansion on many attributes (e.g. `env`).
This PR adds support for `TemplateVariableInfo` (e.g. via `string_flag()`) to bats bazel test rules on the `env` attribute.

Changes:
* Adding call to `ctx.expand_make_variables()` in `_bats_test_impl()`.
  * This is done in addition to (after) expansion for `$(location ...)`.
* Updating `:hello_world_test` (which tests `env` attribute usage) to also test flag-driven envs.
* Adding `@bazel_skylib` to workspace.
  * Only used to declare/reference `string_flag()` in `tests/BUILD.bazel`.
  * While this could have been simply covered by a custom rule (to return a `TemplateVariableInfo`) in a test-specific `.bzl` file, it seemed better to just use the common (external/pre-existing) rule.
  * Refenced via `git_repository()` as the necessary changes are not yet in a tag/release.
  * Only affects tests, and thus does not cause any extra transitive dependencies on libraries that use this project.
* Misc other changes:
  * Updating bats-support and bats-assert rules to use `glob()`.
    * Supports newer versions, which separated out contents into multiple `.bash` files.
    * More flexible than naming exact file names.
  * Replacing attribute dict `update()` call with dict concat operator `|`.
  * Renaming some test cases in `hello_world.bats`.

See https://bazel.build/rules/lib/providers/TemplateVariableInfo, https://bazel.build/docs/configurable-attributes, https://bazel.build/reference/be/general#config_setting, https://bazel.build/extending/config#defining-build-settings
deps.bzl Show resolved Hide resolved
deps.bzl Show resolved Hide resolved
@filmil filmil merged commit 4d1844b into filmil:main Oct 27, 2023
@CauhxMilloy
Copy link
Contributor Author

CauhxMilloy commented Oct 27, 2023

Thanks for the fast review and merge. Can you make a new release/tag with these changes? Thanks!

Edit: I see that you already did. Thanks!

@CauhxMilloy CauhxMilloy deleted the stringFlagsAndCleanup branch March 4, 2024 01:19
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