"Fossies" - the Fresh Open Source Software Archive

Member "scala-2.13.9/bin/scalac" (19 Sep 2022, 6602 Bytes) of package /windows/misc/scala-2.13.9.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 #!/usr/bin/env bash
    2 #
    3 ##############################################################################
    4 # Scala (https://www.scala-lang.org)
    5 #
    6 # Copyright EPFL and Lightbend, Inc.
    7 #
    8 # Licensed under Apache License 2.0
    9 # (http://www.apache.org/licenses/LICENSE-2.0).
   10 #
   11 # See the NOTICE file distributed with this work for
   12 # additional information regarding copyright ownership.
   13 ##############################################################################
   14 
   15 findScalaHome () {
   16   # see scala/bug#2092 and scala/bug#5792
   17   local source="${BASH_SOURCE[0]}"
   18   while [ -h "$source" ] ; do
   19     local linked="$(readlink "$source")"
   20     local dir="$( cd -P "$(dirname "$source")" && cd -P "$(dirname "$linked")" && pwd )"
   21     source="$dir/$(basename "$linked")"
   22   done
   23   ( cd -P "$(dirname "$source")/.." && pwd )
   24 }
   25 execCommand () {
   26   [[ -n $SCALA_RUNNER_DEBUG ]] && echo "" && for arg in "$@"; do echo "$arg"; done && echo "";
   27   "$@"
   28 }
   29 
   30 # Not sure what the right default is here: trying nonzero.
   31 scala_exit_status=127
   32 saved_stty=""
   33 
   34 # restore stty settings (echo in particular)
   35 function restoreSttySettings() {
   36   if [[ -n $SCALA_RUNNER_DEBUG ]]; then
   37     echo "restoring stty:"
   38     echo "$saved_stty"
   39   fi
   40     
   41   stty $saved_stty
   42   saved_stty=""
   43 }
   44 
   45 function onExit() {
   46   [[ "$saved_stty" != "" ]] && restoreSttySettings
   47   exit $scala_exit_status
   48 }
   49 
   50 # to reenable echo if we are interrupted before completing.
   51 trap onExit INT
   52 
   53 # save terminal settings
   54 saved_stty=$(stty -g 2>/dev/null)
   55 # clear on error so we don't later try to restore them
   56 if [[ ! $? ]]; then  
   57   saved_stty=""
   58 fi
   59 if [[ -n $SCALA_RUNNER_DEBUG ]]; then
   60   echo "saved stty:"
   61   echo "$saved_stty"
   62 fi
   63 
   64 unset cygwin
   65 if uname | grep -q ^CYGWIN; then
   66   cygwin="$(uname)"
   67 fi
   68 
   69 unset mingw
   70 if uname | grep -q ^MINGW; then
   71   mingw="$(uname)"
   72 fi
   73 
   74 unset msys
   75 if uname | grep -q ^MSYS; then
   76   msys="$(uname)"
   77 fi
   78 
   79 # Finding the root folder for this Scala distribution
   80 SCALA_HOME="$(findScalaHome)"
   81 SEP=":"
   82 
   83 # Possible additional command line options
   84 WINDOWS_OPT=""
   85 
   86 # Remove spaces from SCALA_HOME on windows
   87 if [[ -n "$cygwin" ]]; then
   88   SCALA_HOME="$(shome="$(cygpath --windows --short-name "$SCALA_HOME")" ; cygpath --unix "$shome")"
   89 # elif uname |grep -q ^MINGW; then
   90 #   SEP=";"
   91 fi
   92 
   93 # Constructing the extension classpath
   94 TOOL_CLASSPATH=""
   95 if [[ -z "$TOOL_CLASSPATH" ]]; then
   96     for ext in "$SCALA_HOME"/lib/* ; do
   97         file_extension="${ext##*.}"
   98         # scala/bug#8967 Only consider directories and files named '*.jar'
   99         if [[ -d "$ext" || $file_extension == "jar" ]]; then
  100           if [[ -z "$TOOL_CLASSPATH" ]]; then
  101               TOOL_CLASSPATH="$ext"
  102           else
  103               TOOL_CLASSPATH="${TOOL_CLASSPATH}${SEP}${ext}"
  104           fi
  105         fi
  106     done
  107 fi
  108 
  109 if [[ -n "$cygwin$mingw$msys" ]]; then
  110     case "$TERM" in
  111         rxvt* | xterm* | cygwin*)
  112             stty -icanon min 1 -echo
  113             WINDOWS_OPT="-Djline.terminal=unix"
  114         ;;
  115     esac
  116 fi
  117 
  118 [[ -n "$JAVA_OPTS" ]] || JAVA_OPTS="-Xmx256M -Xms32M"
  119 
  120 # break out -D and -J options and add them to JAVA_OPTS as well
  121 # so they reach the underlying JVM in time to do some good.  The
  122 # -D options will be available as system properties.
  123 declare -a java_args
  124 declare -a scala_args
  125 
  126 # scala/bug#8358, scala/bug#8368 -- the default should really be false,
  127 # but I don't want to flip the default during 2.11's RC cycle
  128 OVERRIDE_USEJAVACP="-Dscala.usejavacp=true"
  129 
  130 while [[ $# -gt 0 ]]; do
  131   case "$1" in
  132     -D*)
  133       # pass to scala as well: otherwise we lose it sometimes when we
  134       # need it, e.g. communicating with a server compiler.
  135       java_args+=("$1")
  136       scala_args+=("$1")
  137       # respect user-supplied -Dscala.usejavacp
  138       case "$1" in -Dscala.usejavacp*) OVERRIDE_USEJAVACP="";; esac
  139       shift
  140       ;;
  141     -J*)
  142       # as with -D, pass to scala even though it will almost
  143       # never be used.
  144       java_args+=("${1:2}")
  145       scala_args+=("$1")
  146       shift
  147       ;;
  148     -toolcp)
  149       TOOL_CLASSPATH="${TOOL_CLASSPATH}${SEP}${2}"
  150       shift 2
  151       ;;
  152     -nobootcp)
  153       usebootcp="false"
  154       shift
  155       ;;
  156     -usebootcp)
  157       usebootcp="true"
  158       shift
  159       ;;
  160     -debug)
  161       SCALA_RUNNER_DEBUG=1
  162       shift
  163       ;;
  164     *)
  165       scala_args+=("$1")
  166       shift
  167       ;;
  168   esac
  169 done
  170 
  171 # reset "$@" to the remaining args
  172 set -- "${scala_args[@]}"
  173 
  174 if [[ -n "$cygwin$mingw$msys" ]]; then
  175     if [[ "$OS" = "Windows_NT" ]] && cygpath -m .>/dev/null 2>/dev/null ; then
  176         format=mixed
  177     else
  178         format=windows
  179     fi
  180     SCALA_HOME="$(cygpath --$format "$SCALA_HOME")"
  181     if [[ -n "$JAVA_HOME" ]]; then
  182         JAVA_HOME="$(cygpath --$format "$JAVA_HOME")"
  183     fi
  184     TOOL_CLASSPATH="$(cygpath --path --$format "$TOOL_CLASSPATH")"
  185 fi
  186 
  187 if [[ -z "$JAVACMD" && -n "$JAVA_HOME" && -x "$JAVA_HOME/bin/java" ]]; then
  188     JAVACMD="$JAVA_HOME/bin/java"
  189 fi
  190 
  191 declare -a classpath_args
  192 
  193 # default to the boot classpath for speed, except on cygwin/mingw/msys because
  194 # JLine on Windows requires a custom DLL to be loaded.
  195 if [[ "$usebootcp" != "false" && -z "$cygwin$mingw$msys" ]]; then
  196   usebootcp="true"
  197 fi
  198 
  199 # If using the boot classpath, also pass an empty classpath
  200 # to java to suppress "." from materializing.
  201 if [[ "$usebootcp" == "true" ]]; then
  202   classpath_args=("-Xbootclasspath/a:$TOOL_CLASSPATH" -classpath "\"\"")
  203   # Java 9 removed sun.boot.class.path, and the supposed replacement to at least see
  204   # the appended boot classpath (jdk.boot.class.path.append) is not visible.
  205   # So we have to pass a custom system property that PathResolver will find.
  206   # We do this for all JVM versions, rather than getting into the business of JVM version detection.
  207   classpath_args+=("-Dscala.boot.class.path=$TOOL_CLASSPATH")
  208 else
  209   classpath_args=(-classpath "$TOOL_CLASSPATH")
  210 fi
  211 
  212 # Remove newline as delimiter for word splitting the java command.
  213 # This permits the use case:
  214 # export JAVA_OPTS=-Dline.separator=$'\r'$'\n'
  215 # where otherwise the newline char is stripped after expansion.
  216 # The following works with the default IFS:
  217 # scala -J-Dline.separator=$'\r'$'\n'
  218 IFS=" "$'\t'
  219 
  220 # note that variables which may intentionally be empty must not
  221 # be quoted: otherwise an empty string will appear as a command line
  222 # argument, and java will think that is the program to run.
  223 execCommand \
  224   "${JAVACMD:=java}" \
  225   $JAVA_OPTS \
  226   "${java_args[@]}" \
  227   "${classpath_args[@]}" \
  228   -Dscala.home="$SCALA_HOME" \
  229   $OVERRIDE_USEJAVACP \
  230   $WINDOWS_OPT \
  231    scala.tools.nsc.Main  "$@"
  232 
  233 # record the exit status lest it be overwritten:
  234 # then restore IFS, reenable echo and propagate the code.
  235 scala_exit_status=$?
  236 
  237 unset IFS
  238 
  239 onExit