Skip to content

Commit

Permalink
Merge pull request #44 from cvogt/circleci
Browse files Browse the repository at this point in the history
integrate circleci
  • Loading branch information
cvogt committed Mar 6, 2016
2 parents d320c82 + 1a76778 commit c2f53c5
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 36 deletions.
13 changes: 9 additions & 4 deletions DEVELOPER_GUIDE.txt
@@ -1,9 +1,8 @@
Welcome developer.

CBT has a very easy code base that you can fully master in under an hour.
Don't shy away to submit PRs :).

CBT launches in stages in order to bootstrap from source out of Java into Scala and finally CBT.
CBT has a very easy code base that you can fully master it in an afternoon.
Don't shy away from submiting PRs :). And because CBT bootstraps from source
you already have the code there.

The ./cbt bash script starts the process.

Expand All @@ -19,3 +18,9 @@ stage1/ CBT's code that only relies only on Scala/Java built-ins. Co
stage2/ CBT's code that requires additional libs, e.g. barbary watchservice.
test/ Unit tests that can serve as example builds
sonatype.login Sonatype credentials for deployment. Not in git obviously.

CBT follows an optimistic merging approach. (See http://hintjens.com/blog:106).
We strongly suggest well polished PRs, but don't want to stall improvements
by discussions about minor flaws. As long as the PR does not break anything and
improves the product, we should merge it, polishing remaining things afterwards.

89 changes: 57 additions & 32 deletions cbt
@@ -1,5 +1,4 @@
#!/usr/bin/env bash
#gdate +"%T.%N"
# Launcher bash script that bootstraps CBT from source.
# (Some of the code for reporting missing dependencies and waiting for nailgun to come up is a bit weird.)
# This is inentionally kept as small as posible.
Expand All @@ -9,10 +8,33 @@
# - reduction of dependencies
# - performance improvements

# utility function to log message to stderr with stating the time
log () {
msg=$1
enabled=0
while test $# -gt 0; do
case "$1" in
"-Dlog=time") enabled=1 ;;
"-Dlog=all") enabled=1 ;;
esac
shift
done
if [ $enabled -eq 1 ]; then
which gdate 2>&1 > /dev/null
gdate_installed=$?
if [ $gdate_installed -eq 0 ]; then
i=`gdate +"%S.%N"`
echo "[$i] $msg" 1>&2
fi
fi
}

log "Checking for dependencies" $*

which javac 2>&1 > /dev/null
javac_installed=$?
if [ ! $javac_installed -eq 0 ]; then
echo "You need to install javac! CBT needs it to bootstrap from Java sources into Scala." 2>&1
echo "You need to install javac! CBT needs it to bootstrap from Java sources into Scala." 1>&2
exit 1
fi
javac_version=$(javac -version 2>&1 | cut -d ' ' -f 2)
Expand All @@ -29,62 +51,64 @@ ng_server_installed=$?
nailgun_installed=0
if [ ! $ng_installed -eq 0 ] || [ ! $ng_server_installed -eq 0 ]; then
nailgun_installed=1
echo "(Note: nailgun not found. It makes CBT faster! Try 'brew install nailgun'.)" 2>&1
echo "(Note: nailgun not found. It makes CBT faster! Try 'brew install nailgun'.)" 1>&2
fi
which realpath 2>&1 > /dev/null
realpath_installed=$?
which gcc 2>&1 > /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." 2>&1
echo "You need realpath or gcc installed! CBT needs it to locate itself reliably." 1>&2
exit 1
fi

which gpg 2>&1 > /dev/null
gpg_installed=$?
if [ ! $gpg_installed -eq 0 ]; then
echo "(Note: gpg not found. In order to use publishSigned you'll need it.)" 2>&1
echo "(Note: gpg not found. In order to use publishSigned you'll need it.)" 1>&2
fi

NAILGUN_PORT=4444
NG="ng --nailgun-port $NAILGUN_PORT"

CWD=$(pwd)
_DIR=$(dirname $(readlink "$0") 2>/dev/null || dirname "$0" 2>/dev/null )
# find out real path. Build realpath if needed.

log "Find out real path. Build realpath if needed." $*

export CBT_HOME=$(dirname $($_DIR/realpath/realpath.sh $0))

#gdate +"%T.%N"
export SCALA_VERSION="2.11.7"
export NAILGUN=$CBT_HOME/nailgun_launcher/
export STAGE1=$CBT_HOME/stage1/
export TARGET=target/scala-2.11/classes/
INDICATOR=$STAGE1$TARGET/cbt/Stage1.class

mkdir -p $NAILGUN$TARGET
mkdir -p $STAGE1$TARGET

which nc 2>&1 > /dev/null
nc_installed=$?

log "Check for running nailgun with nc." $*

server_up=1
if [ $nc_installed -eq 0 ]; then
nc -z -n -w 1 127.0.0.1 $NAILGUN_PORT > /dev/null 2>&1
server_up=$?
else
echo "(Note: nc not found. It will make slightly startup faster.)" 2>&1
echo "(Note: nc not found. It will make slightly startup faster.)" 1>&2
fi

