From ef56167c252f31f1c1c490cf6066be8d5b1b8178 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Ka=C5=BAmierczak?= <119811949+wkazmierczak@users.noreply.github.com> Date: Wed, 10 Jul 2024 16:13:54 +0200 Subject: [PATCH] Move generating_json_schema to `generate` crate (#608) --- .github/workflows/check.yml | 4 ++-- .github/workflows/deploy_docs.yml | 5 +++-- Cargo.lock | 3 +++ Cargo.toml | 7 ++++--- build_tools/nix/package.nix | 2 -- generate/Cargo.toml | 6 ++++++ .../src/bin/generate_from_types}/definition.rs | 0 .../src/bin/generate_from_types}/docs_config.rs | 0 .../src/bin/generate_from_types}/document.rs | 0 .../bin/generate_from_types/generate_docs.rs | 17 +++++------------ .../generate_json_schema.rs | 14 ++++++-------- generate/src/bin/generate_from_types/main.rs | 14 ++++++++++++++ .../src/bin/generate_from_types}/markdown.rs | 0 .../generate_from_types}/markdown/overrides.rs | 0 .../generate_from_types}/markdown/properties.rs | 0 .../markdown/type_definition.rs | 0 .../bin/generate_from_types}/schema_parser.rs | 0 .../generate_from_types}/schema_parser/utils.rs | 0 18 files changed, 43 insertions(+), 29 deletions(-) rename {src/bin/generate_docs => generate/src/bin/generate_from_types}/definition.rs (100%) rename {src/bin/generate_docs => generate/src/bin/generate_from_types}/docs_config.rs (100%) rename {src/bin/generate_docs => generate/src/bin/generate_from_types}/document.rs (100%) rename src/bin/generate_docs/main.rs => generate/src/bin/generate_from_types/generate_docs.rs (89%) rename {src/bin => generate/src/bin/generate_from_types}/generate_json_schema.rs (87%) create mode 100644 generate/src/bin/generate_from_types/main.rs rename {src/bin/generate_docs => generate/src/bin/generate_from_types}/markdown.rs (100%) rename {src/bin/generate_docs => generate/src/bin/generate_from_types}/markdown/overrides.rs (100%) rename {src/bin/generate_docs => generate/src/bin/generate_from_types}/markdown/properties.rs (100%) rename {src/bin/generate_docs => generate/src/bin/generate_from_types}/markdown/type_definition.rs (100%) rename {src/bin/generate_docs => generate/src/bin/generate_from_types}/schema_parser.rs (100%) rename {src/bin/generate_docs => generate/src/bin/generate_from_types}/schema_parser/utils.rs (100%) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 40ded6baa..0449488b7 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -57,9 +57,9 @@ jobs: cargo build --no-default-features - name: ๐Ÿ“„ Generate JSON schema + working-directory: ./generate run: | - cargo run --bin generate_json_schema --features decklink - cargo run --bin generate_docs --features decklink + cargo run --bin generate_from_types -- --check - name: ๐Ÿงช Run tests run: | diff --git a/.github/workflows/deploy_docs.yml b/.github/workflows/deploy_docs.yml index 0a7ad5a7c..8956a12d3 100644 --- a/.github/workflows/deploy_docs.yml +++ b/.github/workflows/deploy_docs.yml @@ -7,7 +7,7 @@ on: paths: - "docs/**" - "schemas/**" - - "src/bin/generate_docs/**" + - "generate/src/bin/generate_from_types/**" - ".github/workflows/deploy_docs.yml" permissions: @@ -49,7 +49,8 @@ jobs: uses: dtolnay/rust-toolchain@stable - name: ๐Ÿ“„ Generate docs from JSON schema - run: cargo run --bin generate_docs --features decklink + working-directory: ./generate + run: cargo run --bin generate_from_types - name: ๐Ÿ›  Install dependencies run: npm ci diff --git a/Cargo.lock b/Cargo.lock index 8018c2993..01cc7d6c8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1051,9 +1051,12 @@ dependencies = [ "reqwest", "rtcp", "rtp", + "schemars", + "serde", "serde_json", "socket2", "tracing", + "tracing-subscriber", "webrtc-util", ] diff --git a/Cargo.toml b/Cargo.toml index c14b32bf5..6b4d3dffa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -47,6 +47,9 @@ rubato = "0.15.0" futures-util = "0.3.30" tokio = { version = "1", features = ["full"] } wgpu = { version = "0.19.1", features = ["naga-ir"] } +schemars = { git = "https://github.com/membraneframework-labs/schemars", rev = "a5ad1f9", features = [ + "preserve_order", +] } [dependencies] compositor_render = { workspace = true } @@ -63,9 +66,7 @@ log = { workspace = true } signal-hook = { workspace = true } shared_memory = { workspace = true } fs_extra = "1.3.0" -schemars = { git = "https://github.com/membraneframework-labs/schemars", rev = "a5ad1f9", features = [ - "preserve_order", -] } +schemars = { workspace = true} image = { workspace = true } thiserror = { workspace = true } rtp = { workspace = true } diff --git a/build_tools/nix/package.nix b/build_tools/nix/package.nix index 4f5c3e5ac..c080f5a9b 100644 --- a/build_tools/nix/package.nix +++ b/build_tools/nix/package.nix @@ -61,8 +61,6 @@ rustPlatform.buildRustPackage { postFixup = '' - rm -f $out/bin/generate_docs - rm -f $out/bin/generate_json_schema rm -f $out/bin/live_compositor rm -f $out/bin/package_for_release rm -f $out/bin/update_snapshots diff --git a/generate/Cargo.toml b/generate/Cargo.toml index e0427c0b8..e2c660875 100644 --- a/generate/Cargo.toml +++ b/generate/Cargo.toml @@ -6,10 +6,14 @@ license = "BUSL-1.1" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[features] +decklink = ["live_compositor/decklink"] + [dependencies] live_compositor = { path = ".." } reqwest = { workspace = true } anyhow = { workspace = true } +serde = { workspace = true } serde_json = { workspace = true } ffmpeg-next = { workspace = true } compositor_render = { workspace = true } @@ -23,3 +27,5 @@ tracing = { workspace = true } opus = { workspace = true } pitch-detection = "0.3.0" rand = { workspace = true } +schemars = { workspace = true} +tracing-subscriber = { version = "0.3.18", features = ["json", "env-filter"] } diff --git a/src/bin/generate_docs/definition.rs b/generate/src/bin/generate_from_types/definition.rs similarity index 100% rename from src/bin/generate_docs/definition.rs rename to generate/src/bin/generate_from_types/definition.rs diff --git a/src/bin/generate_docs/docs_config.rs b/generate/src/bin/generate_from_types/docs_config.rs similarity index 100% rename from src/bin/generate_docs/docs_config.rs rename to generate/src/bin/generate_from_types/docs_config.rs diff --git a/src/bin/generate_docs/document.rs b/generate/src/bin/generate_from_types/document.rs similarity index 100% rename from src/bin/generate_docs/document.rs rename to generate/src/bin/generate_from_types/document.rs diff --git a/src/bin/generate_docs/main.rs b/generate/src/bin/generate_from_types/generate_docs.rs similarity index 89% rename from src/bin/generate_docs/main.rs rename to generate/src/bin/generate_from_types/generate_docs.rs index 19a6bb2ef..206306c04 100644 --- a/src/bin/generate_docs/main.rs +++ b/generate/src/bin/generate_from_types/generate_docs.rs @@ -1,21 +1,14 @@ -use docs_config::DocsConfig; -use document::generate; +use super::docs_config::DocsConfig; +use super::document::generate; +use super::markdown::overrides; use live_compositor::types::{ DeckLink, Image, ImageSpec, InputStream, Mp4, Rescaler, RtpInputStream, RtpOutputStream, Shader, ShaderSpec, Text, Tiles, View, WebRendererSpec, WebView, }; -use markdown::overrides; use std::{fs, path::PathBuf}; -mod definition; -mod docs_config; -mod document; -mod markdown; -mod schema_parser; - -fn main() { - tracing_subscriber::fmt().init(); - let docs_path = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("docs/pages/api/generated"); +pub fn generate_docs() { + let docs_path = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../docs/pages/api/generated"); if docs_path.exists() { fs::remove_dir_all(&docs_path).unwrap(); } diff --git a/src/bin/generate_json_schema.rs b/generate/src/bin/generate_from_types/generate_json_schema.rs similarity index 87% rename from src/bin/generate_json_schema.rs rename to generate/src/bin/generate_from_types/generate_json_schema.rs index 4a6951c83..5d212fdc8 100644 --- a/src/bin/generate_json_schema.rs +++ b/generate/src/bin/generate_from_types/generate_json_schema.rs @@ -23,12 +23,10 @@ enum ApiTypes { UpdateOutput(types::UpdateOutputRequest), } -fn main() { - let update_flag = std::env::args().any(|arg| &arg == "--update"); - - let (scene_schema_action, api_schema_action) = match update_flag { - true => (SchemaAction::Update, SchemaAction::Update), - false => (SchemaAction::CheckIfChanged, SchemaAction::Nothing), +pub fn generate_json_schema(check_flag: bool) { + let (scene_schema_action, api_schema_action) = match check_flag { + true => (SchemaAction::CheckIfChanged, SchemaAction::Nothing), + false => (SchemaAction::Update, SchemaAction::Update), }; generate_schema( schema_for!(types::UpdateOutputRequest), @@ -79,7 +77,7 @@ fn generate_schema(mut current_schema: RootSchema, name: &'static str, action: S flatten_definitions_with_one_of(&mut current_schema); let root_dir: PathBuf = ROOT_DIR.into(); - let schema_path = root_dir.join(format!("schemas/{}.schema.json", name)); + let schema_path = root_dir.join(format!("../schemas/{}.schema.json", name)); fs::create_dir_all(schema_path.parent().unwrap()).unwrap(); let json_from_disk = match fs::read_to_string(&schema_path) { @@ -93,7 +91,7 @@ fn generate_schema(mut current_schema: RootSchema, name: &'static str, action: S match action { SchemaAction::Update => fs::write(schema_path, &json_current).unwrap(), SchemaAction::CheckIfChanged => { - panic!("Schema changed. Rerun with --update to regenerate it.") + panic!("Schema changed. Rerun without --check arg to regenerate it.") } SchemaAction::Nothing => (), }; diff --git a/generate/src/bin/generate_from_types/main.rs b/generate/src/bin/generate_from_types/main.rs new file mode 100644 index 000000000..584a458eb --- /dev/null +++ b/generate/src/bin/generate_from_types/main.rs @@ -0,0 +1,14 @@ +mod definition; +mod docs_config; +mod document; +mod generate_docs; +mod generate_json_schema; +mod markdown; +mod schema_parser; + +fn main() { + tracing_subscriber::fmt().init(); + let check_flag = std::env::args().any(|arg| &arg == "--check"); + generate_docs::generate_docs(); + generate_json_schema::generate_json_schema(check_flag); +} diff --git a/src/bin/generate_docs/markdown.rs b/generate/src/bin/generate_from_types/markdown.rs similarity index 100% rename from src/bin/generate_docs/markdown.rs rename to generate/src/bin/generate_from_types/markdown.rs diff --git a/src/bin/generate_docs/markdown/overrides.rs b/generate/src/bin/generate_from_types/markdown/overrides.rs similarity index 100% rename from src/bin/generate_docs/markdown/overrides.rs rename to generate/src/bin/generate_from_types/markdown/overrides.rs diff --git a/src/bin/generate_docs/markdown/properties.rs b/generate/src/bin/generate_from_types/markdown/properties.rs similarity index 100% rename from src/bin/generate_docs/markdown/properties.rs rename to generate/src/bin/generate_from_types/markdown/properties.rs diff --git a/src/bin/generate_docs/markdown/type_definition.rs b/generate/src/bin/generate_from_types/markdown/type_definition.rs similarity index 100% rename from src/bin/generate_docs/markdown/type_definition.rs rename to generate/src/bin/generate_from_types/markdown/type_definition.rs diff --git a/src/bin/generate_docs/schema_parser.rs b/generate/src/bin/generate_from_types/schema_parser.rs similarity index 100% rename from src/bin/generate_docs/schema_parser.rs rename to generate/src/bin/generate_from_types/schema_parser.rs diff --git a/src/bin/generate_docs/schema_parser/utils.rs b/generate/src/bin/generate_from_types/schema_parser/utils.rs similarity index 100% rename from src/bin/generate_docs/schema_parser/utils.rs rename to generate/src/bin/generate_from_types/schema_parser/utils.rs