]> git.proxmox.com Git - cargo.git/commitdiff
Remove auto-cleaning of the build directory
authorAlex Crichton <alex@alexcrichton.com>
Wed, 14 Jan 2015 05:23:43 +0000 (21:23 -0800)
committerAlex Crichton <alex@alexcrichton.com>
Wed, 4 Feb 2015 22:58:33 +0000 (14:58 -0800)
Over time this functionality has become obsolete through other means. Due to the
usage of `-L dependency=foo` it's not possible to pick up stale dependencies by
accident, and due to `--extern` you can only pick up a dependency. All of the
cases that auto-cleaning was fixing are now fixed through other methods, so
there's not much use ensuring a "clean build directory" any more.

This has the benefit of fixing issues like #961 where the downside of long
compiles outweighs the benefits of a "let's pretend we started from scratch"
build.

Closes #961

src/cargo/ops/cargo_rustc/fingerprint.rs
src/cargo/ops/cargo_rustc/layout.rs
src/cargo/ops/cargo_rustc/mod.rs
tests/test_cargo_compile_path_deps.rs
tests/test_cargo_test.rs

index 297173a31a3f9e48f2b55af1f48a1abcbefbb87d..7fc4a13dc889104fb63c75ae672f8d79f47a4f1a 100644 (file)
@@ -46,7 +46,6 @@ pub fn prepare_target<'a, 'b>(cx: &mut Context<'a, 'b>,
                                     pkg.get_package_id(), target));
     let new = dir(cx, pkg, kind);
     let loc = new.join(filename(target));
-    cx.layout(pkg, kind).proxy().whitelist(&loc);
 
     info!("fingerprint at: {}", loc.display());
 
