Skip to content

Commit

Permalink
update logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Boris Zhguchev committed May 11, 2024
1 parent 675a383 commit ba8180b
Show file tree
Hide file tree
Showing 12 changed files with 21,351 additions and 429 deletions.
716 changes: 422 additions & 294 deletions Cargo.lock

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,28 @@ license-file = "LICENSE"

[dependencies]
parsit = "0.2.0"
graphviz-rust = "0.6.2"
graphviz-rust = "0.9.0"
logos = "0.13.0"
itertools = "0.11.0"
strum = { version = "0.25.0", features = [] }
strum_macros = "0.25.1"
itertools = "0.12.1"
strum = { version = "0.26.2", features = [] }
strum_macros = "0.26.2"
log = "0.4"
env_logger = "0.10.0"
env_logger = "0.11.3"
serde = { version = "1.0.166", features = ["derive"] }
serde_json = { version = "1.0.99" }
serde_yaml = "0.9.22"
reqwest = { version = "0.11", features = ["blocking", "json"] }
reqwest = { version = "0.12.4", features = ["blocking", "json"] }
tracing = "0.1"
axum = "0.6.16"
tokio = { version = "1.29.1", features = ["full"] }
tokio-util = "0.7.9"
tokio = { version = "1.37.0", features = ["full"] }
tokio-util = "0.7.11"
hyper = "0.14.27"
chrono = "0.4.26"
quick-xml = "0.31.0"

tungstenite = "0.20.1"
tungstenite = "0.21.0"
url = "2.4.1"

