Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

updated sbt

  • Loading branch information...
commit 9bc6fb8d5b3edd50daea1d37149d17a4830c8631 1 parent 6407bae
markhibberd authored

Showing 1 changed file with 225 additions and 146 deletions. Show diff stats Hide diff stats

  1. 371  sbt
371  sbt
... ...
@@ -1,8 +1,64 @@
1  
-#!/bin/bash
  1
+#!/usr/bin/env bash
2 2
 #
3 3
 # A more capable sbt runner, coincidentally also called sbt.
4 4
 # Author: Paul Phillips <paulp@typesafe.com>
5 5
 
  6
+# todo - make this dynamic
  7
+declare -r sbt_release_version=0.11.3
  8
+declare -r sbt_snapshot_version=0.13.0-SNAPSHOT
  9
+
  10
+unset sbt_jar sbt_dir sbt_create sbt_snapshot sbt_launch_dir
  11
+unset scala_version java_home sbt_explicit_version
  12
+unset verbose debug quiet
  13
+
  14
+build_props_sbt () {
  15
+  if [[ -f project/build.properties ]]; then
  16
+    versionLine=$(grep ^sbt.version project/build.properties)
  17
+    versionString=${versionLine##sbt.version=}
  18
+    echo "$versionString"
  19
+  fi
  20
+}
  21
+
  22
+update_build_props_sbt () {
  23
+  local ver="$1"
  24
+  local old=$(build_props_sbt)
  25
+
  26
+  if [[ $ver == $old ]]; then
  27
+    return
  28
+  elif [[ -f project/build.properties ]]; then
  29
+    perl -pi -e "s/^sbt\.version=.*\$/sbt.version=${ver}/" project/build.properties
  30
+    grep -q '^sbt.version=' project/build.properties || echo "sbt.version=${ver}" >> project/build.properties
  31
+
  32
+    echo !!!
  33
+    echo !!! Updated file project/build.properties setting sbt.version to: $ver
  34
+    echo !!! Previous value was: $old
  35
+    echo !!!
  36
+  fi
  37
+}
  38
+
  39
+sbt_version () {
  40
+  if [[ -n $sbt_explicit_version ]]; then
  41
+    echo $sbt_explicit_version
  42
+  else
  43
+    local v=$(build_props_sbt)
  44
+    if [[ -n $v ]]; then
  45
+      echo $v
  46
+    else
  47
+      echo $sbt_release_version
  48
+    fi
  49
+  fi
  50
+}
  51
+
  52
+echoerr () {
  53
+  echo 1>&2 "$@"
  54
+}
  55
+vlog () {
  56
+  [[ $verbose || $debug ]] && echoerr "$@"
  57
+}
  58
+dlog () {
  59
+  [[ $debug ]] && echoerr "$@"
  60
+}
  61
+
6 62
 # this seems to cover the bases on OSX, and someone will
7 63
 # have to tell me about the others.
8 64
 get_script_path () {
@@ -13,7 +69,7 @@ get_script_path () {
13 69
   if [[ "${target:0:1}" == "/" ]]; then
14 70
     echo "$target"
15 71
   else
16  
-    echo "$path/$target"
  72
+    echo "$(dirname $path)/$target"
17 73
   fi
18 74
 }
19 75
 
@@ -24,23 +80,31 @@ get_mem_opts () {
24 80
   local perm=$(( $mem / 4 ))
25 81
   (( $perm > 256 )) || perm=256
26 82
   (( $perm < 1024 )) || perm=1024
27  
-  local codecache=$(( $perm / 8 ))
  83
+  local codecache=$(( $perm / 2 ))
28 84
   
29 85
   echo "-Xms${mem}m -Xmx${mem}m -XX:MaxPermSize=${perm}m -XX:ReservedCodeCacheSize=${codecache}m"
30 86
 }
31 87
 
32  
-# todo - make this dynamic
33  
-declare -r sbt_release_version=0.11.0
34  
-declare -r sbt_rc_version=
35  
-declare -r sbt_snapshot_version=0.11.1-SNAPSHOT
36  
-declare -r sbt_snapshot_baseurl="http://typesafe.artifactoryonline.com/typesafe/ivy-snapshots/org.scala-tools.sbt/sbt-launch/"
  88
+die() {
  89
+  echo "Aborting: $@"
  90
+  exit 1
  91
+}
  92
+
  93
+make_url () {
  94
+  groupid="$1"
  95
+  category="$2"
  96
+  version="$3"
  97
+  
  98
+  echo "http://typesafe.artifactoryonline.com/typesafe/ivy-$category/$groupid/sbt-launch/$version/sbt-launch.jar"
  99
+}
37 100
 
38  
-declare -r default_java_opts="-Dfile.encoding=UTF8"
  101
+declare -r default_jvm_opts="-Dfile.encoding=UTF8"
39 102
 declare -r default_sbt_opts="-XX:+CMSClassUnloadingEnabled"
40 103
 declare -r default_sbt_mem=1536
41  
-declare -r noshare_opts="-Dsbt.global.base=project/.sbt -Dsbt.boot.directory=project/.boot -Dsbt.ivy.home=project/.ivy"
  104
+declare -r noshare_opts="-Dsbt.global.base=project/.sbtboot -Dsbt.boot.directory=project/.boot -Dsbt.ivy.home=project/.ivy"
42 105
 declare -r sbt_opts_file=".sbtopts"
43  
-declare -r latest_28="2.8.1"
  106
+declare -r jvm_opts_file=".jvmopts"
  107
+declare -r latest_28="2.8.2"
44 108
 declare -r latest_29="2.9.1"
45 109
 declare -r latest_210="2.10.0-SNAPSHOT"
46 110
 
@@ -48,27 +112,17 @@ declare -r script_path=$(get_script_path "$BASH_SOURCE")
48 112
 declare -r script_dir="$(dirname $script_path)"
49 113
 declare -r script_name="$(basename $script_path)"
50 114
 
  115
+# some non-read-onlies set with defaults
51 116
 declare java_cmd=java
  117
+declare sbt_launch_dir="$script_dir/.lib"
52 118
 declare sbt_mem=$default_sbt_mem
53  
-declare java_opts="${JAVA_OPTS:-$default_java_opts}"
54  
-
55  
-unset sbt_jar sbt_create sbt_version sbt_snapshot
56  
-unset scala_version
57  
-unset java_home
58  
-unset verbose debug
59 119
 
60 120
 # pull -J and -D options to give to java.
61 121
 declare -a residual_args
62 122
 declare -a java_args
  123
+declare -a scalac_args
63 124
 declare -a sbt_commands
64 125
 
65  
-build_props_sbt () {
66  
-  if [[ -f project/build.properties ]]; then
67  
-    versionLine=$(grep ^sbt.version project/build.properties)
68  
-    versionString=${versionLine##sbt.version=}
69  
-    echo "$versionString"
70  
-  fi
71  
-}
72 126
 build_props_scala () {
73 127
   if [[ -f project/build.properties ]]; then
74 128
     versionLine=$(grep ^build.scala.versions project/build.properties)
@@ -77,13 +131,6 @@ build_props_scala () {
77 131
   fi
78 132
 }
79 133
 
80  
-isSnapshot () {
81  
-  [[ "$sbt_version" = *-SNAPSHOT* ]]
82  
-}
83  
-isRC () {
84  
-  [[ "$sbt_version" = *-RC* ]]
85  
-}
86  
-
87 134
 execRunner () {
88 135
   # print the arguments one to a line, quoting any containing spaces
89 136
   [[ $verbose || $debug ]] && echo "# Executing command line:" && {
@@ -97,84 +144,70 @@ execRunner () {
97 144
     echo ""
98 145
   }
99 146
 
100  
-  "$@"
101  
-}
102  
-
103  
-echoerr () {
104  
-  echo 1>&2 "$@"
105  
-}
106  
-dlog () {
107  
-  [[ $verbose || $debug ]] && echoerr "$@"
108  
-}
109  
-
110  
-sbtjar_07_url () {
111  
-  echo "http://simple-build-tool.googlecode.com/files/sbt-launch-${1}.jar"
  147
+  exec "$@"
112 148
 }
113  
-sbtjar_release_url () {
114  
-  echo "http://typesafe.artifactoryonline.com/typesafe/ivy-releases/org.scala-tools.sbt/sbt-launch/$sbt_version/sbt-launch.jar"
115  
-}
116  
-sbtjar_snapshot_url () {
117  
-  local ver="$sbt_version"
118  
-  if [[ "$sbt_version" = *-SNAPSHOT ]]; then
119  
-    ver=$(sbt_snapshot_actual_version -SNAPSHOT)
120  
-    echoerr "sbt snapshot is $ver"
121  
-  elif [[ "$sbt_version" = *-SNAPSHOT ]]; then
122  
-    ver=$(sbt_snapshot_actual_version -RC)
123  
-    echoerr "sbt rc is $ver"
124  
-  fi
125 149
 
126  
-  echo "${sbt_snapshot_baseurl}${ver}/sbt-launch.jar"
127  
-}
128  
-jar_url () {
129  
-  case $sbt_version in
130  
-      0.7.4*) sbtjar_07_url 0.7.4 ;;
131  
-      0.7.5*) sbtjar_07_url 0.7.5 ;;
132  
-      0.7.7*) sbtjar_07_url 0.7.7 ;;
133  
-       0.7.*) sbtjar_07_url 0.7.7 ;;
134  
- *-SNAPSHOT*) sbtjar_snapshot_url ;;
135  
-       *-RC*) sbtjar_snapshot_url ;;
136  
-           *) sbtjar_release_url ;;
  150
