-
Notifications
You must be signed in to change notification settings - Fork 0
/
manager.sh
executable file
·313 lines (295 loc) · 7.72 KB
/
manager.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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
#!/bin/bash
script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
flow=$1
selection=$2
all_args="${@:2}"
os_type=$(uname)
cd $script_dir
# Run tests with different crates including the available features.
function test_crates() {
echo "${1}"
cd $script_dir
case "$1" in
"cli")
run_test wekan-cli
;;
"cli-store")
cd crates/wekan-cli
cargo test --features store -- --nocapture
;;
"core")
run_test wekan-core
cargo test --features store -- --nocapture
;;
*)
echo "Run members tests"
cargo test
cargo test --features store -- --nocapture
;;
esac
}
function run_test() {
cd crates/$1
cargo test -- --nocapture
}
# Run E2E tests and show results.
function e2e() {
echo "E2E $1"
cd $script_dir
case "$1" in
"c"|"cli")
run_e2e
;;
"rerun"|"r")
cd e2e
./e2e.sh rerun
;;
"l")
docker logs wekan-cli
;;
*)
e2e cli
;;
esac
}
function run_e2e() {
cargo build --features integration
cd e2e
./e2e.sh ab
}
# Clippy all crates
function clippy() {
echo "${1}"
cd $script_dir
case "$1" in
"cli")
run_clippy wekan-cli
cargo clippy --features store -- -Dwarnings
;;
"core")
run_clippy wekan-core
cargo clippy --features store -- -Dwarnings
;;
"common")
run_clippy wekan-common
;;
"macro")
clippy wekan-core-derive
clippy wekan-cli-derive
;;
*)
echo "Run members clippy"
cargo clippy -- -Dwarnings
;;
esac
}
function run_clippy() {
cd crates/$1
cargo clippy -- -Dwarnings
}
# Cmt all crates
function fmt() {
echo "fmt crates"
cargo fmt
}
# Build release artifact for specified platforms.
function release() {
echo "${1}"
cd $script_dir
case "$1" in
"apple")
cd crates/wekan-cli
cargo build -r --target aarch64-apple-darwin
cargo build -r --target x86_64-apple-darwin
;;
"linux")
cd crates/wekan-cli
cargo build -r --target x86_64-unknown-linux-gnu
;;
"windows")
cd crates/wekan-cli
cargo build -r --target x86_64-pc-windows-gnu
;;
*)
cd crates/wekan-cli
cargo build -r
;;
esac
}
# Run wekan-cli with cargo run.
function run() {
cd $script_dir
case "$1" in
"cli")
echo "Run: $1 with $all_args"
cargo run -- ${all_args}
;;
"cli-store")
echo "Run: $1 with $all_args"
cargo run --features store -- $all_args
;;
"container")
docker run -d --name wekan-cli --network e2e_wekan-e2e-tier concafe/wekan-cli:release /bin/bash
exit $?
;;
*)
run cli-store
;;
esac
}
# RECOMMENDED
# https://github.com/mozilla/grcov
function mozilla_gcov() {
grcov_exist="$(grcov &>/dev/null)"
if [ "$?" != "1" ]; then
echo "Install grcov first with 'cargo install grcov'"
exit 1
fi
case "$1" in
"gen")
grcov . -s . --binary-path ./target/debug/ -t html \
--branch --ignore-not-existing -o ./target/debug/coverage/
rm_llvm_profiles
if [ "$?" == "0" ]; then
case "$os_type" in
"Darwin")
# Opening with Safari as default choice. use Please Firefox :)
open "$script_dir/crates/wekan-cli/target/debug/coverage/index.html"
;;
"*")
echo "Open $script_dir/crates/wekan-cli/target/debug/coverage/index.html"
;;
esac
fi
;;
"rm")
rm_llvm_profiles
;;
*)
export RUSTFLAGS=-Cinstrument-coverage
cargo build --features store
export LLVM_PROFILE_FILE=llvm-profile-%p-%m.profraw
cargo test --features store
mozilla_gcov gen
;;
esac
}
function rm_llvm_profiles () {
echo "Cleaning up generated files"
cd $script_dir
rm default.profraw 2>/dev/null
rm llvm-profile*.profraw 2>/dev/null
cd crates/wekan-cli
rm default.profraw 2>/dev/null
rm llvm-profile*.profraw 2>/dev/null
cd "$script_dir/crates/wekan-core"
rm default.profraw 2>/dev/null
rm llvm-profile*.profraw 2>/dev/null
cd "$script_dir/crates/wekan-common"
rm default.profraw 2>/dev/null
rm llvm-profile*.profraw 2>/dev/null
}
# ------ OUTDATED OR NOT WORKING ----
# Not working!!
# https://users.rust-lang.org/t/howto-generating-a-branch-coverage-report/8524
function lcov_coverage() {
cd crates/wekan-cli
os_type=$(uname)
case "$os_type" in
"Darwin")
{
cargo +nightly rustc --bin wekan-cli -- \
--test \
-Ccodegen-units=1 \
-Clink-dead-code \
-Cpasses=insert-gcov-profiling \
-Zno-landing-pads \
-L/Library/Developer/CommandLineTools/usr/lib/clang/8.1.0/lib/darwin/ \
-lclang_rt.profile_osx
} ;;
"Linux")
{
cargo +nightly rustc --bin wekan-cli -- --test \
-Ccodegen-units=1 \
-Clink-dead-code \
-Cpasses=insert-gcov-profiling \
-Zno-landing-pads \
-L/usr/lib/llvm-3.8/lib/clang/3.8.1/lib/linux/ \
-lclang_rt.profile-x86_64
} ;;
*)
{
echo "Unsupported OS, exiting"
exit
} ;;
esac
LCOVOPTS="--gcov-tool llvm-gcov --rc lcov_branch_coverage=1"
LCOVOPTS="${LCOVOPTS} --rc lcov_excl_line=assert"
lcov ${LCOVOPTS} --capture --directory . --base-directory . \
-o target/coverage/raw.lcov
lcov ${LCOVOPTS} --extract target/coverage/raw.lcov "$(pwd)/*" \
-o target/coverage/raw_crate.lcov
genhtml --branch-coverage --demangle-cpp --legend \
-o target/coverage/ target/coverage/raw_crate.lcov
}
# Decide which flow to run.
case $flow in
"b"|"build")
echo "Build without feature"
cargo build
echo "Build feture store"
cargo build --features store
echo "Build integration"
cargo build --features integration
;;
"b:target")
echo "Build release binary"
release $selection
;;
"c"|"clippy")
clippy $selection
;;
"cov"|"lcov")
mozilla_gcov $selection
;;
"d"|"dev")
cd $script_dir
export EMACSSAVEMODEDIR=.
emacs
;;
"d:b")
docker build -t concafe/wekan-cli:release .
;;
"e"|"e2e"|"2e"|"2ee")
e2e $selection
;;
"f"|"fmt")
fmt
;;
"r"|"run")
run $selection
;;
"r:s")
run cli-store
;;
"t"|"test")
test_crates $selection
;;
"ts")
echo "TEST cli with feature store"
test_crates cli-store
;;
"qa"|"q")
echo "QA (fmt, clippy, ut, e2e)"
set -e
fmt
clippy
echo "TEST"
test_crates
e2e
;;
*)
echo "Nothing selected"
;;
esac
exit $?