summaryrefslogtreecommitdiff
path: root/core/src
diff options
context:
space:
mode:
authorLi Haoyi <haoyi.sg@gmail.com>2018-02-07 07:55:07 -0800
committerLi Haoyi <haoyi.sg@gmail.com>2018-02-07 09:16:47 -0800
commite381552b992a5ba4743fa54f5111db9a2e9d98e2 (patch)
tree394b6eace1d4e30f42c0790f31ed0b25cdcd17e5 /core/src
parent3ba213bc51e33a54787d3a1e758384dff8052c1e (diff)
downloadmill-e381552b992a5ba4743fa54f5111db9a2e9d98e2.tar.gz
mill-e381552b992a5ba4743fa54f5111db9a2e9d98e2.tar.bz2
mill-e381552b992a5ba4743fa54f5111db9a2e9d98e2.zip
attempt to fix publishAll
Diffstat (limited to 'core/src')
-rw-r--r--core/src/mill/define/BaseModule.scala18
-rw-r--r--core/src/mill/eval/Evaluator.scala2
-rw-r--r--core/src/mill/main/ReplApplyHandler.scala2
-rw-r--r--core/src/mill/main/Resolve.scala12
-rw-r--r--core/src/mill/main/RunScript.scala25
5 files changed, 41 insertions, 18 deletions
diff --git a/core/src/mill/define/BaseModule.scala b/core/src/mill/define/BaseModule.scala
index 5b804658..12a01e89 100644
--- a/core/src/mill/define/BaseModule.scala
+++ b/core/src/mill/define/BaseModule.scala
@@ -31,12 +31,7 @@ abstract class BaseModule(millSourcePath0: Path, external0: Boolean = false)
override implicit def millModuleBasePath: BasePath = BasePath(millSourcePath)
implicit def millImplicitBaseModule: BaseModule.Implicit = BaseModule.Implicit(this)
def millDiscover: Discover[this.type]
-// implicit def millScoptModuleReads[T <: mill.Module] = new mill.main.ModuleScopt[T, this.type](
-// this, millDiscover
-// )
- implicit def millScoptTargetReads[T] = new TargetScopt[T, this.type](
- this, millDiscover
- )
+ implicit def millScoptTargetReads[T] = new TargetScopt[T]()
}
@@ -55,10 +50,19 @@ abstract class ExternalModule(implicit millModuleEnclosing0: sourcecode.Enclosin
}
}
-class TargetScopt[T, M <: BaseModule](rootModule: M, d: => Discover[M])
+object TargetScopt{
+ // This needs to be a ThreadLocal because we need to pass it into the body of
+ // the TargetScopt#read call, which does not accept additional parameters.
+ // Until we migrate our CLI parsing off of Scopt (so we can pass the BaseModule
+ // in directly) we are forced to pass it in via a ThreadLocal
+ val currentRootModule = new ThreadLocal[BaseModule]
+}
+class TargetScopt[T]()
extends scopt.Read[Seq[mill.define.Target[T]]]{
def arity = 1
def reads = s => try{
+ val rootModule = TargetScopt.currentRootModule.get
+ val d = rootModule.millDiscover
val (expanded, Nil) = ParseArgs(Seq(s)).fold(e => throw new Exception(e), identity)
val resolved = expanded.map{
case (Some(scoping), segments) =>
diff --git a/core/src/mill/eval/Evaluator.scala b/core/src/mill/eval/Evaluator.scala
index 4afbe233..fe43d0a3 100644
--- a/core/src/mill/eval/Evaluator.scala
+++ b/core/src/mill/eval/Evaluator.scala
@@ -27,7 +27,7 @@ case class Labelled[T](task: NamedTask[T],
}
class Evaluator[T](val outPath: Path,
val externalOutPath: Path,
- val rootModule: mill.Module,
+ val rootModule: mill.define.BaseModule,
val discover: Discover[T],
log: Logger,
val classLoaderSig: Seq[(Path, Long)] = Evaluator.classLoaderSig){
diff --git a/core/src/mill/main/ReplApplyHandler.scala b/core/src/mill/main/ReplApplyHandler.scala
index 5a84c344..0849f2c8 100644
--- a/core/src/mill/main/ReplApplyHandler.scala
+++ b/core/src/mill/main/ReplApplyHandler.scala
@@ -11,7 +11,7 @@ import scala.collection.mutable
object ReplApplyHandler{
def apply[T](colors: ammonite.util.Colors,
pprinter0: pprint.PPrinter,
- rootModule: mill.Module,
+ rootModule: mill.define.BaseModule,
discover: Discover[_]) = {
new ReplApplyHandler(
pprinter0,
diff --git a/core/src/mill/main/Resolve.scala b/core/src/mill/main/Resolve.scala
index 589f2c52..7ecd4ac8 100644
--- a/core/src/mill/main/Resolve.scala
+++ b/core/src/mill/main/Resolve.scala
@@ -14,7 +14,6 @@ object Resolve {
remainingCrossSelectors: List[List[String]],
revSelectorsSoFar: List[Segment]): Either[String, Seq[Task[Any]]] = {
- pprint.log(remainingSelector)
remainingSelector match{
case Segment.Cross(_) :: Nil => Left("Selector cannot start with a [cross] segment")
case Segment.Label(last) :: Nil =>
@@ -70,7 +69,7 @@ object Resolve {
val newRevSelectorsSoFar = head :: revSelectorsSoFar
head match{
case Segment.Label(singleLabel) =>
- if (singleLabel == "_") {
+ if (singleLabel == "__") {
val matching =
obj.millInternal.modules
@@ -79,6 +78,15 @@ object Resolve {
if (matching.nonEmpty)Right(matching)
else Left("Cannot resolve module " + Segments(newRevSelectorsSoFar.reverse:_*).render)
+ } else if (singleLabel == "_") {
+
+ val matching =
+ obj.millModuleDirectChildren
+ .map(resolve(tail, _, discover, rest, remainingCrossSelectors, newRevSelectorsSoFar))
+ .collect{case Right(vs) => vs}.flatten
+
+ if (matching.nonEmpty)Right(matching)
+ else Left("Cannot resolve module " + Segments(newRevSelectorsSoFar.reverse:_*).render)
}else{
obj.millInternal.reflectNestedObjects[mill.Module].find{
diff --git a/core/src/mill/main/RunScript.scala b/core/src/mill/main/RunScript.scala
index fd969524..613d6441 100644
--- a/core/src/mill/main/RunScript.scala
+++ b/core/src/mill/main/RunScript.scala
@@ -76,7 +76,7 @@ object RunScript{
def evaluateMapping(wd: Path,
path: Path,
- interp: ammonite.interp.Interpreter): Res[(mill.Module, Discover[Any])] = {
+ interp: ammonite.interp.Interpreter): Res[(mill.define.BaseModule, Discover[Any])] = {
val (pkg, wrapper) = Util.pathToPackageWrapper(Seq(), path relativeTo wd)
@@ -107,7 +107,7 @@ object RunScript{
Res.Success(
buildCls.getMethod("millSelf")
.invoke(null)
- .asInstanceOf[Some[mill.Module]]
+ .asInstanceOf[Some[mill.define.BaseModule]]
.get
)
}
@@ -149,11 +149,22 @@ object RunScript{
case Segment.Cross(x) => x.toList.map(_.toString)
case _ => Nil
}
- mill.main.Resolve.resolve(
- sel.value.toList, rootModule,
- discover,
- args, crossSelectors.toList, Nil
- )
+
+ try {
+ // We inject the `evaluator.rootModule` into the TargetScopt, rather
+ // than the `rootModule`, because even if you are running an external
+ // module we still want you to be able to resolve targets from your
+ // main build. Resolving targets from external builds as CLI arguments
+ // is not currently supported
+ mill.define.TargetScopt.currentRootModule.set(evaluator.rootModule)
+ mill.main.Resolve.resolve(
+ sel.value.toList, rootModule,
+ discover,
+ args, crossSelectors.toList, Nil
+ )
+ } finally{
+ mill.define.TargetScopt.currentRootModule.set(null)
+ }
}
EitherOps.sequence(selected)
}