chore: add codegen crate

This commit is contained in:
nathan 2022-12-01 14:56:20 +08:00
parent 30e7323cf7
commit 44f9254c0a
50 changed files with 151 additions and 145 deletions

View File

@ -570,10 +570,10 @@ dependencies = [
"crossbeam-utils",
"dart-notify",
"ffi-support",
"flowy-codegen",
"flowy-derive",
"flowy-sdk",
"lib-dispatch",
"lib-infra",
"log",
"once_cell",
"protobuf",
@ -588,10 +588,10 @@ version = "0.1.0"
dependencies = [
"allo-isolate",
"bytes",
"flowy-codegen",
"flowy-derive",
"lazy_static",
"lib-dispatch",
"lib-infra",
"log",
"protobuf",
]
@ -816,6 +816,29 @@ dependencies = [
"syn",
]
[[package]]
name = "flowy-codegen"
version = "0.1.0"
dependencies = [
"cmd_lib",
"console",
"fancy-regex",
"flowy-ast",
"itertools",
"lazy_static",
"log",
"phf 0.8.0",
"protoc-bin-vendored",
"protoc-rust",
"serde",
"serde_json",
"similar",
"syn",
"tera",
"toml",
"walkdir",
]
[[package]]
name = "flowy-database"
version = "0.1.0"
@ -834,8 +857,8 @@ version = "0.1.0"
dependencies = [
"dashmap",
"flowy-ast",
"flowy-codegen",
"lazy_static",
"lib-infra",
"proc-macro2",
"quote",
"serde_json",
@ -857,6 +880,7 @@ dependencies = [
"derive_more",
"diesel",
"diesel_derives",
"flowy-codegen",
"flowy-database",
"flowy-derive",
"flowy-document",
@ -891,13 +915,13 @@ name = "flowy-error"
version = "0.1.0"
dependencies = [
"bytes",
"flowy-codegen",
"flowy-database",
"flowy-derive",
"flowy-error-code",
"flowy-sync",
"http-flowy",
"lib-dispatch",
"lib-infra",
"lib-ot",
"lib-sqlite",
"protobuf",
@ -910,8 +934,8 @@ name = "flowy-error-code"
version = "0.1.0"
dependencies = [
"derive_more",
"flowy-codegen",
"flowy-derive",
"lib-infra",
"protobuf",
]
@ -923,6 +947,7 @@ dependencies = [
"dart-notify",
"diesel",
"diesel_derives",
"flowy-codegen",
"flowy-database",
"flowy-derive",
"flowy-document",
@ -965,6 +990,7 @@ dependencies = [
"dashmap",
"diesel",
"fancy-regex",
"flowy-codegen",
"flowy-database",
"flowy-derive",
"flowy-error",
@ -1002,6 +1028,7 @@ name = "flowy-http-model"
version = "0.1.0"
dependencies = [
"bytes",
"flowy-codegen",
"flowy-derive",
"lib-infra",
"md5",
@ -1017,6 +1044,7 @@ dependencies = [
"bytes",
"config",
"dashmap",
"flowy-codegen",
"flowy-derive",
"flowy-document",
"flowy-error",
@ -1178,6 +1206,7 @@ dependencies = [
"diesel_derives",
"fake",
"fancy-regex",
"flowy-codegen",
"flowy-database",
"flowy-derive",
"flowy-error",
@ -1740,27 +1769,10 @@ version = "0.1.0"
dependencies = [
"bytes",
"chrono",
"cmd_lib",
"console",
"fancy-regex",
"flowy-ast",
"futures-core",
"itertools",
"lazy_static",
"log",
"phf 0.8.0",
"pin-project",
"protoc-bin-vendored",
"protoc-rust",
"rand 0.8.5",
"serde",
"serde_json",
"similar",
"syn",
"tera",
"tokio",
"toml",
"walkdir",
]
[[package]]
@ -1827,6 +1839,7 @@ version = "0.1.0"
dependencies = [
"bytes",
"dashmap",
"flowy-codegen",
"flowy-derive",
"futures",
"futures-channel",

View File

@ -37,6 +37,7 @@ http_sync = ["flowy-sdk/http_sync", "flowy-sdk/use_bunyan"]
openssl_vendored = ["flowy-sdk/openssl_vendored"]
[build-dependencies]
lib-infra = { path = "../../../shared-lib/lib-infra", features = [
flowy-codegen= { path = "../../../shared-lib/flowy-codegen", features = [
"dart",
] }
]}

View File

@ -1,5 +1,3 @@
use lib_infra::code_gen;
fn main() {
code_gen::protobuf_file::gen(env!("CARGO_PKG_NAME"));
flowy_codegen::protobuf_file::gen(env!("CARGO_PKG_NAME"));
}

View File

@ -16,7 +16,7 @@ flowy-derive = {path = "../../../shared-lib/flowy-derive" }
lib-dispatch = {path = "../lib-dispatch" }
[features]
dart = ["lib-infra/dart"]
dart = ["flowy-codegen/dart"]
[build-dependencies]
lib-infra = { path = "../../../shared-lib/lib-infra", features = ["proto_gen"] }
flowy-codegen= { path = "../../../shared-lib/flowy-codegen"}

View File

@ -1,5 +1,3 @@
use lib_infra::code_gen;
fn main() {
code_gen::protobuf_file::gen(env!("CARGO_PKG_NAME"));
flowy_codegen::protobuf_file::gen(env!("CARGO_PKG_NAME"));
}

View File

@ -52,10 +52,11 @@ criterion = "0.3"
rand = "0.8.5"
[build-dependencies]
lib-infra = { path = "../../../shared-lib/lib-infra", features = [ "proto_gen"] }
flowy-codegen= { path = "../../../shared-lib/flowy-codegen"}
[features]
sync = []
cloud_sync = ["sync"]
flowy_unit_test = ["lib-ot/flowy_unit_test", "flowy-revision/flowy_unit_test"]
dart = ["lib-infra/dart"]
dart = ["flowy-codegen/dart"]

View File

@ -1,9 +1,7 @@
use lib_infra::code_gen;
fn main() {
let crate_name = env!("CARGO_PKG_NAME");
code_gen::protobuf_file::gen(crate_name);
flowy_codegen::protobuf_file::gen(crate_name);
#[cfg(feature = "dart")]
code_gen::dart_event::gen(crate_name);
flowy_codegen::dart_event::gen(crate_name);
}

View File

@ -27,7 +27,7 @@ ot = ["lib-ot"]
serde = ["serde_json"]
http_server = ["http-flowy"]
db = ["flowy-database", "lib-sqlite", "r2d2"]
dart = ["flowy-error-code/dart", "lib-infra/dart"]
dart = ["flowy-error-code/dart", "flowy-codegen/dart"]
[build-dependencies]
lib-infra = { path = "../../../shared-lib/lib-infra", features = ["proto_gen"] }
flowy-codegen= { path = "../../../shared-lib/flowy-codegen"}

View File

@ -1,5 +1,3 @@
use lib_infra::code_gen;
fn main() {
code_gen::protobuf_file::gen("flowy-error");
flowy_codegen::protobuf_file::gen("flowy-error");
}

View File

@ -42,11 +42,12 @@ flowy-folder = { path = "../flowy-folder", features = ["flowy_unit_test"]}
flowy-test = { path = "../flowy-test" }
[build-dependencies]
lib-infra = { path = "../../../shared-lib/lib-infra", features = [ "proto_gen"] }
flowy-codegen= { path = "../../../shared-lib/flowy-codegen"}
[features]
default = []
sync = []
cloud_sync = ["sync"]
flowy_unit_test = ["lib-ot/flowy_unit_test", "flowy-revision/flowy_unit_test"]
dart = ["lib-infra/dart"]
dart = ["flowy-codegen/dart"]

View File

@ -1,9 +1,7 @@
use lib_infra::code_gen;
fn main() {
let crate_name = env!("CARGO_PKG_NAME");
code_gen::protobuf_file::gen(crate_name);
flowy_codegen::protobuf_file::gen(crate_name);
#[cfg(feature = "dart")]
code_gen::dart_event::gen(crate_name);
flowy_codegen::dart_event::gen(crate_name);
}

View File

@ -51,10 +51,11 @@ flowy-test = { path = "../flowy-test" }
flowy-grid = { path = "../flowy-grid", features = ["flowy_unit_test"]}
[build-dependencies]
lib-infra = { path = "../../../shared-lib/lib-infra", features = ["proto_gen"] }
flowy-codegen= { path = "../../../shared-lib/flowy-codegen"}
[features]
default = []
dart = ["lib-infra/dart"]
dart = ["flowy-codegen/dart"]
flowy_unit_test = ["flowy-revision/flowy_unit_test"]

View File

@ -1,9 +1,7 @@
use lib_infra::code_gen;
fn main() {
let crate_name = env!("CARGO_PKG_NAME");
code_gen::protobuf_file::gen(crate_name);
flowy_codegen::protobuf_file::gen(crate_name);
#[cfg(feature = "dart")]
code_gen::dart_event::gen(crate_name);
flowy_codegen::dart_event::gen(crate_name);
}

View File

@ -42,10 +42,10 @@ nanoid = "0.4.0"
[features]
http_server = []
dart = [
"lib-infra/dart",
"flowy-codegen/dart",
"flowy-user/dart",
"flowy-error/dart",
]
[build-dependencies]
lib-infra = { path = "../../../shared-lib/lib-infra", features = ["proto_gen"] }
flowy-codegen = { path = "../../../shared-lib/flowy-codegen"}

View File

@ -1,9 +1,7 @@
use lib_infra::code_gen;
fn main() {
let crate_name = env!("CARGO_PKG_NAME");
code_gen::protobuf_file::gen(crate_name);
flowy_codegen::protobuf_file::gen(crate_name);
#[cfg(feature = "dart")]
code_gen::dart_event::gen(crate_name);
flowy_codegen::dart_event::gen(crate_name);
}

View File

@ -45,7 +45,7 @@ rand_core = "0.6.3"
rand = "0.8.5"
[features]
dart = ["lib-infra/dart"]
dart = ["flowy-codegen/dart"]
[build-dependencies]
lib-infra = { path = "../../../shared-lib/lib-infra", features = ["proto_gen"] }
flowy-codegen= { path = "../../../shared-lib/flowy-codegen"}

View File

@ -1,9 +1,7 @@
use lib_infra::code_gen;
fn main() {
let crate_name = env!("CARGO_PKG_NAME");
code_gen::protobuf_file::gen(crate_name);
flowy_codegen::protobuf_file::gen(crate_name);
#[cfg(feature = "dart")]
code_gen::dart_event::gen(crate_name);
flowy_codegen::dart_event::gen(crate_name);
}

View File

@ -17,7 +17,7 @@ script_runner = "@shell"
[tasks.rm_macro_build_cache]
script = [
"""
path = canonicalize ../shared-lib/lib-infra/.cache
path = canonicalize ../shared-lib/flowy-codegen/.cache
if is_path_exists ${path}
rm -rf ${path}
end

View File

@ -8,6 +8,7 @@ members = [
"lib-infra",
"flowy-derive",
"flowy-ast",
"flowy-codegen",
"flowy-error-code",
"grid-rev-model",
]

View File

@ -0,0 +1,49 @@
[package]
name = "flowy-codegen"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
log = "0.4.14"
serde = { version = "1.0", features = ["derive"]}
serde_json = "1.0"
flowy-ast = { path = "../flowy-ast"}
cmd_lib = { version = "1", optional = true }
protoc-rust = { version = "2", optional = true }
walkdir = { version = "2", optional = true }
similar = { version = "1.2.2", optional = true }
syn = { version = "1.0.60", features = ["extra-traits", "parsing", "derive", "full"], optional = true }
fancy-regex = { version = "0.10.0", optional = true }
lazy_static = { version = "1.4.0", optional = true }
tera = { version = "1.5.0", optional = true}
itertools = { version = "0.10", optional = true }
phf = { version = "0.8.0", features = ["macros"], optional = true }
console = {version = "0.14.0", optional = true}
protoc-bin-vendored = { version = "3.0", optional = true }
toml = {version = "0.5.8", optional = true}
[features]
proto_gen = [
"similar",
"syn",
"fancy-regex",
"lazy_static",
"tera",
"itertools",
"phf",
"walkdir",
"console",
"toml",
"cmd_lib",
"protoc-rust",
"walkdir",
"protoc-bin-vendored",
]
dart_event = ["walkdir", "tera", "syn"]
dart = ["proto_gen", "dart_event"]

View File

@ -1,6 +1,6 @@
use super::event_template::*;
use crate::code_gen::flowy_toml::{parse_crate_config_from, CrateConfig};
use crate::code_gen::util::{is_crate_dir, is_hidden, path_string_with_component, read_file};
use crate::flowy_toml::{parse_crate_config_from, CrateConfig};
use crate::util::{is_crate_dir, is_hidden, path_string_with_component, read_file};
use flowy_ast::{event_ast::*, *};
use std::fs::File;
use std::io::Write;

View File

@ -1,4 +1,4 @@
use crate::code_gen::util::get_tera;
use crate::util::get_tera;
use tera::Context;
pub struct EventTemplate {

View File

@ -2,9 +2,9 @@
#![allow(dead_code)]
#![allow(unused_imports)]
#![allow(unused_results)]
use crate::code_gen::protobuf_file::template::{EnumTemplate, StructTemplate, RUST_TYPE_MAP};
use crate::code_gen::protobuf_file::{parse_crate_info_from_path, ProtoFile, ProtobufCrateContext};
use crate::code_gen::util::*;
use crate::protobuf_file::template::{EnumTemplate, StructTemplate, RUST_TYPE_MAP};
use crate::protobuf_file::{parse_crate_info_from_path, ProtoFile, ProtobufCrateContext};
use crate::util::*;
use fancy_regex::Regex;
use flowy_ast::*;
use lazy_static::lazy_static;

View File

@ -6,7 +6,7 @@ mod proto_gen;
mod proto_info;
mod template;
use crate::code_gen::util::path_string_with_component;
use crate::util::path_string_with_component;
use itertools::Itertools;
use log::info;
pub use proto_gen::*;

View File

@ -2,11 +2,11 @@
#![allow(dead_code)]
#![allow(unused_imports)]
#![allow(unused_results)]
use crate::code_gen::protobuf_file::ast::parse_protobuf_context_from;
use crate::code_gen::protobuf_file::proto_info::ProtobufCrateContext;
use crate::code_gen::protobuf_file::ProtoFile;
use crate::code_gen::util::*;
use crate::code_gen::ProtoCache;
use crate::protobuf_file::ast::parse_protobuf_context_from;
use crate::protobuf_file::proto_info::ProtobufCrateContext;
use crate::protobuf_file::ProtoFile;
use crate::util::*;
use crate::ProtoCache;
use std::collections::HashMap;
use std::fs::File;
use std::path::Path;

View File

@ -1,6 +1,6 @@
#![allow(dead_code)]
use crate::code_gen::flowy_toml::{parse_crate_config_from, CrateConfig, FlowyConfig};
use crate::code_gen::util::*;
use crate::flowy_toml::{parse_crate_config_from, CrateConfig, FlowyConfig};
use crate::util::*;
use std::fs::OpenOptions;
use std::io::Write;
use std::path::PathBuf;

View File

@ -1,4 +1,4 @@
use crate::code_gen::util::get_tera;
use crate::util::get_tera;
use itertools::Itertools;
use tera::Context;

View File

@ -1,5 +1,5 @@
use crate::code_gen::protobuf_file::ast::FlowyEnum;
use crate::code_gen::util::get_tera;
use crate::protobuf_file::ast::FlowyEnum;
use crate::util::get_tera;
use tera::Context;
pub struct EnumTemplate {

View File

@ -1,4 +1,4 @@
use crate::code_gen::util::get_tera;
use crate::util::get_tera;
use flowy_ast::*;
use phf::phf_map;
use tera::Context;

View File

@ -142,7 +142,7 @@ pub fn suffix_relative_to_path(path: &str, base: &str) -> String {
}
pub fn get_tera(directory: &str) -> Tera {
let mut root = format!("{}/src/code_gen/", env!("CARGO_MANIFEST_DIR"));
let mut root = format!("{}/src/", env!("CARGO_MANIFEST_DIR"));
root.push_str(directory);
let root_absolute_path = match std::fs::canonicalize(&root) {

View File

@ -20,7 +20,7 @@ proc-macro2 = "1.0"
flowy-ast = { path = "../flowy-ast" }
lazy_static = {version = "1.4.0"}
dashmap = "5"
lib-infra = { path = "../lib-infra", features = ["proto_gen"]}
flowy-codegen= { path = "../flowy-codegen"}
serde_json = "1.0"
walkdir = "2.3.1"

View File

@ -1,7 +1,7 @@
use dashmap::{DashMap, DashSet};
use flowy_ast::{Ctxt, TyInfo};
use flowy_codegen::ProtoCache;
use lazy_static::lazy_static;
use lib_infra::code_gen::ProtoCache;
use std::fs::File;
use std::io::Read;
use std::sync::atomic::{AtomicBool, Ordering};
@ -50,7 +50,7 @@ pub fn category_from_str(type_str: String) -> TypeCategory {
IS_LOAD.store(true, Ordering::SeqCst);
// Dependents on another crate file is not good, just leave it here.
// Maybe find another way to read the .cache in the future.
let cache_dir = format!("{}/../lib-infra/.cache", env!("CARGO_MANIFEST_DIR"));
let cache_dir = format!("{}/../flowy-codegen/.cache", env!("CARGO_MANIFEST_DIR"));
for path in WalkDir::new(cache_dir)
.into_iter()
.filter_map(|e| e.ok())

View File

@ -11,7 +11,8 @@ protobuf = {version = "2.18.0"}
derive_more = {version = "0.99", features = ["display"]}
[build-dependencies]
lib-infra = { path = "../lib-infra", features = ["proto_gen"] }
flowy-codegen= { path = "../flowy-codegen"}
[features]
dart = ["lib-infra/dart"]
dart = ["flowy-codegen/dart"]

View File

@ -1,5 +1,3 @@
use lib_infra::code_gen;
fn main() {
code_gen::protobuf_file::gen(env!("CARGO_PKG_NAME"));
flowy_codegen::protobuf_file::gen(env!("CARGO_PKG_NAME"));
}

View File

@ -13,5 +13,6 @@ protobuf = {version = "2.18.0"}
md5 = "0.7.0"
[build-dependencies]
lib-infra = { path = "../lib-infra", features = ["proto_gen"] }
flowy-codegen= { path = "../flowy-codegen"}

View File

@ -1,5 +1,3 @@
use lib_infra::code_gen;
fn main() {
code_gen::protobuf_file::gen(env!("CARGO_PKG_NAME"));
flowy_codegen::protobuf_file::gen(env!("CARGO_PKG_NAME"));
}

View File

@ -6,50 +6,10 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
log = "0.4.14"
chrono = "0.4.19"
bytes = { version = "1.0" }
pin-project = "1.0"
futures-core = { version = "0.3" }
tokio = { version = "1.0", features = ["time", "rt"] }
rand = "0.8.5"
serde = { version = "1.0", features = ["derive"]}
serde_json = "1.0"
cmd_lib = { version = "1", optional = true }
protoc-rust = { version = "2", optional = true }
walkdir = { version = "2", optional = true }
flowy-ast = { path = "../flowy-ast", optional = true}
similar = { version = "1.2.2", optional = true }
syn = { version = "1.0.60", features = ["extra-traits", "parsing", "derive", "full"], optional = true }
fancy-regex = { version = "0.10.0", optional = true }
lazy_static = { version = "1.4.0", optional = true }
tera = { version = "1.5.0", optional = true}
itertools = { version = "0.10", optional = true }
phf = { version = "0.8.0", features = ["macros"], optional = true }
console = {version = "0.14.0", optional = true}
protoc-bin-vendored = { version = "3.0", optional = true }
toml = {version = "0.5.8", optional = true}
[features]
proto_gen = [
"flowy-ast",
"similar",
"syn",
"fancy-regex",
"lazy_static",
"tera",
"itertools",
"phf",
"walkdir",
"console",
"toml",
"cmd_lib",
"protoc-rust",
"walkdir",
"protoc-bin-vendored",
]
dart_event = ["walkdir", "flowy-ast", "tera", "syn"]
dart = ["proto_gen", "dart_event"]

View File

@ -1,4 +1,3 @@
pub mod code_gen;
pub mod future;
pub mod ref_map;
pub mod retry;

View File

@ -28,11 +28,11 @@ parking_lot = "0.12.1"
dashmap = "5"
[build-dependencies]
lib-infra = { path = "../lib-infra", features = ["proto_gen"] }
flowy-codegen= { path = "../flowy-codegen"}
[dev-dependencies]
tokio = {version = "1", features = ["full"]}
env_logger = "0.8.2"
[features]
dart = ["lib-infra/dart"]
dart = ["flowy-codegen/dart"]

View File

@ -1,5 +1,3 @@
use lib_infra::code_gen;
fn main() {
code_gen::protobuf_file::gen(env!("CARGO_PKG_NAME"));
flowy_codegen::protobuf_file::gen(env!("CARGO_PKG_NAME"));
}