diff options
author | Li Haoyi <haoyi.sg@gmail.com> | 2018-01-14 12:55:05 -0800 |
---|---|---|
committer | Li Haoyi <haoyi.sg@gmail.com> | 2018-01-14 12:55:05 -0800 |
commit | fd9189b4d11756edceaef5f3269f6f02291d1a16 (patch) | |
tree | ea3406a3465fdf65095945f2a1fcaf63cefc43a7 /core/src/main/scala | |
parent | 785d3666a5d386d9a39573d1a24fa03da9a2cac0 (diff) | |
download | mill-fd9189b4d11756edceaef5f3269f6f02291d1a16.tar.gz mill-fd9189b4d11756edceaef5f3269f6f02291d1a16.tar.bz2 mill-fd9189b4d11756edceaef5f3269f6f02291d1a16.zip |
Fix GenIdea logic again...
Diffstat (limited to 'core/src/main/scala')
-rw-r--r-- | core/src/main/scala/mill/define/Cross.scala | 2 | ||||
-rw-r--r-- | core/src/main/scala/mill/define/Module.scala | 16 | ||||
-rw-r--r-- | core/src/main/scala/mill/main/MainRunner.scala | 2 | ||||
-rw-r--r-- | core/src/main/scala/mill/main/ReplApplyHandler.scala | 4 | ||||
-rw-r--r-- | core/src/main/scala/mill/main/Resolve.scala | 9 |
5 files changed, 19 insertions, 14 deletions
diff --git a/core/src/main/scala/mill/define/Cross.scala b/core/src/main/scala/mill/define/Cross.scala index 2975f97b..8bbf9bfd 100644 --- a/core/src/main/scala/mill/define/Cross.scala +++ b/core/src/main/scala/mill/define/Cross.scala @@ -20,7 +20,7 @@ object Cross{ yield q"v.productElement($n).asInstanceOf[${a.info}]" val instance = c.Expr[(Product, mill.define.Ctx) => T]( - q"{ (v, ctx0) => new $tpe(..$argTupleValues){ override def ctx = ctx0 } }" + q"{ (v, ctx0) => new $tpe(..$argTupleValues){ override def parentCtx = ctx0 } }" ) reify { mill.define.Cross.Factory[T](instance.splice) } diff --git a/core/src/main/scala/mill/define/Module.scala b/core/src/main/scala/mill/define/Module.scala index 77bc7e36..b690d7c2 100644 --- a/core/src/main/scala/mill/define/Module.scala +++ b/core/src/main/scala/mill/define/Module.scala @@ -14,14 +14,14 @@ import scala.reflect.macros.blackbox * instantiation site so they can capture the enclosing/line information of * the concrete instance. */ -class Module(implicit ctx0: mill.define.Ctx) extends mill.moduledefs.Cacher{ +class Module(implicit parentCtx0: mill.define.Ctx) extends mill.moduledefs.Cacher{ def traverse[T](f: Module => Seq[T]): Seq[T] = { def rec(m: Module): Seq[T] = f(m) ++ m.modules.flatMap(rec) rec(this) } - lazy val segmentsToModules = traverse{m => Seq(m.ctx.segments -> m)} + lazy val segmentsToModules = traverse{m => Seq(m.parentCtx.segments -> m)} .toMap lazy val modules = this.reflectNestedObjects[Module] @@ -31,22 +31,22 @@ class Module(implicit ctx0: mill.define.Ctx) extends mill.moduledefs.Cacher{ lazy val targets = segmentsToTargets.valuesIterator.toSet lazy val segmentsToCommands = traverse{ - m => m.reflectNames[Command[_]].map(c => m.ctx.segments ++ Seq(Segment.Label(c))) + m => m.reflectNames[Command[_]].map(c => m.parentCtx.segments ++ Seq(Segment.Label(c))) }.toSet - def ctx = ctx0 + def parentCtx = parentCtx0 // 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.enclosing - val millModuleLine = ctx.lineNum - def basePath: Path = ctx.basePath / (ctx.segment match{ + val millModuleEnclosing = parentCtx.enclosing + val millModuleLine = parentCtx.lineNum + def basePath: Path = parentCtx.basePath / (parentCtx.segment match{ case Segment.Label(s) => List(s) case Segment.Cross(vs) => vs.map(_.toString) }) implicit def millModuleBasePath: BasePath = BasePath(basePath) implicit def millModuleSegments: Segments = { - ctx.segments0 ++ Seq(ctx.segment) + parentCtx.segments0 ++ Seq(parentCtx.segment) } def reflect[T: ClassTag] = { this diff --git a/core/src/main/scala/mill/main/MainRunner.scala b/core/src/main/scala/mill/main/MainRunner.scala index 5dd451c2..70cc350c 100644 --- a/core/src/main/scala/mill/main/MainRunner.scala +++ b/core/src/main/scala/mill/main/MainRunner.scala @@ -98,7 +98,7 @@ class MainRunner(config: ammonite.main.Cli.Config, | // even if it does nothing... | def $$main() = Iterator[String]() | - | val millDiscover = mill.define.Discover[$wrapName] + | val millDiscover: mill.define.Discover = mill.define.Discover[this.type] | // 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) diff --git a/core/src/main/scala/mill/main/ReplApplyHandler.scala b/core/src/main/scala/mill/main/ReplApplyHandler.scala index 909f25f7..1dc5410b 100644 --- a/core/src/main/scala/mill/main/ReplApplyHandler.scala +++ b/core/src/main/scala/mill/main/ReplApplyHandler.scala @@ -70,7 +70,7 @@ class ReplApplyHandler(pprinter0: pprint.PPrinter, val millHandlers: PartialFunction[Any, pprint.Tree] = { case c: Cross[_] => pprint.Tree.Lazy( ctx => - Iterator(c.ctx.enclosing , ":", c.ctx.lineNum.toString, ctx.applyPrefixColor("\nChildren:").toString) ++ + Iterator(c.parentCtx.enclosing , ":", c.parentCtx.lineNum.toString, ctx.applyPrefixColor("\nChildren:").toString) ++ c.items.iterator.map(x => "\n (" + x._1.map(pprint.PPrinter.BlackWhite.apply(_)).mkString(", ") + ")" ) @@ -79,7 +79,7 @@ class ReplApplyHandler(pprinter0: pprint.PPrinter, pprint.Tree.Lazy( ctx => Iterator(m.millModuleEnclosing, ":", m.millModuleLine.toString) ++ (if (m.reflect[mill.Module].isEmpty) Nil - else ctx.applyPrefixColor("\nChildren:").toString +: m.reflect[mill.Module].map("\n ." + _.ctx.segments.render)) ++ + else ctx.applyPrefixColor("\nChildren:").toString +: m.reflect[mill.Module].map("\n ." + _.parentCtx.segments.render)) ++ (discover.value.get(m.getClass) match{ case None => Nil case Some(commands) => diff --git a/core/src/main/scala/mill/main/Resolve.scala b/core/src/main/scala/mill/main/Resolve.scala index aedcc619..b6f754d4 100644 --- a/core/src/main/scala/mill/main/Resolve.scala +++ b/core/src/main/scala/mill/main/Resolve.scala @@ -13,6 +13,9 @@ object Resolve { remainingCrossSelectors: List[List[String]], revSelectorsSoFar: List[Segment]): Either[String, Task[Any]] = { + pprint.log(discover.value.keySet) + pprint.log(obj.getClass) + pprint.log(remainingSelector) remainingSelector match{ case Segment.Cross(_) :: Nil => Left("Selector cannot start with a [cross] segment") case Segment.Label(last) :: Nil => @@ -23,6 +26,8 @@ object Resolve { .map(Right(_)) def invokeCommand[V](target: mill.Module, name: String) = { + pprint.log(target) + pprint.log(discover.value.get(target.getClass)) for(cmd <- discover.value.get(target.getClass).toSeq.flatten.find(_.name == name)) yield cmd.asInstanceOf[EntryPoint[mill.Module]].invoke(target, ammonite.main.Scripts.groupArgs(rest.toList)) match { case Router.Result.Success(v) => Right(v) @@ -32,7 +37,7 @@ object Resolve { val runDefault = for{ child <- obj.reflectNestedObjects[mill.Module] - if child.ctx.segment == Segment.Label(last) + if child.parentCtx.segment == Segment.Label(last) res <- child match{ case taskMod: TaskModule => Some(invokeCommand(child, taskMod.defaultCommandName())) case _ => None @@ -56,7 +61,7 @@ object Resolve { head match{ case Segment.Label(singleLabel) => obj.reflectNestedObjects[mill.Module].find{ - _.ctx.segment == Segment.Label(singleLabel) + _.parentCtx.segment == Segment.Label(singleLabel) } match{ case Some(child: mill.Module) => resolve(tail, child, discover, rest, remainingCrossSelectors, newRevSelectorsSoFar) case None => Left("Cannot resolve module " + Segments(newRevSelectorsSoFar.reverse:_*).render) |