Back to home page

OSCL-LXR

 
 

    


0001 #!/usr/bin/env bash
0002 
0003 #
0004 # Licensed to the Apache Software Foundation (ASF) under one or more
0005 # contributor license agreements.  See the NOTICE file distributed with
0006 # this work for additional information regarding copyright ownership.
0007 # The ASF licenses this file to You under the Apache License, Version 2.0
0008 # (the "License"); you may not use this file except in compliance with
0009 # the License.  You may obtain a copy of the License at
0010 #
0011 #    http://www.apache.org/licenses/LICENSE-2.0
0012 #
0013 # Unless required by applicable law or agreed to in writing, software
0014 # distributed under the License is distributed on an "AS IS" BASIS,
0015 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0016 # See the License for the specific language governing permissions and
0017 # limitations under the License.
0018 #
0019 
0020 # When creating new tests for Spark SQL Hive, the HADOOP_CLASSPATH must contain the hive jars so
0021 # that we can run Hive to generate the golden answer.  This is not required for normal development
0022 # or testing.
0023 if [ -n "$HIVE_HOME" ]; then
0024     for i in "$HIVE_HOME"/lib/*
0025     do HADOOP_CLASSPATH="$HADOOP_CLASSPATH:$i"
0026     done
0027     export HADOOP_CLASSPATH
0028 fi
0029 
0030 realpath () {
0031 (
0032   TARGET_FILE="$1"
0033 
0034   cd "$(dirname "$TARGET_FILE")"
0035   TARGET_FILE="$(basename "$TARGET_FILE")"
0036 
0037   COUNT=0
0038   while [ -L "$TARGET_FILE" -a $COUNT -lt 100 ]
0039   do
0040       TARGET_FILE="$(readlink "$TARGET_FILE")"
0041       cd $(dirname "$TARGET_FILE")
0042       TARGET_FILE="$(basename $TARGET_FILE)"
0043       COUNT=$(($COUNT + 1))
0044   done
0045 
0046   echo "$(pwd -P)/"$TARGET_FILE""
0047 )
0048 }
0049 
0050 . "$(dirname "$(realpath "$0")")"/sbt-launch-lib.bash
0051 
0052 
0053 declare -r noshare_opts="-Dsbt.global.base=project/.sbtboot -Dsbt.boot.directory=project/.boot -Dsbt.ivy.home=project/.ivy"
0054 declare -r sbt_opts_file=".sbtopts"
0055 declare -r etc_sbt_opts_file="/etc/sbt/sbtopts"
0056 
0057 usage() {
0058  cat <<EOM
0059 Usage: $script_name [options]
0060 
0061   -h | -help         print this message
0062   -v | -verbose      this runner is chattier
0063   -d | -debug        set sbt log level to debug
0064   -no-colors         disable ANSI color codes
0065   -sbt-create        start sbt even if current directory contains no sbt project
0066   -sbt-dir   <path>  path to global settings/plugins directory (default: ~/.sbt)
0067   -sbt-boot  <path>  path to shared boot directory (default: ~/.sbt/boot in 0.11 series)
0068   -ivy       <path>  path to local Ivy repository (default: ~/.ivy2)
0069   -mem    <integer>  set memory options (default: $sbt_default_mem, which is $(get_mem_opts $sbt_default_mem))
0070   -no-share          use all local caches; no sharing
0071   -no-global         uses global caches, but does not use global ~/.sbt directory.
0072   -jvm-debug <port>  Turn on JVM debugging, open at the given port.
0073   -batch             Disable interactive mode
0074 
0075   # sbt version (default: from project/build.properties if present, else latest release)
0076   -sbt-version  <version>   use the specified version of sbt
0077   -sbt-jar      <path>      use the specified jar as the sbt launcher
0078   -sbt-rc                   use an RC version of sbt
0079   -sbt-snapshot             use a snapshot version of sbt
0080 
0081   # java version (default: java from PATH, currently $(java -version 2>&1 | grep version))
0082   -java-home <path>         alternate JAVA_HOME
0083 
0084   # jvm options and output control
0085   JAVA_OPTS          environment variable, if unset uses "$java_opts"
0086   SBT_OPTS           environment variable, if unset uses "$default_sbt_opts"
0087   .sbtopts           if this file exists in the current directory, it is
0088                      prepended to the runner args
0089   /etc/sbt/sbtopts   if this file exists, it is prepended to the runner args
0090   -Dkey=val          pass -Dkey=val directly to the java runtime
0091   -J-X               pass option -X directly to the java runtime
0092                      (-J is stripped)
0093   -S-X               add -X to sbt's scalacOptions (-S is stripped)
0094   -PmavenProfiles    Enable a maven profile for the build.
0095 
0096 In the case of duplicated or conflicting options, the order above
0097 shows precedence: JAVA_OPTS lowest, command line options highest.
0098 EOM
0099 }
0100 
0101 process_my_args () {
0102   while [[ $# -gt 0 ]]; do
0103     case "$1" in
0104      -no-colors) addJava "-Dsbt.log.noformat=true" && shift ;;
0105       -no-share) addJava "$noshare_opts" && shift ;;
0106      -no-global) addJava "-Dsbt.global.base=$(pwd)/project/.sbtboot" && shift ;;
0107       -sbt-boot) require_arg path "$1" "$2" && addJava "-Dsbt.boot.directory=$2" && shift 2 ;;
0108        -sbt-dir) require_arg path "$1" "$2" && addJava "-Dsbt.global.base=$2" && shift 2 ;;
0109      -debug-inc) addJava "-Dxsbt.inc.debug=true" && shift ;;
0110          -batch) exec </dev/null && shift ;;
0111 
0112     -sbt-create) sbt_create=true && shift ;;
0113 
0114               *) addResidual "$1" && shift ;;
0115     esac
0116   done
0117 
0118   # Now, ensure sbt version is used.
0119   [[ "${sbt_version}XXX" != "XXX" ]] && addJava "-Dsbt.version=$sbt_version"
0120 }
0121 
0122 loadConfigFile() {
0123   cat "$1" | sed '/^\#/d'
0124 }
0125 
0126 # if sbtopts files exist, prepend their contents to $@ so it can be processed by this runner
0127 [[ -f "$etc_sbt_opts_file" ]] && set -- $(loadConfigFile "$etc_sbt_opts_file") "$@"
0128 [[ -f "$sbt_opts_file" ]] && set -- $(loadConfigFile "$sbt_opts_file") "$@"
0129 
0130 exit_status=127
0131 saved_stty=""
0132 
0133 restoreSttySettings() {
0134   stty $saved_stty
0135   saved_stty=""
0136 }
0137 
0138 onExit() {
0139   if [[ "$saved_stty" != "" ]]; then
0140     restoreSttySettings
0141   fi
0142   exit $exit_status
0143 }
0144 
0145 saveSttySettings() {
0146   saved_stty=$(stty -g 2>/dev/null)
0147   if [[ ! $? ]]; then
0148     saved_stty=""
0149   fi
0150 }
0151 
0152 saveSttySettings
0153 trap onExit INT
0154 
0155 run "$@"
0156 
0157 exit_status=$?
0158 onExit