diff --git a/adl/adl.work.json b/adl/adl.work.json index 2f0d0186..3f0efcad 100644 --- a/adl/adl.work.json +++ b/adl/adl.work.json @@ -1,35 +1,14 @@ { "adlc": "0.0.0", - "defaultGenOptions": [ - { - "tsgen": { - "referenceable": "remote", - "outputs": { - "outputDir": "", - "manifest": null - }, - "includeRuntime": false, - "runtimeDir": null, - "generate_transitive": false, - "include_resolver": false, - "modules": "all", - "capitalize_branch_names_in_types": true, - "capitalize_type_names": true - } - } - ], "use": [ { - "path": "./adlc_dev" + "path": "./adlc" }, { "path": "./tests/test31/lib" }, { - "path": "./stdlib/adlc" - }, - { - "path": "./stdlib/sys" + "path": "./stdlib" }, { "path": "./tests/test31/proj", diff --git a/adl/adlc/adl.pkg.json b/adl/adlc/adl.pkg.json new file mode 100644 index 00000000..1fd37cc9 --- /dev/null +++ b/adl/adlc/adl.pkg.json @@ -0,0 +1,5 @@ +{ + "path" : "github.com/adl-lang/adl/adl/adlc", + "globalAlias": "adlc", + "adlc": "0.0.0" +} \ No newline at end of file diff --git a/adl/stdlib/adlc/config/cpp.adl b/adl/adlc/adlc/config/cpp.adl similarity index 100% rename from adl/stdlib/adlc/config/cpp.adl rename to adl/adlc/adlc/config/cpp.adl diff --git a/adl/stdlib/adlc/config/haskell.adl b/adl/adlc/adlc/config/haskell.adl similarity index 100% rename from adl/stdlib/adlc/config/haskell.adl rename to adl/adlc/adlc/config/haskell.adl diff --git a/adl/stdlib/adlc/config/java.adl b/adl/adlc/adlc/config/java.adl similarity index 100% rename from adl/stdlib/adlc/config/java.adl rename to adl/adlc/adlc/config/java.adl diff --git a/adl/stdlib/adlc/config/rust.adl b/adl/adlc/adlc/config/rust.adl similarity index 100% rename from adl/stdlib/adlc/config/rust.adl rename to adl/adlc/adlc/config/rust.adl diff --git a/adl/stdlib/adlc/config/typescript.adl b/adl/adlc/adlc/config/typescript.adl similarity index 100% rename from adl/stdlib/adlc/config/typescript.adl rename to adl/adlc/adlc/config/typescript.adl diff --git a/adl/stdlib/adlc/packaging.adl b/adl/adlc/adlc/packaging.adl similarity index 100% rename from adl/stdlib/adlc/packaging.adl rename to adl/adlc/adlc/packaging.adl diff --git a/adl/adlc_dev/testing_table.adl b/adl/adlc/adlc/testing_table.adl similarity index 93% rename from adl/adlc_dev/testing_table.adl rename to adl/adlc/adlc/testing_table.adl index 69c7403b..fd019d45 100644 --- a/adl/adlc_dev/testing_table.adl +++ b/adl/adlc/adlc/testing_table.adl @@ -1,4 +1,4 @@ -module testing_table { +module adlc.testing_table { type TestFilesMetaData = Vector; diff --git a/adl/adlc_dev/adl.pkg.json b/adl/adlc_dev/adl.pkg.json deleted file mode 100644 index 818e73d2..00000000 --- a/adl/adlc_dev/adl.pkg.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "path" : "github.com/adl-lang/adl/adl/adkc_dev", - "adlc": "0.0.0" -} \ No newline at end of file diff --git a/adl/stdlib/sys/adl.pkg.json b/adl/stdlib/adl.pkg.json similarity index 100% rename from adl/stdlib/sys/adl.pkg.json rename to adl/stdlib/adl.pkg.json diff --git a/adl/stdlib/adlc/adl.pkg.json b/adl/stdlib/adlc/adl.pkg.json deleted file mode 100644 index 5fee7ae7..00000000 --- a/adl/stdlib/adlc/adl.pkg.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "path" : "github.com/adl-lang/adl/adl/stdlib/adlc", - "globalAlias": "adlc", - "adlc": "0.0.0" -} \ No newline at end of file diff --git a/adl/tests/test31/proj/adl.pkg.json b/adl/tests/test31/proj/adl.pkg.json index 151f1e96..d74880bb 100644 --- a/adl/tests/test31/proj/adl.pkg.json +++ b/adl/tests/test31/proj/adl.pkg.json @@ -1,4 +1,5 @@ { "path" : "github.com/adl-lang/adl/adl/tests/test31/proj", + "globalAlias": "protoclient", "adlc": "0.0.0" } \ No newline at end of file diff --git a/adl/tests/testing_table.json b/adl/tests/testing_table.json index 4e08e528..d7169e18 100644 --- a/adl/tests/testing_table.json +++ b/adl/tests/testing_table.json @@ -76,5 +76,12 @@ "It is resolved as sys.annotation.SerializedName" ] }, + { + "module_root": "test31/proj", + "output_dir": "test_app/protoapp/src/adlgen", + "modules": ["protoclient.protoapp.api" ], + "title": "protoapp", + "lib_paths": [ "test31/lib" ] + }, { "module_root": "demo1", "modules": ["picture" ] } ] diff --git a/haskell/compiler/lib/adl/adlc b/haskell/compiler/lib/adl/adlc index 35f70239..915760b0 120000 --- a/haskell/compiler/lib/adl/adlc +++ b/haskell/compiler/lib/adl/adlc @@ -1 +1 @@ -../../../../adl/stdlib/adlc \ No newline at end of file +../../../../adl/adlc \ No newline at end of file diff --git a/rust/compiler/Readme.md b/rust/compiler/Readme.md index 63743e0f..b824cef8 100644 --- a/rust/compiler/Readme.md +++ b/rust/compiler/Readme.md @@ -23,4 +23,9 @@ adlc ast --searchdir ../../adl/stdlib --searchdir ../../adl/tests/test4 --combi cd build/ast jq -S . test30_04.adlc.ast.json > test30_04.adlc.sorted.ast.json code -d test30_04.adlc.sorted.ast.json test30_04.rust.sorted.ast.json +``` + +### Testing Workspace Gen +``` +cargo +nightly run gen ../../adl/tests/test31/proj ``` \ No newline at end of file diff --git a/rust/compiler/genadl.sh b/rust/compiler/genadl.sh index 40fe4c49..639e4c96 100755 --- a/rust/compiler/genadl.sh +++ b/rust/compiler/genadl.sh @@ -14,16 +14,16 @@ adlc rust \ --runtime-module adlrt \ --include-rt \ --searchdir $ADL_STDLIB_DIR \ - $ADL_STDLIB_DIR/sys/adlast2.adl $ADL_STDLIB_DIR/adlc/packaging.adl + $ADL_STDLIB_DIR/sys/adlast2.adl $ADL_STDLIB_DIR/adlc/adlc/packaging.adl $ADL_STDLIB_DIR/adlc/adlc/testing_table.adl -ADL_DIR=../../adl +# ADL_DIR=../../adl -adlc rust \ - --no-overwrite \ - --verbose \ - --generate-transitive \ - --outputdir ./src \ - --module adlgen_dev \ - --runtime-module adlrt \ - --searchdir $ADL_DIR/stdlib \ - $ADL_DIR/adlc_dev/testing_table.adl +# adlc rust \ +# --no-overwrite \ +# --verbose \ +# --generate-transitive \ +# --outputdir ./src \ +# --module adlgen_dev \ +# --runtime-module adlrt \ +# --searchdir $ADL_DIR/stdlib \ +# $ADL_DIR/adlc/adlc/testing_table.adl diff --git a/rust/compiler/src/adlgen/adlc/mod.rs b/rust/compiler/src/adlgen/adlc/mod.rs index 74795cd9..cbf8cac6 100644 --- a/rust/compiler/src/adlgen/adlc/mod.rs +++ b/rust/compiler/src/adlgen/adlc/mod.rs @@ -1,2 +1,3 @@ pub mod config; -pub mod packaging; \ No newline at end of file +pub mod packaging; +pub mod testing_table; \ No newline at end of file diff --git a/rust/compiler/src/adlgen_dev/testing_table.rs b/rust/compiler/src/adlgen/adlc/testing_table.rs similarity index 97% rename from rust/compiler/src/adlgen_dev/testing_table.rs rename to rust/compiler/src/adlgen/adlc/testing_table.rs index 0b1e1631..d89ea0a6 100644 --- a/rust/compiler/src/adlgen_dev/testing_table.rs +++ b/rust/compiler/src/adlgen/adlc/testing_table.rs @@ -1,4 +1,4 @@ -// @generated from adl module testing_table +// @generated from adl module adlc.testing_table use serde::Deserialize; use serde::Serialize; diff --git a/rust/compiler/src/adlgen_dev/mod.rs b/rust/compiler/src/adlgen_dev/mod.rs deleted file mode 100644 index 3794897e..00000000 --- a/rust/compiler/src/adlgen_dev/mod.rs +++ /dev/null @@ -1,2 +0,0 @@ -pub mod sys; -pub mod testing_table; \ No newline at end of file diff --git a/rust/compiler/src/adlgen_dev/sys/annotations.rs b/rust/compiler/src/adlgen_dev/sys/annotations.rs deleted file mode 100644 index 29e6a1ca..00000000 --- a/rust/compiler/src/adlgen_dev/sys/annotations.rs +++ /dev/null @@ -1,23 +0,0 @@ -// @generated from adl module sys.annotations - -use serde::Deserialize; -use serde::Serialize; - -pub type Doc = String; - -pub type SerializedName = String; - -#[derive(Clone,Debug,Deserialize,Eq,Hash,PartialEq,Serialize)] -pub struct SerializedWithInternalTag { - pub tag: String, -} - -impl SerializedWithInternalTag { - pub fn new(tag: String) -> SerializedWithInternalTag { - SerializedWithInternalTag { - tag: tag, - } - } -} - -pub type CustomSerialization = bool; diff --git a/rust/compiler/src/adlgen_dev/sys/mod.rs b/rust/compiler/src/adlgen_dev/sys/mod.rs deleted file mode 100644 index adf10224..00000000 --- a/rust/compiler/src/adlgen_dev/sys/mod.rs +++ /dev/null @@ -1 +0,0 @@ -pub mod annotations; \ No newline at end of file diff --git a/rust/compiler/src/cli/tsgen/tests.rs b/rust/compiler/src/cli/tsgen/tests.rs index b7750e04..513b83c3 100644 --- a/rust/compiler/src/cli/tsgen/tests.rs +++ b/rust/compiler/src/cli/tsgen/tests.rs @@ -4,8 +4,7 @@ use std::path::PathBuf; use serde::Deserialize; -use crate::adlgen_dev::testing_table::TestFilesMetaData; -use crate::cli::{AdlSearchOpts, OutputOpts}; +use crate::{cli::{AdlSearchOpts, OutputOpts}, adlgen::adlc::testing_table::TestFilesMetaData}; use super::*; @@ -56,6 +55,7 @@ fn generate_ts_from_test_files() { let mut search_path = vec![]; search_path.push(PathBuf::from("../../adl/stdlib")); + search_path.push(PathBuf::from("../../adl/adlc")); { let mut sp = PathBuf::from("../../adl/tests/"); sp.push(t.module_root.clone()); @@ -127,7 +127,7 @@ fn generate_ts_from_test_files() { // TODO consider failed. // t.fail - match tsgen(&opts) { + match tsgen(loader_from_search_paths(&opts.search.path), &opts) { Ok(_) => { println!( "{} {} - ts gen output; {}", diff --git a/rust/compiler/src/cli/workspace.rs b/rust/compiler/src/cli/workspace.rs index cf59b5dd..e83bef8c 100644 --- a/rust/compiler/src/cli/workspace.rs +++ b/rust/compiler/src/cli/workspace.rs @@ -1,4 +1,4 @@ -use std::path::PathBuf; +use std::path::{Path, PathBuf}; use std::{env, fs}; use anyhow::anyhow; @@ -9,8 +9,8 @@ use crate::adlgen::adlc::packaging::{AdlPackage, AdlWorkspace0, AdlWorkspace1, G use crate::adlrt::custom::sys::types::pair::Pair; use crate::processing::loader::loader_from_workspace; -use super::{tsgen, TsStyle}; use super::TsOpts; +use super::{tsgen, TsStyle}; pub(crate) fn workspace(opts: &super::GenOpts) -> Result<(), anyhow::Error> { let pkg_defs = collect_work_and_pkg(&opts.dir)?; @@ -36,16 +36,23 @@ pub(crate) fn workspace(opts: &super::GenOpts) -> Result<(), anyhow::Error> { }, modules: match &opts.modules { crate::adlgen::adlc::packaging::ModuleSrc::All => { - let mut ms = vec![]; - ms - }, + let pkg_root = wrk1.0.join(pkg.0 .0.path.clone()).canonicalize()?; + if let Some(pkg_root_str) = pkg_root.as_os_str().to_str() { + walk_and_collect_adl_modules(pkg_root_str, &pkg_root) + } else { + return Err(anyhow!("Could get str from pkg_root")); + } + } crate::adlgen::adlc::packaging::ModuleSrc::Modules(ms) => ms.clone(), }, capitalize_branch_names_in_types: opts.capitalize_branch_names_in_types, capitalize_type_names: opts.capitalize_type_names, }; let loader = loader_from_workspace(wrk1.0.clone(), wrk1.1.clone()); - println!("TsGen for pkg {:?} in workspace {:?} output dir {}", pkg.0.0, wrk1.0, opts.outputs.output_dir); + println!( + "TsGen for pkg {:?} in workspace {:?} output dir {}", + pkg.0 .0, wrk1.0, opts.outputs.output_dir + ); tsgen::tsgen(loader, &tsopts)?; } } @@ -54,12 +61,39 @@ pub(crate) fn workspace(opts: &super::GenOpts) -> Result<(), anyhow::Error> { Ok(()) } +fn walk_and_collect_adl_modules(pkg_root: &str, cwd: &PathBuf) -> Vec { + let mut mods = vec![]; + if let Ok(files) = fs::read_dir(cwd) { + for file in files { + if let Ok(file) = file { + let path = file.path(); + if path.is_file() { + if let Some(ext) = path.extension() { + if ext == "adl" { + if let Some(name) = path.to_str() { + let name1 = &name[(pkg_root.len() + 1)..(name.len() - 4)]; + let name2 = name1.replace("/", "."); + println!(" adding module {}", name2); + mods.push(name2); + } + } + } + } + if path.is_dir() { + mods.append(&mut walk_and_collect_adl_modules(pkg_root, &path)); + } + } + } + } + mods +} + fn collection_to_workspace( pkg_defs: Vec<(PkgDef, PathBuf, &str)>, ) -> Result<(PathBuf, AdlWorkspace1), anyhow::Error> { for porw in pkg_defs { let porw_path = porw.1.join(porw.2); - let content = fs::read_to_string(&porw_path)?; + let content = fs::read_to_string(&porw_path).map_err(|e| anyhow!("{:?}: {}", porw_path, e.to_string()))?; let mut de = serde_json::Deserializer::from_str(&content); match porw.0 { PkgDef::Pkg => { @@ -76,7 +110,7 @@ fn collection_to_workspace( }; for p in wrk0.r#use.iter() { let p_path = porw.1.join(&p.path).join("adl.pkg.json"); - let content = fs::read_to_string(&p_path)?; + let content = fs::read_to_string(&p_path).map_err(|e| anyhow!("Can't read pkg specified in workspace.\n\tworkspace {:?}\n\t package {:?}\n\t error: {}", porw_path, p_path, e.to_string()))?; let mut de = serde_json::Deserializer::from_str(&content); let pkg = AdlPackage::deserialize(&mut de) .map_err(|e| anyhow!("{:?}: {}", p_path, e.to_string()))?; diff --git a/rust/compiler/src/lib.rs b/rust/compiler/src/lib.rs index fde53686..204bfae6 100644 --- a/rust/compiler/src/lib.rs +++ b/rust/compiler/src/lib.rs @@ -5,5 +5,3 @@ pub mod parser; pub mod processing; pub mod utils; pub mod adlstdlib; - -mod adlgen_dev; \ No newline at end of file diff --git a/rust/compiler/src/processing/loader.rs b/rust/compiler/src/processing/loader.rs index b15b6b88..f87ca9c9 100644 --- a/rust/compiler/src/processing/loader.rs +++ b/rust/compiler/src/processing/loader.rs @@ -43,6 +43,7 @@ impl AdlLoader for WorkspaceLoader { fn load(&mut self, module_name: &adlast::ModuleName) -> Result, anyhow::Error> { for pkg in &self.workspace.r#use { let pkg_path = pkg.0.1.path.as_str(); + println!(" looking for {} in {} or {:?}", module_name, pkg_path, pkg.0.1.global_alias.clone()); let pkg_name = if module_name.starts_with(pkg_path) { Some(pkg.0.1.path.clone()) } else if let Some(alias) = pkg.0.1.global_alias.clone() {