./scripts/watchany.sh

- watches for changes to any .u, .hs, or .scala file
- initial .u file can be provided as command-line argument, otherwise most-recently modified .u file will be used
- defer building scala runtime until .u typechecks or .scala files are edited
This commit is contained in:
Arya Irani 2018-08-20 21:46:28 -04:00
parent 73d7164278
commit 452fa3066a
2 changed files with 125 additions and 0 deletions

107
scripts/execany.sh Executable file
View File

@ -0,0 +1,107 @@
#!/usr/bin/env bash
source="$1"
unison_files_changed="$source"
haskell_needs_rebuild=x
scala_needs_rebuild=x
haskell_files_changed=
scala_files_changed=
binary=`mktemp`
function build_haskell {
if [ -n "$haskell_needs_rebuild" ]; then
echo "Building typechecker..."
stack build && echo "Typechecker built!" && haskell_needs_rebuild=""
fi
}
function build_scala {
if [ -n "$scala_needs_rebuild" ]; then
echo "Building runtime..."
(cd runtime-jvm; sbt main/compile) && echo "Runtime built!" && scala_needs_rebuild=""
fi
}
function typecheck {
build_haskell && \
echo "Parsing/typechecking $source" && \
stack exec bootstrap "$source" "$binary"
}
function execute {
build_scala && \
echo "Executing $source ($binary)" && \
scala \
-cp runtime-jvm/main/target/scala-2.12/classes org.unisonweb.Bootstrap \
"$binary"
}
function horizontal_line {
cols=`tput cols`
char="="
printf "%0.s$char" $(seq 1 $cols)
echo
}
function wait {
if [ -n "$source" ]; then
echo "Waiting for changes (selected: $source)..."
else
echo "Waiting for changes (no Unison source selected)..."
fi
}
function process_batch {
if [ -n "$unison_files_changed" ]; then
horizontal_line
typecheck && execute
wait
else
if [ -n "$haskell_files_changed" ]; then
build_haskell
if [ -n "$scala_files_changed" ]; then
build_scala
fi
wait
elif [ -n "$scala_files_changed" ]; then
build_scala
wait
fi
fi
haskell_files_changed=
scala_files_changed=
unison_files_changed=
}
if [ -z "$binary" ]; then
echo "error running `mktemp` to generate a temporary file name"
exit 1
fi
build_haskell
if [ -n "$source" ]; then process_batch; else wait; fi
while IFS= read -r changed; do
# echo "debug: $changed"
case $changed in
NoOp)
process_batch
;;
*.hs)
echo "detected change in $changed"
hasktags -cx parser-typechecker
haskell_needs_rebuild=x
haskell_files_changed=x
;;
*.scala)
echo "detected change in $changed"
scala_needs_rebuild=x
scala_files_changed=x
;;
*.u)
echo "detected change in $changed"
source="$changed"
unison_files_changed=x
;;
esac
done

18
scripts/watchany.sh Executable file
View File

@ -0,0 +1,18 @@
#!/usr/bin/env bash
source="$1"
assert_command_exists () {
if ! ( type "$1" &> /dev/null ); then
echo "Sorry, I need the '$1' command, but couldn't find it installed." >&2
exit 1
fi
}
assert_command_exists mktemp
assert_command_exists stack
assert_command_exists sbt
assert_command_exists scala
assert_command_exists fswatch
fswatch --batch . | \
"`dirname $0`/execany.sh" "$source"