aboutsummaryrefslogtreecommitdiff
path: root/cbt.bat
diff options
context:
space:
mode:
authorChavXO <mchavinda@colgate.edu>2016-04-04 10:15:03 -0400
committerChristopher Vogt <oss.nsp@cvogt.org>2016-06-02 01:13:56 -0400
commit7231476f9144ccf56be3724636f2be27a40b08b1 (patch)
tree411982c373c31c440a0735fb520eac33ba6fd5d8 /cbt.bat
parent48e2c38cf17e9dc5489e3ce3e4885a6db1f418f7 (diff)
downloadcbt-7231476f9144ccf56be3724636f2be27a40b08b1.tar.gz
cbt-7231476f9144ccf56be3724636f2be27a40b08b1.tar.bz2
cbt-7231476f9144ccf56be3724636f2be27a40b08b1.zip
Added batch script to run on Windows
Diffstat (limited to 'cbt.bat')
-rw-r--r--cbt.bat196
1 files changed, 196 insertions, 0 deletions
diff --git a/cbt.bat b/cbt.bat
new file mode 100644
index 0000000..6de056d
--- /dev/null
+++ b/cbt.bat
@@ -0,0 +1,196 @@
+@ECHO OFF
+REM Launcher bash script that bootstraps CBT from source.
+REM (Some of the code for reporting missing dependencies and waiting for nailgun to come up is a bit weird.)
+REM This is inentionally kept as small as posible.
+REM Welcome improvements to this file:
+REM - reduce code size through better ideas
+REM - reduce code size by moving more of this into type-checked Java/Scala code (if possible without performance loss).
+REM - reduction of dependencies
+REM - performance improvements
+
+REM utility function to log message to stderr with stating the time
+setlocal EnableExtensions EnableDelayedExpansion
+
+where javac > nul 2>&1
+
+if ERRORLEVEL 1 (
+ ECHO You need to install javac! CBT needs it to bootstrap from Java sources into Scala.
+ GOTO :EOF
+)
+
+javac -version > %CBT_HOME%temp.txt 2>&1
+SET /p javac_version_output=<%CBT_HOME%temp.txt
+
+FOR /f "tokens=2" %%G IN ("%javac_version_output%") DO SET javac_version=%%G
+
+FOR /f "tokens=2 delims=." %%G IN ("%javac_version%") DO SET javac_version_minor=%%G
+
+IF javac_version_minor LSS 8 (
+ echo You need to install javac version 1.7 or greater!
+ echo Current javac version is %javac_version
+ GOTO :EOF
+)
+
+SET nailgun_installed=0
+
+where ng > nul 2>&1
+
+if ERRORLEVEL 1 (
+ ECHO You need to install Nailgun to make CBT slightly faster. > nul 2>&1
+) ELSE ( SET nailgun_installed=1 )
+
+where ng-server > nul 2>&1
+
+if ERRORLEVEL 1 (
+ ECHO You need to install Nailgun Server to make CBT slightly faster.
+) ELSE ( SET nailgun_installed=1 )
+
+IF %nailgun_installed%==0 ECHO Note: nailgun not found. It makes CBT faster! > nul 2>&1
+
+where gpg > nul 2>&1
+SET gpg_installed=0
+if ERRORLEVEL 1 (
+ ECHO You need to install gpg for login.
+) ELSE ( SET gpg_installed=0 )
+
+
+
+SET NAILGUN_PORT=4444
+SET NG=ng --nailgun-port %NAILGUN_PORT%
+
+for /f "delims=" %%i in ('chdir') do SET CWD=%%i
+
+SET CBT_HOME=%~dp0
+
+SET SCALA_VERSION=2.11.8
+
+SET NAILGUN=%CBT_HOME%nailgun_launcher\
+SET STAGE1=%CBT_HOME%stage1\
+SET TARGET=target\scala-2.11\classes\
+
+mkdir %NAILGUN%%TARGET% > nul 2>&1
+mkdir %STAGE1%%TARGET% > nul 2>&1
+
+SET nailgun_out=%NAILGUN%\target\nailgun.stdout.log
+SET nailgun_err=%NAILGUN%\target\nailgun.strerr.log
+
+where nc > nul 2>&1
+
+SET nc_installed=1
+SET server_up=0
+
+IF ERRORLEVEL 1 (
+ ECHO Note: nc not found. It will make slightly startup faster.
+) ELSE (
+ nc -z -n -w 1 127.0.0.1 %NAILGUN_PORT% > nul 2>&1
+ SET server_up=1
+)
+
+IF "%1%"=="kill" (
+ echo Stopping nailgun 1>&2
+ %NG% ng-stop >> %nailgun_out 2>> %nailgun_err%
+ GOTO :EOF
+)
+
+SET use_nailgun=1
+
+SET res=0
+IF %nailgun_installed%==0 SET res=1
+IF "%1%"=="publishSigned" SET res=1
+IF "%2%"=="publishSigned" SET res=1
+IF "%1%"=="direct" SET res=1
+IF "%2%"=="direct" SET res=1
+
+IF %res%==1 SET use_nailgun=0
+
+REM IF NOT %server_up%==1
+REM >> %nailgun_out 2>> %nailgun_err
+IF %use_nailgun%==1 (
+ REM try to start nailgun-server, just in case it's not up
+ START ng-server 127.0.0.1:%NAILGUN_PORT%
+)
+
+:RUN
+ CALL :stage1 %*
+ IF NOT "%1%"=="loop" (
+ GOTO :EOF
+ ) ELSE (
+ GOTO :RUN
+ echo "======= Restarting CBT =======" 1>&2
+ )
+
+:stage1
+SETLOCAL
+SET NAILGUN_INDICATOR=%NAILGUN%%TARGET%cbt\NailgunLauncher.class
+SET changed=0
+
+FOR %%i IN (%NAILGUN%*.java) DO (
+ FOR /F %%z IN ('DIR /B /O:D %%i%% %NAILGUN_INDICATOR% 2^> nul') DO SET NEWEST=%%z
+ if "%NEWEST:~-4%"=="java" ( SET changed=1 )
+)
+
+IF %changed%==1 (
+ REM defensive delete of potentially broken class files
+ REM DEL /s /q /f %NAILGUN%%TARGET%cbt\*.class > nul 2>&1
+
+ echo Compiling cbt/nailgun_launcher
+
+ CD %NAILGUN%
+
+ dir /B /A:-D *.java > %CBT_HOME%temp.txt
+
+ CD %CWD%
+
+ FOR /F "tokens=*" %%j in (%CBT_HOME%temp.txt) do SET "files=!files! %NAILGUN%%%j"
+
+ ECHO javac -Xlint:deprecation -d %NAILGUN%%TARGET% !files!
+ GOTO :EOF
+
+ IF ERRORLEVEL 1 (
+ REM triggers recompilation next time.
+ DEL %NAILGUN%TARGET/cbt/*.class 2> NUL REM triggers recompilation next time.
+ GOTO :eof
+ )
+
+ IF %use_nailgun%==0 (
+ REM echo "Stopping nailgun" 1>&2
+ %NG% ng-stop >> %nailgun_out% 2>> %nailgun_err%
+ REM echo "Restarting nailgun" 1>&2
+ ng-server 127.0.0.1:%NAILGUN_PORT% >> %nailgun_out% 2>> %nailgun_err%
+ )
+)
+
+
+IF %use_nailgun%==0 java -cp %NAILGUN%%TARGET% cbt.NailgunLauncher %CWD% %*
+IF %use_nailgun%==0 GOTO :ENDIF
+
+SET /A counter=0
+:BEGINFOR
+REM ECHO %counter%
+IF /I "%counter%" EQU "10" GOTO :ENDFOR
+%NG% ng-cp %NAILGUN%%TARGET%
+%NG% cbt.NailgunLauncher check-alive
+%NG% ng-cp %NAILGUN%%TARGET% >> %nailgun_out% 2>> %nailgun_err%
+%NG% cbt.NailgunLauncher check-alive >> %nailgun_out% 2>> %nailgun_err%
+
+SET isAlive=0
+IF %errorlevel%==131 SET isAlive=1
+IF %errorlevel%==33 SET isAlive=1
+
+
+REM IF ERRORLEVEL 1 (
+ REM ECHO Waiting for nailgun
+REM ) ELSE (
+ REM GOTO :ENDFOR
+REM )
+
+SLEEP 2
+SET /A counter=%counter% + 1
+REM GOTO :BEGINFOR
+:ENDFOR
+%NG% cbt.NailgunLauncher %CWD% %*
+ENDLOCAL
+:ENDIF
+:ENDPROGRAM
+ENDLOCAL
+REM DEL %CBT_HOME%temp.txt > NUL 1>&2 \ No newline at end of file