From cdd53de9a740b5df16c288d9fcf60b05fc35c47c Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Sun, 14 Jun 2015 00:46:48 +0300 Subject: [PATCH] CLI: get rid of duplication in JVM/JS scripts --- compiler/cli/bin/kotlinc | 98 +++++++++++++++++++++++++++----- compiler/cli/bin/kotlinc-js | 96 +++++-------------------------- compiler/cli/bin/kotlinc-js.bat | 56 +++++------------- compiler/cli/bin/kotlinc-jvm | 96 +++++-------------------------- compiler/cli/bin/kotlinc-jvm.bat | 56 +++++------------- compiler/cli/bin/kotlinc.bat | 59 ++++++++++++++----- 6 files changed, 185 insertions(+), 276 deletions(-) diff --git a/compiler/cli/bin/kotlinc b/compiler/cli/bin/kotlinc index ba5bcad2564..e5d3efafeea 100755 --- a/compiler/cli/bin/kotlinc +++ b/compiler/cli/bin/kotlinc @@ -1,17 +1,87 @@ #!/bin/bash --posix +# +############################################################################## +# Copyright 2002-2011, LAMP/EPFL +# Copyright 2011-2015, JetBrains +# +# This is free software; see the distribution for copying conditions. +# There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. +############################################################################## -# Copyright 2010-2015 JetBrains s.r.o. -# -# 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. +[ -n "$KOTLIN_COMPILER" ] || KOTLIN_COMPILER=org.jetbrains.kotlin.cli.jvm.K2JVMCompiler -"$(dirname "$(which "$0")")"/kotlinc-jvm "$@" +cygwin=false; +case "`uname`" in + CYGWIN*) cygwin=true ;; +esac + +# Finding the root folder for this Kotlin distribution +SOURCE=$0; +SCRIPT=`basename "$SOURCE"`; +while [ -h "$SOURCE" ]; do + SCRIPT=`basename "$SOURCE"`; + LOOKUP=`ls -ld "$SOURCE"`; + TARGET=`expr "$LOOKUP" : '.*-> \(.*\)$'`; + if expr "${TARGET:-.}/" : '/.*/$' > /dev/null; then + SOURCE=${TARGET:-.}; + else + SOURCE=`dirname "$SOURCE"`/${TARGET:-.}; + fi; +done; + +# see #2092 +KOTLIN_HOME=`dirname "$SOURCE"` +KOTLIN_HOME=`cd "$KOTLIN_HOME"; pwd -P` +KOTLIN_HOME=`cd "$KOTLIN_HOME"/..; pwd` + +if $cygwin; then + # Remove spaces from KOTLIN_HOME on windows + KOTLIN_HOME=`cygpath --windows --short-name "$KOTLIN_HOME"` +fi + +[ -n "$JAVA_OPTS" ] || JAVA_OPTS="-Xmx256M -Xms32M -noverify" + +# break out -D and -J options and add them to JAVA_OPTS as well +# so they reach the underlying JVM in time to do some good. The +# -D options will be available as system properties. +declare -a java_args +declare -a kotlin_args + +while [ $# -gt 0 ]; do + case "$1" in + -D*) + # pass to kotlin as well: otherwise we lose it sometimes when we + # need it, e.g. communicating with a server compiler. + java_args=("${java_args[@]}" "$1") + kotlin_args=("${kotlin_args[@]}" "$1") + shift + ;; + -J*) + # as with -D, pass to kotlin even though it will almost + # never be used. + java_args=("${java_args[@]}" "${1:2}") + kotlin_args=("${kotlin_args[@]}" "$1") + shift + ;; + *) + kotlin_args=("${kotlin_args[@]}" "$1") + shift + ;; + esac +done + +# reset "$@" to the remaining args +set -- "${kotlin_args[@]}" + +if [ -z "$JAVACMD" -a -n "$JAVA_HOME" -a -x "$JAVA_HOME/bin/java" ]; then + JAVACMD="$JAVA_HOME/bin/java" +fi + +"${JAVACMD:=java}" \ + $JAVA_OPTS \ + "${java_args[@]}" \ + -cp "${KOTLIN_HOME}/lib/kotlin-preloader.jar" \ + org.jetbrains.kotlin.preloading.Preloader \ + "${KOTLIN_HOME}/lib/kotlin-compiler.jar" \ + $KOTLIN_COMPILER 4096 notime "$@" diff --git a/compiler/cli/bin/kotlinc-js b/compiler/cli/bin/kotlinc-js index 64e1802ff99..3f66a7c8cd4 100755 --- a/compiler/cli/bin/kotlinc-js +++ b/compiler/cli/bin/kotlinc-js @@ -1,87 +1,19 @@ #!/bin/bash --posix + +# Copyright 2010-2015 JetBrains s.r.o. # -############################################################################## -# Copyright 2002-2011, LAMP/EPFL -# Copyright 2011-2015, JetBrains +# 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 # -# This is free software; see the distribution for copying conditions. -# There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A -# PARTICULAR PURPOSE. -############################################################################## +# 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. -cygwin=false; -case "`uname`" in - CYGWIN*) cygwin=true ;; -esac +export KOTLIN_COMPILER=org.jetbrains.kotlin.cli.js.K2JSCompiler -# Finding the root folder for this Kotlin distribution -SOURCE=$0; -SCRIPT=`basename "$SOURCE"`; -while [ -h "$SOURCE" ]; do - SCRIPT=`basename "$SOURCE"`; - LOOKUP=`ls -ld "$SOURCE"`; - TARGET=`expr "$LOOKUP" : '.*-> \(.*\)$'`; - if expr "${TARGET:-.}/" : '/.*/$' > /dev/null; then - SOURCE=${TARGET:-.}; - else - SOURCE=`dirname "$SOURCE"`/${TARGET:-.}; - fi; -done; - -# see #2092 -KOTLIN_HOME=`dirname "$SOURCE"` -KOTLIN_HOME=`cd "$KOTLIN_HOME"; pwd -P` -KOTLIN_HOME=`cd "$KOTLIN_HOME"/..; pwd` - -if $cygwin; then - # Remove spaces from KOTLIN_HOME on windows - KOTLIN_HOME=`cygpath --windows --short-name "$KOTLIN_HOME"` -fi - -[ -n "$JAVA_OPTS" ] || JAVA_OPTS="-Xmx256M -Xms32M -noverify" - -# break out -D and -J options and add them to JAVA_OPTS as well -# so they reach the underlying JVM in time to do some good. The -# -D options will be available as system properties. -declare -a java_args -declare -a kotlin_args - -while [ $# -gt 0 ]; do - case "$1" in - -D*) - # pass to kotlin as well: otherwise we lose it sometimes when we - # need it, e.g. communicating with a server compiler. - java_args=("${java_args[@]}" "$1") - kotlin_args=("${kotlin_args[@]}" "$1") - shift - ;; - -J*) - # as with -D, pass to kotlin even though it will almost - # never be used. - java_args=("${java_args[@]}" "${1:2}") - kotlin_args=("${kotlin_args[@]}" "$1") - shift - ;; - *) - kotlin_args=("${kotlin_args[@]}" "$1") - shift - ;; - esac -done - -# reset "$@" to the remaining args -set -- "${kotlin_args[@]}" - -if [ -z "$JAVACMD" -a -n "$JAVA_HOME" -a -x "$JAVA_HOME/bin/java" ]; then - JAVACMD="$JAVA_HOME/bin/java" -fi - -CPSELECT="-cp " - -"${JAVACMD:=java}" \ - $JAVA_OPTS \ - "${java_args[@]}" \ - ${CPSELECT}"${KOTLIN_HOME}/lib/kotlin-preloader.jar" \ - org.jetbrains.kotlin.preloading.Preloader \ - "${KOTLIN_HOME}/lib/kotlin-compiler.jar" \ - org.jetbrains.kotlin.cli.js.K2JSCompiler 4096 notime "$@" +"$(dirname "$(which "$0")")"/kotlinc "$@" diff --git a/compiler/cli/bin/kotlinc-js.bat b/compiler/cli/bin/kotlinc-js.bat index e1ab1e6c9ba..db8c6a21b79 100644 --- a/compiler/cli/bin/kotlinc-js.bat +++ b/compiler/cli/bin/kotlinc-js.bat @@ -1,45 +1,19 @@ @echo off -rem based on scalac.bat from the Scala distribution -rem ########################################################################## -rem # Copyright 2002-2011, LAMP/EPFL -rem # Copyright 2011-2015, JetBrains -rem # -rem # This is free software; see the distribution for copying conditions. -rem # There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A -rem # PARTICULAR PURPOSE. -rem ########################################################################## -rem We adopt the following conventions: -rem - System/user environment variables start with a letter -rem - Local batch variables start with an underscore ('_') +rem Copyright 2010-2015 JetBrains s.r.o. +rem +rem Licensed under the Apache License, Version 2.0 (the "License"); +rem you may not use this file except in compliance with the License. +rem You may obtain a copy of the License at +rem +rem http://www.apache.org/licenses/LICENSE-2.0 +rem +rem Unless required by applicable law or agreed to in writing, software +rem distributed under the License is distributed on an "AS IS" BASIS, +rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +rem See the License for the specific language governing permissions and +rem limitations under the License. -@setlocal -call :set_home +set KOTLIN_COMPILER=org.jetbrains.kotlin.cli.js.K2JSCompiler -if not "%JAVA_HOME%"=="" ( - if exist "%JAVA_HOME%\bin\java.exe" set "_JAVACMD=%JAVA_HOME%\bin\java.exe" -) - -if "%_JAVACMD%"=="" set _JAVACMD=java - -rem We use the value of the JAVA_OPTS environment variable if defined -set _JAVA_OPTS=-Xmx256M -Xms32M -noverify - -"%_JAVACMD%" %_JAVA_OPTS% -cp "%_KOTLIN_HOME%\lib\kotlin-preloader.jar" ^ - org.jetbrains.kotlin.preloading.Preloader "%_KOTLIN_HOME%\lib\kotlin-compiler.jar" ^ - org.jetbrains.kotlin.cli.js.K2JSCompiler 4096 notime %* - -exit /b %ERRORLEVEL% -goto end - -rem ########################################################################## -rem # subroutines - -:set_home - set _BIN_DIR= - for %%i in (%~sf0) do set _BIN_DIR=%_BIN_DIR%%%~dpsi - set _KOTLIN_HOME=%_BIN_DIR%.. -goto :eof - -:end -@endlocal +call %~dps0kotlinc.bat %* diff --git a/compiler/cli/bin/kotlinc-jvm b/compiler/cli/bin/kotlinc-jvm index 42b60bb183c..d8e823a634c 100755 --- a/compiler/cli/bin/kotlinc-jvm +++ b/compiler/cli/bin/kotlinc-jvm @@ -1,87 +1,17 @@ #!/bin/bash --posix + +# Copyright 2010-2015 JetBrains s.r.o. # -############################################################################## -# Copyright 2002-2011, LAMP/EPFL -# Copyright 2011-2015, JetBrains +# 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 # -# This is free software; see the distribution for copying conditions. -# There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A -# PARTICULAR PURPOSE. -############################################################################## +# 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. -cygwin=false; -case "`uname`" in - CYGWIN*) cygwin=true ;; -esac - -# Finding the root folder for this Kotlin distribution -SOURCE=$0; -SCRIPT=`basename "$SOURCE"`; -while [ -h "$SOURCE" ]; do - SCRIPT=`basename "$SOURCE"`; - LOOKUP=`ls -ld "$SOURCE"`; - TARGET=`expr "$LOOKUP" : '.*-> \(.*\)$'`; - if expr "${TARGET:-.}/" : '/.*/$' > /dev/null; then - SOURCE=${TARGET:-.}; - else - SOURCE=`dirname "$SOURCE"`/${TARGET:-.}; - fi; -done; - -# see #2092 -KOTLIN_HOME=`dirname "$SOURCE"` -KOTLIN_HOME=`cd "$KOTLIN_HOME"; pwd -P` -KOTLIN_HOME=`cd "$KOTLIN_HOME"/..; pwd` - -if $cygwin; then - # Remove spaces from KOTLIN_HOME on windows - KOTLIN_HOME=`cygpath --windows --short-name "$KOTLIN_HOME"` -fi - -[ -n "$JAVA_OPTS" ] || JAVA_OPTS="-Xmx256M -Xms32M -noverify" - -# break out -D and -J options and add them to JAVA_OPTS as well -# so they reach the underlying JVM in time to do some good. The -# -D options will be available as system properties. -declare -a java_args -declare -a kotlin_args - -while [ $# -gt 0 ]; do - case "$1" in - -D*) - # pass to kotlin as well: otherwise we lose it sometimes when we - # need it, e.g. communicating with a server compiler. - java_args=("${java_args[@]}" "$1") - kotlin_args=("${kotlin_args[@]}" "$1") - shift - ;; - -J*) - # as with -D, pass to kotlin even though it will almost - # never be used. - java_args=("${java_args[@]}" "${1:2}") - kotlin_args=("${kotlin_args[@]}" "$1") - shift - ;; - *) - kotlin_args=("${kotlin_args[@]}" "$1") - shift - ;; - esac -done - -# reset "$@" to the remaining args -set -- "${kotlin_args[@]}" - -if [ -z "$JAVACMD" -a -n "$JAVA_HOME" -a -x "$JAVA_HOME/bin/java" ]; then - JAVACMD="$JAVA_HOME/bin/java" -fi - -CPSELECT="-cp " - -"${JAVACMD:=java}" \ - $JAVA_OPTS \ - "${java_args[@]}" \ - ${CPSELECT}"${KOTLIN_HOME}/lib/kotlin-preloader.jar" \ - org.jetbrains.kotlin.preloading.Preloader \ - "${KOTLIN_HOME}/lib/kotlin-compiler.jar" \ - org.jetbrains.kotlin.cli.jvm.K2JVMCompiler 4096 notime "$@" +"$(dirname "$(which "$0")")"/kotlinc "$@" diff --git a/compiler/cli/bin/kotlinc-jvm.bat b/compiler/cli/bin/kotlinc-jvm.bat index fdf5fd171d7..dd60b1cb786 100644 --- a/compiler/cli/bin/kotlinc-jvm.bat +++ b/compiler/cli/bin/kotlinc-jvm.bat @@ -1,45 +1,17 @@ @echo off -rem based on scalac.bat from the Scala distribution -rem ########################################################################## -rem # Copyright 2002-2011, LAMP/EPFL -rem # Copyright 2011-2015, JetBrains -rem # -rem # This is free software; see the distribution for copying conditions. -rem # There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A -rem # PARTICULAR PURPOSE. -rem ########################################################################## -rem We adopt the following conventions: -rem - System/user environment variables start with a letter -rem - Local batch variables start with an underscore ('_') +rem Copyright 2010-2015 JetBrains s.r.o. +rem +rem Licensed under the Apache License, Version 2.0 (the "License"); +rem you may not use this file except in compliance with the License. +rem You may obtain a copy of the License at +rem +rem http://www.apache.org/licenses/LICENSE-2.0 +rem +rem Unless required by applicable law or agreed to in writing, software +rem distributed under the License is distributed on an "AS IS" BASIS, +rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +rem See the License for the specific language governing permissions and +rem limitations under the License. -@setlocal -call :set_home - -if not "%JAVA_HOME%"=="" ( - if exist "%JAVA_HOME%\bin\java.exe" set "_JAVACMD=%JAVA_HOME%\bin\java.exe" -) - -if "%_JAVACMD%"=="" set _JAVACMD=java - -rem We use the value of the JAVA_OPTS environment variable if defined -set _JAVA_OPTS=-Xmx256M -Xms32M -noverify - -"%_JAVACMD%" %_JAVA_OPTS% -cp "%_KOTLIN_HOME%\lib\kotlin-preloader.jar" ^ - org.jetbrains.kotlin.preloading.Preloader "%_KOTLIN_HOME%\lib\kotlin-compiler.jar" ^ - org.jetbrains.kotlin.cli.jvm.K2JVMCompiler 4096 notime %* - -exit /b %ERRORLEVEL% -goto end - -rem ########################################################################## -rem # subroutines - -:set_home - set _BIN_DIR= - for %%i in (%~sf0) do set _BIN_DIR=%_BIN_DIR%%%~dpsi - set _KOTLIN_HOME=%_BIN_DIR%.. -goto :eof - -:end -@endlocal +call %~dps0kotlinc.bat %* diff --git a/compiler/cli/bin/kotlinc.bat b/compiler/cli/bin/kotlinc.bat index 3f44a40c982..820d634ace1 100644 --- a/compiler/cli/bin/kotlinc.bat +++ b/compiler/cli/bin/kotlinc.bat @@ -1,17 +1,48 @@ @echo off +rem based on scalac.bat from the Scala distribution +rem ########################################################################## +rem # Copyright 2002-2011, LAMP/EPFL +rem # Copyright 2011-2015, JetBrains +rem # +rem # This is free software; see the distribution for copying conditions. +rem # There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A +rem # PARTICULAR PURPOSE. +rem ########################################################################## -rem Copyright 2010-2015 JetBrains s.r.o. -rem -rem Licensed under the Apache License, Version 2.0 (the "License"); -rem you may not use this file except in compliance with the License. -rem You may obtain a copy of the License at -rem -rem http://www.apache.org/licenses/LICENSE-2.0 -rem -rem Unless required by applicable law or agreed to in writing, software -rem distributed under the License is distributed on an "AS IS" BASIS, -rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -rem See the License for the specific language governing permissions and -rem limitations under the License. +rem We adopt the following conventions: +rem - System/user environment variables start with a letter +rem - Local batch variables start with an underscore ('_') + +@setlocal +call :set_home + +if "%KOTLIN_COMPILER%"=="" set KOTLIN_COMPILER=org.jetbrains.kotlin.cli.jvm.K2JVMCompiler + +if not "%JAVA_HOME%"=="" ( + if exist "%JAVA_HOME%\bin\java.exe" set "_JAVACMD=%JAVA_HOME%\bin\java.exe" +) + +if "%_JAVACMD%"=="" set _JAVACMD=java + +rem We use the value of the JAVA_OPTS environment variable if defined +set _JAVA_OPTS=-Xmx256M -Xms32M -noverify + +"%_JAVACMD%" %_JAVA_OPTS% -cp "%_KOTLIN_HOME%\lib\kotlin-preloader.jar" ^ + org.jetbrains.kotlin.preloading.Preloader "%_KOTLIN_HOME%\lib\kotlin-compiler.jar" ^ + %KOTLIN_COMPILER% 4096 notime %* + +exit /b %ERRORLEVEL% +goto end + +rem ########################################################################## +rem # subroutines + +:set_home + set _BIN_DIR= + for %%i in (%~sf0) do set _BIN_DIR=%_BIN_DIR%%%~dpsi + set _KOTLIN_HOME=%_BIN_DIR%.. +goto :eof + +:end +@endlocal -call %~dps0kotlinc-jvm.bat %*