-
Notifications
You must be signed in to change notification settings - Fork 6
/
coqproject.sh
executable file
·93 lines (78 loc) · 2.17 KB
/
coqproject.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
#!/usr/bin/env bash
### coqproject.sh
### Creates a _CoqProject file, including external dependencies.
### See the README.md file for a description.
## Implementation
if [ -z ${DIRS+x} ]; then DIRS=(.); fi
COQPROJECT_TMP=_CoqProject.tmp
rm -f $COQPROJECT_TMP
touch $COQPROJECT_TMP
function dep_dirs_lines(){
dep_dirs_var="$2"_DIRS
local -a 'dep_dirs=("${'"$dep_dirs_var"'[@]}")'
if [ "x${dep_dirs[0]}" = "x" ]; then dep_dirs=(.); fi
for dep_dir in "${dep_dirs[@]}"; do
namespace_var=NAMESPACE_"$2"_"$dep_dir"
namespace_var=${namespace_var//\//_}
namespace_var=${namespace_var//-/_}
namespace_var=${namespace_var//./_}
namespace=${!namespace_var:=$2}
if [ $dep_dir = "." ]; then
LINE="-Q $1 $namespace"
else
LINE="-Q $1/$dep_dir $namespace"
fi
echo $LINE >> $COQPROJECT_TMP
done
}
for dep in ${DEPS[@]}; do
path_var="$dep"_PATH
if [ ! "x${!path_var}" = "x" ]; then
path=${!path_var}
if [ ! -d "$path" ]; then
echo "$dep not found at $path."
exit 1
fi
pushd "$path" > /dev/null
path=$(pwd)
popd > /dev/null
echo "$dep found at $path"
dep_dirs_lines $path $dep
fi
done
COQTOP="coqtop $(cat $COQPROJECT_TMP)"
function check_canary(){
echo "Require Import $@." | $COQTOP 2>&1 | grep -i error 1> /dev/null 2>&1
}
i=0
len="${#CANARIES[@]}"
while [ $i -lt $len ]; do
if check_canary ${CANARIES[$i]}; then
echo "Error: ${CANARIES[$((i + 1))]}"
exit 1
fi
let "i+=2"
done
for dir in ${DIRS[@]}; do
namespace_var=NAMESPACE_"$dir"
namespace_var=${namespace_var//\//_}
namespace_var=${namespace_var//-/_}
namespace_var=${namespace_var//./_}
namespace=${!namespace_var:="''"}
LINE="-Q $dir $namespace"
echo $LINE >> $COQPROJECT_TMP
done
if [ ! "x${ARG}" = "x" ]; then
echo "-arg \"${ARG}\"" >> $COQPROJECT_TMP
fi
for dir in ${DIRS[@]}; do
echo >> $COQPROJECT_TMP
find $dir -iname '*.v' -not -name '*\#*' >> $COQPROJECT_TMP
done
for extra in ${EXTRA[@]}; do
if ! grep --quiet "^$extra\$" $COQPROJECT_TMP; then
echo >> $COQPROJECT_TMP
echo $extra >> $COQPROJECT_TMP
fi
done
mv $COQPROJECT_TMP _CoqProject