aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Christopher Vogt <oss.nsp@cvogt.org>2017-03-12 15:49:08 -0400
committerGitHub <noreply@github.com>2017-03-12 15:49:08 -0400
commitc14e288996d2b56b6b06a0624f4f2fca315369c7 (patch)
tree5fde2735672672582aa5681acc146a8d0d3d60e9
parenta6eadada6e6d1f9efa1b5edecef5ce42b2099706 (diff)
parent8567e2557467f838e371fd8e6b267d5a417ef78e (diff)
downloadcbt-c14e288996d2b56b6b06a0624f4f2fca315369c7.tar.gz
cbt-c14e288996d2b56b6b06a0624f4f2fca315369c7.tar.bz2
cbt-c14e288996d2b56b6b06a0624f4f2fca315369c7.zip
Merge pull request #423 from cvogt/chris
various changes
-rwxr-xr-xcbt90
-rw-r--r--circle.yml6
-rw-r--r--stage1/Stage1.scala7
-rw-r--r--stage2/ToolsStage2.scala2
-rw-r--r--test/build/build.scala1
-rw-r--r--test/test.scala12
6 files changed, 73 insertions, 45 deletions
diff --git a/cbt b/cbt
index 1f3d581..22c789e 100755
--- a/cbt
+++ b/cbt
@@ -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
@@ -42,10 +42,11 @@ log () {
msg=$1
enabled=1
while test $# -gt 0; do
- case "$1" in
- "-Dlog=time") enabled=0 ;;
- "-Dlog=all") enabled=0 ;;
- esac
+ if [[ "$1" == "-Dlog="* ]]; then
+ if [[ "$1" == *"time"* ]] || [[ "$1" == *"bash"* ]] || [[ "$1" == *"all"* ]]; then
+ enabled=0
+ fi
+ fi
shift
done
if [ $enabled -eq 0 ]; then
@@ -56,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
@@ -76,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
@@ -101,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
@@ -133,7 +144,7 @@ foo(){
done
}
-foo $@
+foo "$@"
if [ "$1" = "kill" ]; then
echo "Stopping background process (nailgun)" 1>&2
@@ -141,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." "$@"
@@ -155,7 +166,11 @@ else
fi
use_nailgun=0
-if [ $nailgun_installed -eq 1 ] || [ "$1" = "publishSigned" ] || [ "$2" = "publishSigned" ] || [ "$1" = "direct" ] || [ "$2" = "direct" ]; then
+if [ "$1" = "direct" ]; then
+ use_nailgun=1
+ shift
+fi
+if [ $nailgun_installed -eq 1 ] || [ "$1" = "publishSigned" ]; then
use_nailgun=1
fi
@@ -168,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 &
@@ -193,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=$?
@@ -222,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." "$@"
@@ -272,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
diff --git a/circle.yml b/circle.yml
index 92b8983..40a7f27 100644
--- a/circle.yml
+++ b/circle.yml
@@ -6,6 +6,12 @@ dependencies:
# cache_directories:
# - "cache"
override:
+ - sudo apt-add-repository "deb http://archive.ubuntu.com/ubuntu trusty-backports main restricted universe"
+ - sudo apt-get update
+ - sudo apt-get install -t trusty-backports shellcheck
+
+compile:
+ override:
- ./cbt compile
- ./cbt direct
- ./cbt -Dlog=all
diff --git a/stage1/Stage1.scala b/stage1/Stage1.scala
index 85ec0e9..48d0ae9 100644
--- a/stage1/Stage1.scala
+++ b/stage1/Stage1.scala
@@ -5,8 +5,7 @@ import java.util._
import scala.collection.JavaConverters._
-final case class Stage1ArgsParser(__args: Seq[String]) {
- val _args = __args.drop(1)
+final case class Stage1ArgsParser(_args: Seq[String]) {
/**
* Raw parameters including their `-D` flag.
**/
@@ -162,7 +161,7 @@ object Stage1{
buildStage1: BuildStage1Result,
persistentCache: java.util.Map[AnyRef,AnyRef]
): Int = {
- val args = Stage1ArgsParser(_args.toVector)
+ val args = Stage1ArgsParser(_args.toVector.drop(1))
implicit val logger = new Logger(args.enabledLoggers, buildStage1.start)
logger.stage1(s"Stage1 start")
@@ -173,7 +172,7 @@ object Stage1{
val stage2Args = new Stage2Args(
new File( args.args(0) ),
- args.args.drop(1).dropWhile(_ == "direct").toVector,
+ args.args.drop(1).toVector,
// launcher changes cause entire nailgun restart, so no need for them here
stage2LastModified = stage2LastModified,
cache,
diff --git a/stage2/ToolsStage2.scala b/stage2/ToolsStage2.scala
index ba7a27f..7765e82 100644
--- a/stage2/ToolsStage2.scala
+++ b/stage2/ToolsStage2.scala
@@ -2,7 +2,7 @@ package cbt
import java.io._
object ToolsStage2 extends Stage2Base{
def run( _args: Stage2Args ): ExitCode = {
- val args = _args.args.dropWhile(Seq("tools","direct") contains _)
+ val args = _args.args.dropWhile(Seq("tools") contains _)
val lib = new Lib(_args.logger)
val toolsTasks = new ToolsTasks(lib, args, _args.cwd, _args.cache, _args.cbtHome, _args.stage2LastModified)(_args.classLoaderCache)
lib.callReflective(toolsTasks, args.lift(0), null)
diff --git a/test/build/build.scala b/test/build/build.scala
index 9e02144..2777511 100644
--- a/test/build/build.scala
+++ b/test/build/build.scala
@@ -2,4 +2,5 @@ import cbt._
class Build(val context: cbt.Context) extends BaseBuild{
override def dependencies = super.dependencies :+ context.cbtDependency
def apply = run
+ def args = context.args
}
diff --git a/test/test.scala b/test/test.scala
index 4d1d7fb..bbecd94 100644
--- a/test/test.scala
+++ b/test/test.scala
@@ -14,17 +14,27 @@ object Main{
implicit val logger: Logger = new Logger(args.enabledLoggers, System.currentTimeMillis)
val lib = new Lib(logger)
val cbtHome = new File(System.getenv("CBT_HOME"))
-
val slow = (
System.getenv("CIRCLECI") != null // enable only on circle
|| args.args.contains("slow")
)
val compat = !args.args.contains("no-compat")
+ val shellcheck = !args.args.contains("no-shellcheck")
if(!slow) System.err.println( "Skipping slow tests" )
if(!compat) System.err.println( "Skipping cbt version compatibility tests" )
+ if(shellcheck){
+ val pb = new ProcessBuilder( "/usr/bin/env", "shellcheck", (cbtHome / "cbt").string )
+ val p = pb.start
+ val out = new java.io.InputStreamReader(p.getInputStream)
+ val errors = Iterator.continually(out.read).takeWhile(_ != -1).map(_.toChar).mkString
+ if( p.waitFor != 0 ){
+ throw new Exception("Linting error in ./cbt bash launcher script:\n" + errors)
+ }
+ } else System.err.println( "Skipping shellcheck" )
+
var successes = 0
var failures = 0
def assertException[T:scala.reflect.ClassTag](msg: String = "")(code: => Unit)(implicit logger: Logger) = {