summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLi Haoyi <haoyi.sg@gmail.com>2018-02-11 01:52:32 -0800
committerLi Haoyi <haoyi.sg@gmail.com>2018-02-11 01:52:32 -0800
commit2063febc08963321c367a516b3498d16c21b34ee (patch)
tree17ab661532e23ca387eb99fd11724c8d05257a23
parentde9e237c7f9cd3fe2939399527df17270cbd322a (diff)
downloadmill-2063febc08963321c367a516b3498d16c21b34ee.tar.gz
mill-2063febc08963321c367a516b3498d16c21b34ee.tar.bz2
mill-2063febc08963321c367a516b3498d16c21b34ee.zip
Refactor ScalaModule to simplify it and delay ivy resolution until the last moment
-rw-r--r--main/test/src/mill/util/TestEvaluator.scala4
-rw-r--r--scalajslib/src/mill/scalajslib/ScalaJSModule.scala10
-rw-r--r--scalalib/src/mill/scalalib/GenIdea.scala11
-rw-r--r--scalalib/src/mill/scalalib/PublishModule.scala4
-rw-r--r--scalalib/src/mill/scalalib/ScalaModule.scala83
5 files changed, 48 insertions, 64 deletions
diff --git a/main/test/src/mill/util/TestEvaluator.scala b/main/test/src/mill/util/TestEvaluator.scala
index a5be0488..285aa659 100644
--- a/main/test/src/mill/util/TestEvaluator.scala
+++ b/main/test/src/mill/util/TestEvaluator.scala
@@ -28,8 +28,8 @@ class TestEvaluator[T <: TestUtil.BaseModule](module: T)
tp: TestPath){
val outPath = TestUtil.getOutPath()
- val logger = DummyLogger
-// val logger = new PrintLogger(true, ammonite.util.Colors.Default, System.out, System.out, System.err)
+// val logger = DummyLogger
+ val logger = new PrintLogger(true, ammonite.util.Colors.Default, System.out, System.out, System.err)
val evaluator = new Evaluator(outPath, TestEvaluator.externalOutPath, module, discover, logger)
def apply[T](t: Task[T]): Either[Result.Failing[T], (T, Int)] = {
diff --git a/scalajslib/src/mill/scalajslib/ScalaJSModule.scala b/scalajslib/src/mill/scalajslib/ScalaJSModule.scala
index 7344b54a..018d098c 100644
--- a/scalajslib/src/mill/scalajslib/ScalaJSModule.scala
+++ b/scalajslib/src/mill/scalajslib/ScalaJSModule.scala
@@ -70,7 +70,7 @@ trait ScalaJSModule extends scalalib.ScalaModule { outer =>
ScalaJSBridge.scalaJSBridge(),
toolsClasspath(),
Seq(compile()),
- compileDepClasspath(),
+ runClasspath(),
mainClass(),
FastOpt
)
@@ -81,7 +81,7 @@ trait ScalaJSModule extends scalalib.ScalaModule { outer =>
ScalaJSBridge.scalaJSBridge(),
toolsClasspath(),
Seq(compile()),
- compileDepClasspath(),
+ runClasspath(),
mainClass(),
FullOpt
)
@@ -107,7 +107,7 @@ trait ScalaJSModule extends scalalib.ScalaModule { outer =>
ScalaJSBridge.scalaJSBridge(),
toolsClasspath(),
Seq(compile()),
- compileDepClasspath(),
+ runClasspath(),
Some(mainClass),
FastOpt
)
@@ -150,7 +150,7 @@ trait ScalaJSModule extends scalalib.ScalaModule { outer =>
super.scalacPluginIvyDeps() ++
Seq(ivy"org.scala-js:::scalajs-compiler:${scalaJSVersion()}")
}
- override def scalaLibraryDeps = T{
+ override def scalaLibraryIvyDeps = T{
Seq(ivy"org.scala-js::scalajs-library:${scalaJSVersion()}")
}
@@ -183,7 +183,7 @@ trait TestScalaJSModule extends ScalaJSModule with TestModule {
ScalaJSBridge.scalaJSBridge(),
toolsClasspath(),
compile() +: upstreamCompileOutput(),
- scalaJSTestDeps() ++ compileDepClasspath(),
+ scalaJSTestDeps() ++ runClasspath(),
None,
FastOpt
)
diff --git a/scalalib/src/mill/scalalib/GenIdea.scala b/scalalib/src/mill/scalalib/GenIdea.scala
index 420e79b9..abf8a2a2 100644
--- a/scalalib/src/mill/scalalib/GenIdea.scala
+++ b/scalalib/src/mill/scalalib/GenIdea.scala
@@ -65,8 +65,17 @@ object GenIdea {
}
val resolved = for((path, mod) <- modules) yield {
+ val allIvyDeps = T.task{mod.transitiveIvyDeps() ++ mod.scalaLibraryIvyDeps()}
+ val externalDependencies = T.task{
+ mod.resolveDeps(allIvyDeps)() ++
+ Task.traverse(mod.transitiveModuleDeps)(_.unmanagedClasspath)().flatten
+ }
+
+ val externalSources = T.task{
+ mod.resolveDeps(allIvyDeps, sources = true)()
+ }
val Seq(resolvedCp: Loose.Agg[PathRef], resolvedSrcs: Loose.Agg[PathRef]) =
- evaluator.evaluate(Agg(mod.externalCompileDepClasspath, mod.externalCompileDepSources))
+ evaluator.evaluate(Agg(externalDependencies, externalSources))
.values
(path, resolvedCp.map(_.path).filter(_.ext == "jar") ++ resolvedSrcs.map(_.path), mod)
diff --git a/scalalib/src/mill/scalalib/PublishModule.scala b/scalalib/src/mill/scalalib/PublishModule.scala
index 611e2540..d0741128 100644
--- a/scalalib/src/mill/scalalib/PublishModule.scala
+++ b/scalalib/src/mill/scalalib/PublishModule.scala
@@ -49,7 +49,7 @@ trait PublishModule extends ScalaModule { outer =>
def publishLocal(): define.Command[Unit] = T.command {
LocalPublisher.publish(
jar = jar().path,
- sourcesJar = sourcesJar().path,
+ sourcesJar = sourceJar().path,
docsJar = docsJar().path,
pom = pom().path,
ivy = ivy().path,
@@ -67,7 +67,7 @@ trait PublishModule extends ScalaModule { outer =>
artifactMetadata(),
Seq(
jar() -> s"$baseName.jar",
- sourcesJar() -> s"$baseName-sources.jar",
+ sourceJar() -> s"$baseName-sources.jar",
docsJar() -> s"$baseName-javadoc.jar",
pom() -> s"$baseName.pom"
)
diff --git a/scalalib/src/mill/scalalib/ScalaModule.scala b/scalalib/src/mill/scalalib/ScalaModule.scala
index 9c30ad7c..339c6623 100644
--- a/scalalib/src/mill/scalalib/ScalaModule.scala
+++ b/scalalib/src/mill/scalalib/ScalaModule.scala
@@ -39,22 +39,21 @@ trait ScalaModule extends mill.Module with TaskModule { outer =>
)
def moduleDeps = Seq.empty[ScalaModule]
- def depClasspath = T{ Agg.empty[PathRef] }
+ def transitiveModuleDeps: Seq[ScalaModule] = {
+ Seq(this) ++ moduleDeps.flatMap(_.transitiveModuleDeps).distinct
+ }
+ def unmanagedClasspath = T{ Agg.empty[PathRef] }
- def upstreamRunClasspath = T{
- Task.traverse(moduleDeps)(p =>
- T.task(p.runDepClasspath() ++ p.runClasspath())
- )
+ def transitiveIvyDeps: T[Agg[Dep]] = T{
+ ivyDeps() ++ Task.traverse(moduleDeps)(_.transitiveIvyDeps)().flatten
}
-
def upstreamCompileOutput = T{
Task.traverse(moduleDeps)(_.compile)
}
- def upstreamCompileClasspath = T{
- externalCompileDepClasspath() ++
- upstreamCompileOutput().map(_.classes) ++
- Task.traverse(moduleDeps)(_.compileDepClasspath)().flatten
+
+ def upstreamRunClasspath: T[Agg[PathRef]] = T{
+ Task.traverse(moduleDeps)(_.runClasspath)().flatten
}
def resolveDeps(deps: Task[Agg[Dep]], sources: Boolean = false) = T.task{
@@ -68,29 +67,6 @@ trait ScalaModule extends mill.Module with TaskModule { outer =>
}
def platformSuffix = T{ "" }
- def externalCompileDepClasspath: T[Agg[PathRef]] = T{
- Agg.from(Task.traverse(moduleDeps)(_.externalCompileDepClasspath)().flatten) ++
- resolveDeps(
- T.task{ivyDeps() ++ compileIvyDeps() ++ scalaCompilerIvyDeps(scalaVersion())}
- )()
- }
-
- def externalCompileDepSources: T[Agg[PathRef]] = T{
- Agg.from(Task.traverse(moduleDeps)(_.externalCompileDepSources)().flatten) ++
- resolveDeps(
- T.task{ivyDeps() ++ compileIvyDeps() ++ scalaCompilerIvyDeps(scalaVersion())},
- sources = true
- )()
- }
-
- /**
- * Things that need to be on the classpath in order for this code to compile;
- * might be less than the runtime classpath
- */
- def compileDepClasspath: T[Agg[PathRef]] = T{
- upstreamCompileClasspath() ++
- depClasspath()
- }
def compilerBridgeSources = T{
resolveDependencies(
@@ -101,12 +77,11 @@ trait ScalaModule extends mill.Module with TaskModule { outer =>
)
}
- def scalacPluginClasspath: T[Agg[PathRef]] =
- resolveDeps(
- T.task{scalacPluginIvyDeps()}
- )()
+ def scalacPluginClasspath: T[Agg[PathRef]] = T {
+ resolveDeps(scalacPluginIvyDeps)()
+ }
- def scalaLibraryDeps = T{ scalaRuntimeIvyDeps(scalaVersion()) }
+ def scalaLibraryIvyDeps = T{ scalaRuntimeIvyDeps(scalaVersion()) }
/**
* Classpath of the Scala Compiler & any compiler plugins
*/
@@ -116,16 +91,6 @@ trait ScalaModule extends mill.Module with TaskModule { outer =>
)()
}
- /**
- * Things that need to be on the classpath in order for this code to run
- */
- def runDepClasspath: T[Agg[PathRef]] = T{
- Agg.from(upstreamRunClasspath().flatten) ++
- depClasspath() ++
- resolveDeps(
- T.task{ivyDeps() ++ runIvyDeps() ++ scalaLibraryDeps() }
- )()
- }
def prependShellScript: T[String] = T{ "" }
@@ -139,7 +104,7 @@ trait ScalaModule extends mill.Module with TaskModule { outer =>
scalaVersion(),
allSources().map(_.path),
compilerBridgeSources().map(_.path),
- compileDepClasspath().map(_.path),
+ compileClasspath().map(_.path),
scalaCompilerClasspath().map(_.path),
scalacPluginClasspath().map(_.path),
scalacOptions(),
@@ -148,9 +113,20 @@ trait ScalaModule extends mill.Module with TaskModule { outer =>
upstreamCompileOutput()
)
}
-
+
+ def compileClasspath = T{
+ upstreamRunClasspath() ++
+ resources() ++
+ unmanagedClasspath() ++
+ resolveDeps(T.task{compileIvyDeps() ++ scalaLibraryIvyDeps() ++ transitiveIvyDeps()})()
+ }
+
def runClasspath = T{
- runDepClasspath() ++ resources() ++ Seq(compile().classes)
+ upstreamRunClasspath() ++
+ Agg(compile().classes) ++
+ resources() ++
+ unmanagedClasspath() ++
+ resolveDeps(T.task{runIvyDeps() ++ scalaLibraryIvyDeps() ++ transitiveIvyDeps()})()
}
def assembly = T{
@@ -183,19 +159,18 @@ trait ScalaModule extends mill.Module with TaskModule { outer =>
if p.isFile
} yield p.toNIO.toString
-
val options = Seq("-d", javadocDir.toNIO.toString, "-usejavacp")
if (files.nonEmpty) subprocess(
"scala.tools.nsc.ScalaDoc",
- compileDepClasspath().filter(_.path.ext != "pom").map(_.path),
+ runClasspath().filter(_.path.ext != "pom").map(_.path),
mainArgs = (files ++ options).toSeq
)
createJar(Agg(javadocDir))(outDir)
}
- def sourcesJar = T {
+ def sourceJar = T {
createJar((allSources() ++ resources()).map(_.path).filter(exists))
}