-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add command to show dependency graph as DOT file
- Loading branch information
Showing
7 changed files
with
73 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
pub mod change_environment; | ||
pub mod clean; | ||
pub mod dep_graph; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
use anyhow::Result; | ||
use itertools::Itertools; | ||
use std::io::Write; | ||
|
||
use rustc_hash::FxHashMap; | ||
|
||
use crate::{ | ||
db::{dependency_graph, Document, Workspace}, | ||
Db, | ||
}; | ||
|
||
pub fn show_dependency_graph(db: &dyn Db) -> Result<String> { | ||
let workspace = Workspace::get(db); | ||
|
||
let documents = workspace | ||
.documents(db) | ||
.iter() | ||
.enumerate() | ||
.map(|(i, doc)| (*doc, format!("v{i:0>5}"))) | ||
.collect::<FxHashMap<Document, String>>(); | ||
|
||
let mut writer = Vec::new(); | ||
writeln!(&mut writer, "digraph G {{")?; | ||
writeln!(&mut writer, "rankdir = LR;")?; | ||
|
||
for (document, node) in &documents { | ||
let label = document.location(db).uri(db).as_str(); | ||
let shape = if document.can_be_root(db) { | ||
"tripleoctagon" | ||
} else if document.can_be_built(db) { | ||
"doubleoctagon" | ||
} else { | ||
"octagon" | ||
}; | ||
|
||
writeln!(&mut writer, "\t{node} [label=\"{label}\", shape={shape}];")?; | ||
} | ||
|
||
for edge in workspace | ||
.documents(db) | ||
.iter() | ||
.flat_map(|start| dependency_graph(db, *start).edges.iter()) | ||
.unique() | ||
{ | ||
let source = &documents[&edge.source]; | ||
let target = &documents[&edge.target]; | ||
let label = edge | ||
.origin | ||
.as_ref() | ||
.map_or("<artifact>", |origin| &origin.link.path(db).text(db)); | ||
|
||
writeln!(&mut writer, "\t{source} -> {target} [label=\"{label}\"];")?; | ||
} | ||
|
||
writeln!(&mut writer, "}}")?; | ||
Ok(String::from_utf8(writer)?) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters