-
Notifications
You must be signed in to change notification settings - Fork 1
/
iterative-dev.sh
95 lines (76 loc) · 2.55 KB
/
iterative-dev.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
#!/bin/bash
# This script sets up an iterative loop to accelerate development of
# server-side swift applications. It periodically checks the filesystem
# contents to look for changes in any .swift files. If any are found,
# it will kill the currently running server process, rebuild, and restart
# both the server process and lldb-server (debug) process.
# kills the executable for this project and the lldb debug server (if running)
function killServerProcesses() {
pid="$(pgrep k-bug)"
if [ "$pid" != "" ]
then
echo "killing k-bug"
kill $pid
fi
pid="$(pgrep lldb-server)"
if [ "$pid" != "" ]
then
echo "killing lldb-server"
kill $pid
fi
}
# called on signal interrupt (CTRL-C)
function interrupt ()
{
printf "\n\nuser cancelled\n"
killServerProcesses
printf "\n"
exit 2
}
# trap to handle signal interrupt
trap "interrupt" INT
# Using an infinite loop/polling mechanism b/c it appears that
# inotifywait (os file system events) does not pickup changes
# on a volume, where the change orignates from the host OS (outside of the container)
# the poll just checks the contents of a recursive ls command for *files* only with full timestamps.
#
# If the ls output changes between loop iterations, the script
# will kill the existing server process and restart it.
#
# This recursively looks for file changes for swift files only,
echo "setting up watcher..."
lastOutput=""
# check if tools-utils.sh exists. if so, assume you are inside of Dockerfile-tools container
if [ -e /swift-utils/tools-utils.sh ]
then
cd /swift-project/
fi
while true; do
unamestr=`uname`
lsCommand='ls -lt -R --time-style=full-iso'
if [[ "$unamestr" == 'Darwin' ]]; then
lsCommand='ls -lT -R'
fi
temp="$($lsCommand | grep -i ^-[-r][-w][-x][-r][-w][-x][-r][-w][-x].*\.swift$)"
if [ "$lastOutput" != "$temp" ]
then
lastOutput="$temp"
killServerProcesses
echo "starting server..."
if [ -e /swift-utils/tools-utils.sh ]
then
# assumes you are inside of Dockerfile-tools container
# starts debug server on port 1024
cd /swift-project/
/swift-utils/tools-utils.sh debug k-bug 1024
else
# assumes you are running from "normal"/host operating system
swift build
if [[ $? == 0 ]]; then
# only start server is build was successful (result code 0)
./.build/debug/k-bug &
fi
fi
fi
sleep 2.0
done