summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLi Haoyi <haoyi.sg@gmail.com>2018-01-14 12:55:05 -0800
committerLi Haoyi <haoyi.sg@gmail.com>2018-01-14 12:55:05 -0800
commitfd9189b4d11756edceaef5f3269f6f02291d1a16 (patch)
treeea3406a3465fdf65095945f2a1fcaf63cefc43a7
parent785d3666a5d386d9a39573d1a24fa03da9a2cac0 (diff)
downloadmill-fd9189b4d11756edceaef5f3269f6f02291d1a16.tar.gz
mill-fd9189b4d11756edceaef5f3269f6f02291d1a16.tar.bz2
mill-fd9189b4d11756edceaef5f3269f6f02291d1a16.zip
Fix GenIdea logic again...
-rw-r--r--core/src/main/scala/mill/define/Cross.scala2
-rw-r--r--core/src/main/scala/mill/define/Module.scala16
-rw-r--r--core/src/main/scala/mill/main/MainRunner.scala2
-rw-r--r--core/src/main/scala/mill/main/ReplApplyHandler.scala4
-rw-r--r--core/src/main/scala/mill/main/Resolve.scala9
-rw-r--r--scalalib/src/main/scala/mill/scalalib/GenIdea.scala46
6 files changed, 42 insertions, 37 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)
diff --git a/scalalib/src/main/scala/mill/scalalib/GenIdea.scala b/scalalib/src/main/scala/mill/scalalib/GenIdea.scala
index e4c6e701..2dd972d7 100644
--- a/scalalib/src/main/scala/mill/scalalib/GenIdea.scala
+++ b/scalalib/src/main/scala/mill/scalalib/GenIdea.scala
@@ -5,7 +5,7 @@ import mill.define.{Segment, Segments, Target}
import mill.eval.{Evaluator, PathRef, RootModuleLoader}
import mill.scalalib
import mill.util.Ctx.{LoaderCtx, LogCtx}
-import mill.util.PrintLogger
+import mill.util.{Loose, PrintLogger, Strict}
import mill.util.Strict.Agg
object GenIdea {
@@ -27,10 +27,10 @@ object GenIdea {
def xmlFileLayout[T](evaluator: Evaluator[T], rootModule: mill.Module): Seq[(RelPath, scala.xml.Node)] = {
- val modules = rootModule.modules.collect{case x: scalalib.Module => (x.ctx.segments, x)}.toSeq
+ val modules = rootModule.modules.collect{case x: scalalib.Module => (x.millModuleSegments, x)}.toSeq
val resolved = for((path, mod) <- modules) yield {
- val Seq(resolvedCp: Seq[PathRef], resolvedSrcs: Seq[PathRef]) =
+ val Seq(resolvedCp: Loose.Agg[PathRef], resolvedSrcs: Loose.Agg[PathRef]) =
evaluator.evaluate(Agg(mod.externalCompileDepClasspath, mod.externalCompileDepSources))
.values
@@ -68,8 +68,11 @@ object GenIdea {
}
val moduleFiles = resolved.map{ case (path, resolvedDeps, mod) =>
- val Seq(sourcesPathRef: PathRef, generatedSourcePathRefs: Seq[PathRef], allSourcesPathRefs: Seq[PathRef]) =
- evaluator.evaluate(Agg(mod.sources, mod.generatedSources, mod.allSources)).values
+ val Seq(
+ sourcesPathRef: Loose.Agg[PathRef],
+ generatedSourcePathRefs: Loose.Agg[PathRef],
+ allSourcesPathRefs: Loose.Agg[PathRef]
+ ) = evaluator.evaluate(Agg(mod.sources, mod.generatedSources, mod.allSources)).values
val generatedSourcePaths = generatedSourcePathRefs.map(_.path)
val normalSourcePaths = (allSourcesPathRefs.map(_.path).toSet -- generatedSourcePaths.toSet).toSeq
@@ -80,13 +83,11 @@ object GenIdea {
)
val elem = moduleXmlTemplate(
- sourcesPathRef.path,
- normalSourcePaths,
- generatedSourcePaths,
- Seq(paths.out),
- resolvedDeps.map(pathToLibName),
- for(m <- mod.projectDeps)
- yield moduleName(moduleLabels(m))
+ Strict.Agg.from(normalSourcePaths),
+ Strict.Agg.from(generatedSourcePaths),
+ Strict.Agg(paths.out),
+ Strict.Agg.from(resolvedDeps.map(pathToLibName)),
+ Strict.Agg.from(mod.projectDeps.map{m => moduleName(moduleLabels(m))}.distinct)
)
Tuple2(".idea_modules"/s"${moduleName(path)}.iml", elem)
}
@@ -151,29 +152,28 @@ object GenIdea {
</library>
</component>
}
- def moduleXmlTemplate(basePath: Path,
- normalSourcePaths: Seq[Path],
- generatedSourcePaths: Seq[Path],
- outputPaths: Seq[Path],
- libNames: Seq[String],
- depNames: Seq[String]) = {
+ def moduleXmlTemplate(normalSourcePaths: Strict.Agg[Path],
+ generatedSourcePaths: Strict.Agg[Path],
+ outputPaths: Strict.Agg[Path],
+ libNames: Strict.Agg[String],
+ depNames: Strict.Agg[String]) = {
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager">
{
- for(outputPath <- outputPaths)
+ for(outputPath <- outputPaths.toSeq)
yield <output url={"file://$MODULE_DIR$/" + relify(outputPath) + "/dest/classes"} />
}
<exclude-output />
{
- for (normalSourcePath <- normalSourcePaths)
+ for (normalSourcePath <- normalSourcePaths.toSeq)
yield
<content url={"file://$MODULE_DIR$/" + relify(normalSourcePath)}>
<sourceFolder url={"file://$MODULE_DIR$/" + relify(normalSourcePath)} isTestSource="false" />
</content>
}
{
- for (generatedSourcePath <- generatedSourcePaths)
+ for (generatedSourcePath <- generatedSourcePaths.toSeq)
yield
<content url={"file://$MODULE_DIR$/" + relify(generatedSourcePath)}>
<sourceFolder url={"file://$MODULE_DIR$/" + relify(generatedSourcePath)} isTestSource="false" generated="true" />
@@ -183,12 +183,12 @@ object GenIdea {
<orderEntry type="sourceFolder" forTests="false" />
{
- for(name <- libNames)
+ for(name <- libNames.toSeq)
yield <orderEntry type="library" name={name} level="project" />
}
{
- for(depName <- depNames)
+ for(depName <- depNames.toSeq)
yield <orderEntry type="module" module-name={depName} exported="" />
}
</component>