Skip to content

Commit 185ab69

Browse files
Merge pull request #24 from asglover/main
2 parents 68f3d82 + 8fbe93a commit 185ab69

File tree

4 files changed

+25
-18
lines changed

4 files changed

+25
-18
lines changed

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ readme = "README.md"
1313
default = ["serde"]
1414
serde = ["dep:serde", "dep:serde_json", "indexmap/serde", "ordered-float/serde"]
1515
graphviz = ["dep:graphviz-rust"]
16+
graphviz-exec = ["graphviz", "graphviz-rust/graphviz-exec"]
1617

1718
[dependencies]
1819
indexmap = "2"
@@ -31,6 +32,7 @@ optional = true
3132
version = "1.0.100"
3233

3334
[dependencies.graphviz-rust]
35+
default-features = false
3436
optional = true
3537
version = "0.9"
3638

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,10 @@ Don't forget to add something to `root_eclasses` on the resulting serialized egr
4242

4343
Check out the [`./tests-viz`](./tests-viz/README.md) directory to view visualizations of all the test cases with Graphviz.
4444

45+
To remake them, run `make tests` from the root of this repo.
4546

46-
To remake them, run `make tests` from the root of this repo. Any tests that don't have SVG visualizations created yet will be generated. You'll need to have [Graphviz](https://graphviz.org/) installed.
47+
### SVG Generation
48+
Generating SVG files requires having [Graphviz](https://graphviz.org/) installed. This cannot be distributed through rust's crates toolchain, so the function `to_svg_file` is gated behind the `graphviz-exec` feature flag.
49+
50+
### DOT Generation
51+
The `graphviz-rust` crate can produce `.dot` files without requiring the existence of the [Graphviz](https://graphviz.org/) CLI tool. Therefore creation of dot files and other functionality which only relies on `graphviz-rust` is gated behind the `graphviz` feature flag.

src/graphviz.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ impl EGraph {
1616
self.to_graphviz().print(&mut PrinterContext::default())
1717
}
1818

19+
#[cfg(feature = "graphviz-exec")]
1920
pub fn to_svg_file(&self, path: impl AsRef<std::path::Path>) -> std::io::Result<()> {
2021
graphviz_rust::exec_dot(
2122
self.to_dot(),

tests/round_trip.rs

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::path::{Path, PathBuf};
22

33
use egraph_serialize::*;
44

5+
#[cfg(feature = "serde")]
56
#[test]
67
fn test_round_trip() {
78
let mut n_tested = 0;
@@ -14,25 +15,20 @@ fn test_round_trip() {
1415
assert!(n_tested > 0);
1516
}
1617

17-
#[cfg(feature = "graphviz")]
18+
#[cfg(all(feature = "serde", feature = "graphviz"))]
1819
#[test]
1920
fn test_graphviz() {
20-
// Check if `dot` command is available
21-
let no_dot = std::process::Command::new("dot")
22-
.arg("-V")
23-
.status()
24-
.is_err();
25-
2621
let mut names = Vec::new();
2722
for entry in test_files() {
2823
println!("Testing graphviz {entry:?}");
2924
let mut egraph = EGraph::from_json_file(entry.as_path()).unwrap();
3025
names.push(entry.file_stem().unwrap().to_str().unwrap().to_string());
3126

32-
// If graphviz isn't installed, just test that we can create the dot string, not generate the SVG
33-
if no_dot {
34-
egraph.to_dot();
35-
} else {
27+
egraph.to_dot(); // Always test `to_dot`
28+
29+
// Test `to_svg` only when the graphviz-exec feature is available
30+
#[cfg(feature = "graphviz-exec")]
31+
{
3632
let path = Path::new("./tests-viz")
3733
.join(entry.file_name().unwrap())
3834
.with_extension("svg");
@@ -46,9 +42,10 @@ fn test_graphviz() {
4642
// Generate graphs with inlined leaves as well
4743
egraph.inline_leaves();
4844

49-
if no_dot {
50-
egraph.to_dot();
51-
} else {
45+
egraph.to_dot();
46+
47+
#[cfg(feature = "graphviz-exec")]
48+
{
5249
let path = Path::new("./tests-viz").join(format!(
5350
"{}-inlined.svg",
5451
entry.file_stem().unwrap().to_str().unwrap()
@@ -63,9 +60,11 @@ fn test_graphviz() {
6360

6461
// Saturate inlining
6562
egraph.saturate_inline_leaves();
66-
if no_dot {
67-
egraph.to_dot();
68-
} else {
63+
64+
egraph.to_dot();
65+
66+
#[cfg(feature = "graphviz-exec")]
67+
{
6968
let path = Path::new("./tests-viz").join(format!(
7069
"{}-inlined-saturated.svg",
7170
entry.file_stem().unwrap().to_str().unwrap()

0 commit comments

Comments
 (0)