Skip to content

Commit

Permalink
[Rolling release] Do not forward legacy cmd.exe variables to the se…
Browse files Browse the repository at this point in the history
…rver (bazelbuild#24500)

This fixes startup failures such as:
```
ERROR: While parsing option --client_env==C:=C:\Users\wyv: Variable definitions must be in the form of a 'name=value' assignment
```

Fixes bazelbuild#24448

Closes bazelbuild#24451.

PiperOrigin-RevId: 699115724
Change-Id: Id7a2445e82b24384e9ade0c92ddb343f00e9ab2b

Co-authored-by: Fabian Meumertzheim <fabian@meumertzhe.im>
  • Loading branch information
keertk and fmeum authored Nov 26, 2024
1 parent f3761b7 commit 4754de2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 42 deletions.
9 changes: 8 additions & 1 deletion src/main/cpp/option_processor_windows.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,14 @@ static void PreprocessEnvString(std::string* env_str) {
#endif // defined(__CYGWIN__)

static bool IsValidEnvName(std::string_view s) {
std::string_view name = s.substr(0, s.find('='));
std::size_t first_equal = s.find('=');
if (first_equal == 0) {
// Skip over legacy environment variables that start with '=', e.g. '=C:'
// These are set by cmd.exe and can't be parsed by the Bazel server if
// passed into --client_env.
return false;
}
std::string_view name = s.substr(0, first_equal);
return std::all_of(name.begin(), name.end(), [](char c) {
return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') ||
(c >= '0' && c <= '9') || c == '_' || c == '(' || c == ')';
Expand Down
41 changes: 0 additions & 41 deletions src/test/shell/integration/run_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -678,47 +678,6 @@ EOF
fi
}

function test_run_under_command_change_preserves_cache() {
if $is_windows; then
echo "This test requires --run_under to be able to run echo."
return
fi

local -r pkg="pkg${LINENO}"
mkdir -p "${pkg}"
cat > "$pkg/BUILD" <<'EOF'
load(":defs.bzl", "my_rule")
my_rule(
name = "my_rule",
)
EOF
cat > "$pkg/defs.bzl" <<'EOF'
def _my_rule_impl(ctx):
print("my_rule is being analyzed")
out = ctx.actions.declare_file(ctx.label.name)
ctx.actions.write(out, "echo 'from rule'", is_executable = True)
return [DefaultInfo(executable = out)]
my_rule = rule(
implementation = _my_rule_impl,
executable = True,
)
EOF

bazel run "${pkg}:my_rule" >$TEST_log 2>&1 \
|| fail "expected run to pass"
expect_log "my_rule is being analyzed"
expect_log "from rule"
expect_not_log "from run_under"

# Use > to clear the previous log.
bazel run --run_under="echo 'from run_under' &&" "${pkg}:my_rule" >$TEST_log 2>&1 \
|| fail "expected run to pass"
expect_not_log "my_rule is being analyzed"
expect_log "from rule"
expect_log "from run_under"
}

function test_build_id_env_var() {
local -r pkg="pkg${LINENO}"
mkdir -p "${pkg}"
Expand Down

0 comments on commit 4754de2

Please sign in to comment.