diff options
| author | bors <bors@rust-lang.org> | 2019-11-11 18:19:07 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2019-11-11 18:19:07 +0000 |
| commit | bc56788fe637f6ff16c1e445a230b01544d2d9cf (patch) | |
| tree | 5745c62a7ac55f3b676eff281de2710246b63bd0 /src/main.rs | |
| parent | 9544ba10294d4959b0a761c04d86ef8ceeba3838 (diff) | |
| parent | 36a033b87a6549c1e5639c908bf7381c84f4f425 (diff) | |
Auto merge of #233 - jrvidal:rustc-check, r=fmoko
feat(cli): check for rustc before doing anything
Addresses #190. From the backtraces shown there, it seems like we're not able to launch `rustc` (which is odd, given that they probably compiled and installed `rustlings` :woman_shrugging:)
Diffstat (limited to 'src/main.rs')
| -rw-r--r-- | src/main.rs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs index d1d0d6d..9505650 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,6 +7,7 @@ use notify::{RecommendedWatcher, RecursiveMode, Watcher}; use std::ffi::OsStr; use std::fs; use std::path::Path; +use std::process::{Command, Stdio}; use std::sync::mpsc::channel; use std::time::Duration; @@ -56,6 +57,13 @@ fn main() { std::process::exit(1); } + if !rustc_exists() { + println!("We cannot find `rustc`."); + println!("Try running `rustc --version` to diagnose your problem."); + println!("For instructions on how to install Rust, check the README."); + std::process::exit(1); + } + let toml_str = &fs::read_to_string("info.toml").unwrap(); let exercises = toml::from_str::<ExerciseList>(toml_str).unwrap().exercises; @@ -134,3 +142,13 @@ fn watch(exercises: &[Exercise]) -> notify::Result<()> { } } } + +fn rustc_exists() -> bool { + Command::new("rustc") + .args(&["--version"]) + .stdout(Stdio::null()) + .spawn() + .and_then(|mut child| child.wait()) + .map(|status| status.success()) + .unwrap_or(false) +} |
