@@ -37,6 +37,10 @@ object DottyBuild extends Build {
37
37
lazy val dotc =
38
38
inputKey[Unit ](" run the compiler using the correct classpath, or the user supplied classpath" )
39
39
40
+ // Used to run binaries similar to ./bin/dotr script
41
+ lazy val dotr =
42
+ inputKey[Unit ](" run compiled binary using the correct classpath, or the user supplied classpath" )
43
+
40
44
override def settings : Seq [Setting [_]] = {
41
45
super .settings ++ Seq (
42
46
scalaVersion in Global := " 2.11.5" ,
@@ -77,6 +81,7 @@ object DottyBuild extends Build {
77
81
dependsOn(`dotty-library`).
78
82
dependsOn(`dotty-interfaces`).
79
83
settings(
84
+ addCommandAlias(" dotr" , " dotty-compiler/dotr" ) ++
80
85
addCommandAlias(" dotc" , " dotty-compiler/dotc" ) ++
81
86
addCommandAlias(" repl" , " dotty-compiler/repl" ) ++
82
87
addCommandAlias(
@@ -172,6 +177,9 @@ object DottyBuild extends Build {
172
177
) map { case (k, v) => (k, v.getAbsolutePath) }
173
178
},
174
179
180
+ // Set run baseDir to be root of project, makes dotc saner
181
+ baseDirectory in run := baseDirectory.value / " .." ,
182
+
175
183
repl := Def .inputTaskDyn {
176
184
val args : Seq [String ] = spaceDelimited(" <arg>" ).parsed
177
185
val dottyLib = packageAll.value(" dotty-library" )
@@ -180,8 +188,27 @@ object DottyBuild extends Build {
180
188
)
181
189
}.evaluated,
182
190
183
- // Set run baseDir to be root of project, makes dotc saner
184
- baseDirectory in run := baseDirectory.value / " .." ,
191
+ // Override run to be able to run compiled classfiles
192
+ dotr := {
193
+ val args : Seq [String ] = spaceDelimited(" <arg>" ).parsed
194
+ val java : String = Process (" which" :: " java" :: Nil ) !!
195
+ val scalaLib = (dependencyClasspath in Runtime , packageAll)
196
+ .map { (attList, _) =>
197
+ attList
198
+ .map(_.data.getAbsolutePath)
199
+ .find(_.contains(" scala-library" ))
200
+ .toList.mkString(" :" )
201
+ }.value
202
+
203
+ if (java == " " )
204
+ println(" Couldn't find java executable on path, please install java to a default location" )
205
+ else if (scalaLib == " " ) {
206
+ println(" Couldn't find scala-library on classpath, please run using script in bin dir instead" )
207
+ } else {
208
+ val dottyLib = packageAll.value(" dotty-library" )
209
+ s """ $java -classpath .: $dottyLib: $scalaLib ${args.mkString(" " )}""" !
210
+ }
211
+ },
185
212
dotc := Def .inputTaskDyn {
186
213
val dottyLib = packageAll.value(" dotty-library" )
187
214
val args : Seq [String ] = spaceDelimited(" <arg>" ).parsed
0 commit comments