[dev-dependencies]
wiremock = "0.5.19"
wiremock = "0.6.0"
forester-http = "0.1.0"
1 change: 1 addition & 0 deletions src/runtime/action/builtin/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ mod tests {
use wiremock::{Mock, MockServer, ResponseTemplate};

#[test]
#[ignore]
fn smoke() {
let env = RtEnv::try_new().unwrap();

Expand Down
1 change: 1 addition & 0 deletions src/runtime/ros/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ mod tests {
use crate::runtime::ros::client::{publish};

#[test]
#[ignore]
fn smoke() {
let value = RtValue::Object(HashMap::from_iter(vec![("a".to_string(), RtValue::int(10))]));
publish("test".to_owned(), value, "ws://localhost:9090".to_string())
Expand Down
28 changes: 18 additions & 10 deletions src/runtime/rtree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub mod transform;
use crate::runtime::action::ActionName;
use crate::runtime::args::transform::{to_dec_rt_args, to_rt_args};

use crate::runtime::rtree::rnode::{DecoratorType, RNode, RNodeId};
use crate::runtime::rtree::rnode::{DecoratorType, FlowType, RNode, RNodeId};
use crate::runtime::rtree::transform::{StackItem, Transformer};
use crate::runtime::{RtOk, RtResult, RuntimeError};
use crate::tree::parser::ast::call::Call;
Expand All @@ -22,6 +22,7 @@ use std::collections::{HashMap, HashSet, VecDeque};
use std::path::PathBuf;
use crate::converter::Converter;
use crate::converter::to_nav::ToRosNavConverter;
use log::debug;

/// The auxiliary structure that encapsulates the runtime tree
/// and some additional information about actions
Expand Down Expand Up @@ -79,10 +80,10 @@ impl RuntimeTree {
///
/// let analyzer = tree.analyze();
///
/// let a1 = analyzer.find_by(|n| n.is_name("action1")).unwrap();
/// let a2 = analyzer.find_by(|n| n.is_name("action2")).unwrap();
/// let root = analyzer.find_by(|n| n.is_name("root")).unwrap();
/// let seq = analyzer.find_by(|n| n.is_name("seq")).unwrap();
/// let a1 = analyzer.find_id_by(|n| n.is_name("action1")).unwrap();
/// let a2 = analyzer.find_id_by(|n| n.is_name("action2")).unwrap();
/// let root = analyzer.find_id_by(|n| n.is_name("root")).unwrap();
/// let seq = analyzer.find_id_by(|n| n.is_name("seq")).unwrap();
///
/// assert_eq!(analyzer.parent(&a1), Some(&seq));
/// assert_eq!(analyzer.parent(&a2), Some(&root));
Expand Down Expand Up @@ -122,6 +123,7 @@ impl RuntimeTree {
match call {
// for lambda there is not many actions since it does not have arguments so just grab a type and children
Call::Lambda(tpe, calls) => {
debug!(target:"tree[construct]", "found lambda {tpe}: id {id} and parent {parent_id}");
let children = builder.push_vec(calls, id, file_name.clone());
builder.add_chain_lambda(id, parent_id);
r_tree
Expand All @@ -134,6 +136,7 @@ impl RuntimeTree {
// - since we found it we transform it into a simple invocation call and process it at the next step.
// - if it is lambda we already found it
Call::HoInvocation(key) => {
debug!(target:"tree[construct]", "found ho invocation with id {id} in parent {parent_id}");
let (p_id, parent_args, parent_params) =
builder.get_chain_skip_lambda(&parent_id)?.get_tree();
let call = builder.find_ho_call(&parent_id, &key)?;
Expand All @@ -154,6 +157,7 @@ impl RuntimeTree {
}
// just take the arguments and transform them into runtime args and push further
Call::Decorator(tpe, decor_args, call) => {
debug!(target:"tree[construct]", "found decorator {tpe}, id {id} in parent {parent_id}");
let (_, parent_args, parent_params) =
builder.get_chain_skip_lambda(&parent_id)?.get_tree();
builder.add_chain(id, parent_id, parent_args.clone(), parent_params.clone());
Expand All @@ -167,13 +171,14 @@ impl RuntimeTree {
// firstly we need to find the definition either in the file or in the imports
// with a consideration of a possible alias and transform the args
Call::Invocation(name, args) => {
debug!(target:"tree[construct]", "found invocation , id {id} in parent {parent_id}");
let (_, parent_args, parent_params) = builder
.get_chain_skip_lambda(&parent_id)
.map(|e| e.get_tree())
.unwrap_or_default();
match curr_file.definitions.get(&name) {
Some(tree) => {
let (rt_args,upd_args) = to_rt_args(
let (rt_args, upd_args) = to_rt_args(
name.as_str(),
args.clone(),
tree.params.clone(),
Expand All @@ -194,11 +199,12 @@ impl RuntimeTree {
}
}
None => {
debug!(target:"tree[construct]", "found import from another file, id {id} in parent {parent_id}");
let (tree, file) = import_map.find(&name, &project)?;
if file.contains("::") {
std_actions.insert((tree.name.clone(), file.clone()));
}
let (rt_args,upd_args) = to_rt_args(
let (rt_args, upd_args) = to_rt_args(
name.as_str(),
args.clone(),
tree.params.clone(),
Expand Down Expand Up @@ -280,6 +286,7 @@ mod tests {
use crate::tree::project::Project;
use std::collections::{HashMap, HashSet};
use itertools::Itertools;
use crate::tests::turn_on_logs;


#[test]
Expand Down Expand Up @@ -436,13 +443,14 @@ mod tests {

let st_tree = RuntimeTree::build(project).unwrap().tree;

let item = st_tree.nodes.iter().find(|(id,_)|**id == 4).unwrap().1.args();
let item = st_tree.nodes.iter().find(|(id, _)| **id == 4).unwrap().1.args();
assert_eq!(
item,
RtArgs(vec![
RtArgument::new("arg0".to_string(), RtValue::int(1) ),
RtArgument::new("arg".to_string(), RtValue::str("-b-".to_string()))
RtArgument::new("arg0".to_string(), RtValue::int(1)),
RtArgument::new("arg".to_string(), RtValue::str("-b-".to_string())),
])
);
}

}
34 changes: 26 additions & 8 deletions src/runtime/rtree/analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,33 @@ impl<'a> RtTreeAnalyzer<'a> {
self.parents.get(id)
}

/// Returns the parent of the node with the given id
pub fn find_by<F>(&self, filter: F) -> Option<RNodeId>
where
F: Fn(&RNode) -> bool,
/// Returns the node_id by filter
pub fn find_id_by<F>(&self, filter: F) -> Option<RNodeId>
where
F: Fn(&RNode) -> bool,
{
self.tree
.iter()
.find_map(|(id, node)| if filter(node) { Some(id) } else { None })
}
/// Returns the node by filter
pub fn find_node_by<F>(&self, filter: F) -> Option<(RNodeId, &RNode)>
where
F: Fn(&RNode) -> bool,
{
self.tree
.iter()
.find(|(id, node)| filter(node))
}
/// Returns the node by filter
pub fn find_map_by<F, T>(&self, filter_map: F) -> Option<(RNodeId, T)>
where
F: Fn(&RNode) -> Option<T>,
{
self.tree
.iter()
.find_map(|(id, node)| filter_map(node).map(|v| (id, v)))
}
}

#[cfg(test)]
Expand All @@ -62,10 +80,10 @@ mod tests {
let tree = rtb.build().unwrap().0;

let analyzer = tree.analyze();
let a1 = analyzer.find_by(|n| n.is_name("action1")).unwrap();
let a2 = analyzer.find_by(|n| n.is_name("action2")).unwrap();
let root = analyzer.find_by(|n| n.is_name("root")).unwrap();
let seq = analyzer.find_by(|n| n.is_name("seq")).unwrap();
let a1 = analyzer.find_id_by(|n| n.is_name("action1")).unwrap();
let a2 = analyzer.find_id_by(|n| n.is_name("action2")).unwrap();
let root = analyzer.find_id_by(|n| n.is_name("root")).unwrap();
let seq = analyzer.find_id_by(|n| n.is_name("seq")).unwrap();

assert_eq!(analyzer.parent(&a1), Some(&seq));
assert_eq!(analyzer.parent(&a2), Some(&root));
Expand Down
1 change: 1 addition & 0 deletions src/tests/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ fn builtin_test() {
}

#[test]
#[ignore]
fn mix_test() {
let mut fb = fb("actions/mix_test");
let mut f = fb.build().unwrap();
Expand Down
2 changes: 1 addition & 1 deletion src/tree/parser/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ pub enum Token {
#[token("import")]
Import,

#[regex(r"(?s)/\*.*\*/", logos::skip)]
#[regex(r"(?s)/\*[^*/]*\*/", logos::skip)]
#[regex(r"//[^\r\n]*", logos::skip)]
Comment,

Expand Down
25 changes: 13 additions & 12 deletions src/visualizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl Visualizer {
tree: Option<&String>,
output: Option<&String>,
) -> Result<String, TreeError> {
let (rts, output_pb) = runtime_tree_default(root, file, tree, output,"svg".to_string())?;
let (rts, output_pb) = runtime_tree_default(root, file, tree, output, "svg".to_string())?;
debug!(target:"visualizer","visualize a given project to a file {:?}", &output_pb);
Visualizer::rt_tree_svg_to_file(&rts.tree, output_pb)
}
Expand All @@ -84,6 +84,7 @@ impl Visualizer {
vec![Format::Svg.into(), CommandArg::Output(p.to_string())],
)
.map_err(|e| TreeError::VisualizationError(e.to_string()))
.map(|r| String::from_utf8_lossy(&r).to_string())
}
}

Expand Down Expand Up @@ -120,19 +121,19 @@ mod tests {
assert_eq!(
result,
r#"strict digraph {
1[label="(1) root
1[label="(1) root
main ",shape=rect,color=black]
1 -> 2
2[label="(2) sequence",shape=rect,color=darkred]
2 -> 3
2 -> 4
3[label="(3) fallback
1 -> 2
2[label="(2) sequence",shape=rect,color=darkred]
2 -> 3
2 -> 4
3[label="(3) fallback
one (a=a1(<>))",shape=rect,color=blue]
3 -> 5
3 -> 6
4[label="(4) a1 ",shape=component,color=green]
5[label="(5) a1 ",shape=component,color=green]
6[label="(6) a1 ",shape=component,color=green]
3 -> 5
3 -> 6
4[label="(4) a1 ",shape=component,color=green]
5[label="(5) a1 ",shape=component,color=green]
6[label="(6) a1 ",shape=component,color=green]
}"#
);
}
Expand Down
Loading

0 comments on commit ba8180b

Please sign in to comment.