Skip to content

Commit

Permalink
crate_universe: Don't preform path translation on out_dir (#2844)
Browse files Browse the repository at this point in the history
Bug: #2801
  • Loading branch information
konkers committed Sep 13, 2024
1 parent 07dc023 commit 30df2ef
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 5 deletions.
43 changes: 43 additions & 0 deletions .bazelci/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
- "--"
- "//..."
Expand Down Expand Up @@ -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
Expand Down
16 changes: 11 additions & 5 deletions crate_universe/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
}
Expand Down

0 comments on commit 30df2ef

Please sign in to comment.