Skip to content

Commit

Permalink
1st working version of a workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
millergarym committed Apr 17, 2023
1 parent 7736092 commit 5c940b7
Show file tree
Hide file tree
Showing 26 changed files with 82 additions and 86 deletions.
25 changes: 2 additions & 23 deletions adl/adl.work.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
5 changes: 5 additions & 0 deletions adl/adlc/adl.pkg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"path" : "github.com/adl-lang/adl/adl/adlc",
"globalAlias": "adlc",
"adlc": "0.0.0"
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module testing_table {
module adlc.testing_table {

type TestFilesMetaData = Vector<TestFileMetaData>;

Expand Down
4 changes: 0 additions & 4 deletions adl/adlc_dev/adl.pkg.json

This file was deleted.

File renamed without changes.
5 changes: 0 additions & 5 deletions adl/stdlib/adlc/adl.pkg.json

This file was deleted.

1 change: 1 addition & 0 deletions adl/tests/test31/proj/adl.pkg.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"path" : "github.com/adl-lang/adl/adl/tests/test31/proj",
"globalAlias": "protoclient",
"adlc": "0.0.0"
}
7 changes: 7 additions & 0 deletions adl/tests/testing_table.json
Original file line number Diff line number Diff line change
Expand Up @@ -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" ] }
]
2 changes: 1 addition & 1 deletion haskell/compiler/lib/adl/adlc
5 changes: 5 additions & 0 deletions rust/compiler/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
22 changes: 11 additions & 11 deletions rust/compiler/genadl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion rust/compiler/src/adlgen/adlc/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pub mod config;
pub mod packaging;
pub mod packaging;
pub mod testing_table;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @generated from adl module testing_table
// @generated from adl module adlc.testing_table

use serde::Deserialize;
use serde::Serialize;
Expand Down
2 changes: 0 additions & 2 deletions rust/compiler/src/adlgen_dev/mod.rs

This file was deleted.

23 changes: 0 additions & 23 deletions rust/compiler/src/adlgen_dev/sys/annotations.rs

This file was deleted.

1 change: 0 additions & 1 deletion rust/compiler/src/adlgen_dev/sys/mod.rs

This file was deleted.

6 changes: 3 additions & 3 deletions rust/compiler/src/cli/tsgen/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;

Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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; {}",
Expand Down
50 changes: 42 additions & 8 deletions rust/compiler/src/cli/workspace.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::path::PathBuf;
use std::path::{Path, PathBuf};
use std::{env, fs};

use anyhow::anyhow;
Expand All @@ -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)?;
Expand All @@ -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)?;
}
}
Expand All @@ -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<String> {
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 => {
Expand All @@ -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()))?;
Expand Down
2 changes: 0 additions & 2 deletions rust/compiler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,3 @@ pub mod parser;
pub mod processing;
pub mod utils;
pub mod adlstdlib;

mod adlgen_dev;
1 change: 1 addition & 0 deletions rust/compiler/src/processing/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ impl AdlLoader for WorkspaceLoader {
fn load(&mut self, module_name: &adlast::ModuleName) -> Result<Option<Module0>, 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() {
Expand Down

0 comments on commit 5c940b7

Please sign in to comment.