Skip to content

Legacy doctest launchers discard Bazel test and runfiles environment variables #4292

Description

@jrandolf

Description

The Unix launcher for a legacy rust_doc_test starts rustdoc through exec env - and restores the recorded action environment. This discards the TEST_* and RUNFILES_* variables that Bazel supplied for the test invocation, including paths needed for runfiles lookup and temporary files. The Windows launcher can also overwrite invocation values with recorded action values.

The child process should receive the current invocation's test/runfiles variables. TMPDIR, TMP and TEMP should point to TEST_TMPDIR when Bazel provides it.

Reproduction steps

A legacy doctest that checks std::env::var("TEST_TMPDIR").is_ok() demonstrates the Unix problem: Bazel supplies that variable to the test, but the launcher removes it before rustdoc runs. Use --//rust/settings:experimental_compile_rustdoc_tests=false to select this path.

The writer regression in #4277 makes the precedence problem explicit. It generates a launcher around /usr/bin/env, records TEST_TMPDIR=action tmp and RUNFILES_DIR=action runfiles, then invokes it with invocation tmp and invocation runfiles plus RUNFILES_MANIFEST_FILE. The child should report the invocation values and preserve spaces in them.

The PR adds this owning target:

bazel test //rust/private/rustdoc:rustdoc_test_writer_test

Its tests cover Unix execution, Windows script generation and a Windows execution case for CI.

Additional context

Proposed fix: #4277. Capture the invocation variables before applying the action environment, then restore them before starting the child.

Related: #4209 requests user-facing env / env_inherit support. This report covers preservation of Bazel's existing test invocation variables; the proposed fix does not add those attributes.

Impact

Legacy doctests lose Bazel's paths for runtime data and temporary files, and can inherit stale paths from the action that generated the launcher.

Bazel and rules_rust version

Affected rules_rust revision: c708b236. The existing regression work used Bazel 9.2.0 on macOS arm64.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions