Skip to content

Commit cf22066

Browse files
committed
Auto merge of #1269 - alexcrichton:issue-961, r=brson
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
2 parents 0557065 + cd869ef commit cf22066

File tree

4 files changed

+32
-67
lines changed

4 files changed

+32
-67
lines changed

src/cargo/ops/cargo_rustc/fingerprint.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ pub fn prepare_target<'a, 'b>(cx: &mut Context<'a, 'b>,
4646
pkg.get_package_id(), target));
4747
let new = dir(cx, pkg, kind);
4848
let loc = new.join(filename(target));
49-
cx.layout(pkg, kind).proxy().whitelist(&loc);
5049

5150
info!("fingerprint at: {}", loc.display());
5251

@@ -58,7 +57,6 @@ pub fn prepare_target<'a, 'b>(cx: &mut Context<'a, 'b>,
5857
if !target.get_profile().is_doc() {
5958
for filename in try!(cx.target_filenames(target)).iter() {
6059
let dst = root.join(filename);
61-
cx.layout(pkg, kind).proxy().whitelist(&dst);
6260
missing_outputs |= !dst.exists();
6361

6462
if target.get_profile().is_test() {
@@ -237,7 +235,6 @@ pub fn prepare_build_cmd(cx: &mut Context, pkg: &Package, kind: Kind,
237235
pkg.get_package_id()));
238236
let new = dir(cx, pkg, kind);
239237
let loc = new.join("build");
240-
cx.layout(pkg, kind).proxy().whitelist(&loc);
241238

242239
info!("fingerprint at: {}", loc.display());
243240

@@ -306,9 +303,7 @@ pub fn dir(cx: &Context, pkg: &Package, kind: Kind) -> Path {
306303
/// Returns the (old, new) location for the dep info file of a target.
307304
pub fn dep_info_loc(cx: &Context, pkg: &Package, target: &Target,
308305
kind: Kind) -> Path {
309-
let ret = dir(cx, pkg, kind).join(format!("dep-{}", filename(target)));
310-
cx.layout(pkg, kind).proxy().whitelist(&ret);
311-
return ret;
306+
dir(cx, pkg, kind).join(format!("dep-{}", filename(target)))
312307
}
313308

314309
fn is_fresh(loc: &Path, new_fingerprint: &Fingerprint) -> CargoResult<bool> {

src/cargo/ops/cargo_rustc/layout.rs

Lines changed: 10 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,8 @@
4545
//! .fingerprint/
4646
//! ```
4747
48-
use std::cell::RefCell;
49-
use std::collections::HashSet;
5048
use std::old_io::fs::PathExtensions;
5149
use std::old_io::{self, fs, IoResult};
52-
use std::mem;
5350

5451
use core::Package;
5552
use util::hex::short_hash;
@@ -61,7 +58,6 @@ pub struct Layout {
6158
build: Path,
6259
fingerprint: Path,
6360
examples: Path,
64-
to_delete: RefCell<HashSet<Path>>,
6561
}
6662

6763
pub struct LayoutProxy<'a> {
@@ -91,7 +87,6 @@ impl Layout {
9187
fingerprint: root.join(".fingerprint"),
9288
examples: root.join("examples"),
9389
root: root,
94-
to_delete: RefCell::new(HashSet::new()),
9590
}
9691
}
9792

@@ -100,34 +95,16 @@ impl Layout {
10095
try!(fs::mkdir_recursive(&self.root, old_io::USER_RWX));
10196
}
10297

103-
try!(mkdir(self, &self.deps, false));
104-
try!(mkdir(self, &self.native, false));
105-
try!(mkdir(self, &self.fingerprint, true));
106-
try!(mkdir(self, &self.examples, false));
107-
try!(mkdir(self, &self.build, false));
108-
109-
for file in try!(fs::readdir(&self.root)).into_iter() {
110-
if !file.is_file() { continue }
111-
112-
self.to_delete.borrow_mut().insert(file);
113-
}
98+
try!(mkdir(&self.deps));
99+
try!(mkdir(&self.native));
100+
try!(mkdir(&self.fingerprint));
101+
try!(mkdir(&self.examples));
102+
try!(mkdir(&self.build));
114103

115104
return Ok(());
116105

117-
fn mkdir(layout: &Layout, dir: &Path, deep: bool) -> IoResult<()> {
118-
if dir.exists() {
119-
if deep {
120-
for file in try!(fs::walk_dir(dir)) {
121-
if !file.is_dir() {
122-
layout.to_delete.borrow_mut().insert(file);
123-
}
124-
}
125-
} else {
126-
for file in try!(fs::readdir(dir)).into_iter() {
127-
layout.to_delete.borrow_mut().insert(file);
128-
}
129-
}
130-
} else {
106+
fn mkdir(dir: &Path) -> IoResult<()> {
107+
if !dir.exists() {
131108
try!(fs::mkdir(dir, old_io::USER_DIR));
132109
}
133110
Ok(())
@@ -140,44 +117,20 @@ impl Layout {
140117

141118
// TODO: deprecated, remove
142119
pub fn native(&self, package: &Package) -> Path {
143-
let ret = self.native.join(self.pkg_dir(package));
144-
self.whitelist(&ret);
145-
ret
120+
self.native.join(self.pkg_dir(package))
146121
}
147122
pub fn fingerprint(&self, package: &Package) -> Path {
148-
let ret = self.fingerprint.join(self.pkg_dir(package));
149-
self.whitelist(&ret);
150-
ret
123+
self.fingerprint.join(self.pkg_dir(package))
151124
}
152125

153126
pub fn build(&self, package: &Package) -> Path {
154-
let ret = self.build.join(self.pkg_dir(package));
155-
self.whitelist(&ret);
156-
ret
127+
self.build.join(self.pkg_dir(package))
157128
}
158129

159130
pub fn build_out(&self, package: &Package) -> Path {
160131
self.build(package).join("out")
161132
}
162133

163-
pub fn clean(&self) -> IoResult<()> {
164-
let set = mem::replace(&mut *self.to_delete.borrow_mut(),
165-
HashSet::new());
166-
for file in set.iter() {
167-
info!("dirty: {}", file.display());
168-
if file.is_dir() {
169-
try!(fs::rmdir_recursive(file));
170-
} else {
171-
try!(fs::unlink(file));
172-
}
173-
}
174-
Ok(())
175-
}
176-
177-
pub fn whitelist(&self, p: &Path) {
178-
self.to_delete.borrow_mut().remove(p);
179-
}
180-
181134
fn pkg_dir(&self, pkg: &Package) -> String {
182135
format!("{}-{}", pkg.get_name(), short_hash(pkg.get_package_id()))
183136
}

src/cargo/ops/cargo_rustc/mod.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,6 @@ pub fn compile_targets<'a, 'b>(env: &str,
183183

184184
try!(compile(targets, pkg, true, &mut cx, &mut queue));
185185

186-
// Clean out any old files sticking around in directories.
187-
try!(cx.layout(pkg, Kind::Host).proxy().clean());
188-
try!(cx.layout(pkg, Kind::Target).proxy().clean());
189-
190186
// Now that we've figured out everything that we're going to do, do it!
191187
try!(queue.execute(cx.config));
192188

tests/test_cargo_test.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1311,3 +1311,24 @@ test!(example_with_dev_dep {
13111311
{running} `rustc [..] --crate-name ex [..] --extern a=[..]`
13121312
", running = RUNNING).as_slice()));
13131313
});
1314+
1315+
test!(bin_is_preserved {
1316+
let p = project("foo")
1317+
.file("Cargo.toml", r#"
1318+
[package]
1319+
name = "foo"
1320+
version = "0.0.1"
1321+
authors = []
1322+
"#)
1323+
.file("src/lib.rs", "")
1324+
.file("src/main.rs", "fn main() {}");
1325+
1326+
assert_that(p.cargo_process("build").arg("-v"),
1327+
execs().with_status(0));
1328+
assert_that(&p.bin("foo"), existing_file());
1329+
1330+
println!("testing");
1331+
assert_that(p.process(cargo_dir().join("cargo")).arg("test").arg("-v"),
1332+
execs().with_status(0));
1333+
assert_that(&p.bin("foo"), existing_file());
1334+
});

0 commit comments

Comments
 (0)