fix(crate_universe): fix OUTPUT_BASE env var value format in crates_vendor
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_BASEset, the parsed value frombazel infooutput is used - With
OUTPUT_BASEset, it overrides the parsed value with the correct path
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.