diff options
author | Aleksey Kladov <[email protected]> | 2019-08-19 09:05:49 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-08-19 09:42:39 +0100 |
commit | 5633829a1684fb622d44d1aeb3baede4e7c0ff26 (patch) | |
tree | fc3d0ce648fd16842de918df2c6d61d60275e865 /crates | |
parent | 832b40a075285063b857bf05a69a8cf979d9078a (diff) |
drop tera dependency
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_tools/Cargo.toml | 1 | ||||
-rw-r--r-- | crates/ra_tools/src/lib.rs | 28 |
2 files changed, 25 insertions, 4 deletions
diff --git a/crates/ra_tools/Cargo.toml b/crates/ra_tools/Cargo.toml index a40a452aa..4c9aa1cc3 100644 --- a/crates/ra_tools/Cargo.toml +++ b/crates/ra_tools/Cargo.toml | |||
@@ -6,7 +6,6 @@ authors = ["rust-analyzer developers"] | |||
6 | publish = false | 6 | publish = false |
7 | 7 | ||
8 | [dependencies] | 8 | [dependencies] |
9 | teraron = "0.1.0" | ||
10 | walkdir = "2.1.3" | 9 | walkdir = "2.1.3" |
11 | itertools = "0.8.0" | 10 | itertools = "0.8.0" |
12 | clap = "2.32.0" | 11 | clap = "2.32.0" |
diff --git a/crates/ra_tools/src/lib.rs b/crates/ra_tools/src/lib.rs index de8c472d1..c02dee953 100644 --- a/crates/ra_tools/src/lib.rs +++ b/crates/ra_tools/src/lib.rs | |||
@@ -11,8 +11,6 @@ use std::{ | |||
11 | 11 | ||
12 | use itertools::Itertools; | 12 | use itertools::Itertools; |
13 | 13 | ||
14 | pub use teraron::{Mode, Overwrite, Verify}; | ||
15 | |||
16 | pub use self::codegen::generate; | 14 | pub use self::codegen::generate; |
17 | 15 | ||
18 | pub type Result<T> = std::result::Result<T, Box<dyn Error>>; | 16 | pub type Result<T> = std::result::Result<T, Box<dyn Error>>; |
@@ -26,6 +24,13 @@ pub const SYNTAX_KINDS: &str = "crates/ra_parser/src/syntax_kind/generated.rs.te | |||
26 | pub const AST: &str = "crates/ra_syntax/src/ast/generated.rs"; | 24 | pub const AST: &str = "crates/ra_syntax/src/ast/generated.rs"; |
27 | const TOOLCHAIN: &str = "stable"; | 25 | const TOOLCHAIN: &str = "stable"; |
28 | 26 | ||
27 | #[derive(Debug, PartialEq, Eq, Clone, Copy)] | ||
28 | pub enum Mode { | ||
29 | Overwrite, | ||
30 | Verify, | ||
31 | } | ||
32 | pub use Mode::*; | ||
33 | |||
29 | #[derive(Debug)] | 34 | #[derive(Debug)] |
30 | pub struct Test { | 35 | pub struct Test { |
31 | pub name: String, | 36 | pub name: String, |
@@ -222,7 +227,7 @@ pub fn gen_tests(mode: Mode) -> Result<()> { | |||
222 | tests_dir.join(file_name) | 227 | tests_dir.join(file_name) |
223 | } | 228 | } |
224 | }; | 229 | }; |
225 | teraron::update(&path, &test.text, mode)?; | 230 | update(&path, &test.text, mode)?; |
226 | } | 231 | } |
227 | Ok(()) | 232 | Ok(()) |
228 | } | 233 | } |
@@ -306,3 +311,20 @@ fn existing_tests(dir: &Path, ok: bool) -> Result<HashMap<String, (PathBuf, Test | |||
306 | } | 311 | } |
307 | Ok(res) | 312 | Ok(res) |
308 | } | 313 | } |
314 | |||
315 | /// A helper to update file on disk if it has changed. | ||
316 | /// With verify = false, | ||
317 | pub fn update(path: &Path, contents: &str, mode: Mode) -> Result<()> { | ||
318 | match fs::read_to_string(path) { | ||
319 | Ok(ref old_contents) if old_contents == contents => { | ||
320 | return Ok(()); | ||
321 | } | ||
322 | _ => (), | ||
323 | } | ||
324 | if mode == Verify { | ||
325 | Err(format!("`{}` is not up-to-date", path.display()))?; | ||
326 | } | ||
327 | eprintln!("updating {}", path.display()); | ||
328 | fs::write(path, contents)?; | ||
329 | Ok(()) | ||
330 | } | ||