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