if [ ! $nc_installed -eq 0 ] || [ ! $server_up -eq 0 ]; then
echo "Starting up nailgun" 2>&1
log "Starting up nailgun server." $*
# try to start nailgun-server, just in case it's not up
ng-server 127.0.0.1:$NAILGUN_PORT >> $NAILGUN/target/nailgun.stdout.log 2>> $NAILGUN/target/nailgun.stderr.log &
fi

#gdate +"%T.%N"
log "Grabbing Scala classpath..." $*
# fetch / find scala jars
export SCALA_CLASSPATH=`$CBT_HOME/bootstrap_scala/bootstrap_scala $SCALA_VERSION`
if [ ! $? -eq 0 ]; then echo "Problem with bootstrap_scala" 2>&1; exit 1; fi
if [ ! $? -eq 0 ]; then echo "Problem with bootstrap_scala" 1>&2; exit 1; fi

#gdate +"%T.%N"
# detect source changes in CBT itself
Expand All @@ -99,6 +123,7 @@ done
compiles1=0
compiles2=0

log "Checking for source changes in CBT and maybe compiling." $*
# recompile CBT itself if needed
if [ ! $changed -eq 0 ]
then
Expand All @@ -119,9 +144,9 @@ then
-d $STAGE1$TARGET\
`ls $STAGE1/*.scala`
compiles2=$?
echo "Stopping nailgun" 2>&1
echo "Stopping nailgun" 1>&2
$NG ng-stop >> $NAILGUN/target/nailgun.stdout.log 2>> $NAILGUN/target/nailgun.stderr.log &
echo "Restarting nailgun" 2>&1
echo "Restarting nailgun" 1>&2
ng-server 127.0.0.1:$NAILGUN_PORT >> $NAILGUN/target/nailgun.stdout.log 2>> $NAILGUN/target/nailgun.stderr.log &
fi

Expand All @@ -130,33 +155,32 @@ build ()
CP=$STAGE1$TARGET:$SCALA_CLASSPATH
if [ $nailgun_installed -eq 1 ] || [ "$1" = "publishSigned" ] || [ "$2" = "publishSigned" ] || [ "$1" = "direct" ] || [ "$2" = "direct" ]
then
#echo "Running jvm directly" 1>&2
log "Running JVM directly" $*
# -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=localhost:5005
java -cp $NAILGUN$TARGET cbt.NailgunLauncher $mainClass $CP "$CWD" $*
else
#echo "Running via nailgun" 1>&2
#gdate +"%T.%N"
$NG ng-cp $NAILGUN$TARGET >> $NAILGUN/target/nailgun.stdout.log 2>> $NAILGUN/target/nailgun.stderr.log
#gdate +"%T.%N"
$NG cbt.NailgunLauncher cbt.CheckAlive $CP "$CWD" $* >> $NAILGUN/target/nailgun.stdout.log 2>> $NAILGUN/target/nailgun.stderr.log
#gdate +"%T.%N"
alive=$?
while [[ $alive -ne 33 ]]
do
log "Running via nailgun." $*
while true; do
echo "Waiting for nailgun to start..." 1>&2
sleep 1
log "Adding classpath." $*
$NG ng-cp $NAILGUN$TARGET >> $NAILGUN/target/nailgun.stdout.log 2>> $NAILGUN/target/nailgun.stderr.log
log "Checking if nailgun is up yet." $*
$NG cbt.NailgunLauncher cbt.CheckAlive $CP "$CWD" $* >> $NAILGUN/target/nailgun.stdout.log 2>> $NAILGUN/target/nailgun.stderr.log
alive=$?
if [[ $alive -eq 33 ]]; then
break
else
log "Nope. Sleeping for 1 second" $*
sleep 1
fi
done
#gdate +"%T.%N"
log "Running $mainClass via Nailgun." $*
$NG cbt.NailgunLauncher $mainClass $CP "$CWD" $*
#gdate +"%T.%N"

fi
log "Done running $mainClass." $*
}
#gdate +"%T.%N"
# run CBT and loop if desired. This allows recompiling CBT itself as part of compile looping.

log "run CBT and loop if desired. This allows recompiling CBT itself as part of compile looping." $*
if [ $compiles1 -eq 0 ] && [ $compiles2 -eq 0 ]
then
if [ "$1" = "admin" ]; then
Expand All @@ -168,9 +192,10 @@ then
if [ "$1" = "loop" ]
then
while true; do
echo "======= Restarting CBT =======" 2>&1
echo "======= Restarting CBT =======" 1>&2
build $*
done
fi
fi
#gdate +"%T.%N"

log "Exiting CBT" $*
16 changes: 16 additions & 0 deletions circle.yml
@@ -0,0 +1,16 @@
machine:
java:
version: oraclejdk8

dependencies:
cache_directories:
- "bootstrap_scala/cache"
- "bootstrap_scala/target"
- "cache"
- "nailgun_launcher/target"
- "stage1/target"
- "stage2/target"

test:
override:
- ./cbt test
1 change: 1 addition & 0 deletions test/test.scala
Expand Up @@ -73,5 +73,6 @@ object Main{

println(" DONE!")
println(successes+" succeeded, "+ failures+" failed" )
if(failures > 0) System.exit(1) else System.exit(0)
}
}

0 comments on commit c2f53c5

Please sign in to comment.