Skip to content

Commit 6a3f3c2

Browse files
felixmuldersmarter
authored andcommitted
Make dotr run binaries similar to script in bin
1 parent f547053 commit 6a3f3c2

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
@@ -38,6 +38,10 @@ object DottyBuild extends Build {
3838
lazy val dotc =
3939
inputKey[Unit]("run the compiler using the correct classpath, or the user supplied classpath")
4040

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+
4145
override def settings: Seq[Setting[_]] = {
4246
super.settings ++ Seq(
4347
scalaVersion in Global := "2.11.5",
@@ -78,6 +82,7 @@ object DottyBuild extends Build {
7882
dependsOn(`dotty-library`).
7983
dependsOn(`dotty-interfaces`).
8084
settings(
85+
addCommandAlias("dotr", "dotty-compiler/dotr") ++
8186
addCommandAlias("dotc", "dotty-compiler/dotc") ++
8287
addCommandAlias("repl", "dotty-compiler/repl") ++
8388
addCommandAlias(
@@ -173,6 +178,9 @@ object DottyBuild extends Build {
173178
) map { case (k, v) => (k, v.getAbsolutePath) }
174179
},
175180

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

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

0 commit comments

Comments
 (0)