Skip to content

Commit

Permalink
Show a direnv error after bazel clean (#3)
Browse files Browse the repository at this point in the history
Fixes #2
  • Loading branch information
fmeum authored May 31, 2024
1 parent df1300d commit 6f82101
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
3 changes: 3 additions & 0 deletions bazel_env.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down
5 changes: 5 additions & 0 deletions examples/.envrc
Original file line number Diff line number Diff line change
@@ -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
7 changes: 6 additions & 1 deletion status.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6f82101

Please sign in to comment.