+sbt_groupid () {
  151
+  case $(sbt_version) in
  152
+        0.7.*) echo org.scala-tools.sbt ;;
  153
+       0.10.*) echo org.scala-tools.sbt ;;
  154
+    0.11.[12]) echo org.scala-tools.sbt ;;
  155
+            *) echo org.scala-sbt ;;
137 156
   esac
138 157
 }
139 158
 
140  
-jar_file () {
141  
-  echo "$script_dir/.lib/$1/sbt-launch.jar"
142  
-}
143  
-
144 159
 sbt_artifactory_list () {
145  
-  local type="$1" # -RC or -SNAPSHOT
146  
-  local version=${sbt_version%-SNAPSHOT}
  160
+  local version0=$(sbt_version)
  161
+  local version=${version0%-SNAPSHOT}
  162
+  local url="http://typesafe.artifactoryonline.com/typesafe/ivy-snapshots/$(sbt_groupid)/sbt-launch/"
  163
+  dlog "Looking for snapshot list at: $url "
147 164
   
148  
-  curl -s --list-only "$sbt_snapshot_baseurl" | \
  165
+  curl -s --list-only "$url" | \
149 166
     grep -F $version | \
150 167
     perl -e 'print reverse <>' | \
151 168
     perl -pe 's#^<a href="([^"/]+).*#$1#;'
152 169
 }
