Skip to content

Commit

Permalink
Allow crates_vendor to read the CARGO_BAZEL_DEBUG env var (#2862)
Browse files Browse the repository at this point in the history
Previously the environment variable was discarded. Now users can see
debug info about how crates are being rendered.
  • Loading branch information
UebelAndre authored Sep 13, 2024
1 parent bad49c4 commit 07dc023
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions crate_universe/private/crates_vendor.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,43 @@ load("//rust/platform:triple_mappings.bzl", "SUPPORTED_PLATFORM_TRIPLES")

_UNIX_WRAPPER = """\
#!/usr/bin/env bash
set -euo pipefail
export RUNTIME_PWD="$(pwd)"
if [[ -z "${{BAZEL_REAL:-}}" ]]; then
BAZEL_REAL="$(which bazel || echo 'bazel')"
fi
_ENVIRON=()
_ENVIRON+=(BAZEL_REAL="${{BAZEL_REAL}}")
_ENVIRON+=(BUILD_WORKSPACE_DIRECTORY="${{BUILD_WORKSPACE_DIRECTORY}}")
_ENVIRON+=(PATH="${{PATH}}")
if [[ -n "${{CARGO_BAZEL_DEBUG:-}}" ]]; then
_ENVIRON+=(CARGO_BAZEL_DEBUG="${{CARGO_BAZEL_DEBUG}}")
fi
# The path needs to be preserved to prevent bazel from starting with different
# startup options (requiring a restart of bazel).
# If you provide an empty path, bazel starts itself with
# --default_system_javabase set to the empty string, but if you provide a path,
# it may set it to a value (eg. "/usr/local/buildtools/java/jdk11").
exec env - BAZEL_REAL="${{BAZEL_REAL}}" BUILD_WORKSPACE_DIRECTORY="${{BUILD_WORKSPACE_DIRECTORY}}" PATH="${{PATH}}" {env} \\
"{bin}" {args} "$@"
exec env - \\
${{_ENVIRON[@]}} \\
{env} \\
"{bin}" \\
{args} \\
"$@"
"""

_WINDOWS_WRAPPER = """\
@ECHO OFF
set RUNTIME_PWD=%CD%
{env}
call {bin} {args} %@%
{bin} {args} %*
exit %ERRORLEVEL%
"""

CARGO_BAZEL_GENERATOR_PATH = "CARGO_BAZEL_GENERATOR_PATH"
Expand Down

0 comments on commit 07dc023

Please sign in to comment.