From 952b0ab3e12b332fcc4237f5e4b87caf962e591b Mon Sep 17 00:00:00 2001 From: Paul Woolcock Date: Tue, 7 Feb 2017 12:41:36 -0500 Subject: [PATCH] Assume that a `build.rs` file is a build script If cargo sees a `build.rs` file in the same directory as the current `Cargo.toml`, it will assume that the `build.rs` file is a build script, _unless there is_ `build = false` _in the _ `Cargo.toml` _file_. Closes #3391 --- src/cargo/util/toml.rs | 17 +++++------------ tests/build-script.rs | 13 +++---------- 2 files changed, 8 insertions(+), 22 deletions(-) diff --git a/src/cargo/util/toml.rs b/src/cargo/util/toml.rs index 3cb35184da7..d12c73c679e 100644 --- a/src/cargo/util/toml.rs +++ b/src/cargo/util/toml.rs @@ -534,7 +534,7 @@ impl TomlManifest { } // processing the custom build script - let new_build = self.maybe_custom_build(&project.build, &layout.root, &mut warnings); + let new_build = self.maybe_custom_build(&project.build, &layout.root); // Get targets let targets = normalize(&layout.root, @@ -768,8 +768,7 @@ impl TomlManifest { fn maybe_custom_build(&self, build: &Option, - project_dir: &Path, - warnings: &mut Vec) + project_dir: &Path) -> Option { let build_rs = project_dir.join("build.rs"); match *build { @@ -778,15 +777,9 @@ impl TomlManifest { Some(StringOrBool::String(ref s)) => Some(PathBuf::from(s)), None => { match fs::metadata(&build_rs) { - // 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 - }, + // If there is a build.rs file next to the Cargo.toml, assume it is + // a build script + Ok(ref e) if e.is_file() => Some(build_rs.into()), Ok(_) => None, Err(_) => None, } diff --git a/tests/build-script.rs b/tests/build-script.rs index 74297a86e35..b0a17a489f7 100644 --- a/tests/build-script.rs +++ b/tests/build-script.rs @@ -2350,8 +2350,8 @@ fn assume_build_script_when_build_rs_present() { "#) .file("src/main.rs", r#" fn main() { - if cfg!(foo) { - panic!("the build script was run"); + if ! cfg!(foo) { + panic!("the build script was not run"); } } "#) @@ -2363,14 +2363,7 @@ fn assume_build_script_when_build_rs_present() { p.build(); assert_that(p.cargo("run").arg("-v"), - 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 [..] -")); + execs().with_status(0)); } #[test]