diff options
author | Li Haoyi <haoyi.sg@gmail.com> | 2018-03-03 07:11:13 -0800 |
---|---|---|
committer | Li Haoyi <haoyi.sg@gmail.com> | 2018-03-03 07:11:20 -0800 |
commit | 9f6151f438d7661590c09be13af0f2df8bf5e701 (patch) | |
tree | a161cd56641c4b05f96907636f1147a6c6be150a /scalalib/src | |
parent | 2bc394a02ec18aadaa34c95805e94dab46aae465 (diff) | |
download | mill-9f6151f438d7661590c09be13af0f2df8bf5e701.tar.gz mill-9f6151f438d7661590c09be13af0f2df8bf5e701.tar.bz2 mill-9f6151f438d7661590c09be13af0f2df8bf5e701.zip |
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.
Diffstat (limited to 'scalalib/src')
-rw-r--r-- | scalalib/src/mill/scalalib/ScalaModule.scala | 41 |
1 files changed, 22 insertions, 19 deletions
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 { |