diff options
Diffstat (limited to 'xtask/src/lib.rs')
-rw-r--r-- | xtask/src/lib.rs | 41 |
1 files changed, 4 insertions, 37 deletions
diff --git a/xtask/src/lib.rs b/xtask/src/lib.rs index 51a868dee..fb853e71a 100644 --- a/xtask/src/lib.rs +++ b/xtask/src/lib.rs | |||
@@ -1,13 +1,14 @@ | |||
1 | //! FIXME: write short doc here | 1 | //! FIXME: write short doc here |
2 | 2 | ||
3 | pub mod codegen; | 3 | pub mod codegen; |
4 | pub mod install; | ||
5 | pub mod pre_commit; | ||
4 | mod ast_src; | 6 | mod ast_src; |
5 | 7 | ||
6 | use anyhow::Context; | 8 | use anyhow::Context; |
7 | pub use anyhow::Result; | 9 | pub use anyhow::Result; |
8 | use std::{ | 10 | use std::{ |
9 | env, fs, | 11 | env, |
10 | io::{Error as IoError, ErrorKind}, | ||
11 | path::{Path, PathBuf}, | 12 | path::{Path, PathBuf}, |
12 | process::{Command, Output, Stdio}, | 13 | process::{Command, Output, Stdio}, |
13 | }; | 14 | }; |
@@ -79,23 +80,11 @@ pub fn run_rustfmt(mode: Mode) -> Result<()> { | |||
79 | Ok(()) | 80 | Ok(()) |
80 | } | 81 | } |
81 | 82 | ||
82 | pub fn install_rustfmt() -> Result<()> { | 83 | fn install_rustfmt() -> Result<()> { |
83 | run(&format!("rustup toolchain install {}", TOOLCHAIN), ".")?; | 84 | run(&format!("rustup toolchain install {}", TOOLCHAIN), ".")?; |
84 | run(&format!("rustup component add rustfmt --toolchain {}", TOOLCHAIN), ".") | 85 | run(&format!("rustup component add rustfmt --toolchain {}", TOOLCHAIN), ".") |
85 | } | 86 | } |
86 | 87 | ||
87 | pub fn install_pre_commit_hook() -> Result<()> { | ||
88 | let result_path = | ||
89 | PathBuf::from(format!("./.git/hooks/pre-commit{}", std::env::consts::EXE_SUFFIX)); | ||
90 | if !result_path.exists() { | ||
91 | let me = std::env::current_exe()?; | ||
92 | fs::copy(me, result_path)?; | ||
93 | } else { | ||
94 | Err(IoError::new(ErrorKind::AlreadyExists, "Git hook already created"))?; | ||
95 | } | ||
96 | Ok(()) | ||
97 | } | ||
98 | |||
99 | pub fn run_clippy() -> Result<()> { | 88 | pub fn run_clippy() -> Result<()> { |
100 | match Command::new("rustup") | 89 | match Command::new("rustup") |
101 | .args(&["run", TOOLCHAIN, "--", "cargo", "clippy", "--version"]) | 90 | .args(&["run", TOOLCHAIN, "--", "cargo", "clippy", "--version"]) |
@@ -144,28 +133,6 @@ pub fn run_fuzzer() -> Result<()> { | |||
144 | run("rustup run nightly -- cargo fuzz run parser", "./crates/ra_syntax") | 133 | run("rustup run nightly -- cargo fuzz run parser", "./crates/ra_syntax") |
145 | } | 134 | } |
146 | 135 | ||
147 | pub fn reformat_staged_files() -> Result<()> { | ||
148 | run_rustfmt(Mode::Overwrite)?; | ||
149 | let root = project_root(); | ||
150 | let output = Command::new("git") | ||
151 | .arg("diff") | ||
152 | .arg("--diff-filter=MAR") | ||
153 | .arg("--name-only") | ||
154 | .arg("--cached") | ||
155 | .current_dir(&root) | ||
156 | .output()?; | ||
157 | if !output.status.success() { | ||
158 | anyhow::bail!( | ||
159 | "`git diff --diff-filter=MAR --name-only --cached` exited with {}", | ||
160 | output.status | ||
161 | ); | ||
162 | } | ||
163 | for line in String::from_utf8(output.stdout)?.lines() { | ||
164 | run(&format!("git update-index --add {}", root.join(line).to_string_lossy()), ".")?; | ||
165 | } | ||
166 | Ok(()) | ||
167 | } | ||
168 | |||
169 | fn do_run<F>(cmdline: &str, dir: &str, mut f: F) -> Result<Output> | 136 | fn do_run<F>(cmdline: &str, dir: &str, mut f: F) -> Result<Output> |
170 | where | 137 | where |
171 | F: FnMut(&mut Command), | 138 | F: FnMut(&mut Command), |