diff --git a/ecosystem/python/exporter/Cargo.toml b/ecosystem/python/exporter/Cargo.toml index e681105b..47bff036 100644 --- a/ecosystem/python/exporter/Cargo.toml +++ b/ecosystem/python/exporter/Cargo.toml @@ -12,5 +12,4 @@ readme.workspace = true [dependencies] ligen-ir.workspace = true -ligen-traits.workspace = true -ligen-common.workspace = true \ No newline at end of file +ligen-generator.workspace = true diff --git a/ecosystem/python/exporter/src/lib.rs b/ecosystem/python/exporter/src/lib.rs index b1af4e5d..dcd02d0c 100644 --- a/ecosystem/python/exporter/src/lib.rs +++ b/ecosystem/python/exporter/src/lib.rs @@ -4,14 +4,14 @@ use std::{path::PathBuf, str::FromStr}; use ligen_ir::{Module, Library}; use prelude::*; -use ligen_traits::generator::file_generator::{TemplateRegister, Template, TemplateBasedGenerator}; - +use ligen_generator::{file_generator::{TemplateRegister, Template, TemplateBasedGenerator}, register_templates}; #[derive(Debug, Default)] pub struct PythonGenerator {} impl TemplateRegister for PythonGenerator { - fn register_templates(&self, _template: &mut Template) -> Result<()> { + fn register_templates(&self, template: &mut Template) -> Result<()> { + register_templates!(template, module); // register_templates!(template, identifier, arguments, implementation, method, function, module, object, parameters, library); Ok(()) } @@ -26,14 +26,12 @@ impl TemplateBasedGenerator for PythonGenerator { PathBuf::from("python".to_string()) } - fn module_generation_path(&self, _library: &Library, _module: &Module) -> PathBuf { - // let is_root_module = library.root_module == *module; - // let name = if is_root_module { "lib.rs" } else { "mod.rs" }; - let path = PathBuf::from_str("src").unwrap(); - // path = path.join(PathBuf::from(module.path.clone().without_first())); - // path = path.join(name); - // FIXME: This is not working. - println!("{}", path.display()); + fn module_generation_path(&self, library: &Library, module: &Module) -> PathBuf { + let is_root_module = library.root_module == *module; + let name = if is_root_module { "lib.rs" } else { "mod.rs" }; + let mut path = PathBuf::from_str("src").unwrap(); + path = path.join(PathBuf::from(module.identifier.name.clone())); + path = path.join(name); path } } diff --git a/ecosystem/python/exporter/src/prelude.rs b/ecosystem/python/exporter/src/prelude.rs index efa293ac..18913d41 100644 --- a/ecosystem/python/exporter/src/prelude.rs +++ b/ecosystem/python/exporter/src/prelude.rs @@ -1 +1 @@ -pub use ligen_common::*; \ No newline at end of file +pub use ligen_generator::prelude::*; \ No newline at end of file diff --git a/ecosystem/python/exporter/src/templates/ligen/python/instagrapi/src b/ecosystem/python/exporter/src/templates/ligen/python/instagrapi/src new file mode 100644 index 00000000..d5676343 --- /dev/null +++ b/ecosystem/python/exporter/src/templates/ligen/python/instagrapi/src @@ -0,0 +1,129 @@ +fn main() { + println!("Hello!") +} +fn main() { + println!("Hello!") +} +fn main() { + println!("Hello!") +} +fn main() { + println!("Hello!") +} +fn main() { + println!("Hello!") +} +fn main() { + println!("Hello!") +} +fn main() { + println!("Hello!") +} +fn main() { + println!("Hello!") +} +fn main() { + println!("Hello!") +} +fn main() { + println!("Hello!") +} +fn main() { + println!("Hello!") +} +fn main() { + println!("Hello!") +} +fn main() { + println!("Hello!") +} +fn main() { + println!("Hello!") +} +fn main() { + println!("Hello!") +} +fn main() { + println!("Hello!") +} +fn main() { + println!("Hello!") +} +fn main() { + println!("Hello!") +} +fn main() { + println!("Hello!") +} +fn main() { + println!("Hello!") +} +fn main() { + println!("Hello!") +} +fn main() { + println!("Hello!") +} +fn main() { + println!("Hello!") +} +fn main() { + println!("Hello!") +} +fn main() { + println!("Hello!") +} +fn main() { + println!("Hello!") +} +fn main() { + println!("Hello!") +} +fn main() { + println!("Hello!") +} +fn main() { + println!("Hello!") +} +fn main() { + println!("Hello!") +} +fn main() { + println!("Hello!") +} +fn main() { + println!("Hello!") +} +fn main() { + println!("Hello!") +} +fn main() { + println!("Hello!") +} +fn main() { + println!("Hello!") +} +fn main() { + println!("Hello!") +} +fn main() { + println!("Hello!") +} +fn main() { + println!("Hello!") +} +fn main() { + println!("Hello!") +} +fn main() { + println!("Hello!") +} +fn main() { + println!("Hello!") +} +fn main() { + println!("Hello!") +} +fn main() { + println!("Hello!") +} diff --git a/ecosystem/python/exporter/src/templates/module.hbs b/ecosystem/python/exporter/src/templates/module.hbs new file mode 100644 index 00000000..4a60a2f8 --- /dev/null +++ b/ecosystem/python/exporter/src/templates/module.hbs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello!") +} \ No newline at end of file diff --git a/ecosystem/rust/cargo/Cargo.toml b/ecosystem/rust/cargo/Cargo.toml index 2a96bae4..fd725cff 100644 --- a/ecosystem/rust/cargo/Cargo.toml +++ b/ecosystem/rust/cargo/Cargo.toml @@ -8,6 +8,7 @@ license.workspace = true [dependencies] ligen-ir.workspace = true ligen-traits.workspace = true +ligen-generator.workspace = true ligen-utils.workspace = true ligen-parser.workspace = true ligen-rust-parser.workspace = true diff --git a/ecosystem/rust/cargo/src/exporter/mod.rs b/ecosystem/rust/cargo/src/exporter/mod.rs index 7236a298..780cddc6 100644 --- a/ecosystem/rust/cargo/src/exporter/mod.rs +++ b/ecosystem/rust/cargo/src/exporter/mod.rs @@ -1,5 +1,5 @@ use ligen_ir::Library; -use ligen_traits::generator::file_generator::{FileGenerator, FileSet}; +use ligen_generator::file_generator::{FileGenerator, FileSet}; use std::path::PathBuf; use std::str::FromStr; use ligen_traits::prelude::*; diff --git a/ligen/generator/Cargo.toml b/ligen/generator/Cargo.toml index 3ab51234..0c1fbc25 100644 --- a/ligen/generator/Cargo.toml +++ b/ligen/generator/Cargo.toml @@ -10,4 +10,8 @@ readme.workspace = true [dependencies] ligen-common.workspace = true -ligen-ir.workspace = true \ No newline at end of file +ligen-ir.workspace = true +ligen-utils.workspace = true + +serde_json.workspace = true +handlebars = "4.1.6" diff --git a/ligen/traits/src/generator/file_generator/file.rs b/ligen/generator/src/generator/file_generator/file.rs similarity index 100% rename from ligen/traits/src/generator/file_generator/file.rs rename to ligen/generator/src/generator/file_generator/file.rs diff --git a/ligen/traits/src/generator/file_generator/mod.rs b/ligen/generator/src/generator/file_generator/mod.rs similarity index 73% rename from ligen/traits/src/generator/file_generator/mod.rs rename to ligen/generator/src/generator/file_generator/mod.rs index d9e4ff21..9b15268f 100644 --- a/ligen/traits/src/generator/file_generator/mod.rs +++ b/ligen/generator/src/generator/file_generator/mod.rs @@ -11,7 +11,7 @@ use crate::generator::Generator; use ligen_ir::Library; use ligen_utils::fs::write_file; -use std::path::{Path, PathBuf}; +use std::path::PathBuf; /// File generator. pub trait FileGenerator { @@ -23,15 +23,8 @@ pub trait FileGenerator { fn generate_files(&self, library: &Library, file_set: &mut FileSet) -> Result<()>; /// Saves the file set. - fn save_file_set(&self, library: &Library, file_set: FileSet) -> Result<()> { - let target = std::env::var("OUT_DIR") - .ok() - .map(PathBuf::from) - .and_then(|path| path - .ancestors() - .nth(4) - .map(Path::to_path_buf)) - .unwrap_or(std::env::current_dir()?); + fn save_file_set(&self, library: &Library, file_set: FileSet, folder: &std::path::Path) -> Result<()> { + let target = folder.to_path_buf(); let target_ligen_dir = target .join("ligen") .join(self.base_path()); @@ -45,10 +38,10 @@ pub trait FileGenerator { } impl Generator for T { - fn generate(&self, library: &Library) -> Result<()> { + fn generate(&self, library: &Library, folder: &std::path::Path) -> Result<()> { let mut file_set = FileSet::default(); self.generate_files(library, &mut file_set)?; - self.save_file_set(library, file_set)?; + self.save_file_set(library, file_set, folder)?; Ok(()) } } \ No newline at end of file diff --git a/ligen/traits/src/generator/file_generator/template_based/builtin_functions.rs b/ligen/generator/src/generator/file_generator/template_based/builtin_functions.rs similarity index 100% rename from ligen/traits/src/generator/file_generator/template_based/builtin_functions.rs rename to ligen/generator/src/generator/file_generator/template_based/builtin_functions.rs diff --git a/ligen/traits/src/generator/file_generator/template_based/mod.rs b/ligen/generator/src/generator/file_generator/template_based/mod.rs similarity index 100% rename from ligen/traits/src/generator/file_generator/template_based/mod.rs rename to ligen/generator/src/generator/file_generator/template_based/mod.rs diff --git a/ligen/traits/src/generator/file_generator/template_based/template.rs b/ligen/generator/src/generator/file_generator/template_based/template.rs similarity index 100% rename from ligen/traits/src/generator/file_generator/template_based/template.rs rename to ligen/generator/src/generator/file_generator/template_based/template.rs diff --git a/ligen/generator/src/generator/mod.rs b/ligen/generator/src/generator/mod.rs index 253b9e48..afb30e04 100644 --- a/ligen/generator/src/generator/mod.rs +++ b/ligen/generator/src/generator/mod.rs @@ -2,8 +2,10 @@ use crate::prelude::*; +pub mod file_generator; + /// Generator trait. pub trait Generator { /// The Generator's entry point. - fn generate(&self, library: &ligen_ir::Library) -> Result<()>; + fn generate(&self, library: &ligen_ir::Library, folder: &std::path::Path) -> Result<()>; } diff --git a/ligen/src/prelude.rs b/ligen/src/prelude.rs index 6b6b704b..42950fb1 100644 --- a/ligen/src/prelude.rs +++ b/ligen/src/prelude.rs @@ -2,5 +2,5 @@ pub use ligen_utils::prelude::*; -pub use ligen_traits::generator::Generator; +pub use ligen_generator::Generator; pub use ligen_ir::prelude::*; diff --git a/ligen/traits/Cargo.toml b/ligen/traits/Cargo.toml index 1a2994e3..8a45d345 100644 --- a/ligen/traits/Cargo.toml +++ b/ligen/traits/Cargo.toml @@ -14,4 +14,3 @@ ligen-utils.workspace = true ligen-common.workspace = true serde.workspace = true serde_json.workspace = true -handlebars = "4.1.6" diff --git a/ligen/traits/src/generator/mod.rs b/ligen/traits/src/generator/mod.rs deleted file mode 100644 index fb19c37b..00000000 --- a/ligen/traits/src/generator/mod.rs +++ /dev/null @@ -1,11 +0,0 @@ -//! Generators. - -use crate::prelude::*; - -pub mod file_generator; - -/// Generator trait. -pub trait Generator { - /// The Generator's entry point. - fn generate(&self, library: &ligen_ir::Library) -> Result<()>; -} diff --git a/ligen/traits/src/lib.rs b/ligen/traits/src/lib.rs index 389187ba..46ea156d 100644 --- a/ligen/traits/src/lib.rs +++ b/ligen/traits/src/lib.rs @@ -1,4 +1,3 @@ pub mod prelude; pub mod marshalling; pub mod build; -pub mod generator; \ No newline at end of file diff --git a/tools/editor/Cargo.toml b/tools/editor/Cargo.toml index f5177b50..187ba9db 100644 --- a/tools/editor/Cargo.toml +++ b/tools/editor/Cargo.toml @@ -16,6 +16,7 @@ ligen-parser.workspace = true ligen-cargo.workspace = true ligen-python-parser.workspace = true ligen-traits.workspace = true +ligen-generator.workspace = true ligen-python-exporter.workspace = true egui_tiles = "0.2.0" stacker = "0.1.15" diff --git a/tools/editor/src/gui/ui/layout/editor/generators/generator.rs b/tools/editor/src/gui/ui/layout/editor/generators/generator.rs index 58a98210..76ebf392 100644 --- a/tools/editor/src/gui/ui/layout/editor/generators/generator.rs +++ b/tools/editor/src/gui/ui/layout/editor/generators/generator.rs @@ -1,16 +1,15 @@ use ligen_cargo::parser::library; -use ligen_traits::generator; use crate::prelude::*; use crate::gui::ui::editor::{widget::Widget, settings::Settings}; pub struct Generator { - generator: Box, + generator: Box, result: String } impl Generator { - pub fn new(generator: T) -> Self { + pub fn new(generator: T) -> Self { let generator = Box::new(generator); let result = Default::default(); Self { generator, result } @@ -22,10 +21,14 @@ impl Widget for Generator { fn show(&mut self, settings: &Settings, ui: &mut egui::Ui, input: &mut Self::Input) { ui.label("Generator"); if ui.button("Generate").clicked() { - match self.generator.generate(input) { - Ok(_) => self.result = "Success".to_string(), - Err(error) => self.result = format!("Error: {:?}", error) - }; + let entry = rfd::FileDialog::new() + .pick_folder(); + if let Some(entry) = entry { + match self.generator.generate(input, &entry) { + Ok(_) => self.result = "Success".to_string(), + Err(error) => self.result = format!("Error: {:?}", error) + }; + } } ui.label(&self.result); } diff --git a/tools/editor/src/gui/ui/layout/editor/parsers/parser/mod.rs b/tools/editor/src/gui/ui/layout/editor/parsers/parser/mod.rs index 670eddf5..8f3c80d4 100644 --- a/tools/editor/src/gui/ui/layout/editor/parsers/parser/mod.rs +++ b/tools/editor/src/gui/ui/layout/editor/parsers/parser/mod.rs @@ -41,4 +41,4 @@ impl Widget for Parser { } }); } -} \ No newline at end of file +}