Debian Codegraph @

docs/_static/build-bidict-types-diagram

raw
1 #!/bin/bash
2 #
3 # Copyright 2009-2026 Joshua Bronson. All rights reserved.
4 #
5 # This Source Code Form is subject to the terms of the Mozilla Public
6 # License, v. 2.0. If a copy of the MPL was not distributed with this
7 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
8
9 set -euo pipefail
10
11 log() {
12 echo >&2 " *" "$@"
13 }
14
15 # Generate a new graph image from its source file if it's been modified.
16 main() {
17 local -r graph_src="bidict-types-diagram.dot"
18 local -r graph_dst="${graph_src%.*}.png"
19
20 if [[ ! "$(git diff --name-only -- "$graph_src")" ]] &&
21 [[ ! "$(git diff --name-only --cached -- "$graph_src")" ]]; then
22 log "$graph_src not modified -> skipping graph update."
23 return 0
24 fi
25
26 if ! command -v dot &>/dev/null; then
27 log "'dot' not found -> skipping graph update. Hint: brew install graphviz"
28 return 1
29 fi
30
31 if ! dot -v -Tpng -o "$graph_dst" <"$graph_src"; then
32 log "dot exited nonzero."
33 return 1
34 fi
35
36 # return 0 if any of the below fail because running dot succeeded, which is the main thing.
37 if ! command -v optipng &>/dev/null; then
38 log "'optipng' not found -> skipping png optimization. Hint: brew install optipng"
39 return 0
40 fi
41
42 if ! optipng "$graph_dst"; then
43 log "optipng exited nonzero."
44 return 0
45 fi
46 }
47
48 main