-
Notifications
You must be signed in to change notification settings - Fork 11
/
bosy.sh
executable file
·187 lines (163 loc) · 5.21 KB
/
bosy.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#!/usr/bin/env bash
function run_original() { #the original behavior. encapsulated into function for readability
if $2; then
swift run -c release BoSy --help
return $?
fi
swift run -c release BoSy "$1"
exit_code=$?
# Terminate all tools that may have been started by BoSy
for f in Tools/*; do
if [ ! -f "$f" ]; then
continue
fi
tool=$(basename "$f")
killall "$tool" &>/dev/null
done
return $exit_code
}
# helper functions
# returns 2 if the default set of tools can't be found, 1 if default tools are complete but additional ones are not compiled,
# and 0 if everything is compiled and ready to use
function check_tools() { #check state of the current build, determines what build commands need to be run
echo "Checking tool state... "
# spell-checker:disable
tools=("abc" "bloqqer" "bloqqer-031" "cadet" "cryptominisat5" "ltl2tgba" "ltl3ba" "idq" "quabs" "rareqs" "syfco" "z3")
tools_full=("aigbmc" "smvtoaig" "caqe" "combine-aiger" "cvc4" "depqbf" "eprover" "picosat-solver" "vampire" "hqs-linux" "hqspre-linux" "ltl2smv" "NuSMV")
# spell-checker:enable
if [ ! -d "./Tools" ]; then
return 2
fi
ret_code=0
for tool in "${tools[@]}"; do #check standard tools
if [ ! -f "./Tools/$tool" ] || [ ! -x "./Tools/$tool" ]; then
ret_code=2
break 1
fi
done
if [ $ret_code -ne 0 ]; then
echo "No complete set of default tools found. Rebuilding if requested"
return $ret_code
fi
echo "Complete set of default tools found! Checking for additional tools... "
for tool in "${tools_full[@]}"; do #check full tool set
if [ ! -f "./Tools/$tool" ] || [ ! -x "./Tools/$tool" ]; then
echo "Additional tools not complete. Build them in you want to use them"
return 1
fi
done
echo "All tools found. Noting to do here."
}
function build_tools() { # $1 fresh-minimal, $2 fresh-full, $3 tool_state
if $1 && [ "$3" -eq 2 ]; then
echo "building default tool-set"
make 2>tool_build_errors.log | tee tool_build.log
fi
if $2 && { [ "$3" -eq 1 ] || [ "$3" -eq 2 ]; }; then
echo "building additional tool-set"
make all 2>tool_build_errors.log | tee tool_build.log
fi
return $?
}
function build_swift_on_demand() {
if ! $1; then # no rebuild of already built binary
if [ -d "./.build" ] || [ ! -f "./.build/release/BoSy" ]; then # build bc no binary present
swift build --configuration release -Xcc -O3 -Xcc -DNDEBUG -Xswiftc -Ounchecked
return $?
fi
elif ! $2; then
swift build --configuration release -Xcc -O3 -Xcc -DNDEBUG -Xswiftc -Ounchecked
return $?
fi
}
function print_help() {
echo "
Usage:
$(basename "$0") [options] [bosy-options]
Options:
--help: shows this help text and exits
--use-existing: use old version of the script, rebuilding the swift code on every run.
--fresh: just rebuild the swift code before running (fast).
--fresh-minimal: rebuild swift-code + default tools (needed for auto-configured bosy run, time intensive)
--fresh-full: rebuild swift + build all tools from scratch (VERY time intensive).
Note: Most thorough fresh* option set will take precedence
For bosy specific options see $(basename "$0") --tool-help
"
}
if [ "$#" -eq 0 ]; then
print_help
exit 0
fi
args=("${@:1}")
use_existing=false
fresh_minimal=false
fresh=false
fresh_full=false
print_help_flag=false
tool_help=false
for i in "${!args[@]}"; do
val=${args[$i]}
case "$val" in
"--use-existing")
use_existing=true
unset "args[$i]"
;;
"--fresh-minimal")
fresh_minimal=true
unset "args[$i]"
;;
"--fresh")
fresh=true
unset "args[key]"
;;
"--fresh-full")
fresh_full=true
unset "args[$i]"
;;
"--help")
print_help_flag=true
break
;;
"--tool-help")
tool_help=true
unset "args[$i]"
break
;;
esac
done
if $print_help_flag; then
print_help
exit 0
fi
echo "'Args passed to bosy: ${args[*]}'"
if $use_existing; then
echo "Running in with original script behavior"
run_original "${args[@]}" "$tool_help"
exit $?
fi
build_swift_on_demand $fresh_full || $fresh_minimal || $fresh $fresh_minimal || $fresh_full
check_tools
tool_state=$?
if [ "$tool_state" -eq 2 ] && ! $fresh_minimal && ! $fresh_full; then
echo "Error: None or not all of the required tools present! Please use at least the --fresh-minimal flag or build them manually"
exit 1
fi
if $fresh_full && [ "$tool_state" -eq 2 ]; then
fresh_minimal=true
fi
build_tools $fresh_minimal $fresh_full $tool_state
if $tool_help; then
.build/release/BoSy --help
else
.build/release/BoSy "${args[@]}"
fi
exit_code=$?
# Terminate all tools that may have been started by BoSy
for f in Tools/*; do
if [ ! -f "$f" ]; then
continue
fi
tool=$(basename "$f")
killall "$tool" &>/dev/null
done
exit $exit_code