-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmake.sh
More file actions
131 lines (112 loc) · 2.38 KB
/
Copy pathmake.sh
File metadata and controls
131 lines (112 loc) · 2.38 KB
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
#!/bin/bash
OUT="out"
BIN=$(basename "$PWD")
DIR="$OUT|doc|Cargo.lock"
do_cargo_check() {
if [ ! -d "$OUT" ]; then
mkdir -p "$OUT"
fi
cargo check -q --target-dir "$OUT"/test
}
do_cargo_test() {
if [ ! -d "$OUT" ]; then
mkdir "$OUT"
fi
cargo test -q --target-dir "$OUT"/test
}
do_cargo_build() {
if [ ! -d "$OUT" ]; then
mkdir "$OUT"
fi
target="x86_64-unknown-linux-musl"
if ! rustup target list --installed | grep -q "$target"; then
echo "installing $target..."
rustup target add "$target"
fi
cargo build -q --release \
--message-format=human\
--target $target \
--target-dir "$OUT"/prod
cp "$OUT"/prod/$target/release/$BIN $OUT/
}
do_show_stats() {
if [ -f "$OUT/$BIN" ]; then
echo $(echo $OUT/$BIN;\
du -b $OUT/$BIN | awk '{print $1/1024 " KB"}')
echo $(ldd $OUT/$BIN)
fi
}
do_run() {
if [ -f "$OUT/$BIN" ]; then
read -p "run with script ? [y/N] " confirm
if [[ $confirm =~ ^[Yy]$ ]]; then
$OUT/$BIN test.md
else
$OUT/$BIN
fi
fi
}
do_erase() {
if [ -d "$OUT" ] || [ -d "target" ]; then
read -p "confirm removing '$OUT/' ? [y/N] " confirm
if [[ $confirm =~ ^[Yy]$ ]]; then
rm -rf "$OUT"
echo "done"
else
echo "abort"
fi
fi
}
do_dir_project() {
tree -I $DIR
}
do_default() {
do_clear_screen
do_menu
}
do_clear_screen() {
clear
}
do_menu() {
echo ""
echo " menu cargo bash $BIN"
echo ""
echo " d -- dir project"
echo " c -- cargo check"
echo " t -- cargo test"
echo " b -- cargo build"
echo " s -- stats build"
echo " r -- run"
echo " e -- clean"
echo " x -- exit"
echo ""
}
do_input() {
read -p '>> ' value
echo "$value"
}
main() {
do_menu
while true; do
value=$(do_input)
case "$value" in
d) do_dir_project;;
c) do_cargo_check;;
t) do_cargo_test;;
b) do_cargo_build;;
s) do_show_stats;;
r) do_run;;
e) do_erase;;
x) break;;
*) do_default;;
esac
done
}
if [ -t 0 ]; then
main
else
title="$BIN"
xfce4-terminal\
--title="$title"\
-e "bash -c './make.sh $@; exec bash'"
fi