@@ -58,7 +57,6 @@ pub fn prepare_target<'a, 'b>(cx: &mut Context<'a, 'b>,
     if !target.get_profile().is_doc() {
         for filename in try!(cx.target_filenames(target)).iter() {
             let dst = root.join(filename);
-            cx.layout(pkg, kind).proxy().whitelist(&dst);
             missing_outputs |= !dst.exists();
 
             if target.get_profile().is_test() {
@@ -236,7 +234,6 @@ pub fn prepare_build_cmd(cx: &mut Context, pkg: &Package, kind: Kind,
                                     pkg.get_package_id()));
     let new = dir(cx, pkg, kind);
     let loc = new.join("build");
-    cx.layout(pkg, kind).proxy().whitelist(&loc);
 
     info!("fingerprint at: {}", loc.display());
 
@@ -305,9 +302,7 @@ pub fn dir(cx: &Context, pkg: &Package, kind: Kind) -> Path {
 /// Returns the (old, new) location for the dep info file of a target.
 pub fn dep_info_loc(cx: &Context, pkg: &Package, target: &Target,
                     kind: Kind) -> Path {
-    let ret = dir(cx, pkg, kind).join(format!("dep-{}", filename(target)));
-    cx.layout(pkg, kind).proxy().whitelist(&ret);
-    return ret;
+    dir(cx, pkg, kind).join(format!("dep-{}", filename(target)))
 }
 
 fn is_fresh(loc: &Path, new_fingerprint: &Fingerprint) -> CargoResult<bool> {
index 87af32150aa1e722134091eee919e10b031441c1..db98584bed461bc5a98f63df4b794564982867da 100644 (file)
 //!     .fingerprint/
 //! ```
 
-use std::cell::RefCell;
-use std::collections::HashSet;
 use std::old_io::fs::PathExtensions;
 use std::old_io::{self, fs, IoResult};
-use std::mem;
 
 use core::Package;
 use util::hex::short_hash;
@@ -61,7 +58,6 @@ pub struct Layout {
     build: Path,
     fingerprint: Path,
     examples: Path,
-    to_delete: RefCell<HashSet<Path>>,
 }
 
 pub struct LayoutProxy<'a> {
@@ -91,7 +87,6 @@ impl Layout {
             fingerprint: root.join(".fingerprint"),
             examples: root.join("examples"),
             root: root,
-            to_delete: RefCell::new(HashSet::new()),
         }
     }
 
@@ -100,34 +95,16 @@ impl Layout {
             try!(fs::mkdir_recursive(&self.root, old_io::USER_RWX));
         }
 
-        try!(mkdir(self, &self.deps, false));
-        try!(mkdir(self, &self.native, false));
-        try!(mkdir(self, &self.fingerprint, true));
-        try!(mkdir(self, &self.examples, false));
-        try!(mkdir(self, &self.build, false));
-
-        for file in try!(fs::readdir(&self.root)).into_iter() {
-            if !file.is_file() { continue }
-
-            self.to_delete.borrow_mut().insert(file);
-        }
+        try!(mkdir(&self.deps));
+        try!(mkdir(&self.native));
+        try!(mkdir(&self.fingerprint));
+        try!(mkdir(&self.examples));
+        try!(mkdir(&self.build));
 
         return Ok(());
 
-        fn mkdir(layout: &Layout, dir: &Path, deep: bool) -> IoResult<()> {
-            if dir.exists() {
-                if deep {
-                    for file in try!(fs::walk_dir(dir)) {
-                        if !file.is_dir() {
-                            layout.to_delete.borrow_mut().insert(file);
-                        }
-                    }
-                } else {
-                    for file in try!(fs::readdir(dir)).into_iter() {
-                        layout.to_delete.borrow_mut().insert(file);
-                    }
-                }
-            } else {
+        fn mkdir(dir: &Path) -> IoResult<()> {
+            if !dir.exists() {
                 try!(fs::mkdir(dir, old_io::USER_DIR));
             }
             Ok(())
@@ -140,44 +117,20 @@ impl Layout {
 
     // TODO: deprecated, remove
     pub fn native(&self, package: &Package) -> Path {
-        let ret = self.native.join(self.pkg_dir(package));
-        self.whitelist(&ret);
-        ret
+        self.native.join(self.pkg_dir(package))
     }
     pub fn fingerprint(&self, package: &Package) -> Path {
-        let ret = self.fingerprint.join(self.pkg_dir(package));
-        self.whitelist(&ret);
-        ret
+        self.fingerprint.join(self.pkg_dir(package))
     }
 
     pub fn build(&self, package: &Package) -> Path {
-        let ret = self.build.join(self.pkg_dir(package));
-        self.whitelist(&ret);
-        ret
+        self.build.join(self.pkg_dir(package))
     }
 
     pub fn build_out(&self, package: &Package) -> Path {
         self.build(package).join("out")
     }
 
-    pub fn clean(&self) -> IoResult<()> {
-        let set = mem::replace(&mut *self.to_delete.borrow_mut(),
-                               HashSet::new());
-        for file in set.iter() {
-            info!("dirty: {}", file.display());
-            if file.is_dir() {
-                try!(fs::rmdir_recursive(file));
-            } else {
-                try!(fs::unlink(file));
-            }
-        }
-        Ok(())
-    }
-
-    pub fn whitelist(&self, p: &Path) {
-        self.to_delete.borrow_mut().remove(p);
-    }
-
     fn pkg_dir(&self, pkg: &Package) -> String {
         format!("{}-{}", pkg.get_name(), short_hash(pkg.get_package_id()))
     }
index 4f097c387d1bb16f7b81d3ef269aca3a6413b928..0e81545b790ae6c83b4ceabfbbd45ea8bdab07f4 100644 (file)
@@ -183,10 +183,6 @@ pub fn compile_targets<'a, 'b>(env: &str,
 
     try!(compile(targets, pkg, true, &mut cx, &mut queue));
 
-    // Clean out any old files sticking around in directories.
-    try!(cx.layout(pkg, Kind::Host).proxy().clean());
-    try!(cx.layout(pkg, Kind::Target).proxy().clean());
-
     // Now that we've figured out everything that we're going to do, do it!
     try!(queue.execute(cx.config));
 
index 31d3ad185537b76d3cf73dac5651fd65edd8e988..9286d7ed20e73329bfccf05ec7c63fbd89bec741 100644 (file)
@@ -1,4 +1,5 @@
-use std::old_io::{fs, File, USER_RWX};
+use std::old_io::{fs, File, USER_RWX, timer};
+use std::time::Duration;
 
 use support::{project, execs, main_file, cargo_dir};
 use support::{COMPILING, RUNNING};
@@ -353,7 +354,7 @@ test!(deep_dependencies_trigger_rebuild {
     //
     // We base recompilation off mtime, so sleep for at least a second to ensure
     // that this write will change the mtime.
-    p.root().move_into_the_past().unwrap();
+    timer::sleep(Duration::seconds(1));
     File::create(&p.root().join("baz/src/baz.rs")).write_str(r#"
         pub fn baz() { println!("hello!"); }
     "#).unwrap();
@@ -366,7 +367,7 @@ test!(deep_dependencies_trigger_rebuild {
                                             COMPILING, p.url())));
 
     // Make sure an update to bar doesn't trigger baz
-    p.root().move_into_the_past().unwrap();
+    timer::sleep(Duration::seconds(1));
     File::create(&p.root().join("bar/src/bar.rs")).write_str(r#"
         extern crate baz;
         pub fn bar() { println!("hello!"); baz::baz(); }
index 4edd7922e5e71705f130db061efb19b588fd35ad..e9279d8eb4cfdef8ffc802eac46c6dfa7753b79b 100644 (file)
@@ -1311,3 +1311,24 @@ test!(example_with_dev_dep {
 {running} `rustc [..] --crate-name ex [..] --extern a=[..]`
 ", running = RUNNING).as_slice()));
 });
+
+test!(bin_is_preserved {
+    let p = project("foo")
+        .file("Cargo.toml", r#"
+            [package]
+            name = "foo"
+            version = "0.0.1"
+            authors = []
+        "#)
+        .file("src/lib.rs", "")
+        .file("src/main.rs", "fn main() {}");
+
+    assert_that(p.cargo_process("build").arg("-v"),
+                execs().with_status(0));
+    assert_that(&p.bin("foo"), existing_file());
+
+    println!("testing");
+    assert_that(p.process(cargo_dir().join("cargo")).arg("test").arg("-v"),
+                execs().with_status(0));
+    assert_that(&p.bin("foo"), existing_file());
+});