From bb61c05217671e80ba381b2cac869130c306baa8 Mon Sep 17 00:00:00 2001 From: Roman Timushev Date: Mon, 11 Dec 2017 17:25:38 +0100 Subject: Resolve compiler bridge jar (#45) * Resolve compiler bridge jar * Create a release artifact --- build.sc | 11 ++++++++++ .../src/main/scala/mill/scalaplugin/Lib.scala | 10 ++++----- .../main/scala/mill/scalaplugin/ScalaModule.scala | 24 +++++++++++++++++----- 3 files changed, 34 insertions(+), 11 deletions(-) diff --git a/build.sc b/build.sc index 3a7dae44..29f1955f 100755 --- a/build.sc +++ b/build.sc @@ -1,6 +1,7 @@ import ammonite.ops._ import mill._ import mill.scalaplugin._ +import mill.modules.Jvm.createAssembly trait MillModule extends SbtScalaModule{ outer => def scalaVersion = "2.12.4" @@ -96,6 +97,16 @@ object ScalaPlugin extends MillModule { for((k, v) <- mapping.toSeq) yield s"-D$k=$v" } + def releaseAssembly = T{ + createAssembly( + (runDepClasspath().filter(_.path.ext != "pom") ++ + Seq(resources(), compile().classes)).map(_.path).filter(exists), + prependShellScript = + "#!/usr/bin/env sh\n" + + s"""exec java $$JAVA_OPTS -cp "$$0" mill.Main "$$@" """ + ) + } + override def prependShellScript = "#!/usr/bin/env sh\n" + s"""exec java ${testArgs().mkString(" ")} $$JAVA_OPTS -cp "$$0" mill.Main "$$@" """ diff --git a/scalaplugin/src/main/scala/mill/scalaplugin/Lib.scala b/scalaplugin/src/main/scala/mill/scalaplugin/Lib.scala index 055b3206..21ecdca1 100644 --- a/scalaplugin/src/main/scala/mill/scalaplugin/Lib.scala +++ b/scalaplugin/src/main/scala/mill/scalaplugin/Lib.scala @@ -36,7 +36,7 @@ object Lib{ sources: Seq[Path], compileClasspath: Seq[Path], compilerClasspath: Seq[Path], - compilerBridge: Seq[Path], + compilerBridge: Path, scalacOptions: Seq[String], scalacPluginClasspath: Seq[Path], javacOptions: Seq[String], @@ -52,10 +52,6 @@ object Lib{ } val compilerJars = compilerClasspath.toArray.map(_.toIO) - val compilerBridgeKey = "MILL_COMPILER_BRIDGE_"+scalaVersion.replace('.', '_') - val compilerBridgePath = sys.props(compilerBridgeKey) - assert(compilerBridgePath != null, "Cannot find compiler bridge " + compilerBridgeKey) - val compilerBridgeJar = new java.io.File(compilerBridgePath) val classloaderSig = compilerClasspath.map(p => p.toString().hashCode + p.mtime.toMillis).sum @@ -123,7 +119,7 @@ object Lib{ scalaInstance, ClasspathOptionsUtil.boot, None, - ZincUtil.scalaCompiler(scalaInstance, compilerBridgeJar) + ZincUtil.scalaCompiler(scalaInstance, compilerBridge.toIO) ), setup = ic.setup( lookup, @@ -186,6 +182,8 @@ object Lib{ def scalaRuntimeIvyDeps(scalaVersion: String) = Seq[Dep]( Dep.Java("org.scala-lang", "scala-library", scalaVersion) ) + def compilerBridgeIvyDep(scalaVersion: String) = + Dep.Point(coursier.Dependency(coursier.Module("com.lihaoyi", "mill-bridge"), "0.1-SNAPSHOT", transitive = false)) val DefaultShellScript: Seq[String] = Seq( "#!/usr/bin/env sh", diff --git a/scalaplugin/src/main/scala/mill/scalaplugin/ScalaModule.scala b/scalaplugin/src/main/scala/mill/scalaplugin/ScalaModule.scala index 8167a4f1..f7db3006 100644 --- a/scalaplugin/src/main/scala/mill/scalaplugin/ScalaModule.scala +++ b/scalaplugin/src/main/scala/mill/scalaplugin/ScalaModule.scala @@ -129,10 +129,24 @@ trait ScalaModule extends Module with TaskModule{ outer => /** * Strange compiler-bridge jar that the Zinc incremental compile needs */ - def compilerBridgeClasspath: T[Seq[PathRef]] = T{ - resolveDeps( - T.task{Seq(Dep("org.scala-sbt", "compiler-bridge", "1.0.5"))}, - )() + def compilerBridge: T[PathRef] = T{ + val compilerBridgeKey = "MILL_COMPILER_BRIDGE_" + scalaVersion().replace('.', '_') + val compilerBridgePath = sys.props(compilerBridgeKey) + if (compilerBridgePath != null) PathRef(Path(compilerBridgePath), quick = true) + else { + val dep = compilerBridgeIvyDep(scalaVersion()) + val classpath = resolveDependencies( + repositories, + scalaVersion(), + scalaBinaryVersion(), + Seq(dep) + ) + classpath match { + case Seq(single) => PathRef(single.path, quick = true) + case Seq() => throw new Exception(dep + " resolution failed") + case _ => throw new Exception(dep + " resolution resulted in more than one file") + } + } } def scalacPluginClasspath: T[Seq[PathRef]] = @@ -171,7 +185,7 @@ trait ScalaModule extends Module with TaskModule{ outer => allSources().map(_.path), compileDepClasspath().map(_.path), scalaCompilerClasspath().map(_.path), - compilerBridgeClasspath().map(_.path), + compilerBridge().path, scalacOptions(), scalacPluginClasspath().map(_.path), javacOptions(), -- cgit v1.2.3