diff options
author | Roman Timushev <rtimush@gmail.com> | 2017-12-11 17:25:38 +0100 |
---|---|---|
committer | Li Haoyi <haoyi.sg@gmail.com> | 2017-12-11 08:25:38 -0800 |
commit | bb61c05217671e80ba381b2cac869130c306baa8 (patch) | |
tree | 93a0ef6dcaa6f1e1b95251f26519ab92b31d078b | |
parent | f4b61e2a28a6eb537dda1136859e7a51429e8adf (diff) | |
download | mill-bb61c05217671e80ba381b2cac869130c306baa8.tar.gz mill-bb61c05217671e80ba381b2cac869130c306baa8.tar.bz2 mill-bb61c05217671e80ba381b2cac869130c306baa8.zip |
Resolve compiler bridge jar (#45)
* Resolve compiler bridge jar
* Create a release artifact
-rwxr-xr-x | build.sc | 11 | ||||
-rw-r--r-- | scalaplugin/src/main/scala/mill/scalaplugin/Lib.scala | 10 | ||||
-rw-r--r-- | scalaplugin/src/main/scala/mill/scalaplugin/ScalaModule.scala | 24 |
3 files changed, 34 insertions, 11 deletions
@@ -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(), |