153 170
 
154  
-# argument is e.g. 0.11.0-SNAPSHOT
  171
+make_release_url () {
  172
+  make_url $(sbt_groupid) releases $(sbt_version)
  173
+}
  174
+
  175
+# argument is e.g. 0.13.0-SNAPSHOT
155 176
 # finds the actual version (with the build id) at artifactory
156  
-sbt_snapshot_actual_version () {
157  
-  for ver in $(sbt_artifactory_list "$1"); do
158  
-    local url="$sbt_snapshot_baseurl$ver/sbt-launch.jar"
  177
+make_snapshot_url () {
  178
+  for ver in $(sbt_artifactory_list); do
  179
+    local url=$(make_url $(sbt_groupid) snapshots $ver)
159 180
     dlog "Testing $url"
160 181
     curl -s --head "$url" >/dev/null
161 182
     dlog "curl returned: $?"
162  
-    echo "$ver"
  183
+    echo "$url"
163 184
     return
164 185
   done
165 186
 }
166 187
 
  188
+jar_url () {
  189
+  case $(sbt_version) in
  190
+             0.7.*) echo "http://simple-build-tool.googlecode.com/files/sbt-launch-0.7.7.jar" ;;
  191
+        *-SNAPSHOT) make_snapshot_url ;;
  192
