Skip to content
This repository was archived by the owner on Aug 18, 2020. It is now read-only.

Commit d848f07

Browse files
authored
Merge pull request #3227 from input-output-hk/mhuesch/CDEC-429
[CDEC-429] Flesh out `package-dep-graph.sh`, document it in `stack.yaml`
2 parents e98465b + 7c24703 commit d848f07

File tree

2 files changed

+91
-5
lines changed

2 files changed

+91
-5
lines changed

scripts/package-dep-graph.sh

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#!/bin/bash -eu
2+
3+
################################################################################
4+
# Check deps
5+
################################################################################
6+
7+
if ! command -v dot >/dev/null 2>&1; then
8+
echo "\`dot\` not found. It is usually in the \`graphviz\` package."
9+
exit 1
10+
fi
11+
12+
if ! command -v tred >/dev/null 2>&1; then
13+
echo "\`tred\` not found. It is usually in the \`graphviz\` package."
14+
exit 1
15+
fi
16+
17+
################################################################################
18+
# Argument processing
19+
################################################################################
20+
21+
script=$(basename "$0")
22+
stack_dot_flags=""
23+
include_test_bench="0"
24+
use_tred="1"
25+
26+
while getopts "hetf" opt; do
27+
case $opt in
28+
h)
29+
echo "usage: ./${script} OPTS" >&2
30+
echo "OPTS:" >&2
31+
echo " -h : show help" >&2
32+
echo " -e : include external dependencies in graph" >&2
33+
echo " -t : include test+bench packages in graph" >&2
34+
echo " -f : don't use \`tred\` - render full deg graph" >&2
35+
exit 0
36+
;;
37+
e)
38+
stack_dot_flags="${stack_dot_flags} --external"
39+
;;
40+
t)
41+
include_test_bench="1"
42+
;;
43+
f)
44+
use_tred="0"
45+
;;
46+
?)
47+
echo "Invalid option: -$OPTARG" >&2
48+
exit 1
49+
;;
50+
esac
51+
done
52+
53+
54+
################################################################################
55+
# Generate graph
56+
################################################################################
57+
58+
tmpdir=$(mktemp -d "${TMPDIR:-/tmp/}$(basename "$0").XXXXXXXXXXXX")
59+
outfile="cardano-sl-pkg-deps.png"
60+
61+
# 'tred' and 'dot' are in the 'graphviz' of most Linux distributions.
62+
63+
if [ "${include_test_bench}" = "0" ]; then
64+
prunefiles=$(find . -name \*.cabal -exec basename {} \; \
65+
| grep -v stack-work | grep "test.cabal\\|bench.cabal" \
66+
| sed 's/\.cabal//' | tr '\n' ',')
67+
stack_dot_flags="${stack_dot_flags} --prune ${prunefiles}"
68+
fi
69+
70+
# This is a weird hack to satisfy shellcheck. While strange, it works, and is
71+
# technically safer.
72+
output="yes"
73+
stack dot ${output:+${stack_dot_flags}} > "${tmpdir}/full-dependencies.dot"
74+
75+
final_dotfile=""
76+
if [ "${use_tred}" = "1" ]; then
77+
final_dotfile="${tmpdir}/direct-dependencies.dot"
78+
tred "${tmpdir}/full-dependencies.dot" > "${final_dotfile}"
79+
else
80+
final_dotfile="${tmpdir}/full-dependencies.dot"
81+
fi
82+
83+
dot -Tpng "${final_dotfile}" -o ${outfile}
84+
85+
rm -rf "${tmpdir:?}/"
86+
87+
echo "Generated ${outfile}"

stack.yaml

+4-5
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@ flags:
66

77
extra-package-dbs: []
88

9-
# util -> networking → binary → crypto → core → db → [lrc, infra]
10-
# → [ssc, txp, update, delegation] → block → lib → ...
11-
# Then we have two branches:
12-
# ... → client → generator → [auxx, explorer, wallet] → wallet-new
13-
# ... → [node, tools]
9+
# The dependency graph which was previously here has been dropped in favor of
10+
# PNG output from the script `scripts/package-dep-graph.sh`, which uses
11+
# `stack dot` to construct a graph which represents the current state exactly.
12+
1413
packages:
1514
- util
1615
- util/test

0 commit comments

Comments
 (0)