aboutsummaryrefslogtreecommitdiff
path: root/xtask/src/lib.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-01-07 13:42:56 +0000
committerAleksey Kladov <[email protected]>2020-01-07 13:42:56 +0000
commit91f9bc2b866fc87dbaadb29a8c72eba10ae57c5c (patch)
tree685e2dc2f1e02aadbcd94de5076692a56a09a475 /xtask/src/lib.rs
parentb02576d5623478526328b4716b1fd9c5c2efd637 (diff)
Refactor xtasks
Diffstat (limited to 'xtask/src/lib.rs')
-rw-r--r--xtask/src/lib.rs41
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
3pub mod codegen; 3pub mod codegen;
4pub mod install;
5pub mod pre_commit;
4mod ast_src; 6mod ast_src;
5 7
6use anyhow::Context; 8use anyhow::Context;
7pub use anyhow::Result; 9pub use anyhow::Result;
8use std::{ 10use 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
82pub fn install_rustfmt() -> Result<()> { 83fn 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
87pub 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
99pub fn run_clippy() -> Result<()> { 88pub 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
147pub 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
169fn do_run<F>(cmdline: &str, dir: &str, mut f: F) -> Result<Output> 136fn do_run<F>(cmdline: &str, dir: &str, mut f: F) -> Result<Output>
170where 137where
171 F: FnMut(&mut Command), 138 F: FnMut(&mut Command),