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

Fix freshness checks for build scripts on renamed dirs #8497

Merged
merged 1 commit into from
Jul 17, 2020
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
6 changes: 1 addition & 5 deletions src/cargo/core/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -873,11 +873,7 @@ impl<'cfg> Workspace<'cfg> {
MaybePackage::Package(ref p) => p.clone(),
MaybePackage::Virtual(_) => continue,
};
let mut src = PathSource::new(
pkg.manifest_path(),
pkg.package_id().source_id(),
self.config,
);
let mut src = PathSource::new(pkg.root(), pkg.package_id().source_id(), self.config);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there's one more case of this going wrong. vendor also passes the manifest path. I think a cursory looks suggests that's the last case though.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I think .parent() is called there so the directory is passed in (I tried to audit all sources of PathSource::new to make sure the directory, not the manifest, was passed in)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, I missed that -- seems like it should be calling Package::root() rather than manually getting the parent though. But indeed not an issue.

src.preload_with(pkg);
registry.add_preloaded(Box::new(src));
}
Expand Down
4 changes: 4 additions & 0 deletions src/cargo/sources/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,10 @@ impl<'cfg> Source for PathSource<'cfg> {

fn fingerprint(&self, pkg: &Package) -> CargoResult<String> {
let (max, max_path) = self.last_modified_file(pkg)?;
// Note that we try to strip the prefix of this package to get a
// relative path to ensure that the fingerprint remains consistent
// across entire project directory renames.
let max_path = max_path.strip_prefix(&self.path).unwrap_or(&max_path);
Ok(format!("{} ({})", max, max_path.display()))
}

Expand Down
26 changes: 18 additions & 8 deletions tests/testsuite/freshness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -857,20 +857,30 @@ fn no_rebuild_when_rename_dir() {
.file(
"Cargo.toml",
r#"
[package]
name = "bar"
version = "0.0.1"
authors = []
[package]
name = "bar"
version = "0.0.1"
authors = []

[dependencies]
foo = { path = "foo" }
"#,
[workspace]

[dependencies]
foo = { path = "foo" }
"#,
)
.file("src/lib.rs", "")
.file("src/_unused.rs", "")
.file("build.rs", "fn main() {}")
.file("foo/Cargo.toml", &basic_manifest("foo", "0.0.1"))
.file("foo/src/lib.rs", "")
.file("foo/build.rs", "fn main() {}")
.build();

// make sure the most recently modified file is `src/lib.rs`, not
// `Cargo.toml`, to expose a historical bug where we forgot to strip the
// `Cargo.toml` path from looking for the package root.
cargo_test_support::sleep_ms(100);
fs::write(p.root().join("src/lib.rs"), "").unwrap();

p.cargo("build").run();
let mut new = p.root();
new.pop();
Expand Down