Skip to content

Commit 06e5146

Browse files
0xh4tydkcumming
andauthored
make: prevent svg/png generation when dot is unavailable (#117)
## Summary This is a small follow up to review comments from PR #111 where adding a fast-fail check for Graphviz (dot) was suggested but not included before merge. ## Changes - Add check-graphviz target - Wire it into svg and png - Add to .PHONY - Provide OS agnostic error message ## Before running: ``` make svg ``` produces many repeated shell errors after generating all .dot files: ``` Converting assert_eq.smir.dot -> assert_eq.smir.svg /bin/sh: line 4: dot: command not found ... make: *** [Makefile:94: svg] Error 127 ``` ## After ``` $ make svg Error: Graphviz is not installed or 'dot' is not in PATH. Please install Graphviz for your system and ensure 'dot' is available. See: https://graphviz.org/download/ ``` ## How to test 1. Temporarily uninstall Graphviz or remove dot from PATH 2. Run: make svg 3. Observe immediate fast-fail message 4. Reinstall Graphviz 5. Run again. Graphs generate normally ## Context Reviewer suggestion here: #111 (comment) #111 (comment) #111 (comment) #111 (comment) Co-authored-by: Daniel Cumming <124537596+dkcumming@users.noreply.github.com>
1 parent 41c7d55 commit 06e5146

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

Makefile

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ test-ui:
7070
fi
7171
bash tests/ui/run_ui_tests.sh "$$RUST_DIR_ROOT" "${VERBOSE}"
7272

73-
.PHONY: dot svg png d2 clean-graphs
73+
.PHONY: dot svg png d2 clean-graphs check-graphviz
7474

7575
OUTDIR_DOT=output-dot
7676
OUTDIR_SVG=output-svg
@@ -80,6 +80,14 @@ OUTDIR_D2=output-d2
8080
clean-graphs:
8181
@rm -rf $(OUTDIR_DOT) $(OUTDIR_SVG) $(OUTDIR_PNG) $(OUTDIR_D2)
8282

83+
check-graphviz:
84+
@command -v dot >/dev/null 2>&1 || { \
85+
echo "Error: Graphviz is not installed or 'dot' is not in PATH."; \
86+
echo "Please install Graphviz for your system and ensure 'dot' is available."; \
87+
echo "See: https://graphviz.org/download/"; \
88+
exit 1; \
89+
}
90+
8391
dot:
8492
@mkdir -p $(OUTDIR_DOT)
8593
@for rs in $(TESTDIR)/*.rs; do \
@@ -89,15 +97,15 @@ dot:
8997
mv $$name.smir.dot $(OUTDIR_DOT)/ 2>/dev/null || true; \
9098
done
9199

92-
svg: dot
100+
svg: check-graphviz dot
93101
@mkdir -p $(OUTDIR_SVG)
94102
@for dotfile in $(OUTDIR_DOT)/*.dot; do \
95103
name=$$(basename $$dotfile .dot); \
96104
echo "Converting $$name.dot -> $$name.svg"; \
97105
dot -Tsvg $$dotfile -o $(OUTDIR_SVG)/$$name.svg; \
98106
done
99107

100-
png: dot
108+
png: check-graphviz dot
101109
@mkdir -p $(OUTDIR_PNG)
102110
@for dotfile in $(OUTDIR_DOT)/*.dot; do \
103111
name=$$(basename $$dotfile .dot); \

0 commit comments

Comments
 (0)