summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorLi Haoyi <haoyi.sg@gmail.com>2018-02-02 10:23:12 -0800
committerLi Haoyi <haoyi.sg@gmail.com>2018-02-02 10:23:12 -0800
commit4d79af93f907264a16abe3661ea417a268b0ef67 (patch)
tree54d2cfd7e7ba63121eb2f733733876249fe3838f /core
parentf1153f8fff92be3711fd238cd2c7c06ac2a7a5bc (diff)
downloadmill-4d79af93f907264a16abe3661ea417a268b0ef67.tar.gz
mill-4d79af93f907264a16abe3661ea417a268b0ef67.tar.bz2
mill-4d79af93f907264a16abe3661ea417a268b0ef67.zip
Move `ScalaWorkerApi`/`ScalaJSBridge` over to new `ExternalModule` class
Also add a simple unit to validate that you can use `ExternalModule`s as part of a build, and that the
Diffstat (limited to 'core')
-rw-r--r--core/src/mill/define/Module.scala17
-rw-r--r--core/test/src/mill/eval/ModuleTests.scala47
-rw-r--r--core/test/src/mill/util/TestEvaluator.scala8
-rw-r--r--core/test/src/mill/util/TestUtil.scala2
4 files changed, 67 insertions, 7 deletions
diff --git a/core/src/mill/define/Module.scala b/core/src/mill/define/Module.scala
index 09e8e974..11a98d95 100644
--- a/core/src/mill/define/Module.scala
+++ b/core/src/mill/define/Module.scala
@@ -95,10 +95,9 @@ object BaseModule{
class BaseModule(basePath0: Path)
(implicit millModuleEnclosing0: sourcecode.Enclosing,
millModuleLine0: sourcecode.Line,
- millName0: sourcecode.Name,
- overrides0: Overrides)
+ millName0: sourcecode.Name)
extends Module()(
- mill.define.Ctx.make(implicitly, implicitly, implicitly, BasePath(basePath0), Segments(), implicitly)
+ mill.define.Ctx.make(implicitly, implicitly, implicitly, BasePath(basePath0), Segments(), Overrides(0))
){
// A BaseModule should provide an empty Segments list to it's children, since
// it is the root of the module tree, and thus must not include it's own
@@ -107,4 +106,16 @@ class BaseModule(basePath0: Path)
override def basePath = millOuterCtx.basePath
override implicit def millModuleBasePath: BasePath = BasePath(basePath)
implicit def millImplicitBaseModule: BaseModule.Implicit = BaseModule.Implicit(this)
+}
+
+class ExternalModule(implicit millModuleEnclosing0: sourcecode.Enclosing,
+ millModuleLine0: sourcecode.Line,
+ millName0: sourcecode.Name) extends BaseModule(ammonite.ops.pwd){
+ assert(
+ !" #".exists(millModuleEnclosing0.value.contains(_)),
+ "External modules must be at a top-level static path, not " + millModuleEnclosing0.value
+ )
+ override implicit def millModuleSegments = {
+ Segments(millModuleEnclosing0.value.split('.').map(Segment.Label):_*)
+ }
} \ No newline at end of file
diff --git a/core/test/src/mill/eval/ModuleTests.scala b/core/test/src/mill/eval/ModuleTests.scala
new file mode 100644
index 00000000..110e8c79
--- /dev/null
+++ b/core/test/src/mill/eval/ModuleTests.scala
@@ -0,0 +1,47 @@
+package mill.eval
+
+import ammonite.ops._
+import mill.util.{TestEvaluator, TestUtil}
+import mill.T
+import mill.util.TestEvaluator.implicitDisover
+import utest._
+
+
+object ModuleTests extends TestSuite{
+ object ExternalModule extends mill.define.ExternalModule {
+ def x = T{13}
+ object inner extends mill.Module{
+ def y = T{17}
+ }
+ }
+ object Build extends TestUtil.BaseModule{
+ def z = T{ ExternalModule.x() + ExternalModule.inner.y() }
+ }
+ val tests = Tests {
+ 'externalModuleTargetsAreNamespacedByModulePackagePath - {
+ val check = new TestEvaluator(
+ Build,
+ pwd / 'target / 'workspace / "module-tests" / "externalModule",
+ pwd
+ )
+
+ val Right((30, 1)) = check.apply(Build.z)
+ val base = check.evaluator.workspacePath
+ assert(
+ read(base / 'z / "meta.json").contains("30"),
+ read(base / 'mill / 'eval / 'ModuleTests / 'ExternalModule / 'x / "meta.json").contains("13"),
+ read(base / 'mill / 'eval / 'ModuleTests / 'ExternalModule / 'inner / 'y / "meta.json").contains("17")
+ )
+ }
+ 'externalModuleMustBeGlobalStatic - {
+
+
+ object Build extends mill.define.ExternalModule {
+
+ def z = T{ ExternalModule.x() + ExternalModule.inner.y() }
+ }
+
+ intercept[java.lang.AssertionError]{ Build }
+ }
+ }
+}
diff --git a/core/test/src/mill/util/TestEvaluator.scala b/core/test/src/mill/util/TestEvaluator.scala
index 2301efe6..41830d48 100644
--- a/core/test/src/mill/util/TestEvaluator.scala
+++ b/core/test/src/mill/util/TestEvaluator.scala
@@ -9,10 +9,10 @@ import language.experimental.macros
object TestEvaluator{
implicit def implicitDisover[T]: Discover[T] = macro applyImpl[T]
}
-class TestEvaluator[T <: TestUtil.BaseModule](module: T,
- workspacePath: Path,
- basePath: Path)
- (implicit discover: Discover[T]){
+class TestEvaluator[T <: TestUtil.TestBuild](module: T,
+ workspacePath: Path,
+ basePath: Path)
+ (implicit discover: Discover[T]){
val evaluator = new Evaluator(workspacePath, basePath, module, discover, DummyLogger)
// val evaluator = new Evaluator(workspacePath, basePath, module, discover, new PrintLogger(true, ammonite.util.Colors.Default, System.out, System.out, System.err))
def apply[T](t: Task[T]): Either[Result.Failing, (T, Int)] = {
diff --git a/core/test/src/mill/util/TestUtil.scala b/core/test/src/mill/util/TestUtil.scala
index 1af12a74..3a025a91 100644
--- a/core/test/src/mill/util/TestUtil.scala
+++ b/core/test/src/mill/util/TestUtil.scala
@@ -8,11 +8,13 @@ import mill.util.Strict.Agg
import scala.collection.mutable
object TestUtil {
+ trait TestBuild extends mill.define.Module
class BaseModule(implicit millModuleEnclosing0: sourcecode.Enclosing,
millModuleLine0: sourcecode.Line,
millName0: sourcecode.Name,
overrides: Overrides)
extends mill.define.BaseModule(ammonite.ops.pwd / millModuleEnclosing0.value)
+ with TestBuild
object test{