Skip to content

Commit 6797cb5

Browse files
committed
Add dotc command with sane classpath
1 parent 3b54fd2 commit 6797cb5

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

project/Build.scala

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ object DottyBuild extends Build {
3333
// Spawns a repl with the correct classpath
3434
lazy val repl = inputKey[Unit]("run the REPL with correct classpath")
3535

36+
// Used to compile files similar to ./bin/dotc script
37+
lazy val dotc =
38+
inputKey[Unit]("run the compiler using the correct classpath, or the user supplied classpath")
39+
3640
override def settings: Seq[Setting[_]] = {
3741
super.settings ++ Seq(
3842
scalaVersion in Global := "2.11.5",
@@ -73,6 +77,7 @@ object DottyBuild extends Build {
7377
dependsOn(`dotty-library`).
7478
dependsOn(`dotty-interfaces`).
7579
settings(
80+
addCommandAlias("dotc", "dotty-compiler/dotc") ++
7681
addCommandAlias("repl", "dotty-compiler/repl") ++
7782
addCommandAlias(
7883
"partest",
@@ -175,6 +180,22 @@ object DottyBuild extends Build {
175180
)
176181
}.evaluated,
177182

183+
// Set run baseDir to be root of project, makes dotc saner
184+
baseDirectory in run := baseDirectory.value / "..",
185+
dotc := Def.inputTaskDyn {
186+
val dottyLib = packageAll.value("dotty-library")
187+
val args: Seq[String] = spaceDelimited("<arg>").parsed
188+
189+
val fullArgs = args.span(_ != "-classpath") match {
190+
case (beforeCp, Nil) => beforeCp ++ ("-classpath" :: dottyLib :: Nil)
191+
case (beforeCp, rest) => beforeCp ++ rest
192+
}
193+
194+
(runMain in Compile).toTask(
195+
s" dotty.tools.dotc.Main " + fullArgs.mkString(" ")
196+
)
197+
}.evaluated,
198+
178199
// enable verbose exception messages for JUnit
179200
testOptions in Test += Tests.Argument(
180201
TestFrameworks.JUnit, "-a", "-v",
@@ -242,15 +263,11 @@ object DottyBuild extends Build {
242263
// } (Set(scalaJSIRSourcesJar)).toSeq
243264
//}.taskValue,
244265

245-
// Adjust classpath for running dotty
246-
mainClass in (Compile, run) := Some("dotty.tools.dotc.Main"),
266+
// Spawn new JVM in run and test
247267
fork in run := true,
248268
fork in Test := true,
249269
parallelExecution in Test := false,
250270

251-
// FIXME: Do something more sensible, like using the Scala bootclasspath
252-
run <<= (run in Compile).partialInput(" -usejavacp"),
253-
254271
// http://grokbase.com/t/gg/simple-build-tool/135ke5y90p/sbt-setting-jvm-boot-paramaters-for-scala
255272
// packageAll should always be run before tests
256273
javaOptions <++= (dependencyClasspath in Runtime, packageAll) map { (attList, _) =>

0 commit comments

Comments
 (0)