Skip to content

Commit 4adb419

Browse files
committed
fetch dependencies on package change during rebuild; cleanup, docs
1 parent f7c665e commit 4adb419

File tree

4 files changed

+28
-15
lines changed

4 files changed

+28
-15
lines changed

Package.resolved

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Projects built with this template will have the following traits:
3434
2. Quick and easy [REPL](https://github.com/tensorflow/swift/blob/master/Usage.md#repl-read-eval-print-loop) access against the project's Swift for Tensorflow code and third-party libraries
3535
3. Easily unit testable
3636
4. Runs anywhere Docker is available with no additional setup necessary - zero conflicts with existing Swift or TensorFlow installations.
37+
5. Swift code is hot-reloaded on change; third-party libraries are downloaded automatically as well. See the `--live` flag.
3738

3839
This will enable both ease of use during the research phase and a rapid transition to a scalable training solution and beyond (production deployment).
3940

@@ -140,6 +141,7 @@ A control script is included for extra convenience for users on macOS/Linux, but
140141

141142
Some example commands:
142143

144+
* `./sts run app --live` - automatically rebuild and run the application on code change; packages are updated automatically as well!
143145
* `./sts build --release`, `./sts build -r`, `./sts build -p`, `./sts build --prod` - build the image with a release executable
144146
* `./sts run repl --build --name myrepl -v` - run a REPL in a container named myrepl, mounting the current directory as a volume, building the project first
145147
* `./sts run test`, `./sts run tests --name testcontainer` - run unit tests

entrypoint

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,46 +12,49 @@ build() {
1212
swift build --configuration ${CONFIG}
1313
}
1414

15-
installApplication() {
15+
install_application() {
1616
cp ./.build/${CONFIG}/libSTSLibrary.so /usr/lib/libSTSLibrary.so
1717
cp ./.build/${CONFIG}/STSLibrary.swiftmodule /usr/lib/STSLibrary.swiftmodule
1818
cp ./.build/${CONFIG}/STSApplication /usr/bin/STSApplication
1919
}
2020

21-
runApplication() {
21+
run_application() {
2222
/usr/bin/STSApplication
2323
}
2424

25-
buildAndRun() {
26-
build && installApplication && runApplication
25+
build_and_run() {
26+
build && install_application && run_application
2727
}
2828

29-
detectChangesLoop() {
30-
while [[ "$KILL" != true ]]
29+
watch_files() {
30+
while [ ${KILL} != true ]
3131
do
32-
files=`find Sources* -type f -newer /usr/bin/STSApplication`
32+
files=`find *.swift -type f -newer /usr/bin/STSApplication`
3333
if [[ ${files} != "" ]] ; then
3434
echo "Changes in files: $files, building..."
35-
buildAndRun
35+
if [[ ${files} = *"Package.swift" ]] ; then
36+
swift package update
37+
fi
38+
build_and_run
3639
echo "Waiting for changes to run application again."
3740
fi
3841
sleep 2
3942
done
4043
}
4144

4245
entrypoint() {
43-
buildAndRun
46+
build_and_run
4447
}
4548

46-
liveEntrypoint() {
47-
buildAndRun
49+
live_entrypoint() {
50+
build_and_run
4851
echo "Waiting for changes to run application again."
49-
detectChangesLoop &
52+
watch_files &
5053
wait
5154
}
5255

53-
if [ "$LIVE" = true ] ; then
54-
liveEntrypoint
56+
if [ ${LIVE} = true ] ; then
57+
live_entrypoint
5558
else
5659
entrypoint
5760
fi

sts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ TXT_GREEN='\033[0;32m'
1010
TXT_YELLOW='\033[0;33m'
1111
TXT_RED='\033[0;31m'
1212

13-
while [[ $# -gt 0 ]]
13+
while [ $# -gt 0 ]
1414
do
1515
key="$1"
1616
case ${key} in

0 commit comments

Comments
 (0)