+                 *) make_release_url ;;
  193
+  esac
  194
+}
  195
+
  196
+jar_file () {
  197
+  echo "$sbt_launch_dir/$1/sbt-launch.jar"
  198
+}
  199
+
167 200
 download_url () {
168 201
   local url="$1"
169 202
   local jar="$2"
170 203
   
171  
-  echo "Downloading sbt launcher $sbt_version:"
  204
+  echo "Downloading sbt launcher $(sbt_version):"
172 205
   echo "  From  $url"
173 206
   echo "    To  $jar"
174 207
 
175 208
   mkdir -p $(dirname "$jar") && {
176 209
     if which curl >/dev/null; then
177  
-      curl --silent "$url" --output "$jar"
  210
+      curl --fail --silent "$url" --output "$jar"
178 211
     elif which wget >/dev/null; then
179 212
       wget --quiet -O "$jar" "$url"
180 213
     fi
@@ -182,41 +215,41 @@ download_url () {
182 215
 }
183 216
 
184 217
 acquire_sbt_jar () {
185  
-  if [[ $sbt_snapshot ]]; then
186  
-    sbt_version=$sbt_snapshot_version
187  
-  elif [[ ! $sbt_version ]]; then
188  
-    sbt_version=$sbt_release_version
189  
-  fi
190  
-  
191 218
   sbt_url="$(jar_url)"
192  
-  sbt_jar="$(jar_file $sbt_version)"
  219
+  sbt_jar="$(jar_file $(sbt_version))"
193 220
 
194 221
   [[ -f "$sbt_jar" ]] || download_url "$sbt_url" "$sbt_jar"
195 222
 }
196 223
 
197  
-
198 224
 usage () {
199 225
   cat <<EOM
200 226
 Usage: $script_name [options]
201 227
 
202  
-  -h | -help        print this message
203  
-  -v | -verbose     this runner is chattier
204  
-  -d | -debug       set sbt log level to debug
205  
-  -no-colors        disable ANSI color codes
206  
-  -sbt-create       start sbt even if current directory contains no sbt project
207  
-  -sbt-dir  <path>  path to global settings/plugins directory (default: ~/.sbt)
208  
-  -sbt-boot <path>  path to shared boot directory (default: ~/.sbt/boot in 0.11 series)
209  
-  -ivy      <path>  path to local Ivy repository (default: ~/.ivy2)
210  
-  -mem   <integer>  set memory options (default: $sbt_mem, which is $(get_mem_opts $sbt_mem))
211  
-  -no-share         use all local caches; no sharing
  228
+  -h | -help         print this message
  229
+  -v | -verbose      this runner is chattier
  230
+  -d | -debug        set sbt log level to Debug
  231
+  -q | -quiet        set sbt log level to Error
  232
+  -no-colors         disable ANSI color codes
  233
+  -sbt-create        start sbt even if current directory contains no sbt project
  234
+  -sbt-dir   <path>  path to global settings/plugins directory (default: ~/.sbt/<version>)
  235
+  -sbt-boot  <path>  path to shared boot directory (default: ~/.sbt/boot in 0.11 series)
  236
+  -ivy       <path>  path to local Ivy repository (default: ~/.ivy2)
  237
+  -mem    <integer>  set memory options (default: $sbt_mem, which is
  238
+                       $(get_mem_opts $sbt_mem) )
  239
+  -no-share          use all local caches; no sharing
  240
+  -offline           put sbt in offline mode
  241
+  -jvm-debug <port>  Turn on JVM debugging, open at the given port.
  242
+  -batch             Disable interactive mode
212 243
 
213 244
   # sbt version (default: from project/build.properties if present, else latest release)
214  
-  -sbt-version  <version>   use the specified version of sbt
  245
+  !!! The only way to accomplish this pre-0.12.0 if there is a build.properties file which
  246
+  !!! contains an sbt.version property is to update the file on disk.  That's what this does.
  247
+  -sbt-version  <version>   use the specified version of sbt 
215 248
   -sbt-jar      <path>      use the specified jar as the sbt launcher
216  
-  -sbt-rc                   use an RC version of sbt
217 249
   -sbt-snapshot             use a snapshot version of sbt
  250
+  -sbt-launch-dir <path>    directory to hold sbt launchers (default: $sbt_launch_dir)
218 251
 
219  
-  # scala version (default: latest release)
  252
+  # scala version (default: as chosen by sbt)
220 253
   -28                       use $latest_28
221 254
   -29                       use $latest_29
222 255
   -210                      use $latest_210
@@ -227,11 +260,13 @@ Usage: $script_name [options]
227 260
   -java-home <path>         alternate JAVA_HOME
228 261
 
229 262
   # jvm options and output control
230  
-  JAVA_OPTS     environment variable, if unset uses "$java_opts"
231  
-  SBT_OPTS      environment variable, if unset uses "$default_sbt_opts"
232  
-  .sbtopts      if this file exists in the sbt root, it is prepended to the runner args
233  
-  -Dkey=val     pass -Dkey=val directly to the java runtime
234  
-  -J-X          pass option -X directly to the java runtime (-J is stripped)
  263
+  JAVA_OPTS     environment variable holding jvm args, if unset uses "$default_jvm_opts"
  264
+  SBT_OPTS      environment variable holding jvm args, if unset uses "$default_sbt_opts"
  265
+  .jvmopts      if file is in sbt root, it is prepended to the args given to the jvm
  266
+  .sbtopts      if file is in sbt root, it is prepended to the args given to **sbt**
  267
+  -Dkey=val     pass -Dkey=val directly to the jvm
  268
+  -J-X          pass option -X directly to the jvm (-J is stripped)
  269
+  -S-X          add -X to sbt's scalacOptions (-J is stripped)
235 270
 
236 271
 In the case of duplicated or conflicting options, the order above
237 272
 shows precedence: JAVA_OPTS lowest, command line options highest.
@@ -246,6 +281,10 @@ addSbt () {
246 281
   dlog "[addSbt] arg = '$1'"
247 282
   sbt_commands=( "${sbt_commands[@]}" "$1" )
248 283
 }
  284
+addScalac () {
  285
+  dlog "[addScalac] arg = '$1'"
  286
+  scalac_args=( "${scalac_args[@]}" "$1" )
  287
+}
249 288
 addResidual () {
250 289
   dlog "[residual] arg = '$1'"
251 290
   residual_args=( "${residual_args[@]}" "$1" )
@@ -253,67 +292,102 @@ addResidual () {
253 292
 addResolver () {
254 293
   addSbt "set resolvers in ThisBuild += $1"
255 294
 }
256  
-addSnapshotRepo () {
257  
-  addResolver "ScalaToolsSnapshots"
  295
+addDebugger () {
  296
+  addJava "-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=$1"
  297
+}
  298
+get_jvm_opts () {
  299
+  echo "${JAVA_OPTS:-$default_jvm_opts}"
  300
+  echo "${SBT_OPTS:-$default_sbt_opts}"
  301
+
  302
+  [[ -f "$jvm_opts_file" ]] && cat "$jvm_opts_file"
258 303
 }
259 304
 
260 305
 process_args ()
261 306
 {
  307
+  require_arg () {
  308
+    local type="$1"
  309
+    local opt="$2"
  310
+    local arg="$3"
  311
+    
  312
+    if [[ -z "$arg" ]] || [[ "${arg:0:1}" == "-" ]]; then
  313
+      die "$opt requires <$type> argument"
  314
+    fi
  315
+  }
262 316
   while [[ $# -gt 0 ]]; do
263 317
     case "$1" in
264 318
        -h|-help) usage; exit 1 ;;
265  
-    -v|-verbose) verbose=1; shift ;;
266  
-      -d|-debug) debug=1; shift ;;
267  
-    # -u|-upgrade) addSbt 'set sbt.version 0.7.7' ; addSbt reload ; shift ;;
268  
-
269  
-           -ivy) addJava "-Dsbt.ivy.home=$2"; shift 2 ;;
270  
-           -mem) sbt_mem="$2"; shift 2 ;;
271  
-     -no-colors) addJava "-Dsbt.log.noformat=true"; shift ;;
272  
-      -no-share) addJava "$noshare_opts"; shift ;;
273  
-      -sbt-boot) addJava "-Dsbt.boot.directory=$2"; shift 2 ;;
274  
-       -sbt-dir) addJava "-Dsbt.global.base=$2"; shift 2 ;;
275  
-     -debug-inc) addJava "-Dxsbt.inc.debug=true"; shift ;;
276  
-
277  
-    -sbt-create) sbt_create=true; shift ;;
278  
-        -sbt-rc) sbt_version=$sbt_rc_version; shift ;;
279  
-  -sbt-snapshot) addSnapshotRepo ; sbt_version=$sbt_snapshot_version; shift ;;
280  
-       -sbt-jar) sbt_jar="$2"; shift 2 ;;
281  
-   -sbt-version) sbt_version="$2"; shift 2 ;;
282  
- -scala-version) addSbt "++ $2"; shift 2 ;;
283  
-    -scala-home) addSbt "set scalaHome in ThisBuild := Some(file(\"$2\"))"; shift 2 ;;
284  
-     -java-home) java_cmd="$2/bin/java"; shift 2 ;;
285  
-
286  
-            -D*) addJava "$1"; shift ;;
287  
-            -J*) addJava "${1:2}"; shift ;;
288  
-            -28) addSbt "++ $latest_28"; shift ;;
289  
-            -29) addSbt "++ $latest_29"; shift ;;
290  
-           -210) addSnapshotRepo ; addSbt "++ $latest_210"; shift ;;
291  
-
292  
-              *) addResidual "$1"; shift ;;
  319
