Skip to content

Commit

Permalink
Rebuild files if target directory is corrupt
Browse files Browse the repository at this point in the history
If manual modifications have been made or if cargo/rustc died for some sort of
error, then we don't consider a target as being fresh. If any of the files
output by a target don't end up existing in the target directory (even if the
fingerprint says they do), then we consider the target not fresh.

cc #986
  • Loading branch information
alexcrichton committed Dec 8, 2014
1 parent 0f6667c commit 523f507
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/cargo/ops/cargo_rustc/fingerprint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ pub fn prepare_target(cx: &mut Context, pkg: &Package, target: &Target,
// First bit of the freshness calculation, whether the dep-info file
// indicates that the target is fresh.
let dep_info = dep_info_loc(cx, pkg, target, kind);
let are_files_fresh = use_pkg ||
try!(calculate_target_fresh(pkg, &dep_info));
let mut are_files_fresh = use_pkg ||
try!(calculate_target_fresh(pkg, &dep_info));

// Second bit of the freshness calculation, whether rustc itself, the
// target are fresh, and the enabled set of features are all fresh.
Expand All @@ -87,6 +87,9 @@ pub fn prepare_target(cx: &mut Context, pkg: &Package, target: &Target,
for filename in try!(cx.target_filenames(target)).iter() {
let dst = root.join(filename);
cx.layout(pkg, kind).proxy().whitelist(&dst);
if are_files_fresh && !dst.exists() {
are_files_fresh = false;
}

if target.get_profile().is_test() {
cx.compilation.tests.push((target.get_name().into_string(), dst));
Expand Down
17 changes: 17 additions & 0 deletions tests/test_cargo_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1496,3 +1496,20 @@ test!(example_bin_same_name {
assert_that(&p.bin("foo"), existing_file());
assert_that(&p.bin("examples/foo"), existing_file());
})

test!(compile_then_delete {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
name = "foo"
version = "0.0.1"
authors = []
"#)
.file("src/main.rs", "fn main() {}");

assert_that(p.cargo_process("run"), execs().with_status(0));
assert_that(&p.bin("foo"), existing_file());
fs::unlink(&p.bin("foo")).unwrap();
assert_that(p.process(cargo_dir().join("cargo")).arg("run"),
execs().with_status(0));
})

5 comments on commit 523f507

@bors
Copy link
Collaborator

@bors bors commented on 523f507 Dec 9, 2014

Choose a reason for hiding this comment

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

saw approval from brson
at alexcrichton@523f507

@bors
Copy link
Collaborator

@bors bors commented on 523f507 Dec 9, 2014

Choose a reason for hiding this comment

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

merging alexcrichton/cargo/issue-986 = 523f507 into auto-cargo

@bors
Copy link
Collaborator

@bors bors commented on 523f507 Dec 9, 2014

Choose a reason for hiding this comment

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

alexcrichton/cargo/issue-986 = 523f507 merged ok, testing candidate = 4e92eb2

@bors
Copy link
Collaborator

@bors bors commented on 523f507 Dec 9, 2014

Choose a reason for hiding this comment

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

@bors
Copy link
Collaborator

@bors bors commented on 523f507 Dec 9, 2014

Choose a reason for hiding this comment

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

fast-forwarding master to auto-cargo = 4e92eb2

Please sign in to comment.