-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmesonic
More file actions
executable file
·98 lines (81 loc) · 2.18 KB
/
mesonic
File metadata and controls
executable file
·98 lines (81 loc) · 2.18 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
#!/bin/bash
#
# mesonic - Helper script for meson projects
#
# Description:
# This script automates the build, run, and install process for meson-based projects.
# It also provides a watch mode that rebuilds the project on file changes.
# Author: ahme.dev
# Usage:
# - Watch and rebuild with `./mesonic`
# - Build once with `./mesonic build`
# - Build and run once with `./mesonic run`
# - Install with `./mesonic install`
#
resetColor='\033[0m'
redColor='\033[1;31m'
greenColor='\033[1;32m'
if [ ! -t 1 ]; then
redColor=''
greenColor=''
fi
command -v meson >/dev/null 2>&1 || { echo -e >&2 "${redColor}==> Error: meson is not installed.${resetColor}"; exit 1; }
command -v inotifywait >/dev/null 2>&1 || { echo -e >&2 "${redColor}==> Error: inotifywait is not installed.${resetColor}"; exit 1; }
PROJECT_NAME=$(awk '/^[[:space:]]*project[[:space:]]*\(/{found=1; next} found && /^[[:space:]]*'"'"'[^'"'"']*'"'"'/{match($0, /'"'"'([^'"'"']*)'"'"'/, arr); print arr[1]; exit}' meson.build)
if [ -z "$PROJECT_NAME" ]; then
echo -e "${redColor}==> Error: Could not determine project name from meson.build${resetColor}"
exit 1
else
echo -e "${greenColor}==> Project name: $PROJECT_NAME${resetColor}"
fi
WATCH_DIR="src"
BUILD_DIR="build"
EXECUTABLE="$BUILD_DIR/$PROJECT_NAME"
DEBOUNCE=1
build() {
echo -e "${greenColor}==> Building${resetColor}"
if [ ! -d "$BUILD_DIR" ]; then
echo -e "==> Setting build dir for the first time"
meson setup "$BUILD_DIR"
fi
meson compile -C "$BUILD_DIR"
}
run() {
if [ $? -eq 0 ]; then
echo -e "${greenColor}==> Running${resetColor}"
"$EXECUTABLE"
else
echo -e "${redColor}==> Build failed${resetColor}"
fi
}
install() {
echo -e "${greenColor}==> Installing${resetColor}"
meson install -C "$BUILD_DIR"
}
test () {
./$BUILD_DIR/runtests
}
# initial build and run, or install if requested
build
if [ "$1" == "build" ]; then
exit 0
fi
if [ "$1" == "install" ]; then
install
exit 0
fi
if [ "$1" == "test" ]; then
test
exit 0
fi
run
if [ "$1" == "run" ]; then
exit 0
fi
# watch for changes and rebuild/run
while true; do
inotifywait -q -e modify,create,delete -r --exclude '(\.swp$|~$)' "$WATCH_DIR"
sleep $DEBOUNCE
build
run
done