rules_rust icon indicating copy to clipboard operation
rules_rust copied to clipboard

fix(crate_universe): fix OUTPUT_BASE env var value format in crates_vendor

Open georgesfarah opened this issue 5 months ago • 1 comments

Summary

Fix the OUTPUT_BASE environment variable override in crate_universe/src/cli/vendor.rs — it has never worked correctly.

Bug

The bazel info output parser splits each line on : and stores only the part after the colon as the HashMap value:

let (k, v) = line.split_at(line.find(':')?);
Ok((k.to_string(), (v[1..]).trim().to_string()))

So for output like output_base: /data/output, the HashMap contains {"output_base" => "/data/output"}.

However, the OUTPUT_BASE env var override stores the full formatted string as the value:

bazel_info.insert("output_base".to_owned(), format!("output_base: {}", path));

This produces {"output_base" => "output_base: /data/output"}. When TryFrom later converts this to a PathBuf via .map(Into::into), it produces PathBuf("output_base: /data/output") — an invalid path.

Fix

Store the raw path string without the prefix:

bazel_info.insert("output_base".to_owned(), path);

Also extract parse_bazel_info from try_new so the parsing and env var override logic can be unit-tested without spawning a bazel info subprocess.

Test plan

Added test_parse_bazel_info_output_base_env_override which verifies:

  • Without OUTPUT_BASE set, the parsed value from bazel info output is used
  • With OUTPUT_BASE set, it overrides the parsed value with the correct path

georgesfarah avatar Jun 25 '26 09:06 georgesfarah

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

google-cla[bot] avatar Jun 25 '26 09:06 google-cla[bot]