-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Only remove fingerprints and build script artifacts of the requested package #10621
Merged
bors
merged 5 commits into
rust-lang:master
from
CosmicHorrorDev:more-precise-artifact-cleanup
Nov 1, 2022
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1f2d5ef
Only remove fingerprints and build script artifacts of the requested …
CosmicHorrorDev 738f084
Merge branch 'master' of github.com:rust-lang/cargo into more-precise…
CosmicHorrorDev a6d0e96
Add test to verify functionality
CosmicHorrorDev 604aeb5
Address review comments
CosmicHorrorDev 2ebcc75
Actually make test effective
CosmicHorrorDev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -96,33 +96,113 @@ fn clean_multiple_packages_in_glob_char_path() { | |
.build(); | ||
let foo_path = &p.build_dir().join("debug").join("deps"); | ||
|
||
#[cfg(not(target_env = "msvc"))] | ||
let file_glob = "foo-*"; | ||
|
||
#[cfg(target_env = "msvc")] | ||
let file_glob = "foo.pdb"; | ||
|
||
// Assert that build artifacts are produced | ||
p.cargo("build").run(); | ||
assert_ne!(get_build_artifacts(foo_path).len(), 0); | ||
assert_ne!(get_build_artifacts(foo_path, file_glob).len(), 0); | ||
|
||
// Assert that build artifacts are destroyed | ||
p.cargo("clean -p foo").run(); | ||
assert_eq!(get_build_artifacts(foo_path).len(), 0); | ||
assert_eq!(get_build_artifacts(foo_path, file_glob).len(), 0); | ||
} | ||
|
||
fn get_build_artifacts(path: &PathBuf) -> Vec<Result<PathBuf, GlobError>> { | ||
fn get_build_artifacts(path: &PathBuf, file_glob: &str) -> Vec<Result<PathBuf, GlobError>> { | ||
let pattern = path.to_str().expect("expected utf-8 path"); | ||
let pattern = glob::Pattern::escape(pattern); | ||
|
||
#[cfg(not(target_env = "msvc"))] | ||
const FILE: &str = "foo-*"; | ||
|
||
#[cfg(target_env = "msvc")] | ||
const FILE: &str = "foo.pdb"; | ||
|
||
let path = PathBuf::from(pattern).join(FILE); | ||
let path = PathBuf::from(pattern).join(file_glob); | ||
let path = path.to_str().expect("expected utf-8 path"); | ||
glob::glob(path) | ||
.expect("expected glob to run") | ||
.into_iter() | ||
.collect::<Vec<Result<PathBuf, GlobError>>>() | ||
} | ||
|
||
#[cargo_test] | ||
fn clean_p_only_cleans_specified_package() { | ||
let p = project() | ||
.file( | ||
"Cargo.toml", | ||
r#" | ||
[workspace] | ||
members = [ | ||
"foo", | ||
"foo_core", | ||
"foo-base", | ||
] | ||
"#, | ||
) | ||
.file("foo/Cargo.toml", &basic_manifest("foo", "0.1.0")) | ||
.file("foo/src/lib.rs", "//! foo") | ||
.file("foo_core/Cargo.toml", &basic_manifest("foo_core", "0.1.0")) | ||
.file("foo_core/src/lib.rs", "//! foo_core") | ||
.file("foo-base/Cargo.toml", &basic_manifest("foo-base", "0.1.0")) | ||
.file("foo-base/src/lib.rs", "//! foo-base") | ||
.build(); | ||
|
||
let fingerprint_path = &p.build_dir().join("debug").join(".fingerprint"); | ||
|
||
p.cargo("build -p foo -p foo_core -p foo-base").run(); | ||
|
||
let mut fingerprint_names = get_fingerprints_without_hashes(fingerprint_path); | ||
|
||
// Artifacts present for all after building | ||
assert!(fingerprint_names.iter().any(|e| e == "foo")); | ||
let num_foo_core_artifacts = fingerprint_names | ||
.iter() | ||
.filter(|&e| e == "foo_core") | ||
.count(); | ||
assert_ne!(num_foo_core_artifacts, 0); | ||
let num_foo_base_artifacts = fingerprint_names | ||
.iter() | ||
.filter(|&e| e == "foo-base") | ||
.count(); | ||
assert_ne!(num_foo_base_artifacts, 0); | ||
|
||
p.cargo("clean -p foo").run(); | ||
|
||
fingerprint_names = get_fingerprints_without_hashes(fingerprint_path); | ||
|
||
// Cleaning `foo` leaves artifacts for the others | ||
assert!(!fingerprint_names.iter().any(|e| e == "foo")); | ||
assert_eq!( | ||
fingerprint_names | ||
.iter() | ||
.filter(|&e| e == "foo_core") | ||
.count(), | ||
num_foo_core_artifacts, | ||
); | ||
assert_eq!( | ||
fingerprint_names | ||
.iter() | ||
.filter(|&e| e == "foo-base") | ||
.count(), | ||
num_foo_core_artifacts, | ||
); | ||
} | ||
|
||
fn get_fingerprints_without_hashes(fingerprint_path: &Path) -> Vec<String> { | ||
std::fs::read_dir(fingerprint_path) | ||
.expect("Build dir should be readable") | ||
.filter_map(|entry| entry.ok()) | ||
.map(|entry| { | ||
let name = entry.file_name(); | ||
let name = name | ||
.into_string() | ||
.expect("fingerprint name should be UTF-8"); | ||
name.rsplit_once('-') | ||
.expect("Name should contain at least one hyphen") | ||
.0 | ||
.to_owned() | ||
Comment on lines
+198
to
+201
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's a bit unfortunate we duplicate implementation logic here in test helper 😞. If you come up with a better way to avoid |
||
}) | ||
.collect() | ||
} | ||
|
||
#[cargo_test] | ||
fn clean_release() { | ||
let p = project() | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we need to escape this path, otherwise a path that contains one of the glob special characters (like [ or ?) may end up doing weird things. I think there's a helper for that kind of escaping in cargo somewhere already since I think we had another bug (also in clean?) related up that in the past.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes: #10072
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the heads up! I can work on addressing that later this week unless someone else beats me to it