+    -v|-verbose) verbose=1 && shift ;;
  320
+      -d|-debug) debug=1 && shift ;;
  321
+      -q|-quiet) quiet=1 && shift ;;
  322
+
  323
+           -ivy) require_arg path "$1" "$2" && addJava "-Dsbt.ivy.home=$2" && shift 2 ;;
  324
+           -mem) require_arg integer "$1" "$2" && sbt_mem="$2" && shift 2 ;;
  325
+     -no-colors) addJava "-Dsbt.log.noformat=true" && shift ;;
  326
+      -no-share) addJava "$noshare_opts" && shift ;;
  327
+      -sbt-boot) require_arg path "$1" "$2" && addJava "-Dsbt.boot.directory=$2" && shift 2 ;;
  328
+       -sbt-dir) require_arg path "$1" "$2" && sbt_dir="$2" && shift 2 ;;
  329
+     -debug-inc) addJava "-Dxsbt.inc.debug=true" && shift ;;
  330
+       -offline) addSbt "set offline := true" && shift ;;
  331
+     -jvm-debug) require_arg port "$1" "$2" && addDebugger $2 && shift 2 ;;
  332
+         -batch) exec </dev/null && shift ;;
  333
+
  334
+    -sbt-create) sbt_create=true && shift ;;
  335
