Skip to content

Commit

Permalink
change this to only emit a warning right now
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Woolcock committed Dec 6, 2016
1 parent d998dba commit 1b99491
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
17 changes: 14 additions & 3 deletions src/cargo/util/toml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ impl TomlManifest {
}

// processing the custom build script
let new_build = self.maybe_custom_build(&project.build, &layout.root);
let new_build = self.maybe_custom_build(&project.build, &layout.root, &mut warnings);

// Get targets
let targets = normalize(&lib,
Expand Down Expand Up @@ -774,7 +774,10 @@ impl TomlManifest {
Ok(replace)
}

fn maybe_custom_build(&self, build: &Option<StringOrBool>, project_dir: &Path)
fn maybe_custom_build(&self,
build: &Option<StringOrBool>,
project_dir: &Path,
warnings: &mut Vec<String>)
-> Option<PathBuf> {
let build_rs = project_dir.join("build.rs");
match *build {
Expand All @@ -783,7 +786,15 @@ impl TomlManifest {
Some(StringOrBool::String(ref s)) => Some(PathBuf::from(s)),
None => {
match fs::metadata(&build_rs) {
Ok(ref e) if e.is_file() => Some(build_rs.into()),
// Enable this after the warning has been visible for some time
// Ok(ref e) if e.is_file() => Some(build_rs.into()),
Ok(ref e) if e.is_file() => {
warnings.push("`build.rs` files in the same directory \
as your `Cargo.toml` will soon be treated \
as build scripts. Add `build = false` to \
your `Cargo.toml` to prevent this".into());
None
},
Ok(_) => None,
Err(_) => None,
}
Expand Down
15 changes: 13 additions & 2 deletions tests/build-script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2345,8 +2345,12 @@ fn assume_build_script_when_build_rs_present() {
authors = []
"#)
.file("src/main.rs", r#"
use std::path::Path;
fn main() {
println!(include_str!(concat!(env!("OUT_DIR"), "/output")));
let f = env!("OUT_DIR");
assert!(
! Path::new(f).join("output").exists()
);
}
"#)
.file("build.rs", r#"
Expand All @@ -2365,7 +2369,14 @@ fn assume_build_script_when_build_rs_present() {
p.build();

assert_that(p.cargo("run").arg("-v"),
execs().with_status(0).with_stdout("foo\n"));
execs().with_status(0).with_stderr("\
warning: `build.rs` files in the same directory as your `Cargo.toml` will soon be treated \
as build scripts. Add `build = false` to your `Cargo.toml` to prevent this
Compiling builder v0.0.1 ([..])
Running [..]
Finished [..]
Running [..]
"));
}

#[test]
Expand Down

0 comments on commit 1b99491

Please sign in to comment.