From 9f6151f438d7661590c09be13af0f2df8bf5e701 Mon Sep 17 00:00:00 2001 From: Li Haoyi Date: Sat, 3 Mar 2018 07:11:13 -0800 Subject: make mainClass discovery work in ScalaJSModule#run Also disable ScalaJSModule#runMain, since the official Scala.js-SBT plugin does not support it and it requires an expensive re-linking every time it is run. --- scalalib/src/mill/scalalib/ScalaModule.scala | 41 +++++++++++++++------------- 1 file changed, 22 insertions(+), 19 deletions(-) (limited to 'scalalib/src') diff --git a/scalalib/src/mill/scalalib/ScalaModule.scala b/scalalib/src/mill/scalalib/ScalaModule.scala index cc2d1e84..c7dbc322 100644 --- a/scalalib/src/mill/scalalib/ScalaModule.scala +++ b/scalalib/src/mill/scalalib/ScalaModule.scala @@ -29,22 +29,29 @@ trait ScalaModule extends mill.Module with TaskModule { outer => def scalaWorker: ScalaWorkerModule = mill.scalalib.ScalaWorkerModule - def finalMainClass: T[String] = T{ - mainClass() match { - case Some(main) => Result.Success(main) + def finalMainClassOpt: T[Either[String, String]] = T{ + mainClass() match{ + case Some(m) => Right(m) case None => - scalaWorker.worker().discoverMainClasses(compile()) match { - case Seq() => Result.Failure("No main class specified or found") - case Seq(main) => Result.Success(main) + scalaWorker.worker().discoverMainClasses(compile())match { + case Seq() => Left("No main class specified or found") + case Seq(main) => Right(main) case mains => - Result.Failure( + Left( s"Multiple main classes found (${mains.mkString(",")}) " + - "please explicitly specify which one to use by overriding mainClass" + "please explicitly specify which one to use by overriding mainClass" ) } } } + def finalMainClass: T[String] = T{ + finalMainClassOpt() match { + case Right(main) => Result.Success(main) + case Left(msg) => Result.Failure(msg) + } + } + def ivyDeps = T{ Agg.empty[Dep] } def compileIvyDeps = T{ Agg.empty[Dep] } def scalacPluginIvyDeps = T{ Agg.empty[Dep] } @@ -215,17 +222,13 @@ trait ScalaModule extends mill.Module with TaskModule { outer => def forkEnv = T{ sys.env.toMap } def launcher = T{ - mainClass() match { - case None => Result.Failure("Need to specify a main class for launcher") - case Some(cls) => - Result.Success( - Jvm.createLauncher( - cls, - runClasspath().map(_.path), - forkArgs() - ) - ) - } + Result.Success( + Jvm.createLauncher( + finalMainClass(), + runClasspath().map(_.path), + forkArgs() + ) + ) } def runLocal(args: String*) = T.command { -- cgit v1.2.3