-
Notifications
You must be signed in to change notification settings - Fork 8
/
generate.sh
executable file
·119 lines (116 loc) · 3.64 KB
/
generate.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/usr/bin/env bash
srcdir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )
get_yaml() {
# Arg 1: the meta.yml path
# STDIN: the mustache code
local meta="$1" temp
temp=$(mktemp template-XXX)
cat > "$temp"
mustache "$meta" "$temp"
rm -f -- "$temp"
}
for f in "$srcdir"/{,.}*.mustache; do
target=$(basename "$f" .mustache)
case "$target" in
coq.opam)
mustache='{{ opam_name }}'
opam_name=$(get_yaml meta.yml <<<"$mustache")
if [ -n "$opam_name" ]; then
target=${target/coq/$opam_name}
else
mustache='{{ shortname }}'
shortname=$(get_yaml meta.yml <<<"$mustache")
if [ -n "$shortname" ]; then
target=${target/coq/coq-$shortname}
else
continue
fi
fi
;;
extracted.opam)
mustache='{{# extracted }}{{ extracted_shortname }}{{/ extracted }}'
extracted_shortname=$(get_yaml meta.yml <<<"$mustache")
if [ -n "$extracted_shortname" ]; then
target=${target/extracted/$extracted_shortname}
else
continue
fi
;;
dune-project)
mustache='{{ dune }}'
bool=$(get_yaml meta.yml <<<"$mustache")
if [ -n "$bool" ] && [ "$bool" != false ]; then
: noop
else
continue
fi
;;
dune)
mustache='{{ dune }}'
bool=$(get_yaml meta.yml <<<"$mustache")
if [ -n "$bool" ] && [ "$bool" != false ]; then
mkdir -p -v theories && target="theories/$target"
else
continue
fi
;;
index.md)
mustache='{{ coqdoc }}'
bool=$(get_yaml meta.yml <<<"$mustache")
if [ -n "$bool" ] && [ "$bool" != false ]; then
mkdir -p -v resources && target="resources/$target"
else
continue
fi
;;
docker-action.yml)
mustache='{{ action }}'
bool=$(get_yaml meta.yml <<<"$mustache")
if [ -n "$bool" ] && [ "$bool" != false ]; then
mkdir -p -v .github/workflows && target=".github/workflows/$target"
else
continue
fi
;;
nix-action.yml)
action_mustache='{{ action }}'
action_bool=$(get_yaml meta.yml <<<"$action_mustache")
nix_mustache='{{ nix }}'
nix_bool=$(get_yaml meta.yml <<<"$nix_mustache")
if [ -n "$action_bool" ] && [ -n "$nix_bool" ] && [ "$nix_bool" != false ] && [ "$action_bool" != false ]; then
mkdir -p -v .github/workflows && target=".github/workflows/$target"
else
continue
fi
;;
.travis.yml)
mustache='{{ travis }}'
bool=$(get_yaml meta.yml <<<"$mustache")
if [ -n "$bool" ] && [ "$bool" != false ]; then
: noop
else
continue
fi
;;
config.yml)
mustache='{{ circleci }}'
bool=$(get_yaml meta.yml <<<"$mustache")
if [ -n "$bool" ] && [ "$bool" != false ]; then
mkdir -p -v .circleci && target=".circleci/$target"
else
continue
fi
;;
esac
listed=false
for specified_target in "$@"; do
if [ "$specified_target" == "$target" ]; then
listed=true
fi
done
if [ $# -gt 0 ] && [ $listed != true ]; then
continue
fi
echo "Generating $target..."
mustache meta.yml "$f" > "$target"
done