From 7a86e640f354c808a46e9f182209f5c3f03d7344 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Sun, 4 Sep 2011 12:25:45 -0700 Subject: [PATCH] Too much to detail. 0.7 compat, -sbt-rc, try it. --- README.md | 5 +- sbt | 244 +++++++++++++++++++++++++++++++----------------------- 2 files changed, 142 insertions(+), 107 deletions(-) diff --git a/README.md b/README.md index 5827e0f91..52dd980e4 100644 --- a/README.md +++ b/README.md @@ -61,8 +61,6 @@ runs the sbt "about" command. Current -help output: - % ./sbt -help - Usage: sbt [options] -h | -help print this message @@ -71,12 +69,13 @@ Current -help output: -no-colors disable ANSI color codes -sbt-create start sbt even if current directory contains no sbt project -sbt-dir path to global settings/plugins directory (default: ~/.sbt) - -sbt-boot path to shared boot directory (default: none, no sharing) + -sbt-boot path to shared boot directory (default: ~/.sbt/boot in 0.11 series) -ivy path to local Ivy repository (default: ~/.ivy2) # sbt version (default: from project/build.properties if present, else latest release) -sbt-version use the specified version of sbt -sbt-jar use the specified jar as the sbt launcher + -sbt-rc use an RC version of sbt -sbt-snapshot use a snapshot version of sbt # scala version (default: latest release) diff --git a/sbt b/sbt index 4c80c012e..43711e100 100755 --- a/sbt +++ b/sbt @@ -3,11 +3,11 @@ # A more capable sbt runner, coincidentally also called sbt. # Author: Paul Phillips -set -e - # todo - make this dynamic declare -r sbt_release_version=0.10.1 +declare -r sbt_rc_version=0.11.0-RC0 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 default_java_opts="-Dfile.encoding=UTF8" declare -r default_sbt_opts="-XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=512m -Xms1536m -Xmx1536m -Xss2m" @@ -18,88 +18,138 @@ declare -r latest_210="2.10.0-SNAPSHOT" # A bunch of falses and empties as defaults. declare sbt_jar= -declare sbt_create=0 -declare sbt_snapshot=0 +declare sbt_create= declare sbt_version=$( if [[ -f project/build.properties ]]; then versionLine=$(grep ^sbt.version project/build.properties) versionString=${versionLine##sbt.version=} - noRC=${versionString%.RC*} - echo $noRC - - if [[ $noRC =~ ^[0-9]\.[0-9]\.[0-9]$ ]]; then - echo "$noRC" - fi + echo "${versionString%%.RC*}" fi ) - -declare scala_version= +declare scala_version=$( + if [[ -f project/build.properties ]]; then + versionLine=$(grep ^build.scala.versions project/build.properties) + versionString=${versionLine##build.scala.versions=} + echo ${versionString%% .*} + fi +) +declare sbt_snapshot=0 declare java_cmd=java declare java_home= -declare verbose=0 +unset verbose +unset debug -jar_url () { - local where=$1 # releases or snapshots - local ver=$2 +execRunner () { + # print the arguments one to a line, quoting any containing spaces + [[ $verbose || $debug ]] && echo "# Executing command line:" && { + for arg; do + if echo "$arg" | grep -q ' '; then + printf "\"%s\"\n" "$arg" + else + printf "%s\n" "$arg" + fi + done + echo "" + } - if [[ $ver = 0.7* ]]; then - echo "http://simple-build-tool.googlecode.com/files/sbt-launch-$ver.jar" - else - echo "http://typesafe.artifactoryonline.com/typesafe/ivy-$where/org.scala-tools.sbt/sbt-launch/$ver/sbt-launch.jar" - fi + "$@" } +echoerr () { + echo 1>&2 "$@" +} +dlog () { + [[ $verbose || $debug ]] && echoerr "$@" +} + +[[ "$sbt_version" = *-SNAPSHOT* || "$sbt_version" = *-RC* ]] && sbt_snapshot=1 +[[ -n "$sbt_version" ]] && echo "Detected sbt version $sbt_version" +[[ -n "$scala_version" ]] && echo "Detected scala version $scala_version" + +sbtjar_07_url () { + echo "http://simple-build-tool.googlecode.com/files/sbt-launch-${1}.jar" +} +sbtjar_release_url () { + echo "http://typesafe.artifactoryonline.com/typesafe/ivy-releases/org.scala-tools.sbt/sbt-launch/$sbt_version/sbt-launch.jar" +} +sbtjar_snapshot_url () { + local ver="$sbt_version" + [[ "$sbt_version" == *-SNAPSHOT ]] && { + ver=$(sbt_snapshot_actual_version) + echoerr "sbt snapshot is $ver" + } + + echo "${sbt_snapshot_baseurl}${ver}/sbt-launch.jar" +} +jar_url () { + case $sbt_version in + 0.7.4*) sbtjar_07_url 0.7.4 ;; + 0.7.5*) sbtjar_07_url 0.7.5 ;; + 0.7.7*) sbtjar_07_url 0.7.7 ;; + 0.7.*) sbtjar_07_url 0.7.7 ;; + *-SNAPSHOT*) sbtjar_snapshot_url ;; + *-RC*) sbtjar_snapshot_url ;; + *) sbtjar_release_url ;; + esac +} + jar_file () { echo "$script_dir/.lib/$1/sbt-launch.jar" } -# argument is e.g. 0.11.0-SNAPSHOT -sbt_snapshot_actual_version () { - # -> 0.11.0 - local version=${1%-SNAPSHOT} - # trailing slash is important - local base="http://typesafe.artifactoryonline.com/typesafe/ivy-snapshots/org.scala-tools.sbt/sbt-launch/" - # e.g. 0.11.0-20110826-052141/ - curl -s --list-only "$base" | grep -F $version | tail -1 | perl -pe 's#^' | \ + perl -pe 's#^/dev/null + dlog "curl returned: $?" + echo "$ver" + return + done +} + +download_url () { + local url="$1" + local jar="$2" echo "Downloading sbt launcher $sbt_version:" echo " From $url" echo " To $jar" - mkdir -p $(dirname "$jar") && + mkdir -p $(dirname "$jar") && { if which curl >/dev/null; then curl --silent "$url" --output "$jar" elif which wget >/dev/null; then wget --quiet "$url" > "$jar" fi + } && [[ -f "$jar" ]] } +acquire_sbt_jar () { + if (( $sbt_snapshot )); then + sbt_version=$sbt_snapshot_version + elif [[ ! $sbt_version ]]; then + sbt_version=$sbt_release_version + fi + + sbt_url="$(jar_url)" + sbt_jar="$(jar_file $sbt_version)" + + [[ -f "$sbt_jar" ]] || download_url "$sbt_url" "$sbt_jar" +} + + # this seems to cover the bases on OSX, and someone will # have to tell me about the others. get_script_path () { @@ -128,12 +178,13 @@ Usage: $script_name [options] -no-colors disable ANSI color codes -sbt-create start sbt even if current directory contains no sbt project -sbt-dir path to global settings/plugins directory (default: ~/.sbt) - -sbt-boot path to shared boot directory (default: none, no sharing) + -sbt-boot path to shared boot directory (default: ~/.sbt/boot in 0.11 series) -ivy path to local Ivy repository (default: ~/.ivy2) # sbt version (default: from project/build.properties if present, else latest release) -sbt-version use the specified version of sbt -sbt-jar use the specified jar as the sbt launcher + -sbt-rc use an RC version of sbt -sbt-snapshot use a snapshot version of sbt # scala version (default: latest release) @@ -159,7 +210,7 @@ EOM } # pull -J and -D options to give to java. -declare -a args +declare -a residual_args declare -a java_args declare -a sbt_commands @@ -169,22 +220,27 @@ addJava () { addSbt () { sbt_commands=("${sbt_commands[@]}" "$1") } +addResidual () { + residual_args=("${residual_args[@]}" "$1") +} process_args () { - while [ $# -gt 0 ]; do + while [[ $# -gt 0 ]]; do case "$1" in -h|-help) usage; exit 1 ;; -v|-verbose) verbose=1; shift ;; - -d|-debug) debug=1; addSbt "set logLevel in Global := Level.Debug"; shift ;; + -d|-debug) debug=1; shift ;; + # -u|-upgrade) addSbt 'set sbt.version 0.7.7' ; addSbt reload ; shift ;; -ivy) addJava "-Dsbt.ivy.home=$2"; shift 2 ;; -no-colors) addJava "-Dsbt.log.noformat=true"; shift ;; -sbt-boot) addJava "-Dsbt.boot.directory=$2"; shift 2 ;; -sbt-dir) addJava "-Dsbt.global.base=$2"; shift 2 ;; - -sbt-create) sbt_create=1; shift ;; - -sbt-snapshot) sbt_snapshot=1; shift ;; + -sbt-create) sbt_create=true; shift ;; + -sbt-rc) sbt_version=$sbt_rc_version; shift ;; + -sbt-snapshot) sbt_version=$sbt_snapshot_version; shift ;; -sbt-jar) sbt_jar="$2"; shift 2 ;; -sbt-version) sbt_version="$2"; shift 2 ;; -scala-version) addSbt "++ $2"; shift 2 ;; @@ -197,23 +253,31 @@ process_args () -29) addSbt "++ $latest_29"; shift ;; -210) addSbt "++ $latest_210"; shift ;; - *) args=("${args[@]}" "$1") ; shift ;; + *) addResidual "$1"; shift ;; esac done + + [[ $debug ]] && { + case "$sbt_version" in + 0.7*) addSbt "debug" ;; + *) addSbt "set logLevel in Global := Level.Debug" ;; + esac + } } -# if .sbtopts exists, prepend its contents so it can be processed by this runner -[[ -f "$sbt_opts" ]] && set -- $(cat $sbt_opts) "${@}" - -# no args - alert them there's stuff in here -[[ $# -gt 0 ]] || echo "Starting $script_name: invoke with -help for other options" +# if .sbtopts exists, prepend its contents to $@ so it can be processed by this runner +[[ -f "$sbt_opts" ]] && set -- $(cat $sbt_opts) "$@" # process the combined args, then reset "$@" to the residuals process_args "$@" -set -- "${args[@]}" +set -- "${residual_args[@]}" +argumentCount=$# + +# no args - alert them there's stuff in here +(( $argumentCount > 0 )) || echo "Starting $script_name: invoke with -help for other options" # verify this is an sbt dir or -create was given -[[ -f build.sbt ]] || [[ -d project ]] || (( $sbt_create )) || { +[[ -f ./build.sbt || -d ./project || -n "$sbt_create" ]] || { cat <