+  -sbt-snapshot) sbt_explicit_version=$sbt_snapshot_version && shift ;;
  336
+       -sbt-jar) require_arg path "$1" "$2" && sbt_jar="$2" && shift 2 ;;
  337
+   -sbt-version) require_arg version "$1" "$2" && sbt_explicit_version="$2" && shift 2 ;;
  338
+-sbt-launch-dir) require_arg path "$1" "$2" && sbt_launch_dir="$2" && shift 2 ;;
  339
+ -scala-version) require_arg version "$1" "$2" && addSbt "set scalaVersion := \"$2\"" && shift 2 ;;
  340
+    -scala-home) require_arg path "$1" "$2" && addSbt "set scalaHome in ThisBuild := Some(file(\"$2\"))" && shift 2 ;;
  341
+     -java-home) require_arg path "$1" "$2" && java_cmd="$2/bin/java" && shift 2 ;;
  342
+
  343
+            -D*) addJava "$1" && shift ;;
  344
+            -J*) addJava "${1:2}" && shift ;;
  345
+            -S*) addScalac "${1:2}" && shift ;;
  346
+            -28) addSbt "++ $latest_28" && shift ;;
  347
+            -29) addSbt "++ $latest_29" && shift ;;
  348
+           -210) addSbt "++ $latest_210" && shift ;;
  349
