summaryrefslogtreecommitdiffstats
path: root/jack/etc
diff options
context:
space:
mode:
authorJean-Philippe Lesot <jplesot@google.com>2015-03-11 10:50:55 +0100
committerJean-Philippe Lesot <jplesot@google.com>2015-03-11 10:50:55 +0100
commita6ad00e946f9efa9fcaad7ebff51e125a224e4b3 (patch)
treeadc1860f2496d58b222d8008a6a83405ddafe472 /jack/etc
parent14f66d21a64021d5492c56aff5055e5e7382dfd4 (diff)
downloadtoolchain_jack-a6ad00e946f9efa9fcaad7ebff51e125a224e4b3.tar.gz
toolchain_jack-a6ad00e946f9efa9fcaad7ebff51e125a224e4b3.tar.bz2
toolchain_jack-a6ad00e946f9efa9fcaad7ebff51e125a224e4b3.zip
Start support of a small server for Jack compilation
Change-Id: I38d410565da4f480c60cdd9405603eebaa2d9938
Diffstat (limited to 'jack/etc')
-rwxr-xr-xjack/etc/jack85
1 files changed, 85 insertions, 0 deletions
diff --git a/jack/etc/jack b/jack/etc/jack
new file mode 100755
index 00000000..2409a09b
--- /dev/null
+++ b/jack/etc/jack
@@ -0,0 +1,85 @@
+#! /bin/bash
+#
+# Copyright (C) 2015 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+set -o nounset
+
+JACK_NB_COMPILE=4
+JACK_TIMEOUT=15
+
+TMPDIR="/tmp"
+
+JACK_PRG="java -cp /usr/local/google/home/jplesot/Android/ub-jack/toolchain/jack/jack/dist/jack.jar com.android.jack.server.Server"
+JACK_FIFO="$TMPDIR/jack-$USER.cmd"
+JACK_LOCK="$TMPDIR/jack-$USER.lock"
+JACK_LOG="$TMPDIR/jack-$USER.log"
+
+JACK_DIR="$TMPDIR/jack-$USER-$$/"
+JACK_OUT="$JACK_DIR/out"
+JACK_ERR="$JACK_DIR/err"
+JACK_EXIT="$JACK_DIR/exit"
+JACK_CLI="$JACK_DIR/cli"
+JACK_PWD="$PWD"
+
+#
+# Always create the FIFO
+#
+
+mkfifo -m 0000 $JACK_FIFO 2>/dev/null
+
+#
+# Prepare
+#
+
+# Cleanup
+trap "rm -f $JACK_OUT $JACK_ERR $JACK_EXIT $JACK_CLI $JACK_LOCK 2>/dev/null; rmdir $JACK_DIR 2>/dev/null" exit
+
+# Create fifo for a task
+mkdir $JACK_DIR
+mkfifo $JACK_OUT
+mkfifo $JACK_ERR
+mkfifo $JACK_EXIT
+
+# Redirect output and error
+cat <$JACK_OUT >&1 &
+PID_OUT=$!
+cat <$JACK_ERR >&2 &
+PID_ERR=$!
+
+echo \"$PWD\" $* >$JACK_CLI
+
+#
+# Launch compilation
+#
+
+# Try sending a command
+CMD="+ $JACK_OUT $JACK_ERR $JACK_EXIT $JACK_CLI"
+( echo $CMD >>$JACK_FIFO ) 2>/dev/null
+while [ $? -ne 0 ]; do
+ # If not possible, launch the server one time only
+ mkfifo $JACK_LOCK 2>/dev/null
+ if [ $? -eq 0 ]; then
+ echo "Launch background server" $JACK_PRG
+ nohup $JACK_PRG $JACK_NB_COMPILE $JACK_TIMEOUT $JACK_FIFO >$JACK_LOG 2>&1 &
+ fi
+ # Slow down, and retry sending the command
+ sleep 1
+ ( echo $CMD >>$JACK_FIFO ) 2>/dev/null
+done
+
+wait $PID_OUT
+wait $PID_ERR
+
+exit `cat $JACK_EXIT`