diff options
Diffstat (limited to 'xtask/src')
-rw-r--r-- | xtask/src/bin/pre-commit.rs | 4 | ||||
-rw-r--r-- | xtask/src/codegen.rs | 8 | ||||
-rw-r--r-- | xtask/src/codegen/gen_parser_tests.rs | 4 | ||||
-rw-r--r-- | xtask/src/lib.rs | 16 | ||||
-rw-r--r-- | xtask/src/main.rs | 31 |
5 files changed, 31 insertions, 32 deletions
diff --git a/xtask/src/bin/pre-commit.rs b/xtask/src/bin/pre-commit.rs index cc6ccb25e..44507fb74 100644 --- a/xtask/src/bin/pre-commit.rs +++ b/xtask/src/bin/pre-commit.rs | |||
@@ -19,10 +19,10 @@ fn update_staged() -> Result<()> { | |||
19 | .current_dir(&root) | 19 | .current_dir(&root) |
20 | .output()?; | 20 | .output()?; |
21 | if !output.status.success() { | 21 | if !output.status.success() { |
22 | Err(format!( | 22 | anyhow::bail!( |
23 | "`git diff --diff-filter=MAR --name-only --cached` exited with {}", | 23 | "`git diff --diff-filter=MAR --name-only --cached` exited with {}", |
24 | output.status | 24 | output.status |
25 | ))?; | 25 | ); |
26 | } | 26 | } |
27 | for line in String::from_utf8(output.stdout)?.lines() { | 27 | for line in String::from_utf8(output.stdout)?.lines() { |
28 | run(&format!("git update-index --add {}", root.join(line).to_string_lossy()), ".")?; | 28 | run(&format!("git update-index --add {}", root.join(line).to_string_lossy()), ".")?; |
diff --git a/xtask/src/codegen.rs b/xtask/src/codegen.rs index 770b55a9a..53f524f42 100644 --- a/xtask/src/codegen.rs +++ b/xtask/src/codegen.rs | |||
@@ -52,7 +52,7 @@ fn update(path: &Path, contents: &str, mode: Mode) -> Result<()> { | |||
52 | _ => (), | 52 | _ => (), |
53 | } | 53 | } |
54 | if mode == Mode::Verify { | 54 | if mode == Mode::Verify { |
55 | Err(format!("`{}` is not up-to-date", path.display()))?; | 55 | anyhow::bail!("`{}` is not up-to-date", path.display()); |
56 | } | 56 | } |
57 | eprintln!("updating {}", path.display()); | 57 | eprintln!("updating {}", path.display()); |
58 | fs::write(path, contents)?; | 58 | fs::write(path, contents)?; |
@@ -101,10 +101,8 @@ fn do_extract_comment_blocks(text: &str, allow_blocks_with_empty_lins: bool) -> | |||
101 | let is_comment = line.starts_with(prefix); | 101 | let is_comment = line.starts_with(prefix); |
102 | if is_comment { | 102 | if is_comment { |
103 | block.push(line[prefix.len()..].to_string()); | 103 | block.push(line[prefix.len()..].to_string()); |
104 | } else { | 104 | } else if !block.is_empty() { |
105 | if !block.is_empty() { | 105 | res.push(mem::replace(&mut block, Vec::new())); |
106 | res.push(mem::replace(&mut block, Vec::new())) | ||
107 | } | ||
108 | } | 106 | } |
109 | } | 107 | } |
110 | if !block.is_empty() { | 108 | if !block.is_empty() { |
diff --git a/xtask/src/codegen/gen_parser_tests.rs b/xtask/src/codegen/gen_parser_tests.rs index d0f0f683b..2977da2fa 100644 --- a/xtask/src/codegen/gen_parser_tests.rs +++ b/xtask/src/codegen/gen_parser_tests.rs | |||
@@ -102,10 +102,10 @@ fn tests_from_dir(dir: &Path) -> Result<Tests> { | |||
102 | for test in collect_tests(&text) { | 102 | for test in collect_tests(&text) { |
103 | if test.ok { | 103 | if test.ok { |
104 | if let Some(old_test) = res.ok.insert(test.name.clone(), test) { | 104 | if let Some(old_test) = res.ok.insert(test.name.clone(), test) { |
105 | return Err(format!("Duplicate test: {}", old_test.name).into()); | 105 | anyhow::bail!("Duplicate test: {}", old_test.name); |
106 | } | 106 | } |
107 | } else if let Some(old_test) = res.err.insert(test.name.clone(), test) { | 107 | } else if let Some(old_test) = res.err.insert(test.name.clone(), test) { |
108 | return Err(format!("Duplicate test: {}", old_test.name).into()); | 108 | anyhow::bail!("Duplicate test: {}", old_test.name); |
109 | } | 109 | } |
110 | } | 110 | } |
111 | Ok(()) | 111 | Ok(()) |
diff --git a/xtask/src/lib.rs b/xtask/src/lib.rs index bae4c4650..bfee2f9c8 100644 --- a/xtask/src/lib.rs +++ b/xtask/src/lib.rs | |||
@@ -2,10 +2,10 @@ | |||
2 | 2 | ||
3 | pub mod codegen; | 3 | pub mod codegen; |
4 | 4 | ||
5 | use anyhow::Context; | ||
6 | pub use anyhow::Result; | ||
5 | use std::{ | 7 | use std::{ |
6 | env, | 8 | env, fs, |
7 | error::Error, | ||
8 | fs, | ||
9 | io::{Error as IoError, ErrorKind}, | 9 | io::{Error as IoError, ErrorKind}, |
10 | path::{Path, PathBuf}, | 10 | path::{Path, PathBuf}, |
11 | process::{Command, Output, Stdio}, | 11 | process::{Command, Output, Stdio}, |
@@ -13,8 +13,6 @@ use std::{ | |||
13 | 13 | ||
14 | use crate::codegen::Mode; | 14 | use crate::codegen::Mode; |
15 | 15 | ||
16 | pub type Result<T> = std::result::Result<T, Box<dyn Error>>; | ||
17 | |||
18 | const TOOLCHAIN: &str = "stable"; | 16 | const TOOLCHAIN: &str = "stable"; |
19 | 17 | ||
20 | pub fn project_root() -> PathBuf { | 18 | pub fn project_root() -> PathBuf { |
@@ -69,7 +67,7 @@ pub fn run_rustfmt(mode: Mode) -> Result<()> { | |||
69 | .status() | 67 | .status() |
70 | { | 68 | { |
71 | Ok(status) if status.success() => (), | 69 | Ok(status) if status.success() => (), |
72 | _ => install_rustfmt()?, | 70 | _ => install_rustfmt().context("install rustfmt")?, |
73 | }; | 71 | }; |
74 | 72 | ||
75 | if mode == Mode::Verify { | 73 | if mode == Mode::Verify { |
@@ -112,7 +110,7 @@ pub fn run_clippy() -> Result<()> { | |||
112 | .status() | 110 | .status() |
113 | { | 111 | { |
114 | Ok(status) if status.success() => (), | 112 | Ok(status) if status.success() => (), |
115 | _ => install_clippy()?, | 113 | _ => install_clippy().context("install clippy")?, |
116 | }; | 114 | }; |
117 | 115 | ||
118 | let allowed_lints = [ | 116 | let allowed_lints = [ |
@@ -162,9 +160,9 @@ where | |||
162 | let exec = args.next().unwrap(); | 160 | let exec = args.next().unwrap(); |
163 | let mut cmd = Command::new(exec); | 161 | let mut cmd = Command::new(exec); |
164 | f(cmd.args(args).current_dir(proj_dir).stderr(Stdio::inherit())); | 162 | f(cmd.args(args).current_dir(proj_dir).stderr(Stdio::inherit())); |
165 | let output = cmd.output()?; | 163 | let output = cmd.output().with_context(|| format!("running `{}`", cmdline))?; |
166 | if !output.status.success() { | 164 | if !output.status.success() { |
167 | Err(format!("`{}` exited with {}", cmdline, output.status))?; | 165 | anyhow::bail!("`{}` exited with {}", cmdline, output.status); |
168 | } | 166 | } |
169 | Ok(output) | 167 | Ok(output) |
170 | } | 168 | } |
diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 16bddfb28..f14e6c8ae 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs | |||
@@ -9,6 +9,7 @@ | |||
9 | //! `.cargo/config`. | 9 | //! `.cargo/config`. |
10 | mod help; | 10 | mod help; |
11 | 11 | ||
12 | use anyhow::Context; | ||
12 | use core::fmt::Write; | 13 | use core::fmt::Write; |
13 | use core::str; | 14 | use core::str; |
14 | use pico_args::Arguments; | 15 | use pico_args::Arguments; |
@@ -19,7 +20,7 @@ use xtask::{ | |||
19 | }; | 20 | }; |
20 | 21 | ||
21 | // Latest stable, feel free to send a PR if this lags behind. | 22 | // Latest stable, feel free to send a PR if this lags behind. |
22 | const REQUIRED_RUST_VERSION: u32 = 38; | 23 | const REQUIRED_RUST_VERSION: u32 = 39; |
23 | 24 | ||
24 | struct InstallOpt { | 25 | struct InstallOpt { |
25 | client: Option<ClientOpt>, | 26 | client: Option<ClientOpt>, |
@@ -113,21 +114,21 @@ fn handle_extra_flags(e: pico_args::Error) -> Result<()> { | |||
113 | write!(&mut invalid_flags, "{}, ", flag)?; | 114 | write!(&mut invalid_flags, "{}, ", flag)?; |
114 | } | 115 | } |
115 | let (invalid_flags, _) = invalid_flags.split_at(invalid_flags.len() - 2); | 116 | let (invalid_flags, _) = invalid_flags.split_at(invalid_flags.len() - 2); |
116 | Err(format!("Invalid flags: {}", invalid_flags).into()) | 117 | anyhow::bail!("Invalid flags: {}", invalid_flags) |
117 | } else { | 118 | } else { |
118 | Err(e.to_string().into()) | 119 | anyhow::bail!(e.to_string()) |
119 | } | 120 | } |
120 | } | 121 | } |
121 | 122 | ||
122 | fn install(opts: InstallOpt) -> Result<()> { | 123 | fn install(opts: InstallOpt) -> Result<()> { |
123 | if cfg!(target_os = "macos") { | 124 | if cfg!(target_os = "macos") { |
124 | fix_path_for_mac()? | 125 | fix_path_for_mac().context("Fix path for mac")? |
125 | } | 126 | } |
126 | if let Some(server) = opts.server { | 127 | if let Some(server) = opts.server { |
127 | install_server(server)?; | 128 | install_server(server).context("install server")?; |
128 | } | 129 | } |
129 | if let Some(client) = opts.client { | 130 | if let Some(client) = opts.client { |
130 | install_client(client)?; | 131 | install_client(client).context("install client")?; |
131 | } | 132 | } |
132 | Ok(()) | 133 | Ok(()) |
133 | } | 134 | } |
@@ -139,7 +140,7 @@ fn fix_path_for_mac() -> Result<()> { | |||
139 | const ROOT_DIR: &str = ""; | 140 | const ROOT_DIR: &str = ""; |
140 | let home_dir = match env::var("HOME") { | 141 | let home_dir = match env::var("HOME") { |
141 | Ok(home) => home, | 142 | Ok(home) => home, |
142 | Err(e) => Err(format!("Failed getting HOME from environment with error: {}.", e))?, | 143 | Err(e) => anyhow::bail!("Failed getting HOME from environment with error: {}.", e), |
143 | }; | 144 | }; |
144 | 145 | ||
145 | [ROOT_DIR, &home_dir] | 146 | [ROOT_DIR, &home_dir] |
@@ -153,12 +154,12 @@ fn fix_path_for_mac() -> Result<()> { | |||
153 | if !vscode_path.is_empty() { | 154 | if !vscode_path.is_empty() { |
154 | let vars = match env::var_os("PATH") { | 155 | let vars = match env::var_os("PATH") { |
155 | Some(path) => path, | 156 | Some(path) => path, |
156 | None => Err("Could not get PATH variable from env.")?, | 157 | None => anyhow::bail!("Could not get PATH variable from env."), |
157 | }; | 158 | }; |
158 | 159 | ||
159 | let mut paths = env::split_paths(&vars).collect::<Vec<_>>(); | 160 | let mut paths = env::split_paths(&vars).collect::<Vec<_>>(); |
160 | paths.append(&mut vscode_path); | 161 | paths.append(&mut vscode_path); |
161 | let new_paths = env::join_paths(paths)?; | 162 | let new_paths = env::join_paths(paths).context("build env PATH")?; |
162 | env::set_var("PATH", &new_paths); | 163 | env::set_var("PATH", &new_paths); |
163 | } | 164 | } |
164 | 165 | ||
@@ -197,7 +198,7 @@ fn install_client(ClientOpt::VsCode: ClientOpt) -> Result<()> { | |||
197 | 198 | ||
198 | let code_binary = match code_binary { | 199 | let code_binary = match code_binary { |
199 | Some(it) => it, | 200 | Some(it) => it, |
200 | None => Err("Can't execute `code --version`. Perhaps it is not in $PATH?")?, | 201 | None => anyhow::bail!("Can't execute `code --version`. Perhaps it is not in $PATH?"), |
201 | }; | 202 | }; |
202 | 203 | ||
203 | Cmd { | 204 | Cmd { |
@@ -218,8 +219,10 @@ fn install_client(ClientOpt::VsCode: ClientOpt) -> Result<()> { | |||
218 | .run_with_output()?; | 219 | .run_with_output()?; |
219 | 220 | ||
220 | if !str::from_utf8(&output.stdout)?.contains("ra-lsp") { | 221 | if !str::from_utf8(&output.stdout)?.contains("ra-lsp") { |
221 | Err("Could not install the Visual Studio Code extension. \ | 222 | anyhow::bail!( |
222 | Please make sure you have at least NodeJS 10.x installed and try again.")?; | 223 | "Could not install the Visual Studio Code extension. \ |
224 | Please make sure you have at least NodeJS 10.x installed and try again." | ||
225 | ); | ||
223 | } | 226 | } |
224 | 227 | ||
225 | Ok(()) | 228 | Ok(()) |
@@ -239,7 +242,7 @@ fn install_server(opts: ServerOpt) -> Result<()> { | |||
239 | if old_rust { | 242 | if old_rust { |
240 | eprintln!( | 243 | eprintln!( |
241 | "\nWARNING: at least rust 1.{}.0 is required to compile rust-analyzer\n", | 244 | "\nWARNING: at least rust 1.{}.0 is required to compile rust-analyzer\n", |
242 | REQUIRED_RUST_VERSION | 245 | REQUIRED_RUST_VERSION, |
243 | ) | 246 | ) |
244 | } | 247 | } |
245 | 248 | ||
@@ -252,7 +255,7 @@ fn install_server(opts: ServerOpt) -> Result<()> { | |||
252 | if res.is_err() && old_rust { | 255 | if res.is_err() && old_rust { |
253 | eprintln!( | 256 | eprintln!( |
254 | "\nWARNING: at least rust 1.{}.0 is required to compile rust-analyzer\n", | 257 | "\nWARNING: at least rust 1.{}.0 is required to compile rust-analyzer\n", |
255 | REQUIRED_RUST_VERSION | 258 | REQUIRED_RUST_VERSION, |
256 | ) | 259 | ) |
257 | } | 260 | } |
258 | 261 | ||