Skip to content

Commit 30c2716

Browse files
committed
prepare: report build failure if Cargo.toml is invalid
1 parent 4b09fcd commit 30c2716

File tree

8 files changed

+66
-4
lines changed

8 files changed

+66
-4
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
wow! this isn't valid toml? :O
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
println!("Hello, world!");
3+
}

src/errors.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use results::TestResult;
2+
13
error_chain! {
24
foreign_links {
35
IoError(::std::io::Error);
@@ -81,5 +83,10 @@ error_chain! {
8183
BadConfig {
8284
description("the config file contains errors")
8385
}
86+
87+
OverrideResult(result: TestResult) {
88+
description("overridden task result")
89+
display("overridden task result to {}", result.to_str())
90+
}
8491
}
8592
}

src/run.rs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ pub(crate) struct RunCommand {
6161
quiet: bool,
6262
enable_timeout: bool,
6363
local_rustup: bool,
64+
hide_output: bool,
6465
}
6566

6667
impl RunCommand {
@@ -73,6 +74,7 @@ impl RunCommand {
7374
quiet: false,
7475
enable_timeout: true,
7576
local_rustup: false,
77+
hide_output: false,
7678
})
7779
}
7880

@@ -110,6 +112,11 @@ impl RunCommand {
110112
self
111113
}
112114

115+
pub(crate) fn hide_output(mut self, hide_output: bool) -> Self {
116+
self.hide_output = hide_output;
117+
self
118+
}
119+
113120
pub(crate) fn sandboxed(self) -> SandboxedCommand {
114121
SandboxedCommand::new(self)
115122
}
@@ -154,7 +161,13 @@ impl RunCommand {
154161
}
155162

156163
info!("running `{}`", cmdstr);
157-
let out = log_command(cmd, capture, self.quiet, self.enable_timeout).map_err(|e| {
164+
let out = log_command(
165+
cmd,
166+
capture,
167+
self.quiet,
168+
self.enable_timeout,
169+
self.hide_output,
170+
).map_err(|e| {
158171
info!("error running command: {}", e);
159172
e
160173
})?;
@@ -255,6 +268,7 @@ fn log_command(
255268
capture: bool,
256269
quiet: bool,
257270
enable_timeout: bool,
271+
hide_output: bool,
258272
) -> Result<ProcessOutput> {
259273
let (max_timeout, heartbeat_timeout) = if enable_timeout {
260274
let max_timeout = Duration::from_secs(MAX_TIMEOUT_SECS);
@@ -290,14 +304,18 @@ fn log_command(
290304
let stdout = lines(BufReader::new(stdout)).map({
291305
let logger = logger.clone();
292306
move |line| {
293-
slog_info!(logger, "blam! {}", line);
307+
if !hide_output {
308+
slog_info!(logger, "blam! {}", line);
309+
}
294310
line
295311
}
296312
});
297313
let stderr = lines(BufReader::new(stderr)).map({
298314
let logger = logger.clone();
299315
move |line| {
300-
slog_info!(logger, "kablam! {}", line);
316+
if !hide_output {
317+
slog_info!(logger, "kablam! {}", line);
318+
}
301319
line
302320
}
303321
});

src/runner/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ fn run_ex_inner<DB: WriteResults + Sync>(
7979

8080
let result = if config.is_broken(&task.krate) {
8181
TestResult::BuildFail
82+
} else if let ErrorKind::OverrideResult(res) = e.kind() {
83+
*res
8284
} else {
8385
TestResult::Error
8486
};

src/runner/prepare.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crates::Crate;
33
use dirs::{EXPERIMENT_DIR, TEST_SOURCE_DIR};
44
use errors::*;
55
use experiments::Experiment;
6-
use results::WriteResults;
6+
use results::{TestResult, WriteResults};
77
use run::RunCommand;
88
use runner::toml_frobber::TomlFrobber;
99
use std::fs;
@@ -92,6 +92,21 @@ pub(super) fn with_frobbed_toml(ex: &Experiment, krate: &Crate, path: &Path) ->
9292
Ok(())
9393
}
9494

95+
pub(super) fn validate_manifest(ex: &Experiment, krate: &Crate, tc: &Toolchain) -> Result<()> {
96+
info!("validating manifest of {} on toolchain {}", krate, tc);
97+
with_work_crate(ex, tc, krate, |path| {
98+
RunCommand::new(CARGO.toolchain(tc))
99+
.args(&["read-manifest", "--manifest-path", "Cargo.toml"])
100+
.cd(path)
101+
.hide_output(true)
102+
.run()
103+
.chain_err(|| format!("invalid syntax in {}'s Cargo.toml", krate))
104+
.chain_err(|| ErrorKind::OverrideResult(TestResult::BuildFail))?;
105+
106+
Ok(())
107+
})
108+
}
109+
95110
fn lockfile_dir(ex_name: &str) -> PathBuf {
96111
EXPERIMENT_DIR.join(ex_name).join("lockfiles")
97112
}

src/runner/tasks.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ impl Task {
131131
}
132132

133133
::runner::prepare::frob_toml(ex, &self.krate)?;
134+
::runner::prepare::validate_manifest(ex, &self.krate, &MAIN_TOOLCHAIN)?;
134135
::runner::prepare::capture_lockfile(config, ex, &self.krate, &MAIN_TOOLCHAIN)?;
135136
::runner::prepare::fetch_crate_deps(config, ex, &self.krate, &MAIN_TOOLCHAIN)?;
136137

tests/minicrater/full/results.expected.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,21 @@
3030
],
3131
"url": "https://github.com/rust-lang-nursery/crater/tree/master/local-crates/beta-regression"
3232
},
33+
{
34+
"name": "broken-cargotoml (local)",
35+
"res": "SameBuildFail",
36+
"runs": [
37+
{
38+
"log": "stable/local/broken-cargotoml",
39+
"res": "BuildFail"
40+
},
41+
{
42+
"log": "beta/local/broken-cargotoml",
43+
"res": "BuildFail"
44+
}
45+
],
46+
"url": "https://github.com/rust-lang-nursery/crater/tree/master/local-crates/broken-cargotoml"
47+
},
3348
{
3449
"name": "build-fail (local)",
3550
"res": "SameBuildFail",

0 commit comments

Comments
 (0)