diff options
author | Aleksey Kladov <[email protected]> | 2018-10-31 20:57:38 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-10-31 20:58:03 +0000 |
commit | fabb804f3091e1cf0f8c289fcb15a8d39bc960a5 (patch) | |
tree | a137ada7251b2038f9ea61916b35f6e169bb0539 /crates/tools | |
parent | 8f1a83b4cbd86e66599b50eafac49f249320fc95 (diff) |
Speedup fmt
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 | } | ||