summaryrefslogtreecommitdiff
path: root/scalalib
diff options
context:
space:
mode:
authorLi Haoyi <haoyi.sg@gmail.com>2018-03-03 11:14:22 -0800
committerLi Haoyi <haoyi.sg@gmail.com>2018-03-03 11:33:53 -0800
commit8c360c652902b9ccf13060ea1fd050bf473bf2d8 (patch)
treecd7d72f9fb785d193163ae768b46eea234f10b6d /scalalib
parent4edb1740397f6328177042a55a1404e42c1d6439 (diff)
downloadmill-8c360c652902b9ccf13060ea1fd050bf473bf2d8.tar.gz
mill-8c360c652902b9ccf13060ea1fd050bf473bf2d8.tar.bz2
mill-8c360c652902b9ccf13060ea1fd050bf473bf2d8.zip
Split out `upstreamAssembly` from `assembly`
Also re-write `Jvm.createAssembly` to allow incremental assembly construction. This should allow much faster assembly creation in the common case where upstream dependencies do not change
Diffstat (limited to 'scalalib')
-rw-r--r--scalalib/src/mill/scalalib/ScalaModule.scala36
-rw-r--r--scalalib/test/src/mill/scalalib/HelloWorldTests.scala24
2 files changed, 32 insertions, 28 deletions
diff --git a/scalalib/src/mill/scalalib/ScalaModule.scala b/scalalib/src/mill/scalalib/ScalaModule.scala
index c7dbc322..5a355bc6 100644
--- a/scalalib/src/mill/scalalib/ScalaModule.scala
+++ b/scalalib/src/mill/scalalib/ScalaModule.scala
@@ -2,16 +2,15 @@ package mill
package scalalib
import ammonite.ops._
-import coursier.{Cache, MavenRepository, Repository}
-import mill.define.{Cross, Task}
+import coursier.Repository
+import mill.define.Task
import mill.define.TaskModule
import mill.eval.{PathRef, Result}
import mill.modules.Jvm
-import mill.modules.Jvm.{createAssembly, createJar, interactiveSubprocess, runLocal, subprocess}
+import mill.modules.Jvm.{createAssembly, createJar, subprocess}
import Lib._
-import mill.define.Cross.Resolver
import mill.util.Loose.Agg
-import mill.util.{DummyInputStream, Strict}
+import mill.util.DummyInputStream
/**
* Core configuration required to compile a single Scala compilation target
@@ -144,6 +143,7 @@ trait ScalaModule extends mill.Module with TaskModule { outer =>
if path.isFile && (path.ext == "scala" || path.ext == "java")
} yield PathRef(path)
}
+
def compile: T[CompilationResult] = T.persistent{
scalaWorker.worker().compileScala(
scalaVersion(),
@@ -165,19 +165,35 @@ trait ScalaModule extends mill.Module with TaskModule { outer =>
resolveDeps(T.task{compileIvyDeps() ++ scalaLibraryIvyDeps() ++ transitiveIvyDeps()})()
}
- def runClasspath = T{
+ def upstreamAssemblyClasspath = T{
upstreamRunClasspath() ++
- Agg(compile().classes) ++
- resources() ++
unmanagedClasspath() ++
resolveDeps(T.task{runIvyDeps() ++ scalaLibraryIvyDeps() ++ transitiveIvyDeps()})()
}
+ def runClasspath = T{
+ Agg(compile().classes) ++
+ resources() ++
+ upstreamAssemblyClasspath()
+
+ }
+
+ /**
+ * Build the assembly for upstream dependencies separate from the current classpath
+ *
+ * This should allow much faster assembly creation in the common case where
+ * upstream dependencies do not change
+ */
+ def upstreamAssembly = T{
+ createAssembly(upstreamAssemblyClasspath().map(_.path), mainClass())
+ }
+
def assembly = T{
createAssembly(
- runClasspath().map(_.path).filter(exists),
+ Agg.from(resources().map(_.path)) ++ Agg(compile().classes.path),
mainClass(),
- prependShellScript = prependShellScript()
+ prependShellScript(),
+ Some(upstreamAssembly().path)
)
}
diff --git a/scalalib/test/src/mill/scalalib/HelloWorldTests.scala b/scalalib/test/src/mill/scalalib/HelloWorldTests.scala
index 4fb5f5a5..317f9bec 100644
--- a/scalalib/test/src/mill/scalalib/HelloWorldTests.scala
+++ b/scalalib/test/src/mill/scalalib/HelloWorldTests.scala
@@ -50,19 +50,6 @@ object HelloWorldTests extends TestSuite {
}
}
- object HelloWorldWithMainAssembly extends HelloBase {
- object core extends HelloWorldModule{
- def mainClass = Some("Main")
- def assembly = T{
- mill.modules.Jvm.createAssembly(
- runClasspath().map(_.path).filter(exists),
- prependShellScript = prependShellScript(),
- mainClass = mainClass()
- )
- }
- }
- }
-
object HelloWorldWarnUnused extends HelloBase{
object core extends HelloWorldModule {
def scalacOptions = T(Seq("-Ywarn-unused"))
@@ -392,8 +379,8 @@ object HelloWorldTests extends TestSuite {
}
'assembly - {
- 'assembly - workspaceTest(HelloWorldWithMainAssembly){ eval =>
- val Right((result, evalCount)) = eval.apply(HelloWorldWithMainAssembly.core.assembly)
+ 'assembly - workspaceTest(HelloWorldWithMain){ eval =>
+ val Right((result, evalCount)) = eval.apply(HelloWorldWithMain.core.assembly)
assert(
exists(result.path),
evalCount > 0
@@ -401,14 +388,15 @@ object HelloWorldTests extends TestSuite {
val jarFile = new JarFile(result.path.toIO)
val entries = jarFile.entries().asScala.map(_.getName).toSet
- assert(entries.contains("Main.class"))
+ val mainPresent = entries.contains("Main.class")
+ assert(mainPresent)
assert(entries.exists(s => s.contains("scala/Predef.class")))
val mainClass = jarMainClass(jarFile)
assert(mainClass.contains("Main"))
}
- 'run - workspaceTest(HelloWorldWithMainAssembly){eval =>
- val Right((result, evalCount)) = eval.apply(HelloWorldWithMainAssembly.core.assembly)
+ 'run - workspaceTest(HelloWorldWithMain){eval =>
+ val Right((result, evalCount)) = eval.apply(HelloWorldWithMain.core.assembly)
assert(
exists(result.path),