summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLi Haoyi <haoyi.sg@gmail.com>2018-01-14 04:25:56 -0800
committerLi Haoyi <haoyi.sg@gmail.com>2018-01-14 04:47:18 -0800
commitde96a55c3267bb1508e77a6815007807e3fd73fb (patch)
tree6aea7c19e363975ce14396b4ed33998b458ff145
parent478bf87d3f140eaf2671663b5b3c1758354ec856 (diff)
downloadmill-de96a55c3267bb1508e77a6815007807e3fd73fb.tar.gz
mill-de96a55c3267bb1508e77a6815007807e3fd73fb.tar.bz2
mill-de96a55c3267bb1508e77a6815007807e3fd73fb.zip
Some tweaks to get tests passing...
-rw-r--r--core/src/main/scala/mill/define/Cross.scala10
-rw-r--r--core/src/main/scala/mill/define/Discover.scala1
-rw-r--r--core/src/main/scala/mill/define/Module.scala28
-rw-r--r--core/src/main/scala/mill/main/MainRunner.scala3
-rw-r--r--core/src/main/scala/mill/main/RunScript.scala11
-rw-r--r--core/src/test/scala/mill/util/TestUtil.scala6
-rw-r--r--integration/src/test/resources/jawn/build.sc2
-rw-r--r--integration/src/test/scala/mill/integration/IntegrationTestSuite.scala2
-rw-r--r--scalajslib/src/test/scala/mill/scalajslib/HelloJSWorldTests.scala32
-rw-r--r--scalalib/src/test/scala/mill/scalalib/HelloWorldTests.scala103
10 files changed, 91 insertions, 107 deletions
diff --git a/core/src/main/scala/mill/define/Cross.scala b/core/src/main/scala/mill/define/Cross.scala
index 6120d5df..2975f97b 100644
--- a/core/src/main/scala/mill/define/Cross.scala
+++ b/core/src/main/scala/mill/define/Cross.scala
@@ -44,15 +44,9 @@ object Cross{
*/
class Cross[T](cases: Any*)
(implicit ci: Cross.Factory[T],
- ctx: mill.define.Ctx,
- cmds: Module.Cmds) extends mill.define.Module()(ctx, cmds) {
-
- override def traverse[T](f: Module => Seq[T]): Seq[T] = {
- f(this) ++
- this.reflect[Module].flatMap(f) ++
- items.map(_._2).flatMap{case t: Module => f(t)}
- }
+ ctx: mill.define.Ctx) extends mill.define.Module()(ctx) {
+ override lazy val modules = this.reflectNestedObjects[Module] ++ items.collect{case (k, v: mill.define.Module) => v}
val items = for(c0 <- cases.toList) yield{
val c = c0 match{
case p: Product => p
diff --git a/core/src/main/scala/mill/define/Discover.scala b/core/src/main/scala/mill/define/Discover.scala
index a5bcd8c6..0db2d617 100644
--- a/core/src/main/scala/mill/define/Discover.scala
+++ b/core/src/main/scala/mill/define/Discover.scala
@@ -13,7 +13,6 @@ object Discover {
import c.universe._
val seen = mutable.Set.empty[Type]
def rec(tpe: Type): Unit = {
- println("Rec! " + tpe)
if (!seen(tpe)){
seen.add(tpe)
for{
diff --git a/core/src/main/scala/mill/define/Module.scala b/core/src/main/scala/mill/define/Module.scala
index c9ce523c..4634b9a3 100644
--- a/core/src/main/scala/mill/define/Module.scala
+++ b/core/src/main/scala/mill/define/Module.scala
@@ -8,36 +8,23 @@ import ammonite.ops.Path
import scala.language.experimental.macros
import scala.reflect.ClassTag
import scala.reflect.macros.blackbox
-object Module{
- case class Cmds(value: Seq[EntryPoint[Module]])
- object Cmds{
- implicit def make: Cmds = macro makeImpl
- implicit def makeImpl(c: blackbox.Context): c.Expr[Cmds] = {
- import c.universe._
- reify(Cmds(Nil))
- }
- }
-}
/**
* `Module` is a class meant to be extended by `trait`s *only*, in order to
* propagate the implicit parameters forward to the final concrete
* instantiation site so they can capture the enclosing/line information of
* the concrete instance.
*/
-class Module(implicit ctx0: mill.define.Ctx, cmds: Module.Cmds) extends mill.moduledefs.Cacher{
+class Module(implicit ctx0: mill.define.Ctx) extends mill.moduledefs.Cacher{
def traverse[T](f: Module => Seq[T]): Seq[T] = {
- def rec(m: Module): Seq[T] = {
- f(m) ++
- this.reflect[Module].flatMap(f)
- }
+ def rec(m: Module): Seq[T] = f(m) ++ m.modules.flatMap(rec)
rec(this)
}
lazy val segmentsToModules = traverse{m => Seq(m.ctx.segments -> m)}
.toMap
- lazy val modules = segmentsToModules.valuesIterator.toSet
+ lazy val modules = this.reflectNestedObjects[Module]
lazy val segmentsToTargets = traverse{_.reflect[Target[_]]}
.map(t => (t.ctx.segments, t))
.toMap
@@ -78,6 +65,9 @@ class Module(implicit ctx0: mill.define.Ctx, cmds: Module.Cmds) extends mill.mod
.filter(implicitly[ClassTag[T]].runtimeClass isAssignableFrom _.getReturnType)
.map(_.getName)
}
+ // For some reason, this fails to pick up concrete `object`s nested directly within
+ // another top-level concrete `object`. This is fine for now, since Mill's Ammonite
+ // script/REPL runner always wraps user code in a wrapper object/trait
def reflectNestedObjects[T: ClassTag] = {
reflect[T] ++
this
@@ -95,9 +85,7 @@ class BaseModule(basePath: Path)
(implicit millModuleEnclosing0: sourcecode.Enclosing,
millModuleLine0: sourcecode.Line,
millName0: sourcecode.Name,
- overrides0: Overrides,
- cmds: Module.Cmds)
+ overrides0: Overrides)
extends Module()(
- mill.define.Ctx.make(implicitly, implicitly, implicitly, BasePath(basePath), Segments(), implicitly),
- cmds
+ mill.define.Ctx.make(implicitly, implicitly, implicitly, BasePath(basePath), Segments(), implicitly)
) \ No newline at end of file
diff --git a/core/src/main/scala/mill/main/MainRunner.scala b/core/src/main/scala/mill/main/MainRunner.scala
index fd16161f..5dd451c2 100644
--- a/core/src/main/scala/mill/main/MainRunner.scala
+++ b/core/src/main/scala/mill/main/MainRunner.scala
@@ -99,6 +99,9 @@ class MainRunner(config: ammonite.main.Cli.Config,
| def $$main() = Iterator[String]()
|
| val millDiscover = mill.define.Discover[$wrapName]
+ | // Need to wrap the returned Module in Some(...) to make sure it
+ | // doesn't get picked up during reflective child-module discovery
+ | val millSelf = Some(this)
|}
|
|sealed trait $wrapName extends mill.Module{
diff --git a/core/src/main/scala/mill/main/RunScript.scala b/core/src/main/scala/mill/main/RunScript.scala
index 8ad144d3..010f134b 100644
--- a/core/src/main/scala/mill/main/RunScript.scala
+++ b/core/src/main/scala/mill/main/RunScript.scala
@@ -100,9 +100,10 @@ object RunScript{
module <- try {
Util.withContextClassloader(interp.evalClassloader) {
Res.Success(
- buildCls.getField("MODULE$")
- .get(buildCls)
- .asInstanceOf[mill.Module]
+ buildCls.getMethod("millSelf")
+ .invoke(null)
+ .asInstanceOf[Some[mill.Module]]
+ .get
)
}
} catch {
@@ -112,8 +113,8 @@ object RunScript{
Util.withContextClassloader(interp.evalClassloader) {
Res.Success(
buildCls.getMethod("millDiscover")
- .invoke(null)
- .asInstanceOf[Discover]
+ .invoke(null)
+ .asInstanceOf[Discover]
)
}
} catch {
diff --git a/core/src/test/scala/mill/util/TestUtil.scala b/core/src/test/scala/mill/util/TestUtil.scala
index 7a3644dd..c0985c97 100644
--- a/core/src/test/scala/mill/util/TestUtil.scala
+++ b/core/src/test/scala/mill/util/TestUtil.scala
@@ -11,8 +11,7 @@ object TestUtil {
class BaseModule(implicit millModuleEnclosing0: sourcecode.Enclosing,
millModuleLine0: sourcecode.Line,
millName0: sourcecode.Name,
- overrides: Overrides,
- cmds: Module.Cmds)
+ overrides: Overrides)
extends Module()(
mill.define.Ctx.make(
implicitly,
@@ -21,8 +20,7 @@ object TestUtil {
BasePath(ammonite.ops.pwd / millModuleEnclosing0.value),
Segments(),
implicitly
- ),
- cmds
+ )
)
object test{
diff --git a/integration/src/test/resources/jawn/build.sc b/integration/src/test/resources/jawn/build.sc
index b57227e7..161f302a 100644
--- a/integration/src/test/resources/jawn/build.sc
+++ b/integration/src/test/resources/jawn/build.sc
@@ -33,7 +33,7 @@ class JawnModule(crossVersion: String) extends mill.Module{
def projectDeps = Seq(parser, util)
def testProjectDeps = Seq(parser.test, util.test)
}
- class Support(ivyDeps0: Dep*)(implicit ctx: mill.mill.define.Ctx) extends JawnModule{
+ class Support(ivyDeps0: Dep*)(implicit ctx: mill.define.Ctx) extends JawnModule{
def projectDeps = Seq[Module](parser)
def ivyDeps = Agg.from(ivyDeps0)
}
diff --git a/integration/src/test/scala/mill/integration/IntegrationTestSuite.scala b/integration/src/test/scala/mill/integration/IntegrationTestSuite.scala
index 82f4de72..ba4415fa 100644
--- a/integration/src/test/scala/mill/integration/IntegrationTestSuite.scala
+++ b/integration/src/test/scala/mill/integration/IntegrationTestSuite.scala
@@ -8,7 +8,7 @@ import utest._
abstract class IntegrationTestSuite(repoKey: String, workspaceSlug: String) extends TestSuite{
val workspacePath = pwd / 'target / 'workspace / workspaceSlug
val buildFilePath = pwd / 'integration / 'src / 'test / 'resources / workspaceSlug
- val stdOutErr = System.out//new PrintStream(new ByteArrayOutputStream())
+ val stdOutErr = new PrintStream(new ByteArrayOutputStream())
val stdIn = new ByteArrayInputStream(Array())
val runner = new mill.main.MainRunner(
ammonite.main.Cli.Config(wd = workspacePath), false,
diff --git a/scalajslib/src/test/scala/mill/scalajslib/HelloJSWorldTests.scala b/scalajslib/src/test/scala/mill/scalajslib/HelloJSWorldTests.scala
index fce52c87..ca580d71 100644
--- a/scalajslib/src/test/scala/mill/scalajslib/HelloJSWorldTests.scala
+++ b/scalajslib/src/test/scala/mill/scalajslib/HelloJSWorldTests.scala
@@ -13,20 +13,24 @@ import utest._
import scala.collection.JavaConverters._
-trait HelloJSWorldModule extends ScalaJSModule with PublishModule {
- override def basePath = HelloJSWorldTests.workspacePath
- override def mainClass = Some("Main")
-}
-object HelloJSWorld extends TestUtil.BaseModule {
- val matrix = for {
- scalaJS <- Seq("0.6.20", "0.6.21", "1.0.0-M2")
- scala <- Seq("2.11.8", "2.12.3", "2.12.4")
- } yield (scalaJS, scala)
+object HelloJSWorldTests extends TestSuite {
+
+
+ trait HelloJSWorldModule extends ScalaJSModule with PublishModule {
+ override def basePath = HelloJSWorldTests.workspacePath
+ override def mainClass = Some("Main")
+ }
+
+ object HelloJSWorld extends TestUtil.BaseModule {
+ val matrix = for {
+ scalaJS <- Seq("0.6.20", "0.6.21", "1.0.0-M2")
+ scala <- Seq("2.11.8", "2.12.3", "2.12.4")
+ } yield (scalaJS, scala)
- object build extends Cross[BuildModule](matrix:_*)
+ object build extends Cross[BuildModule](matrix:_*)
- class BuildModule(sjsVersion0: String, scalaVersion0: String) extends HelloJSWorldModule {
+ class BuildModule(sjsVersion0: String, scalaVersion0: String) extends HelloJSWorldModule {
def scalaVersion = scalaVersion0
def scalaJSVersion = sjsVersion0
def pomSettings = PomSettings(
@@ -35,7 +39,7 @@ object HelloJSWorld extends TestUtil.BaseModule {
url = "https://github.com/lihaoyi/hello-world-publish",
licenses = Seq(
License("Apache License, Version 2.0",
- "http://www.apache.org/licenses/LICENSE-2.0")),
+ "http://www.apache.org/licenses/LICENSE-2.0")),
scm = SCM(
"https://github.com/lihaoyi/hello-world-publish",
"scm:git:https://github.com/lihaoyi/hello-world-publish"
@@ -44,9 +48,7 @@ object HelloJSWorld extends TestUtil.BaseModule {
Seq(Developer("lihaoyi", "Li Haoyi", "https://github.com/lihaoyi"))
)
}
-}
-
-object HelloJSWorldTests extends TestSuite {
+ }
val srcPath = pwd / 'scalajslib / 'src / 'test / 'resources / "hello-js-world"
val workspacePath = pwd / 'target / 'workspace / "hello-js-world"
diff --git a/scalalib/src/test/scala/mill/scalalib/HelloWorldTests.scala b/scalalib/src/test/scala/mill/scalalib/HelloWorldTests.scala
index 0f525b38..657ddc9e 100644
--- a/scalalib/src/test/scala/mill/scalalib/HelloWorldTests.scala
+++ b/scalalib/src/test/scala/mill/scalalib/HelloWorldTests.scala
@@ -6,7 +6,6 @@ import ammonite.ops._
import ammonite.ops.ImplicitWd._
import mill._
import mill.define.Target
-
import mill.eval.{Evaluator, Result}
import mill.scalalib.publish._
import mill.util.{TestEvaluator, TestUtil}
@@ -15,66 +14,66 @@ import utest._
import scala.collection.JavaConverters._
-trait HelloWorldModule extends scalalib.Module {
- def scalaVersion = "2.12.4"
- def basePath = HelloWorldTests.workingSrcPath
-}
-object HelloWorld extends TestUtil.BaseModule with HelloWorldModule
-object CrossHelloWorld extends TestUtil.BaseModule {
- object cross extends Cross[HelloWorldCross]("2.10.6", "2.11.11", "2.12.3", "2.12.4")
- class HelloWorldCross(v: String) extends HelloWorldModule {
- def scalaVersion = v
+object HelloWorldTests extends TestSuite {
+ trait HelloWorldModule extends scalalib.Module {
+ def scalaVersion = "2.12.4"
+ def basePath = HelloWorldTests.workingSrcPath
}
-}
-object HelloWorldWithMain extends TestUtil.BaseModule with HelloWorldModule {
- def mainClass = Some("Main")
-}
+ object HelloWorld extends TestUtil.BaseModule with HelloWorldModule
+ object CrossHelloWorld extends TestUtil.BaseModule {
+ object cross extends Cross[HelloWorldCross]("2.10.6", "2.11.11", "2.12.3", "2.12.4")
+ class HelloWorldCross(v: String) extends HelloWorldModule {
+ def scalaVersion = v
+ }
+ }
-object HelloWorldWithMainAssembly extends TestUtil.BaseModule with HelloWorldModule {
- def mainClass = Some("Main")
- def assembly = T{
- mill.modules.Jvm.createAssembly(
- runClasspath().map(_.path).filter(exists),
- prependShellScript = prependShellScript(),
- mainClass = mainClass()
- )
+ object HelloWorldWithMain extends TestUtil.BaseModule with HelloWorldModule {
+ def mainClass = Some("Main")
}
-}
-object HelloWorldWarnUnused extends TestUtil.BaseModule with HelloWorldModule {
- def scalacOptions = T(Seq("-Ywarn-unused"))
-}
+ object HelloWorldWithMainAssembly extends TestUtil.BaseModule with HelloWorldModule {
+ def mainClass = Some("Main")
+ def assembly = T{
+ mill.modules.Jvm.createAssembly(
+ runClasspath().map(_.path).filter(exists),
+ prependShellScript = prependShellScript(),
+ mainClass = mainClass()
+ )
+ }
+ }
-object HelloWorldFatalWarnings extends TestUtil.BaseModule with HelloWorldModule {
- def scalacOptions = T(Seq("-Ywarn-unused", "-Xfatal-warnings"))
-}
+ object HelloWorldWarnUnused extends TestUtil.BaseModule with HelloWorldModule {
+ def scalacOptions = T(Seq("-Ywarn-unused"))
+ }
-object HelloWorldWithPublish extends TestUtil.BaseModule with HelloWorldModule with PublishModule {
- def artifactName = "hello-world"
- def publishVersion = "0.0.1"
-
- def pomSettings = PomSettings(
- organization = "com.lihaoyi",
- description = "hello world ready for real world publishing",
- url = "https://github.com/lihaoyi/hello-world-publish",
- licenses = Seq(
- License("Apache License, Version 2.0",
- "http://www.apache.org/licenses/LICENSE-2.0")),
- scm = SCM(
- "https://github.com/lihaoyi/hello-world-publish",
- "scm:git:https://github.com/lihaoyi/hello-world-publish"
- ),
- developers =
- Seq(Developer("lihaoyi", "Li Haoyi", "https://github.com/lihaoyi"))
- )
-}
-object HelloWorldScalaOverride extends TestUtil.BaseModule with HelloWorldModule {
- override def scalaVersion: Target[String] = "2.11.11"
-}
-object HelloWorldTests extends TestSuite {
+ object HelloWorldFatalWarnings extends TestUtil.BaseModule with HelloWorldModule {
+ def scalacOptions = T(Seq("-Ywarn-unused", "-Xfatal-warnings"))
+ }
+ object HelloWorldWithPublish extends TestUtil.BaseModule with HelloWorldModule with PublishModule {
+ def artifactName = "hello-world"
+ def publishVersion = "0.0.1"
+
+ def pomSettings = PomSettings(
+ organization = "com.lihaoyi",
+ description = "hello world ready for real world publishing",
+ url = "https://github.com/lihaoyi/hello-world-publish",
+ licenses = Seq(
+ License("Apache License, Version 2.0",
+ "http://www.apache.org/licenses/LICENSE-2.0")),
+ scm = SCM(
+ "https://github.com/lihaoyi/hello-world-publish",
+ "scm:git:https://github.com/lihaoyi/hello-world-publish"
+ ),
+ developers =
+ Seq(Developer("lihaoyi", "Li Haoyi", "https://github.com/lihaoyi"))
+ )
+ }
+ object HelloWorldScalaOverride extends TestUtil.BaseModule with HelloWorldModule {
+ override def scalaVersion: Target[String] = "2.11.11"
+ }
val srcPath = pwd / 'scalalib / 'src / 'test / 'resources / "hello-world"
val basePath = pwd / 'target / 'workspace / "hello-world"
val workingSrcPath = basePath / 'src