Mike Gerwitz

Activist for User Freedom

aboutsummaryrefslogtreecommitdiffstats
path: root/tamer
diff options
context:
space:
mode:
authorJoseph Frazer <joseph.frazer@ryansg.com>2020-03-25 10:20:25 -0400
committerJoseph Frazer <joseph.frazer@ryansg.com>2020-03-26 08:48:43 -0400
commit6386e096b4f7e2d05eb0f76a60620b130176ce41 (patch)
treebebfe4f0e2927532b5afda2d0eada088d1049f11 /tamer
parent8af93d9339f2209ef2ac2b057f29bd8bb237ae8d (diff)
downloadtame-6386e096b4f7e2d05eb0f76a60620b130176ce41.tar.gz
tame-6386e096b4f7e2d05eb0f76a60620b130176ce41.tar.bz2
tame-6386e096b4f7e2d05eb0f76a60620b130176ce41.zip
[DEV-7133] Clearly show the cycles in the output
Diffstat (limited to 'tamer')
-rw-r--r--tamer/src/ir/asg/graph.rs5
-rw-r--r--tamer/src/ld/poc.rs31
2 files changed, 30 insertions, 6 deletions
diff --git a/tamer/src/ir/asg/graph.rs b/tamer/src/ir/asg/graph.rs
index 7d3f78c..c6e3a30 100644
--- a/tamer/src/ir/asg/graph.rs
+++ b/tamer/src/ir/asg/graph.rs
@@ -259,9 +259,8 @@ impl<Ix: Debug> std::fmt::Display for AsgError<Ix> {
Self::UnexpectedNode(msg) => {
write!(fmt, "unexpected node: {}", msg)
}
- Self::Cycles(path) => {
- write!(fmt, "Cyclic dependencies detected: {:?}", path)
- // write!(fmt, "Cyclic dependencies detected:")
+ Self::Cycles(cycles) => {
+ write!(fmt, "Cyclic dependencies detected: {:?}", cycles)
}
}
}
diff --git a/tamer/src/ld/poc.rs b/tamer/src/ld/poc.rs
index 904d019..224fbeb 100644
--- a/tamer/src/ld/poc.rs
+++ b/tamer/src/ld/poc.rs
@@ -22,8 +22,8 @@
use crate::global;
use crate::ir::asg::{
- Asg, DefaultAsg, IdentKind, IdentObject, ObjectRef, Sections, SortableAsg,
- Source,
+ Asg, AsgError, DefaultAsg, IdentKind, IdentObject, IdentObjectData,
+ ObjectRef, Sections, SortableAsg, Source,
};
use crate::obj::xmle::writer::XmleWriter;
use crate::obj::xmlo::reader::{XmloError, XmloEvent, XmloReader};
@@ -78,7 +78,32 @@ pub fn main(package_path: &str, output: &str) -> Result<(), Box<dyn Error>> {
.filter_map(|sym| depgraph.lookup(sym)),
);
- let mut sorted = depgraph.sort(&roots)?;
+ let mut sorted = match depgraph.sort(&roots) {
+ Ok(sections) => sections,
+ Err(AsgError::Cycles(cycles)) => {
+ let msg: Vec<String> = cycles
+ .into_iter()
+ .map(|cycle| {
+ let mut path: Vec<String> = cycle
+ .into_iter()
+ .map(|obj| {
+ format!(
+ "{}",
+ depgraph.get(obj).unwrap().name().unwrap()
+ )
+ })
+ .collect();
+
+ path.reverse();
+ path.push(path[0].clone());
+ format!("cycle: {}", path.join(" -> "))
+ })
+ .collect();
+
+ return Err(msg.join("\n").into());
+ }
+ Err(e) => return Err(e.into()),
+ };
//println!("Sorted ({}): {:?}", sorted.len(), sorted);