Shuffling around so -sbt-rc works.

This commit is contained in:
Paul Phillips 2011-09-13 10:56:37 -07:00
parent a100c052e6
commit eb413bec84
1 changed files with 48 additions and 24 deletions

70
sbt
View File

@ -1,4 +1,4 @@
#!/usr/bin/env bash #!/usr/bin/env bash --norc
# #
# A more capable sbt runner, coincidentally also called sbt. # A more capable sbt runner, coincidentally also called sbt.
# Author: Paul Phillips <paulp@typesafe.com> # Author: Paul Phillips <paulp@typesafe.com>
@ -17,15 +17,28 @@ get_script_path () {
fi fi
} }
# a ham-fisted attempt to move some memory settings in concert
# so they need not be dicked around with individually.
get_mem_opts () {
local mem=${1:-1536}
local perm=$(( $mem / 4 ))
(( $perm > 256 )) || perm=256
(( $perm < 1024 )) || perm=1024
local codecache=$(( $perm / 8 ))
echo "-Xms${mem}m -Xmx${mem}m -XX:MaxPermSize=${perm}m -XX:ReservedCodeCacheSize=${codecache}m"
}
# todo - make this dynamic # todo - make this dynamic
declare -r sbt_release_version=0.10.1 declare -r sbt_release_version=0.10.1
declare -r sbt_rc_version=0.11.0-RC0 declare -r sbt_rc_version=0.11.0-RC1
declare -r sbt_snapshot_version=0.11.0-SNAPSHOT declare -r sbt_snapshot_version=0.11.0-SNAPSHOT
declare -r sbt_snapshot_baseurl="http://typesafe.artifactoryonline.com/typesafe/ivy-snapshots/org.scala-tools.sbt/sbt-launch/" declare -r sbt_snapshot_baseurl="http://typesafe.artifactoryonline.com/typesafe/ivy-snapshots/org.scala-tools.sbt/sbt-launch/"
declare -r default_java_opts="-Dfile.encoding=UTF8" declare -r default_java_opts="-Dfile.encoding=UTF8"
declare -r default_sbt_opts="-XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=512m -Xms1536m -Xmx1536m -Xss2m" declare -r default_sbt_opts="-XX:+CMSClassUnloadingEnabled"
declare -r sbt_opts=".sbtopts" declare -r default_sbt_mem=1536
declare -r sbt_opts_file=".sbtopts"
declare -r latest_28="2.8.1" declare -r latest_28="2.8.1"
declare -r latest_29="2.9.1" declare -r latest_29="2.9.1"
declare -r latest_210="2.10.0-SNAPSHOT" declare -r latest_210="2.10.0-SNAPSHOT"
@ -34,16 +47,14 @@ declare -r script_path=$(get_script_path "$BASH_SOURCE")
declare -r script_dir="$(dirname $script_path)" declare -r script_dir="$(dirname $script_path)"
declare -r script_name="$(basename $script_path)" declare -r script_name="$(basename $script_path)"
# A bunch of falses and empties as defaults.
declare sbt_jar=
declare sbt_create=
declare sbt_version=
declare scala_version=
declare sbt_snapshot=0
declare java_cmd=java declare java_cmd=java
declare java_home= declare sbt_mem=$default_sbt_mem
unset verbose declare java_opts="${JAVA_OPTS:-$default_java_opts}"
unset debug
unset sbt_jar sbt_create sbt_version sbt_snapshot
unset scala_version
unset java_home
unset verbose debug
# pull -J and -D options to give to java. # pull -J and -D options to give to java.
declare -a residual_args declare -a residual_args
@ -65,6 +76,13 @@ build_props_scala () {
fi fi
} }
isSnapshot () {
[[ "$sbt_version" = *-SNAPSHOT* ]]
}
isRC () {
[[ "$sbt_version" = *-RC* ]]
}
execRunner () { execRunner () {
# print the arguments one to a line, quoting any containing spaces # print the arguments one to a line, quoting any containing spaces
[[ $verbose || $debug ]] && echo "# Executing command line:" && { [[ $verbose || $debug ]] && echo "# Executing command line:" && {
@ -96,10 +114,13 @@ sbtjar_release_url () {
} }
sbtjar_snapshot_url () { sbtjar_snapshot_url () {
local ver="$sbt_version" local ver="$sbt_version"
[[ "$sbt_version" == *-SNAPSHOT ]] && { if [[ "$sbt_version" = *-SNAPSHOT ]]; then
ver=$(sbt_snapshot_actual_version) ver=$(sbt_snapshot_actual_version -SNAPSHOT)
echoerr "sbt snapshot is $ver" echoerr "sbt snapshot is $ver"
} elif [[ "$sbt_version" = *-SNAPSHOT ]]; then
ver=$(sbt_snapshot_actual_version -RC)
echoerr "sbt rc is $ver"
fi
echo "${sbt_snapshot_baseurl}${ver}/sbt-launch.jar" echo "${sbt_snapshot_baseurl}${ver}/sbt-launch.jar"
} }
@ -120,11 +141,11 @@ jar_file () {
} }
sbt_artifactory_list () { sbt_artifactory_list () {
local type="$1" # -RC or -SNAPSHOT
local version=${sbt_version%-SNAPSHOT} local version=${sbt_version%-SNAPSHOT}
curl -s --list-only "$sbt_snapshot_baseurl" | \ curl -s --list-only "$sbt_snapshot_baseurl" | \
grep -F $version | \ grep -F $version | \
grep -v -- '-RC' | \
perl -e 'print reverse <>' | \ perl -e 'print reverse <>' | \
perl -pe 's#^<a href="([^"/]+).*#$1#;' perl -pe 's#^<a href="([^"/]+).*#$1#;'
} }
@ -132,7 +153,7 @@ sbt_artifactory_list () {
# argument is e.g. 0.11.0-SNAPSHOT # argument is e.g. 0.11.0-SNAPSHOT
# finds the actual version (with the build id) at artifactory # finds the actual version (with the build id) at artifactory
sbt_snapshot_actual_version () { sbt_snapshot_actual_version () {
for ver in $(sbt_artifactory_list); do for ver in $(sbt_artifactory_list "$1"); do
local url="$sbt_snapshot_baseurl$ver/sbt-launch.jar" local url="$sbt_snapshot_baseurl$ver/sbt-launch.jar"
dlog "Testing $url" dlog "Testing $url"
curl -s --head "$url" >/dev/null curl -s --head "$url" >/dev/null
@ -160,7 +181,7 @@ download_url () {
} }
acquire_sbt_jar () { acquire_sbt_jar () {
if (( $sbt_snapshot )); then if [[ $sbt_snapshot ]]; then
sbt_version=$sbt_snapshot_version sbt_version=$sbt_snapshot_version
elif [[ ! $sbt_version ]]; then elif [[ ! $sbt_version ]]; then
sbt_version=$sbt_release_version sbt_version=$sbt_release_version
@ -185,6 +206,7 @@ Usage: $script_name [options]
-sbt-dir <path> path to global settings/plugins directory (default: ~/.sbt) -sbt-dir <path> path to global settings/plugins directory (default: ~/.sbt)
-sbt-boot <path> path to shared boot directory (default: ~/.sbt/boot in 0.11 series) -sbt-boot <path> path to shared boot directory (default: ~/.sbt/boot in 0.11 series)
-ivy <path> path to local Ivy repository (default: ~/.ivy2) -ivy <path> path to local Ivy repository (default: ~/.ivy2)
-mem <integer> set memory options (default: $sbt_mem, which is $(get_mem_opts $sbt_mem))
# sbt version (default: from project/build.properties if present, else latest release) # sbt version (default: from project/build.properties if present, else latest release)
-sbt-version <version> use the specified version of sbt -sbt-version <version> use the specified version of sbt
@ -203,7 +225,7 @@ Usage: $script_name [options]
-java-home <path> alternate JAVA_HOME -java-home <path> alternate JAVA_HOME
# jvm options and output control # jvm options and output control
JAVA_OPTS environment variable, if unset uses "$default_java_opts" JAVA_OPTS environment variable, if unset uses "$java_opts"
SBT_OPTS environment variable, if unset uses "$default_sbt_opts" SBT_OPTS environment variable, if unset uses "$default_sbt_opts"
.sbtopts if this file exists in the sbt root, it is prepended to the runner args .sbtopts if this file exists in the sbt root, it is prepended to the runner args
-Dkey=val pass -Dkey=val directly to the java runtime -Dkey=val pass -Dkey=val directly to the java runtime
@ -237,6 +259,7 @@ process_args ()
# -u|-upgrade) addSbt 'set sbt.version 0.7.7' ; addSbt reload ; shift ;; # -u|-upgrade) addSbt 'set sbt.version 0.7.7' ; addSbt reload ; shift ;;
-ivy) addJava "-Dsbt.ivy.home=$2"; shift 2 ;; -ivy) addJava "-Dsbt.ivy.home=$2"; shift 2 ;;
-mem) sbt_mem="$2"; shift 2 ;;
-no-colors) addJava "-Dsbt.log.noformat=true"; shift ;; -no-colors) addJava "-Dsbt.log.noformat=true"; shift ;;
-sbt-boot) addJava "-Dsbt.boot.directory=$2"; shift 2 ;; -sbt-boot) addJava "-Dsbt.boot.directory=$2"; shift 2 ;;
-sbt-dir) addJava "-Dsbt.global.base=$2"; shift 2 ;; -sbt-dir) addJava "-Dsbt.global.base=$2"; shift 2 ;;
@ -270,7 +293,7 @@ process_args ()
} }
# if .sbtopts exists, prepend its contents to $@ so it can be processed by this runner # if .sbtopts exists, prepend its contents to $@ so it can be processed by this runner
[[ -f "$sbt_opts" ]] && set -- $(cat $sbt_opts) "$@" [[ -f "$sbt_opts_file" ]] && set -- $(cat "$sbt_opts_file") "$@"
# process the combined args, then reset "$@" to the residuals # process the combined args, then reset "$@" to the residuals
process_args "$@" process_args "$@"
@ -291,7 +314,7 @@ argumentCount=$#
cat <<EOM cat <<EOM
$(pwd) doesn't appear to be an sbt project. $(pwd) doesn't appear to be an sbt project.
If you want to start sbt anyway, run: If you want to start sbt anyway, run:
$0 -create $0 -sbt-create
EOM EOM
exit 1 exit 1
@ -312,8 +335,9 @@ EOM
# run sbt # run sbt
execRunner "$java_cmd" \ execRunner "$java_cmd" \
${JAVA_OPTS:-$default_java_opts} \ ${java_opts} \
${SBT_OPTS:-$default_sbt_opts} \ ${SBT_OPTS:-$default_sbt_opts} \
$(get_mem_opts $sbt_mem) \
${java_args[@]} \ ${java_args[@]} \
-jar "$sbt_jar" \ -jar "$sbt_jar" \
"${sbt_commands[@]}" \ "${sbt_commands[@]}" \