diff options
author | Christopher Vogt <oss.nsp@cvogt.org> | 2017-03-12 13:02:51 -0400 |
---|---|---|
committer | Christopher Vogt <oss.nsp@cvogt.org> | 2017-03-12 15:29:47 -0400 |
commit | 8567e2557467f838e371fd8e6b267d5a417ef78e (patch) | |
tree | 869e53308505bfe80c987221c4d7c967280ab7c5 /cbt | |
parent | f35f2e0dbabb68511166b647a5018d7f57adcd9a (diff) | |
download | cbt-8567e2557467f838e371fd8e6b267d5a417ef78e.tar.gz cbt-8567e2557467f838e371fd8e6b267d5a417ef78e.tar.bz2 cbt-8567e2557467f838e371fd8e6b267d5a417ef78e.zip |
force successful shellcheck linting for launcher script
Diffstat (limited to 'cbt')
-rwxr-xr-x | cbt | 75 |
1 files changed, 41 insertions, 34 deletions
@@ -21,16 +21,16 @@ nanos() { if [ "$n" = "" ]; then n="0" fi - echo $n + echo 1$n } start_seconds=$(seconds) -start_nanos=1$(nanos) +start_nanos=$(nanos) time_taken() { i=$(( $(seconds) - start_seconds )) - n=$(( $(( 1$(nanos) - start_nanos )) / 1000000 )) - if [[ ( "$n" < 0 ) ]]; then + n=$(( $(( $(nanos) - start_nanos )) / 1000000 )) + if [[ ( $n -lt 0 ) ]]; then i=$(( i-1 )) n=$(( n+1000 )) fi @@ -57,7 +57,7 @@ log () { log "Checking for dependencies" "$@" -which javac 2>&1 > /dev/null +which javac >/dev/null 2>/dev/null javac_installed=$? if [ ! $javac_installed -eq 0 ]; then echo "You need to install javac 1.7 or later! CBT needs it to bootstrap from Java sources into Scala." 1>&2 @@ -77,22 +77,22 @@ fi # fi NG_EXECUTABLE=$(which ng || which ng-nailgun) -NG_SERVER=$(which ng-server || ls /usr/share/java/nailgun-server-*.jar 2>/dev/null | awk '{print "java -jar " $0}') +NG_SERVER=$(which ng-server || find /usr/local/Cellar/nailgun/*/libexec/nailgun-server-*.jar 2>/dev/null | awk '{print "java -jar " $0}') nailgun_installed=0 if [ "$NG_EXECUTABLE" == "" ] || [ "$NG_SERVER" == "" ]; then nailgun_installed=1 echo "(Note: nailgun not found. It makes CBT faster! Try 'brew install nailgun' or 'apt install nailgun'.)" 1>&2 fi -which realpath 2>&1 > /dev/null +which realpath >/dev/null 2>/dev/null realpath_installed=$? -which gcc 2>&1 > /dev/null +which gcc >/dev/null 2>/dev/null gcc_installed=$? if [ ! $realpath_installed -eq 0 ] && [ ! $gcc_installed -eq 0 ]; then echo "You need realpath or gcc installed! CBT needs it to locate itself reliably." 1>&2 - exit 1 + exit 252 fi -which gpg 2>&1 > /dev/null +which gpg >/dev/null 2>/dev/null gpg_installed=$? if [ ! $gpg_installed -eq 0 ]; then echo "(Note: gpg not found. In order to use publishSigned you'll need it.)" 1>&2 @@ -102,15 +102,25 @@ NAILGUN_PORT=4444 NG="$NG_EXECUTABLE --nailgun-port $NAILGUN_PORT" CWD=$(pwd) -_DIR=$(dirname $(readlink "$0") 2>/dev/null || dirname "$0" 2>/dev/null ) + +CBT_SCRIPT="$(readlink "$0")" +if [ "$CBT_SCRIPT" = "" ]; then + CBT_SCRIPT="$0" +fi +if [ "$CBT_SCRIPT" = "" ]; then + echo "cannot locate cbt launcher" 1>&2 + exit 252 +fi +_DIR=$(dirname "$CBT_SCRIPT" 2>/dev/null || dirname "$0" 2>/dev/null ) log "Find out real path. Build realpath if needed." "$@" -export CBT_HOME=$(dirname $($_DIR/realpath/realpath.sh $0)) +export CBT_HOME +CBT_HOME="$(dirname "$("$_DIR"/realpath/realpath.sh "$0")")" -export NAILGUN=$CBT_HOME/nailgun_launcher/ +export NAILGUN="$CBT_HOME"/nailgun_launcher/ export TARGET=target/scala-2.11/classes/ -mkdir -p $NAILGUN$TARGET +mkdir -p "$NAILGUN$TARGET" nailgun_out=$NAILGUN/target/nailgun.stdout.log nailgun_err=$NAILGUN/target/nailgun.strerr.log @@ -134,7 +144,7 @@ foo(){ done } -foo $@ +foo "$@" if [ "$1" = "kill" ]; then echo "Stopping background process (nailgun)" 1>&2 @@ -142,7 +152,7 @@ if [ "$1" = "kill" ]; then exit 1 fi -which nc 2>&1 > /dev/null +which nc >/dev/null 2>/dev/null nc_installed=$? log "Check for running nailgun with nc." "$@" @@ -173,21 +183,21 @@ fi stage1 () { log "Checking for changes in cbt/nailgun_launcher" "$@" NAILGUN_INDICATOR=$NAILGUN$TARGET../classes.last-success - changed=0 - for file in `ls $NAILGUN/*.java`; do - if [ $file -nt $NAILGUN_INDICATOR ]; then changed=1; fi + changed=1 + for file in "$NAILGUN"/*.java; do + if [ "$file" -nt "$NAILGUN_INDICATOR" ]; then changed=0; fi done - compiles=0 - if [ $changed -eq 1 ]; then + exitCode=0 + if [ $changed -eq 0 ]; then echo "Stopping background process (nailgun) if running" 1>&2 $NG ng-stop >> $nailgun_out 2>> $nailgun_err & #rm $NAILGUN$TARGET/cbt/*.class 2>/dev/null # defensive delete of potentially broken class files echo "Compiling cbt/nailgun_launcher" 1>&2 COMPILE_TIME=$(date +%YY%mm%dd%HH%MM.%SS|sed "s/[YmdHMS]//g") - javac -Xlint:deprecation -Xlint:unchecked -d $NAILGUN$TARGET `ls $NAILGUN*.java` - compiles=$? - if [ $compiles -eq 0 ]; then - touch -t $COMPILE_TIME $NAILGUN_INDICATOR + javac -Xlint:deprecation -Xlint:unchecked -d "$NAILGUN$TARGET" "$NAILGUN"*.java + exitCode=$? + if [ $exitCode -eq 0 ]; then + touch -t "$COMPILE_TIME" "$NAILGUN_INDICATOR" if [ $use_nailgun -eq 0 ]; then echo "Starting background process (nailgun)" 1>&2 ng-server 127.0.0.1:$NAILGUN_PORT >> $nailgun_out 2>> $nailgun_err & @@ -198,18 +208,19 @@ stage1 () { log "run CBT and loop if desired. This allows recompiling CBT itself as part of compile looping." "$@" - if [ $compiles -eq 0 ]; then - if [ $use_nailgun -eq 1 ] + if [ $exitCode -eq 0 ]; then + if [ ! $use_nailgun -eq 0 ] then log "Running JVM directly" "$@" + options=($JAVA_OPTS) # JVM options to improve startup time. See https://github.com/cvogt/cbt/pull/262 - java $JAVA_OPTS $DEBUG -Xmx6072m -Xss10M -XX:MaxJavaStackTraceDepth=-1 -XX:+TieredCompilation -XX:TieredStopAtLevel=1 -Xverify:none -cp $NAILGUN$TARGET cbt.NailgunLauncher $(time_taken) "$CWD" "$@" + java "${options[@]}" $DEBUG -Xmx6072m -Xss10M -XX:MaxJavaStackTraceDepth=-1 -XX:+TieredCompilation -XX:TieredStopAtLevel=1 -Xverify:none -cp "$NAILGUN$TARGET" cbt.NailgunLauncher "$(time_taken)" "$CWD" "$@" exitCode=$? else log "Running via background process (nailgun)" "$@" for i in 0 1 2 3 4 5 6 7 8 9; do log "Adding classpath." "$@" - $NG ng-cp $NAILGUN$TARGET >> $nailgun_out 2>> $nailgun_err + $NG ng-cp "$NAILGUN$TARGET" >> $nailgun_out 2>> $nailgun_err log "Checking if nailgun is up yet." "$@" $NG cbt.NailgunLauncher check-alive >> $nailgun_out 2>> $nailgun_err alive=$? @@ -227,7 +238,7 @@ stage1 () { sleep 0.3 done log "Running CBT via Nailgun." "$@" - $NG cbt.NailgunLauncher $(time_taken) "$CWD" "$@" + $NG cbt.NailgunLauncher "$(time_taken)" "$CWD" "$@" exitCode=$? fi log "Done running CBT." "$@" @@ -277,9 +288,5 @@ while true; do echo "======= Restarting CBT =======" 1>&2 done -if [ $compiles -ne 0 ]; then - exitCode=1 -fi - log "Exiting CBT" "$@" exit $exitCode |