Skip to content

Commit f98100f

Browse files
committed
Auto merge of #1701 - alexcrichton:lenient-rustc-flags, r=brson
Some flags to the compiler could cause it to stop early or not emit some files altogether (or perhaps emit files in different locations even). Currently cargo expects a few outputs of the compiler after `cargo rustc` is run, but this commit alters cargo to know that when `cargo rustc` is being run that the outputs may not exist and that's ok. Closes #1675
2 parents ae8b752 + 8230f1f commit f98100f

File tree

3 files changed

+39
-12
lines changed

3 files changed

+39
-12
lines changed

src/cargo/ops/cargo_rustc/fingerprint.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ pub fn prepare_target<'a, 'cfg>(cx: &mut Context<'a, 'cfg>,
6666
}
6767
}
6868

69-
Ok(prepare(is_fresh && !missing_outputs, loc, fingerprint))
69+
let allow_failure = profile.rustc_args.is_some();
70+
Ok(prepare(is_fresh && !missing_outputs, allow_failure, loc, fingerprint))
7071
}
7172

7273
/// A fingerprint can be considered to be a "short string" representing the
@@ -256,7 +257,7 @@ pub fn prepare_build_cmd(cx: &mut Context, pkg: &Package, kind: Kind)
256257

257258
let is_fresh = try!(is_fresh(&loc, &new_fingerprint));
258259

259-
Ok(prepare(is_fresh, loc, new_fingerprint))
260+
Ok(prepare(is_fresh, false, loc, new_fingerprint))
260261
}
261262

262263
/// Prepare work for when a package starts to build
@@ -284,13 +285,19 @@ pub fn prepare_init(cx: &mut Context, pkg: &Package, kind: Kind)
284285
/// Given the data to build and write a fingerprint, generate some Work
285286
/// instances to actually perform the necessary work.
286287
fn prepare(is_fresh: bool,
288+
allow_failure: bool,
287289
loc: PathBuf,
288290
fingerprint: Fingerprint) -> Preparation {
289291
let write_fingerprint = Work::new(move |_| {
290292
debug!("write fingerprint: {}", loc.display());
291-
let fingerprint = try!(fingerprint.resolve(true).chain_error(|| {
293+
let fingerprint = fingerprint.resolve(true).chain_error(|| {
292294
internal("failed to resolve a pending fingerprint")
293-
}));
295+
});
296+
let fingerprint = match fingerprint {
297+
Ok(f) => f,
298+
Err(..) if allow_failure => return Ok(()),
299+
Err(e) => return Err(e),
300+
};
294301
let mut f = try!(File::create(&loc));
295302
try!(f.write_all(fingerprint.as_bytes()));
296303
Ok(())

src/cargo/ops/cargo_rustc/mod.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,7 @@ fn rustc(package: &Package, target: &Target, profile: &Profile,
341341
if !show_warnings {
342342
rustc.arg("-Awarnings");
343343
}
344+
let has_custom_args = profile.rustc_args.is_some();
344345
let exec_engine = cx.exec_engine.clone();
345346

346347
let filenames = try!(cx.target_filenames(package, target, profile,
@@ -407,16 +408,20 @@ fn rustc(package: &Package, target: &Target, profile: &Profile,
407408
let src = dst.with_file_name(dst.file_name().unwrap()
408409
.to_str().unwrap()
409410
.replace(&real_name, &crate_name));
410-
try!(fs::rename(&src, &dst).chain_error(|| {
411-
internal(format!("could not rename crate {:?}", src))
412-
}));
411+
if !has_custom_args || fs::metadata(&src).is_ok() {
412+
try!(fs::rename(&src, &dst).chain_error(|| {
413+
internal(format!("could not rename crate {:?}", src))
414+
}));
415+
}
413416
}
414417

415-
try!(fs::rename(&rustc_dep_info_loc, &dep_info_loc).chain_error(|| {
416-
internal(format!("could not rename dep info: {:?}",
417-
rustc_dep_info_loc))
418-
}));
419-
try!(fingerprint::append_current_dir(&dep_info_loc, &cwd));
418+
if !has_custom_args || fs::metadata(&rustc_dep_info_loc).is_ok() {
419+
try!(fs::rename(&rustc_dep_info_loc, &dep_info_loc).chain_error(|| {
420+
internal(format!("could not rename dep info: {:?}",
421+
rustc_dep_info_loc))
422+
}));
423+
try!(fingerprint::append_current_dir(&dep_info_loc, &cwd));
424+
}
420425

421426
Ok(())
422427

tests/test_cargo_compile.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1886,3 +1886,18 @@ test!(custom_target_dir {
18861886
assert_that(&p.root().join("target/debug").join(&exe_name),
18871887
existing_file());
18881888
});
1889+
1890+
test!(rustc_no_trans {
1891+
let p = project("foo")
1892+
.file("Cargo.toml", r#"
1893+
[package]
1894+
name = "foo"
1895+
version = "0.0.1"
1896+
authors = []
1897+
"#)
1898+
.file("src/main.rs", "fn main() {}");
1899+
p.build();
1900+
1901+
assert_that(p.cargo("rustc").arg("-v").arg("--").arg("-Zno-trans"),
1902+
execs().with_status(0));
1903+
});

0 commit comments

Comments
 (0)