daml_codegen/generator/
code_generator.rs1use daml_lf::DarFile;
2
3use crate::error::DamlCodeGenResult;
4use crate::generator::ModuleOutputMode;
5use crate::generator::combined::generate_archive_combined;
6use crate::generator::generator_options::RenderMethod;
7use crate::generator::module_matcher::ModuleMatcher;
8use crate::generator::separate::generate_archive_separate;
9
10pub fn daml_codegen(
35 dar_file: &str,
36 output_path: &str,
37 module_filter_regex: &[&str],
38 quote_method: RenderMethod,
39 module_output_mode: ModuleOutputMode,
40) -> DamlCodeGenResult<()> {
41 println!("cargo:rerun-if-changed={dar_file}");
42 daml_codegen_internal(dar_file, output_path, module_filter_regex, quote_method, module_output_mode)
43}
44
45#[doc(hidden)]
46pub fn daml_codegen_internal(
47 dar_file: &str,
48 output_path: &str,
49 module_filter_regex: &[&str],
50 render_method: RenderMethod,
51 module_output_mode: ModuleOutputMode,
52) -> DamlCodeGenResult<()> {
53 let dar = DarFile::from_file(dar_file)?;
54 dar.apply(|archive| {
55 let module_matcher = ModuleMatcher::new(module_filter_regex)?;
56 match module_output_mode {
57 ModuleOutputMode::Separate => {
58 generate_archive_separate(archive, output_path.as_ref(), &module_matcher, &render_method)?;
59 },
60 ModuleOutputMode::Combined => {
61 generate_archive_combined(archive, output_path.as_ref(), &module_matcher, &render_method)?;
62 },
63 }
64 Ok(())
65 })?
66}