From e89c0e39613e381da45b6a774c6666dcc3e632a2 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 8 Mar 2021 21:39:09 +0300 Subject: Remove now dead code --- xtask/src/codegen/gen_assists_docs.rs | 18 ++++++++++++------ xtask/src/codegen/gen_diagnostic_docs.rs | 6 ++++-- xtask/src/codegen/gen_feature_docs.rs | 6 ++++-- xtask/src/codegen/gen_lint_completions.rs | 10 +++------- xtask/src/codegen/gen_parser_tests.rs | 12 ++++++------ xtask/src/codegen/gen_syntax.rs | 10 +++++----- 6 files changed, 34 insertions(+), 28 deletions(-) (limited to 'xtask/src/codegen') diff --git a/xtask/src/codegen/gen_assists_docs.rs b/xtask/src/codegen/gen_assists_docs.rs index a5af1331d..158680993 100644 --- a/xtask/src/codegen/gen_assists_docs.rs +++ b/xtask/src/codegen/gen_assists_docs.rs @@ -2,14 +2,16 @@ use std::{fmt, path::Path}; +use xshell::write_file; + use crate::{ - codegen::{self, extract_comment_blocks_with_empty_lines, reformat, Location, Mode, PREAMBLE}, + codegen::{self, extract_comment_blocks_with_empty_lines, reformat, Location, PREAMBLE}, project_root, rust_files_in, Result, }; -pub(crate) fn generate_assists_tests(mode: Mode) -> Result<()> { +pub(crate) fn generate_assists_tests() -> Result<()> { let assists = Assist::collect()?; - generate_tests(&assists, mode) + generate_tests(&assists) } pub(crate) fn generate_assists_docs() -> Result<()> { @@ -17,7 +19,8 @@ pub(crate) fn generate_assists_docs() -> Result<()> { let contents = assists.into_iter().map(|it| it.to_string()).collect::>().join("\n\n"); let contents = format!("//{}\n{}\n", PREAMBLE, contents.trim()); let dst = project_root().join("docs/user/generated_assists.adoc"); - codegen::update(&dst, &contents, Mode::Overwrite) + write_file(dst, &contents)?; + Ok(()) } #[derive(Debug)] @@ -111,7 +114,7 @@ impl fmt::Display for Assist { } } -fn generate_tests(assists: &[Assist], mode: Mode) -> Result<()> { +fn generate_tests(assists: &[Assist]) -> Result<()> { let mut buf = String::from("use super::check_doc_test;\n"); for assist in assists.iter() { @@ -135,7 +138,10 @@ r#####" buf.push_str(&test) } let buf = reformat(&buf)?; - codegen::update(&project_root().join("crates/ide_assists/src/tests/generated.rs"), &buf, mode) + codegen::ensure_file_contents( + &project_root().join("crates/ide_assists/src/tests/generated.rs"), + &buf, + ) } fn hide_hash_comments(text: &str) -> String { diff --git a/xtask/src/codegen/gen_diagnostic_docs.rs b/xtask/src/codegen/gen_diagnostic_docs.rs index 2504e09ef..9cf4d0a88 100644 --- a/xtask/src/codegen/gen_diagnostic_docs.rs +++ b/xtask/src/codegen/gen_diagnostic_docs.rs @@ -2,8 +2,10 @@ use std::{fmt, path::PathBuf}; +use xshell::write_file; + use crate::{ - codegen::{self, extract_comment_blocks_with_empty_lines, Location, Mode, PREAMBLE}, + codegen::{extract_comment_blocks_with_empty_lines, Location, PREAMBLE}, project_root, rust_files, Result, }; @@ -13,7 +15,7 @@ pub(crate) fn generate_diagnostic_docs() -> Result<()> { diagnostics.into_iter().map(|it| it.to_string()).collect::>().join("\n\n"); let contents = format!("//{}\n{}\n", PREAMBLE, contents.trim()); let dst = project_root().join("docs/user/generated_diagnostic.adoc"); - codegen::update(&dst, &contents, Mode::Overwrite)?; + write_file(&dst, &contents)?; Ok(()) } diff --git a/xtask/src/codegen/gen_feature_docs.rs b/xtask/src/codegen/gen_feature_docs.rs index 8509fec26..c373d7d70 100644 --- a/xtask/src/codegen/gen_feature_docs.rs +++ b/xtask/src/codegen/gen_feature_docs.rs @@ -2,8 +2,10 @@ use std::{fmt, path::PathBuf}; +use xshell::write_file; + use crate::{ - codegen::{self, extract_comment_blocks_with_empty_lines, Location, Mode, PREAMBLE}, + codegen::{extract_comment_blocks_with_empty_lines, Location, PREAMBLE}, project_root, rust_files, Result, }; @@ -12,7 +14,7 @@ pub(crate) fn generate_feature_docs() -> Result<()> { let contents = features.into_iter().map(|it| it.to_string()).collect::>().join("\n\n"); let contents = format!("//{}\n{}\n", PREAMBLE, contents.trim()); let dst = project_root().join("docs/user/generated_features.adoc"); - codegen::update(&dst, &contents, Mode::Overwrite)?; + write_file(&dst, &contents)?; Ok(()) } diff --git a/xtask/src/codegen/gen_lint_completions.rs b/xtask/src/codegen/gen_lint_completions.rs index b1c057037..3a2937670 100644 --- a/xtask/src/codegen/gen_lint_completions.rs +++ b/xtask/src/codegen/gen_lint_completions.rs @@ -5,12 +5,9 @@ use std::path::{Path, PathBuf}; use walkdir::WalkDir; use xshell::{cmd, read_file}; -use crate::{ - codegen::{project_root, reformat, update, Mode, Result}, - run_rustfmt, -}; +use crate::codegen::{ensure_file_contents, project_root, reformat, Result}; -pub(crate) fn generate_lint_completions(mode: Mode) -> Result<()> { +pub(crate) fn generate_lint_completions() -> Result<()> { if !Path::new("./target/rust").exists() { cmd!("git clone --depth=1 https://github.com/rust-lang/rust ./target/rust").run()?; } @@ -25,8 +22,7 @@ pub(crate) fn generate_lint_completions(mode: Mode) -> Result<()> { let destination = project_root().join("crates/ide_completion/src/generated_lint_completions.rs"); - update(destination.as_path(), &contents, mode)?; - run_rustfmt(mode)?; + ensure_file_contents(destination.as_path(), &contents)?; Ok(()) } diff --git a/xtask/src/codegen/gen_parser_tests.rs b/xtask/src/codegen/gen_parser_tests.rs index cb8939063..096590653 100644 --- a/xtask/src/codegen/gen_parser_tests.rs +++ b/xtask/src/codegen/gen_parser_tests.rs @@ -8,13 +8,13 @@ use std::{ }; use crate::{ - codegen::{extract_comment_blocks, update, Mode}, + codegen::{ensure_file_contents, extract_comment_blocks}, project_root, Result, }; -pub(crate) fn generate_parser_tests(mode: Mode) -> Result<()> { +pub(crate) fn generate_parser_tests() -> Result<()> { let tests = tests_from_dir(&project_root().join(Path::new("crates/parser/src/grammar")))?; - fn install_tests(tests: &HashMap, into: &str, mode: Mode) -> Result<()> { + fn install_tests(tests: &HashMap, into: &str) -> Result<()> { let tests_dir = project_root().join(into); if !tests_dir.is_dir() { fs::create_dir_all(&tests_dir)?; @@ -35,12 +35,12 @@ pub(crate) fn generate_parser_tests(mode: Mode) -> Result<()> { tests_dir.join(file_name) } }; - update(&path, &test.text, mode)?; + ensure_file_contents(&path, &test.text)?; } Ok(()) } - install_tests(&tests.ok, "crates/syntax/test_data/parser/inline/ok", mode)?; - install_tests(&tests.err, "crates/syntax/test_data/parser/inline/err", mode) + install_tests(&tests.ok, "crates/syntax/test_data/parser/inline/ok")?; + install_tests(&tests.err, "crates/syntax/test_data/parser/inline/err") } #[derive(Debug)] diff --git a/xtask/src/codegen/gen_syntax.rs b/xtask/src/codegen/gen_syntax.rs index 191bc0e9d..80f26e8f5 100644 --- a/xtask/src/codegen/gen_syntax.rs +++ b/xtask/src/codegen/gen_syntax.rs @@ -14,25 +14,25 @@ use ungrammar::{rust_grammar, Grammar, Rule}; use crate::{ ast_src::{AstEnumSrc, AstNodeSrc, AstSrc, Cardinality, Field, KindsSrc, KINDS_SRC}, - codegen::{reformat, update, Mode}, + codegen::{ensure_file_contents, reformat}, project_root, Result, }; -pub(crate) fn generate_syntax(mode: Mode) -> Result<()> { +pub(crate) fn generate_syntax() -> Result<()> { let grammar = rust_grammar(); let ast = lower(&grammar); let syntax_kinds_file = project_root().join("crates/parser/src/syntax_kind/generated.rs"); let syntax_kinds = generate_syntax_kinds(KINDS_SRC)?; - update(syntax_kinds_file.as_path(), &syntax_kinds, mode)?; + ensure_file_contents(syntax_kinds_file.as_path(), &syntax_kinds)?; let ast_tokens_file = project_root().join("crates/syntax/src/ast/generated/tokens.rs"); let contents = generate_tokens(&ast)?; - update(ast_tokens_file.as_path(), &contents, mode)?; + ensure_file_contents(ast_tokens_file.as_path(), &contents)?; let ast_nodes_file = project_root().join("crates/syntax/src/ast/generated/nodes.rs"); let contents = generate_nodes(KINDS_SRC, &ast)?; - update(ast_nodes_file.as_path(), &contents, mode)?; + ensure_file_contents(ast_nodes_file.as_path(), &contents)?; Ok(()) } -- cgit v1.2.3