This repository was archived by the owner on Feb 28, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added iterative dev script, which allows for fast/easy dev iterations for the developer. While the script is running, it will automatically detect changes in the project's `.swift` files and recompile the app accordingly. Sample usage (after generating the project)... From native OS: 1. cd into the project's root directory directory 2. run `./iterative-dev.sh` With `bx dev` cli: 1. build the app using `bx dev build --debug` 2. shell into the tools container using `bx dev shell tools` 3. run `./swift-project/iterative-dev.sh` File system changes are detected using a low-tech infinitely looping poll mechanism, which works in both local OS/filesystem and across host OS->Docker container volume scenarios.
- Loading branch information
Showing
2 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
#!/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 <%- executableModule %>)" | ||
if [ "$pid" != "" ] | ||
then | ||
echo "killing <%- executableModule %>" | ||
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 <%- executableModule %> 1024 | ||
else | ||
# assumes you are running from "normal"/host operating system | ||
swift build | ||
./.build/debug/<%- executableModule %> & | ||
fi | ||
|
||
fi | ||
sleep 2.0 | ||
done |