diff --git a/bazel_env.bzl b/bazel_env.bzl index 868cae2..a40e023 100644 --- a/bazel_env.bzl +++ b/bazel_env.bzl @@ -285,6 +285,9 @@ def _bazel_env_rule_impl(ctx): is_executable = True, substitutions = { "{{name}}": ctx.label.name, + # We assume that the target is in the main repo and want the label to look like this: + # //:bazel_env + "{{label}}": str(ctx.label).removeprefix("@@"), "{{bin_dir}}": unique_name_tool.dirname, "{{unique_name_tool}}": unique_name_tool.basename, "{{has_tools}}": str(bool(tool_infos)), diff --git a/examples/.envrc b/examples/.envrc index a9ffa3a..9657666 100644 --- a/examples/.envrc +++ b/examples/.envrc @@ -1 +1,6 @@ +# Generated by 'bazel run //:bazel_env' +watch_file bazel-out/bazel_env-opt/bin/bazel_env/bin PATH_add bazel-out/bazel_env-opt/bin/bazel_env/bin +if [[ ! -d bazel-out/bazel_env-opt/bin/bazel_env/bin ]]; then + log_error "ERROR[bazel_env.bzl]: Run 'bazel run //:bazel_env' to regenerate bazel-out/bazel_env-opt/bin/bazel_env/bin" +fi diff --git a/status.sh.tpl b/status.sh.tpl index 5728c26..0b57c98 100644 --- a/status.sh.tpl +++ b/status.sh.tpl @@ -25,7 +25,12 @@ else cat << 'EOF' ⚠️ {{name}}'s bin directory is not in PATH. Please add the following snippet to a .envrc file next to your MODULE.bazel file: - PATH_add {{bin_dir}} +# Generated by 'bazel run {{label}}' +watch_file {{bin_dir}} +PATH_add {{bin_dir}} +if [[ ! -d {{bin_dir}} ]]; then + log_error "ERROR[bazel_env.bzl]: Run 'bazel run {{label}}' to regenerate {{bin_dir}}" +fi Then allowlist it with 'direnv allow .envrc'. EOF