Skip to content

Commit 96e834e

Browse files
committed
Make dotr run binaries similar to script in bin
1 parent 2b3cc5e commit 96e834e

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

project/Build.scala

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ object DottyBuild extends Build {
3737
lazy val dotc =
3838
inputKey[Unit]("run the compiler using the correct classpath, or the user supplied classpath")
3939

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+
4044
override def settings: Seq[Setting[_]] = {
4145
super.settings ++ Seq(
4246
scalaVersion in Global := "2.11.5",
@@ -77,6 +81,7 @@ object DottyBuild extends Build {
7781
dependsOn(`dotty-library`).
7882
dependsOn(`dotty-interfaces`).
7983
settings(
84+
addCommandAlias("dotr", "dotty-compiler/dotr") ++
8085
addCommandAlias("dotc", "dotty-compiler/dotc") ++
8186
addCommandAlias("repl", "dotty-compiler/repl") ++
8287
addCommandAlias(
@@ -172,6 +177,9 @@ object DottyBuild extends Build {
172177
) map { case (k, v) => (k, v.getAbsolutePath) }
173178
},
174179

180+
// Set run baseDir to be root of project, makes dotc saner
181+
baseDirectory in run := baseDirectory.value / "..",
182+
175183
repl := Def.inputTaskDyn {
176184
val args: Seq[String] = spaceDelimited("<arg>").parsed
177185
val dottyLib = packageAll.value("dotty-library")
@@ -180,8 +188,27 @@ object DottyBuild extends Build {
180188
)
181189
}.evaluated,
182190

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+
},
185212
dotc := Def.inputTaskDyn {
186213
val dottyLib = packageAll.value("dotty-library")
187214
val args: Seq[String] = spaceDelimited("<arg>").parsed

0 commit comments

Comments
 (0)