summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLi Haoyi <haoyi.sg@gmail.com>2018-01-07 19:43:24 -0800
committerLi Haoyi <haoyi.sg@gmail.com>2018-01-07 19:43:24 -0800
commita30db9485048e8d6e260d5d506894bd6b41f1d72 (patch)
tree4fb50cc081a5db35b68fee5de9a5210763530a56
parentc5638405269326b7eb2fc0506131255ef4237750 (diff)
downloadmill-a30db9485048e8d6e260d5d506894bd6b41f1d72.tar.gz
mill-a30db9485048e8d6e260d5d506894bd6b41f1d72.tar.bz2
mill-a30db9485048e8d6e260d5d506894bd6b41f1d72.zip
Break out `Module.scala` from `Task.scala`
-rw-r--r--core/src/main/scala/mill/define/Module.scala42
-rw-r--r--core/src/main/scala/mill/define/Task.scala80
-rw-r--r--core/src/main/scala/mill/discover/Discovered.scala2
-rw-r--r--core/src/main/scala/mill/main/MainRunner.scala2
-rw-r--r--core/src/main/scala/mill/package.scala4
-rw-r--r--core/src/test/scala/mill/define/MacroErrorTests.scala2
-rw-r--r--core/src/test/scala/mill/util/TestUtil.scala2
-rw-r--r--scalalib/src/main/scala/mill/scalalib/Module.scala2
8 files changed, 70 insertions, 66 deletions
diff --git a/core/src/main/scala/mill/define/Module.scala b/core/src/main/scala/mill/define/Module.scala
new file mode 100644
index 00000000..b2e90a6e
--- /dev/null
+++ b/core/src/main/scala/mill/define/Module.scala
@@ -0,0 +1,42 @@
+package mill.define
+
+import ammonite.ops.Path
+
+case class BasePath(value: Path)
+/**
+ * `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 ctx: Module.Ctx) extends mill.moduledefs.Cacher{
+ // Ensure we do not propagate the implicit parameters as implicits within
+ // the body of any inheriting class/trait/objects, as it would screw up any
+ // one else trying to use sourcecode.{Enclosing,Line} to capture debug info
+ val millModuleEnclosing = ctx.millModuleEnclosing0
+ val millModuleLine = ctx.millModuleLine0
+ def basePath: Path = ctx.millModuleBasePath0.value / ctx.millName0.value
+ implicit def millModuleBasePath: BasePath = BasePath(basePath)
+}
+object Module{
+ case class Ctx(millModuleEnclosing0: sourcecode.Enclosing,
+ millModuleLine0: sourcecode.Line,
+ millName0: sourcecode.Name,
+ millModuleBasePath0: BasePath)
+ object Ctx{
+ implicit def make(implicit millModuleEnclosing0: sourcecode.Enclosing,
+ millModuleLine0: sourcecode.Line,
+ millName0: sourcecode.Name,
+ millModuleBasePath0: BasePath): Ctx = Ctx(
+ millModuleEnclosing0,
+ millModuleLine0,
+ millName0,
+ millModuleBasePath0
+ )
+ }
+}
+class BaseModule(basePath: Path)
+ (implicit millModuleEnclosing0: sourcecode.Enclosing,
+ millModuleLine0: sourcecode.Line,
+ millName0: sourcecode.Name)
+ extends Module()(Module.Ctx.make(implicitly, implicitly, implicitly, BasePath(basePath))) \ No newline at end of file
diff --git a/core/src/main/scala/mill/define/Task.scala b/core/src/main/scala/mill/define/Task.scala
index 0704c7c8..34e56907 100644
--- a/core/src/main/scala/mill/define/Task.scala
+++ b/core/src/main/scala/mill/define/Task.scala
@@ -1,7 +1,6 @@
package mill.define
import ammonite.main.Router.Overrides
-import ammonite.ops.Path
import mill.define.Applicative.Applyable
import mill.eval.{PathRef, Result}
import mill.util.Ctx
@@ -36,7 +35,7 @@ abstract class Task[+T] extends Task.Ops[T] with Applyable[Task, T]{
}
trait NamedTask[+T] extends Task[T]{
- def owner: Task.Module
+ def owner: Module
def name: String
def overrides: Int
}
@@ -55,7 +54,7 @@ object Target extends TargetGenerated with Applicative.Applyer[Task, Task, Resul
e: sourcecode.Enclosing,
l: sourcecode.Line,
n: sourcecode.Name,
- cl: Caller[mill.define.Task.Module],
+ cl: Caller[Module],
o: Overrides): Target[T] = macro targetImpl[T]
def targetImpl[T: c.WeakTypeTag](c: Context)
@@ -65,7 +64,7 @@ object Target extends TargetGenerated with Applicative.Applyer[Task, Task, Resul
e: c.Expr[sourcecode.Enclosing],
l: c.Expr[sourcecode.Line],
n: c.Expr[sourcecode.Name],
- cl: c.Expr[Caller[mill.define.Task.Module]],
+ cl: c.Expr[Caller[Module]],
o: c.Expr[Overrides]): c.Expr[Target[T]] = {
import c.universe._
val lhs = Applicative.impl0[Task, T, Ctx](c)(reify(Result.Success(t.splice)).tree)
@@ -90,7 +89,7 @@ object Target extends TargetGenerated with Applicative.Applyer[Task, Task, Resul
e: sourcecode.Enclosing,
l: sourcecode.Line,
n: sourcecode.Name,
- cl: Caller[mill.define.Task.Module],
+ cl: Caller[Module],
o: Overrides): Target[T] = macro targetResultImpl[T]
def targetResultImpl[T: c.WeakTypeTag](c: Context)
@@ -100,7 +99,7 @@ object Target extends TargetGenerated with Applicative.Applyer[Task, Task, Resul
e: c.Expr[sourcecode.Enclosing],
l: c.Expr[sourcecode.Line],
n: c.Expr[sourcecode.Name],
- cl: c.Expr[Caller[mill.define.Task.Module]],
+ cl: c.Expr[Caller[Module]],
o: c.Expr[Overrides]): c.Expr[Target[T]] = {
import c.universe._
mill.moduledefs.Cacher.impl0[Target[T]](c)(
@@ -124,7 +123,7 @@ object Target extends TargetGenerated with Applicative.Applyer[Task, Task, Resul
e: sourcecode.Enclosing,
l: sourcecode.Line,
n: sourcecode.Name,
- cl: Caller[mill.define.Task.Module],
+ cl: Caller[Module],
o: Overrides): Target[T] = macro targetTaskImpl[T]
def targetTaskImpl[T: c.WeakTypeTag](c: Context)
@@ -134,7 +133,7 @@ object Target extends TargetGenerated with Applicative.Applyer[Task, Task, Resul
e: c.Expr[sourcecode.Enclosing],
l: c.Expr[sourcecode.Line],
n: c.Expr[sourcecode.Name],
- cl: c.Expr[Caller[mill.define.Task.Module]],
+ cl: c.Expr[Caller[Module]],
o: c.Expr[Overrides]): c.Expr[Target[T]] = {
import c.universe._
mill.moduledefs.Cacher.impl0[Target[T]](c)(
@@ -156,7 +155,7 @@ object Target extends TargetGenerated with Applicative.Applyer[Task, Task, Resul
(implicit w: W[T],
e: sourcecode.Enclosing,
n: sourcecode.Name,
- cl: Caller[mill.define.Task.Module],
+ cl: Caller[Module],
o: Overrides): Command[T] = macro commandImpl[T]
def source(value: Result[ammonite.ops.Path])
@@ -165,7 +164,7 @@ object Target extends TargetGenerated with Applicative.Applyer[Task, Task, Resul
e: sourcecode.Enclosing,
l: sourcecode.Line,
n: sourcecode.Name,
- cl: Caller[mill.define.Task.Module],
+ cl: Caller[Module],
o: Overrides): Input[PathRef] = macro sourceImpl
def sourceImpl(c: Context)
@@ -175,7 +174,7 @@ object Target extends TargetGenerated with Applicative.Applyer[Task, Task, Resul
e: c.Expr[sourcecode.Enclosing],
l: c.Expr[sourcecode.Line],
n: c.Expr[sourcecode.Name],
- cl: c.Expr[Caller[mill.define.Task.Module]],
+ cl: c.Expr[Caller[Module]],
o: c.Expr[Overrides]): c.Expr[Input[PathRef]] = {
import c.universe._
val wrapped: c.Expr[Result[PathRef]] = reify(value.splice match{
@@ -203,7 +202,7 @@ object Target extends TargetGenerated with Applicative.Applyer[Task, Task, Resul
e: sourcecode.Enclosing,
l: sourcecode.Line,
n: sourcecode.Name,
- cl: Caller[mill.define.Task.Module],
+ cl: Caller[Module],
o: Overrides): Input[T] = macro inputImpl[T]
def inputImpl[T: c.WeakTypeTag](c: Context)
@@ -213,7 +212,7 @@ object Target extends TargetGenerated with Applicative.Applyer[Task, Task, Resul
e: c.Expr[sourcecode.Enclosing],
l: c.Expr[sourcecode.Line],
n: c.Expr[sourcecode.Name],
- cl: c.Expr[Caller[mill.define.Task.Module]],
+ cl: c.Expr[Caller[Module]],
o: c.Expr[Overrides]): c.Expr[Input[T]] = {
import c.universe._
@@ -233,7 +232,7 @@ object Target extends TargetGenerated with Applicative.Applyer[Task, Task, Resul
}
def command[T](t: Task[T])
- (implicit c: Caller[Task.Module],
+ (implicit c: Caller[Module],
e: sourcecode.Enclosing,
n: sourcecode.Name,
w: W[T],
@@ -244,7 +243,7 @@ object Target extends TargetGenerated with Applicative.Applyer[Task, Task, Resul
(w: c.Expr[W[T]],
e: c.Expr[sourcecode.Enclosing],
n: c.Expr[sourcecode.Name],
- cl: c.Expr[Caller[mill.define.Task.Module]],
+ cl: c.Expr[Caller[Module]],
o: c.Expr[Overrides]): c.Expr[Command[T]] = {
import c.universe._
reify(
@@ -266,7 +265,7 @@ object Target extends TargetGenerated with Applicative.Applyer[Task, Task, Resul
e: sourcecode.Enclosing,
l: sourcecode.Line,
n: sourcecode.Name,
- cl: Caller[mill.define.Task.Module],
+ cl: Caller[Module],
o: Overrides): Target[T] = macro persistentImpl[T]
def persistentImpl[T: c.WeakTypeTag](c: Context)
@@ -276,7 +275,7 @@ object Target extends TargetGenerated with Applicative.Applyer[Task, Task, Resul
e: c.Expr[sourcecode.Enclosing],
l: c.Expr[sourcecode.Line],
n: c.Expr[sourcecode.Name],
- cl: c.Expr[Caller[mill.define.Task.Module]],
+ cl: c.Expr[Caller[Module]],
o: c.Expr[Overrides]): c.Expr[Persistent[T]] = {
import c.universe._
@@ -322,7 +321,7 @@ object Caller {
class TargetImpl[+T](t: Task[T],
val enclosing: String,
val lineNum: Int,
- val owner: Task.Module,
+ val owner: Module,
val name: String,
val readWrite: RW[_],
val overrides: Int) extends Target[T] {
@@ -332,7 +331,7 @@ class TargetImpl[+T](t: Task[T],
}
class Command[+T](t: Task[T],
val enclosing: String,
- val owner: Task.Module,
+ val owner: Module,
val name: String,
val writer: W[_],
val overrides: Int) extends NamedTask[T] {
@@ -343,7 +342,7 @@ class Command[+T](t: Task[T],
class Persistent[+T](t: Task[T],
enclosing: String,
lineNum: Int,
- owner: Task.Module,
+ owner: Module,
name: String,
readWrite: RW[_],
overrides: Int)
@@ -354,7 +353,7 @@ class Persistent[+T](t: Task[T],
class Input[T](t: Task[T],
val enclosing: String,
val lineNum: Int,
- val owner: Task.Module,
+ val owner: Module,
val name: String,
val readWrite: RW[_],
val overrides: Int) extends Target[T]{
@@ -362,50 +361,13 @@ class Input[T](t: Task[T],
def evaluate(args: Ctx) = args[T](0)
override def sideHash = util.Random.nextInt()
}
-case class BasePath(value: Path)
+
object Task {
trait TaskModule extends Module {
def defaultCommandName(): String
}
- /**
- * `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 ctx: Module.Ctx) extends mill.moduledefs.Cacher{
- // Ensure we do not propagate the implicit parameters as implicits within
- // the body of any inheriting class/trait/objects, as it would screw up any
- // one else trying to use sourcecode.{Enclosing,Line} to capture debug info
- val millModuleEnclosing = ctx.millModuleEnclosing0
- val millModuleLine = ctx.millModuleLine0
- def basePath: Path = ctx.millModuleBasePath0.value / ctx.millName0.value
- implicit def millModuleBasePath: BasePath = BasePath(basePath)
- }
- object Module{
- case class Ctx(millModuleEnclosing0: sourcecode.Enclosing,
- millModuleLine0: sourcecode.Line,
- millName0: sourcecode.Name,
- millModuleBasePath0: BasePath)
- object Ctx{
- implicit def make(implicit millModuleEnclosing0: sourcecode.Enclosing,
- millModuleLine0: sourcecode.Line,
- millName0: sourcecode.Name,
- millModuleBasePath0: BasePath): Ctx = Ctx(
- millModuleEnclosing0,
- millModuleLine0,
- millName0,
- millModuleBasePath0
- )
- }
- }
- class BaseModule(basePath: Path)
- (implicit millModuleEnclosing0: sourcecode.Enclosing,
- millModuleLine0: sourcecode.Line,
- millName0: sourcecode.Name)
- extends Module()(Module.Ctx.make(implicitly, implicitly, implicitly, BasePath(basePath)))
class Task0[T](t: T) extends Task[T]{
lazy val t0 = t
diff --git a/core/src/main/scala/mill/discover/Discovered.scala b/core/src/main/scala/mill/discover/Discovered.scala
index 58e2c3bb..44584137 100644
--- a/core/src/main/scala/mill/discover/Discovered.scala
+++ b/core/src/main/scala/mill/discover/Discovered.scala
@@ -1,6 +1,6 @@
package mill.discover
-import mill.define.Task.Module
+import mill.define.Module
import mill.define.{Cross, Target, Task}
import ammonite.main.Router
import ammonite.main.Router.EntryPoint
diff --git a/core/src/main/scala/mill/main/MainRunner.scala b/core/src/main/scala/mill/main/MainRunner.scala
index 322795ea..2305c11e 100644
--- a/core/src/main/scala/mill/main/MainRunner.scala
+++ b/core/src/main/scala/mill/main/MainRunner.scala
@@ -90,7 +90,7 @@ class MainRunner(config: ammonite.main.Cli.Config,
|$imports
|import mill._
|
- |object $wrapName extends mill.define.Task.BaseModule(ammonite.ops.Path(${pprint.Util.literalize(config.wd.toString)})) with $wrapName{
+ |object $wrapName extends mill.define.BaseModule(ammonite.ops.Path(${pprint.Util.literalize(config.wd.toString)})) with $wrapName{
| // Make sure we don't include the `build` wrapper-object's name in
| // the `basePath`s of our build
| override def basePath = super.basePath / ammonite.ops.up
diff --git a/core/src/main/scala/mill/package.scala b/core/src/main/scala/mill/package.scala
index f833b82c..b5ab6429 100644
--- a/core/src/main/scala/mill/package.scala
+++ b/core/src/main/scala/mill/package.scala
@@ -5,8 +5,8 @@ package object mill extends JsonFormatters{
type T[T] = define.Target[T]
val PathRef = mill.eval.PathRef
type PathRef = mill.eval.PathRef
- type Module = define.Task.Module
- val Module = define.Task.Module
+ type Module = define.Module
+ val Module = define.Module
type CrossModule[T, V] = define.CrossModule[T, V]
type CrossModule2[T1, T2, V] = define.CrossModule2[T1, T2, V]
type CrossModule3[T1, T2, T3, V] = define.CrossModule3[T1, T2, T3, V]
diff --git a/core/src/test/scala/mill/define/MacroErrorTests.scala b/core/src/test/scala/mill/define/MacroErrorTests.scala
index 7c1bd3a1..90d4e65a 100644
--- a/core/src/test/scala/mill/define/MacroErrorTests.scala
+++ b/core/src/test/scala/mill/define/MacroErrorTests.scala
@@ -30,7 +30,7 @@ object MacroErrorTests extends TestSuite{
}
}
""")
- assert(e.msg.contains("required: mill.define.Task.Module"))
+ assert(e.msg.contains("required: mill.define.Module"))
}
'neg - {
diff --git a/core/src/test/scala/mill/util/TestUtil.scala b/core/src/test/scala/mill/util/TestUtil.scala
index 8cb1c375..8f5378cb 100644
--- a/core/src/test/scala/mill/util/TestUtil.scala
+++ b/core/src/test/scala/mill/util/TestUtil.scala
@@ -2,7 +2,7 @@ package mill.util
import ammonite.main.Router.Overrides
import ammonite.ops.Path
-import mill.define.Task.Module
+import mill.define.Module
import mill.define.{BasePath, Caller, Target, Task}
import mill.eval.Result
import utest.assert
diff --git a/scalalib/src/main/scala/mill/scalalib/Module.scala b/scalalib/src/main/scala/mill/scalalib/Module.scala
index 6cc47176..dbccbec1 100644
--- a/scalalib/src/main/scala/mill/scalalib/Module.scala
+++ b/scalalib/src/main/scala/mill/scalalib/Module.scala
@@ -4,7 +4,7 @@ package scalalib
import ammonite.ops._
import coursier.{Cache, MavenRepository, Repository}
import mill.define.Task
-import mill.define.Task.{Module, TaskModule}
+import mill.define.Task.TaskModule
import mill.eval.{PathRef, Result}
import mill.modules.Jvm
import mill.modules.Jvm.{createAssembly, createJar, interactiveSubprocess, subprocess}