Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assume that a build.rs file is a build script #3664

Merged
merged 1 commit into from
Feb 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 5 additions & 12 deletions src/cargo/util/toml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -768,8 +768,7 @@ impl TomlManifest {

fn maybe_custom_build(&self,
build: &Option<StringOrBool>,
project_dir: &Path,
warnings: &mut Vec<String>)
project_dir: &Path)
-> Option<PathBuf> {
let build_rs = project_dir.join("build.rs");
match *build {
Expand All @@ -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,
}
Expand Down
13 changes: 3 additions & 10 deletions tests/build-script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
"#)
Expand All @@ -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]
Expand Down