diff options
Diffstat (limited to 'crates/tools/src/lib.rs')
-rw-r--r-- | crates/tools/src/lib.rs | 36 |
1 files changed, 26 insertions, 10 deletions
diff --git a/crates/tools/src/lib.rs b/crates/tools/src/lib.rs index 3c23ed76e..1e29c63d4 100644 --- a/crates/tools/src/lib.rs +++ b/crates/tools/src/lib.rs | |||
@@ -2,7 +2,7 @@ use std::{ | |||
2 | fs, | 2 | fs, |
3 | collections::HashMap, | 3 | collections::HashMap, |
4 | path::{Path, PathBuf}, | 4 | path::{Path, PathBuf}, |
5 | process::{Command, Stdio}, | 5 | process::{Command, Output, Stdio}, |
6 | io::{Error, ErrorKind} | 6 | io::{Error, ErrorKind} |
7 | }; | 7 | }; |
8 | 8 | ||
@@ -80,15 +80,14 @@ pub fn project_root() -> PathBuf { | |||
80 | } | 80 | } |
81 | 81 | ||
82 | pub fn run(cmdline: &str, dir: &str) -> Result<()> { | 82 | pub fn run(cmdline: &str, dir: &str) -> Result<()> { |
83 | eprintln!("\nwill run: {}", cmdline); | 83 | do_run(cmdline, dir, |c| { |
84 | let project_dir = project_root().join(dir); | 84 | c.stdout(Stdio::inherit()); |
85 | let mut args = cmdline.split_whitespace(); | 85 | }) |
86 | let exec = args.next().unwrap(); | 86 | .map(|_| ()) |
87 | let status = Command::new(exec).args(args).current_dir(project_dir).status()?; | 87 | } |
88 | if !status.success() { | 88 | |
89 | bail!("`{}` exited with {}", cmdline, status); | 89 | pub fn run_with_output(cmdline: &str, dir: &str) -> Result<Output> { |
90 | } | 90 | do_run(cmdline, dir, |_| {}) |
91 | Ok(()) | ||
92 | } | 91 | } |
93 | 92 | ||
94 | pub fn run_rustfmt(mode: Mode) -> Result<()> { | 93 | pub fn run_rustfmt(mode: Mode) -> Result<()> { |
@@ -175,6 +174,23 @@ pub fn gen_tests(mode: Mode) -> Result<()> { | |||
175 | install_tests(&tests.err, ERR_INLINE_TESTS_DIR, mode) | 174 | install_tests(&tests.err, ERR_INLINE_TESTS_DIR, mode) |
176 | } | 175 | } |
177 | 176 | ||
177 | fn do_run<F>(cmdline: &str, dir: &str, mut f: F) -> Result<Output> | ||
178 | where | ||
179 | F: FnMut(&mut Command), | ||
180 | { | ||
181 | eprintln!("\nwill run: {}", cmdline); | ||
182 | let proj_dir = project_root().join(dir); | ||
183 | let mut args = cmdline.split_whitespace(); | ||
184 | let exec = args.next().unwrap(); | ||
185 | let mut cmd = Command::new(exec); | ||
186 | f(cmd.args(args).current_dir(proj_dir).stderr(Stdio::inherit())); | ||
187 | let output = cmd.output()?; | ||
188 | if !output.status.success() { | ||
189 | bail!("`{}` exited with {}", cmdline, output.status); | ||
190 | } | ||
191 | Ok(output) | ||
192 | } | ||
193 | |||
178 | #[derive(Default, Debug)] | 194 | #[derive(Default, Debug)] |
179 | struct Tests { | 195 | struct Tests { |
180 | pub ok: HashMap<String, Test>, | 196 | pub ok: HashMap<String, Test>, |