Skip to content

Commit ba7d7a3

Browse files
felixmuldersmarter
authored andcommitted
Add dotc command with sane classpath
1 parent 5c293d0 commit ba7d7a3

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
@@ -34,6 +34,10 @@ object DottyBuild extends Build {
3434
// Spawns a repl with the correct classpath
3535
lazy val repl = inputKey[Unit]("run the REPL with correct classpath")
3636

37+
// Used to compile files similar to ./bin/dotc script
38+
lazy val dotc =
39+
inputKey[Unit]("run the compiler using the correct classpath, or the user supplied classpath")
40+
3741
override def settings: Seq[Setting[_]] = {
3842
super.settings ++ Seq(
3943
scalaVersion in Global := "2.11.5",
@@ -74,6 +78,7 @@ object DottyBuild extends Build {
7478
dependsOn(`dotty-library`).
7579
dependsOn(`dotty-interfaces`).
7680
settings(
81+
addCommandAlias("dotc", "dotty-compiler/dotc") ++
7782
addCommandAlias("repl", "dotty-compiler/repl") ++
7883
addCommandAlias(
7984
"partest",
@@ -176,6 +181,22 @@ object DottyBuild extends Build {
176181
)
177182
}.evaluated,
178183

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

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

252272
// Add git-hash used to package the distribution to the manifest to know it in runtime and report it in REPL
253273
packageOptions += ManifestAttributes(("Git-Hash", VersionUtil.gitHash)),
254274

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

0 commit comments

Comments
 (0)