From 73f086bdea4cd64ba6cc498b47c204233ddf3c38 Mon Sep 17 00:00:00 2001 From: Adam Cozzette Date: Wed, 3 Jun 2026 09:55:13 -0700 Subject: [PATCH 01/10] feat: add $(rlocation ...) syntax as a cleaner alternative to $$RUNFILES_DIR/$(rlocationpath ...) Co-Authored-By: Claude Sonnet 4.6 --- examples/rspack/BUILD.bazel | 2 +- examples/vite3/BUILD.bazel | 2 +- examples/vite6/BUILD.bazel | 2 +- examples/webpack_cli/BUILD.bazel | 2 +- js/private/coverage/bundle/BUILD.bazel | 2 +- js/private/devserver/src/BUILD.bazel | 2 +- js/private/js_binary.bzl | 39 +++++++++++++++++++++--- js/private/test/node-patches/BUILD.bazel | 2 +- js/private/worker/src/BUILD.bazel | 2 +- npm/private/lifecycle/src/BUILD.bazel | 2 +- 10 files changed, 43 insertions(+), 14 deletions(-) diff --git a/examples/rspack/BUILD.bazel b/examples/rspack/BUILD.bazel index e61fe6c7e..79f307fd8 100644 --- a/examples/rspack/BUILD.bazel +++ b/examples/rspack/BUILD.bazel @@ -27,7 +27,7 @@ bin.rspack( fixed_args = [ "build", "--config", - "$$RUNFILES_DIR/$(rlocationpath :rspack_config)", + "$(rlocation :rspack_config)", ], use_execroot_entry_point = False, ) diff --git a/examples/vite3/BUILD.bazel b/examples/vite3/BUILD.bazel index 8503520ab..2d632b67b 100644 --- a/examples/vite3/BUILD.bazel +++ b/examples/vite3/BUILD.bazel @@ -30,7 +30,7 @@ vite_bin.vite( fixed_args = [ "build", "--config", - "$$RUNFILES_DIR/$(rlocationpath :vite-config)", + "$(rlocation :vite-config)", ], out_dirs = ["build"], ) diff --git a/examples/vite6/BUILD.bazel b/examples/vite6/BUILD.bazel index 86f48bfb5..0b649dc6f 100644 --- a/examples/vite6/BUILD.bazel +++ b/examples/vite6/BUILD.bazel @@ -30,7 +30,7 @@ vite_bin.vite( fixed_args = [ "build", "--config", - "$$RUNFILES_DIR/$(rlocationpath :vite-config)", + "$(rlocation :vite-config)", ], out_dirs = ["build"], ) diff --git a/examples/webpack_cli/BUILD.bazel b/examples/webpack_cli/BUILD.bazel index 733d8d93e..5f9e744c9 100644 --- a/examples/webpack_cli/BUILD.bazel +++ b/examples/webpack_cli/BUILD.bazel @@ -35,7 +35,7 @@ bin.webpack_cli( data = [":webpack-config"], fixed_args = [ "--config", - "$$RUNFILES_DIR/$(rlocationpath :webpack-config)", + "$(rlocation :webpack-config)", ], log_level = "debug", ) diff --git a/js/private/coverage/bundle/BUILD.bazel b/js/private/coverage/bundle/BUILD.bazel index 34ce8bb5f..7eafe931f 100644 --- a/js/private/coverage/bundle/BUILD.bazel +++ b/js/private/coverage/bundle/BUILD.bazel @@ -27,7 +27,7 @@ rollup_bin.rollup( fixed_args = [ "c8.js", "--config", - "$$RUNFILES_DIR/$(rlocationpath :config)", + "$(rlocation :config)", "--format", "cjs", "--file", diff --git a/js/private/devserver/src/BUILD.bazel b/js/private/devserver/src/BUILD.bazel index a8ae232f1..27d48a5bc 100644 --- a/js/private/devserver/src/BUILD.bazel +++ b/js/private/devserver/src/BUILD.bazel @@ -22,7 +22,7 @@ rollup_bin.rollup( fixed_args = [ "js_run_devserver.mjs", "--config", - "$$RUNFILES_DIR/$(rlocationpath :config)", + "$(rlocation :config)", "--format", "es", "--file", diff --git a/js/private/js_binary.bzl b/js/private/js_binary.bzl index 3e864f8fd..2ce059be7 100644 --- a/js/private/js_binary.bzl +++ b/js/private/js_binary.bzl @@ -72,20 +72,23 @@ _ATTRS = { "env": attr.string_dict( doc = """Environment variables of the action. - Subject to [$(location)](https://bazel.build/reference/be/make-variables#predefined_label_variables) + Subject to `$(rlocation ...)`, + [$(location)](https://bazel.build/reference/be/make-variables#predefined_label_variables) and ["Make variable"](https://bazel.build/reference/be/make-variables) substitution if `expand_env` is set to True. """, ), "expand_args": attr.bool( default = True, - doc = """Enables [$(location)](https://bazel.build/reference/be/make-variables#predefined_label_variables) + doc = """Enables `$(rlocation ...)`, + [$(location)](https://bazel.build/reference/be/make-variables#predefined_label_variables) and ["Make variable"](https://bazel.build/reference/be/make-variables) substitution for `fixed_args`. This comes at some analysis-time cost even for a set of args that does not have any expansions.""", ), "expand_env": attr.bool( default = True, - doc = """Enables [$(location)](https://bazel.build/reference/be/make-variables#predefined_label_variables) + doc = """Enables `$(rlocation ...)`, + [$(location)](https://bazel.build/reference/be/make-variables#predefined_label_variables) and ["Make variable"](https://bazel.build/reference/be/make-variables) substitution for `env`. This comes at some analysis-time cost even for a set of envs that does not have any expansions.""", @@ -94,7 +97,8 @@ _ATTRS = { doc = """Fixed command line arguments to pass to the Node.js when this binary target is executed. - Subject to [$(location)](https://bazel.build/reference/be/make-variables#predefined_label_variables) + Subject to `$(rlocation ...)`, + [$(location)](https://bazel.build/reference/be/make-variables#predefined_label_variables) and ["Make variable"](https://bazel.build/reference/be/make-variables) substitution if `expand_args` is set to True. Unlike the built-in `args`, which are only passed to the target when it is @@ -275,8 +279,33 @@ _ENV_SET = """export {var}={quoted_value}""" _ENV_SET_IFF_NOT_SET = """if [[ -z "${{{var}:-}}" ]]; then export {var}={quoted_value}; fi""" _NODE_OPTION = """JS_BINARY__NODE_OPTIONS+=(\"{value}\")""" +def _expand_rlocation_refs(value): + """Pre-processes $(rlocation