+
  350
+              *) addResidual "$1" && shift ;;
293 351
     esac
294 352
   done
295 353
   
296 354
   [[ $debug ]] && {
297  
-    case "$sbt_version" in
298  
-      0.7*) addSbt "debug" ;; 
  355
+    case $(sbt_version) in
  356
+     0.7.*) addSbt "debug" ;; 
299 357
          *) addSbt "set logLevel in Global := Level.Debug" ;;
300 358
     esac
301 359
   }
  360
+  [[ $quiet ]] && {
  361
+    case $(sbt_version) in
  362
+     0.7.*) ;; 
  363
+         *) addSbt "set logLevel in Global := Level.Error" ;;
  364
+    esac
  365
+  }
302 366
 }
303 367
 
304 368
 # if .sbtopts exists, prepend its contents to $@ so it can be processed by this runner
305  
-[[ -f "$sbt_opts_file" ]] && set -- $(cat "$sbt_opts_file") "$@"
  369
+[[ -f "$sbt_opts_file" ]] && {
  370
+  sbtargs=()
  371
+  while IFS= read -r arg; do
  372
+    sbtargs=( "${sbtargs[@]}" "$arg" )
  373
+  done <"$sbt_opts_file"
  374
+
  375
+  set -- "${sbtargs[@]}" "$@"
  376
+}
306 377
 
307 378
 # process the combined args, then reset "$@" to the residuals
308 379
 process_args "$@"
309 380
 set -- "${residual_args[@]}"
310 381
 argumentCount=$#
311 382
 
312  
-# figure out the version
313  
-[[ "$sbt_version" ]] || sbt_version=$(build_props_sbt)
314  
-[[ "$sbt_version" = *-SNAPSHOT* || "$sbt_version" = *-RC* ]] && sbt_snapshot=1
315  
-[[ -n "$sbt_version" ]] && echo "Detected sbt version $sbt_version"
316  
-[[ -n "$scala_version" ]] && echo "Detected scala version $scala_version"
  383
+# set scalacOptions if we were given any -S opts
  384
+[[ ${#scalac_args[@]} -eq 0 ]] || addSbt "set scalacOptions in ThisBuild += \"${scalac_args[@]}\""
  385
+
  386
+# Update build.properties no disk to set explicit version - sbt gives us no choice
  387
+[[ -n "$sbt_explicit_version" ]] && update_build_props_sbt "$sbt_explicit_version"
  388
+echo "Detected sbt version $(sbt_version)"
  389
+
  390
+[[ -n "$scala_version" ]] && echo "Overriding scala version to $scala_version"
317 391
 
318 392
 # no args - alert them there's stuff in here
319 393
 (( $argumentCount > 0 )) || echo "Starting $script_name: invoke with -help for other options"
@@ -339,14 +413,19 @@ EOM
339 413
   exit 1
340 414
 }
341 415
 
  416
+[[ -n "$sbt_dir" ]] || {
  417
+  sbt_dir=~/.sbt/$(sbt_version)
  418
+  addJava "-Dsbt.global.base=$sbt_dir"
  419
+  echo "Using $sbt_dir as sbt dir, -sbt-dir to override."
  420
+}
  421
+
342 422
 # since sbt 0.7 doesn't understand iflast
343 423
 (( ${#residual_args[@]} == 0 )) && residual_args=( "shell" )
344 424
 
345 425
 # run sbt
346 426
 execRunner "$java_cmd" \
347  
-  ${java_opts} \
348  
-  ${SBT_OPTS:-$default_sbt_opts} \
349 427
   $(get_mem_opts $sbt_mem) \
  428
+  $(get_jvm_opts) \
350 429
   ${java_args[@]} \
351 430
   -jar "$sbt_jar" \
352 431
   "${sbt_commands[@]}" \

0 notes on commit 9bc6fb8

Please sign in to comment.
Something went wrong with that request. Please try again.