Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions tasks/ast_tools/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ use generators::{
AssertLayouts, AstBuilderGenerator, AstKindGenerator, Generator, TypescriptGenerator,
VisitGenerator, VisitMutGenerator,
};
use output::{write_all_to, Output, RawOutput};
use output::{Output, RawOutput};
use passes::{CalcLayout, Linker};
use schema::Schema;
use util::NormalizeError;

static SOURCE_PATHS: &[&str] = &[
Expand Down Expand Up @@ -90,17 +91,16 @@ fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {

outputs.push(generate_ci_filter(&outputs));

if cli_options.schema {
outputs.push(generate_json_schema(&schema)?);
}

if !cli_options.dry_run {
for output in outputs {
output.write_to_file()?;
}
}

if let CliOptions { schema: true, dry_run: false, .. } = cli_options {
let schema = serde_json::to_string_pretty(&schema.defs).normalize()?;
write_all_to(schema.as_bytes(), SCHEMA_PATH)?;
}

Ok(())
}

Expand All @@ -126,6 +126,15 @@ fn generate_ci_filter(outputs: &[RawOutput]) -> RawOutput {
Output::Yaml { path: GITHUB_WATCH_LIST_PATH.to_string(), code }.into_raw(file!())
}

fn generate_json_schema(schema: &Schema) -> Result<RawOutput> {
log!("Generate JSON schema... ");
let result = serde_json::to_string_pretty(&schema.defs).normalize();
log_result!(result);
let schema = result?;
let output = Output::Raw { path: SCHEMA_PATH.to_string(), code: schema }.into_raw(file!());
Ok(output)
}

#[macro_use]
mod logger {
use std::sync::OnceLock;
Expand Down
2 changes: 2 additions & 0 deletions tasks/ast_tools/src/output/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub enum Output {
Rust { path: String, tokens: TokenStream },
Javascript { path: String, code: String },
Yaml { path: String, code: String },
Raw { path: String, code: String },
}

impl Output {
Expand All @@ -39,6 +40,7 @@ impl Output {
let code = print_yaml(&code, generator_path);
(path, code)
}
Self::Raw { path, code } => (path, code),
};
RawOutput { path, content: code.into_bytes() }
}
Expand Down