diff options
Diffstat (limited to 'crates/tools')
-rw-r--r-- | crates/tools/src/lib.rs | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/crates/tools/src/lib.rs b/crates/tools/src/lib.rs index 3387d0620..8b8e9974e 100644 --- a/crates/tools/src/lib.rs +++ b/crates/tools/src/lib.rs | |||
@@ -4,7 +4,7 @@ extern crate teraron; | |||
4 | 4 | ||
5 | use std::{ | 5 | use std::{ |
6 | path::{Path, PathBuf}, | 6 | path::{Path, PathBuf}, |
7 | process::Command, | 7 | process::{Command, Stdio}, |
8 | }; | 8 | }; |
9 | 9 | ||
10 | use failure::bail; | 10 | use failure::bail; |
@@ -92,14 +92,16 @@ pub fn run(cmdline: &str, dir: &str) -> Result<()> { | |||
92 | } | 92 | } |
93 | 93 | ||
94 | pub fn run_rustfmt(mode: Mode) -> Result<()> { | 94 | pub fn run_rustfmt(mode: Mode) -> Result<()> { |
95 | run(&format!("rustup install {}", TOOLCHAIN), ".")?; | 95 | match Command::new("rustup") |
96 | run( | 96 | .args(&["run", TOOLCHAIN, "--", "cargo", "fmt", "--version"]) |
97 | &format!( | 97 | .stderr(Stdio::null()) |
98 | "rustup component add rustfmt-preview --toolchain {}", | 98 | .stdout(Stdio::null()) |
99 | TOOLCHAIN | 99 | .status() |
100 | ), | 100 | { |
101 | ".", | 101 | Ok(status) if status.success() => (), |
102 | )?; | 102 | _ => install_rustfmt()?, |
103 | }; | ||
104 | |||
103 | if mode == Verify { | 105 | if mode == Verify { |
104 | run( | 106 | run( |
105 | &format!("rustup run {} -- cargo fmt -- --check", TOOLCHAIN), | 107 | &format!("rustup run {} -- cargo fmt -- --check", TOOLCHAIN), |
@@ -110,3 +112,14 @@ pub fn run_rustfmt(mode: Mode) -> Result<()> { | |||
110 | } | 112 | } |
111 | Ok(()) | 113 | Ok(()) |
112 | } | 114 | } |
115 | |||
116 | fn install_rustfmt() -> Result<()> { | ||
117 | run(&format!("rustup install {}", TOOLCHAIN), ".")?; | ||
118 | run( | ||
119 | &format!( | ||
120 | "rustup component add rustfmt-preview --toolchain {}", | ||
121 | TOOLCHAIN | ||
122 | ), | ||
123 | ".", | ||
124 | ) | ||
125 | } | ||