From d1a965735ecee008c203285c1ef37088d322c1fb Mon Sep 17 00:00:00 2001 From: Erik Gilling Date: Fri, 6 Sep 2024 12:05:35 -0700 Subject: [PATCH] crate_universe: Don't preform path translation on `out_dir` Bug: #2801 --- .bazelci/presubmit.yml | 43 +++++++++++++++++++++++++++++++++++++ crate_universe/src/utils.rs | 16 +++++++++----- 2 files changed, 54 insertions(+), 5 deletions(-) diff --git a/.bazelci/presubmit.yml b/.bazelci/presubmit.yml index 0d1da3ee2e..a08e71c25e 100644 --- a/.bazelci/presubmit.yml +++ b/.bazelci/presubmit.yml @@ -13,6 +13,9 @@ nightly_aspects_flags: &nightly_aspects_flags - "--config=clippy" bzlmod_flags: &bzlmod_flags - "--lockfile_mode=error" +bzlmod_plus_repo_names_flags: &bzlmod_plus_repo_names_flags + # `--lockfile_mode=error` is omitted because the repo names leak into the lock file. + - "--incompatible_use_plus_in_repo_names" single_rust_channel_targets: &single_rust_channel_targets - "--" - "//..." @@ -753,6 +756,46 @@ tasks: - "@rules_rust//tools/rust_analyzer:gen_rust_project" test_targets: - "//..." + ubuntu2004_bzlmod_plus_repo_names_bcr: + name: bzlmod BCR presubmit w/ incompatible flags + # A newer version than is specified in the .bazel_version file is needed for + # --incompatible_use_plus_in_repo_names' + bazel: *minimum_bazel_version + platform: ubuntu2004 + working_directory: examples/bzlmod/hello_world + test_flags: *bzlmod_plus_repo_names_flags + run_targets: + - "//third-party:vendor" + - "@rules_rust//tools/rust_analyzer:gen_rust_project" + test_targets: + - "//..." + macos_bzlmod_plus_repo_names_bcr: + name: bzlmod BCR presubmit w/ incompatible flags + # A newer version than is specified in the .bazel_version file is needed for + # --incompatible_use_plus_in_repo_names' + bazel: *minimum_bazel_version + platform: macos + working_directory: examples/bzlmod/hello_world + test_flags: *bzlmod_plus_repo_names_flags + run_targets: + - "//third-party:vendor" + - "@rules_rust//tools/rust_analyzer:gen_rust_project" + test_targets: + - "//..." + windows_bzlmod_plus_repo_names_bcr: + name: bzlmod BCR presubmit w/ incompatible flags + # A newer version than is specified in the .bazel_version file is needed for + # --incompatible_use_plus_in_repo_names' + bazel: *minimum_bazel_version + platform: windows + working_directory: examples/bzlmod/hello_world + test_flags: *bzlmod_plus_repo_names_flags + run_targets: + - "//third-party:vendor" + build_targets: + - "@rules_rust//tools/rust_analyzer:gen_rust_project" + test_targets: + - "//..." bzlmod_no_cargo: name: Cargo-less bzlmod platform: ubuntu2004 diff --git a/crate_universe/src/utils.rs b/crate_universe/src/utils.rs index d625e0572c..041b8f5655 100644 --- a/crate_universe/src/utils.rs +++ b/crate_universe/src/utils.rs @@ -34,7 +34,6 @@ pub(crate) fn normalize_cargo_file_paths( outputs .into_iter() .map(|(path, content)| { - let path = out_dir.join(path); // Get Path Str and Parent Path Str so we can rename the root file let original_path_str = path.to_str().expect("All file paths should be strings"); let original_parent_path_str = path @@ -43,16 +42,23 @@ pub(crate) fn normalize_cargo_file_paths( .to_str() .expect("All file paths should be strings"); - let new_path = if original_parent_path_str.contains('+') { + let path = if original_parent_path_str.contains('+') { let new_parent_file_path = sanitize_repository_name(original_parent_path_str); - std::fs::rename(original_parent_path_str, new_parent_file_path) - .expect("Could not rename paths"); + std::fs::rename( + out_dir.join(original_parent_path_str), + out_dir.join(new_parent_file_path), + ) + .expect("Could not rename paths"); PathBuf::from(&original_path_str.replace('+', "-")) } else { path }; - (new_path, content) + // In recent versions of Bazel, canonical repository paths may contain (+) + // symbols so it is important to apply the transformation only to `outputs` + // and leave `out_dir` untouched. + let path = out_dir.join(path); + (path, content) }) .collect() }