mirror of
https://github.com/rust-lang/cargo.git
synced 2025-09-28 11:20:36 +00:00
Provide more context when src files changed while packaging
Co-authored-by: boxdot <d@zerovolt.org>
This commit is contained in:
parent
285eb4d7b9
commit
9c1124fbcf
@ -330,7 +330,7 @@ fn run_verify(ws: &Workspace, tar: &FileLock, opts: &PackageOpts) -> CargoResult
|
|||||||
let id = SourceId::for_path(&dst)?;
|
let id = SourceId::for_path(&dst)?;
|
||||||
let mut src = PathSource::new(&dst, &id, ws.config());
|
let mut src = PathSource::new(&dst, &id, ws.config());
|
||||||
let new_pkg = src.root_package()?;
|
let new_pkg = src.root_package()?;
|
||||||
let pkg_fingerprint = src.fingerprint(&new_pkg)?;
|
let pkg_fingerprint = src.last_modified_file(&new_pkg)?;
|
||||||
let ws = Workspace::ephemeral(new_pkg, config, None, true)?;
|
let ws = Workspace::ephemeral(new_pkg, config, None, true)?;
|
||||||
|
|
||||||
ops::compile_ws(
|
ops::compile_ws(
|
||||||
@ -354,11 +354,14 @@ fn run_verify(ws: &Workspace, tar: &FileLock, opts: &PackageOpts) -> CargoResult
|
|||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Check that build.rs didn't modify any files in the src directory.
|
// Check that build.rs didn't modify any files in the src directory.
|
||||||
let ws_fingerprint = src.fingerprint(ws.current()?)?;
|
let ws_fingerprint = src.last_modified_file(ws.current()?)?;
|
||||||
if pkg_fingerprint != ws_fingerprint {
|
if pkg_fingerprint != ws_fingerprint {
|
||||||
|
let (_, path) = ws_fingerprint;
|
||||||
bail!(
|
bail!(
|
||||||
"Source directory was modified by build.rs during cargo publish. \
|
"Source directory was modified by build.rs during cargo publish. \
|
||||||
Build scripts should not modify anything outside of OUT_DIR."
|
Build scripts should not modify anything outside of OUT_DIR. \
|
||||||
|
Modified file: {}",
|
||||||
|
path.display()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -467,6 +467,29 @@ impl<'cfg> PathSource<'cfg> {
|
|||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn last_modified_file(&self, pkg: &Package) -> CargoResult<(FileTime, PathBuf)> {
|
||||||
|
if !self.updated {
|
||||||
|
return Err(internal("BUG: source was not updated"));
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut max = FileTime::zero();
|
||||||
|
let mut max_path = PathBuf::new();
|
||||||
|
for file in self.list_files(pkg)? {
|
||||||
|
// An fs::stat error here is either because path is a
|
||||||
|
// broken symlink, a permissions error, or a race
|
||||||
|
// condition where this path was rm'ed - either way,
|
||||||
|
// we can ignore the error and treat the path's mtime
|
||||||
|
// as 0.
|
||||||
|
let mtime = paths::mtime(&file).unwrap_or(FileTime::zero());
|
||||||
|
if mtime > max {
|
||||||
|
max = mtime;
|
||||||
|
max_path = file;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
trace!("last modified file {}: {}", self.path.display(), max);
|
||||||
|
Ok((max, max_path))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'cfg> Debug for PathSource<'cfg> {
|
impl<'cfg> Debug for PathSource<'cfg> {
|
||||||
@ -516,26 +539,7 @@ impl<'cfg> Source for PathSource<'cfg> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn fingerprint(&self, pkg: &Package) -> CargoResult<String> {
|
fn fingerprint(&self, pkg: &Package) -> CargoResult<String> {
|
||||||
if !self.updated {
|
let (max, max_path) = self.last_modified_file(pkg)?;
|
||||||
return Err(internal("BUG: source was not updated"));
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut max = FileTime::zero();
|
|
||||||
let mut max_path = PathBuf::from("");
|
|
||||||
for file in self.list_files(pkg)? {
|
|
||||||
// An fs::stat error here is either because path is a
|
|
||||||
// broken symlink, a permissions error, or a race
|
|
||||||
// condition where this path was rm'ed - either way,
|
|
||||||
// we can ignore the error and treat the path's mtime
|
|
||||||
// as 0.
|
|
||||||
let mtime = paths::mtime(&file).unwrap_or(FileTime::zero());
|
|
||||||
warn!("{} {}", mtime, file.display());
|
|
||||||
if mtime > max {
|
|
||||||
max = mtime;
|
|
||||||
max_path = file;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
trace!("fingerprint {}: {}", self.path.display(), max);
|
|
||||||
Ok(format!("{} ({})", max, max_path.display()))
|
Ok(format!("{} ({})", max, max_path.display()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user