Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crate_universe: Don't preform path translation on out_dir #2844

Merged
merged 1 commit into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading