diff options
author | Li Haoyi <haoyi.sg@gmail.com> | 2018-02-04 14:35:35 -0800 |
---|---|---|
committer | Li Haoyi <haoyi.sg@gmail.com> | 2018-02-04 15:00:58 -0800 |
commit | 7022254ac1b156a466baa45afea1bb723bd59929 (patch) | |
tree | 8bf0fa5bd42765d54ef0d4a9d915550f7586de2b /core | |
parent | f47697c1da18407374cf11372af36c4960d80576 (diff) | |
download | mill-7022254ac1b156a466baa45afea1bb723bd59929.tar.gz mill-7022254ac1b156a466baa45afea1bb723bd59929.tar.bz2 mill-7022254ac1b156a466baa45afea1bb723bd59929.zip |
allow Result.Failure to take a value
Diffstat (limited to 'core')
-rw-r--r-- | core/src/mill/eval/Evaluator.scala | 24 | ||||
-rw-r--r-- | core/src/mill/eval/Result.scala | 26 | ||||
-rw-r--r-- | core/src/mill/main/ReplApplyHandler.scala | 2 | ||||
-rw-r--r-- | core/src/mill/main/RunScript.scala | 2 | ||||
-rw-r--r-- | core/test/src/mill/util/TestEvaluator.scala | 6 | ||||
-rw-r--r-- | core/test/src/mill/util/TestUtil.scala | 6 |
6 files changed, 46 insertions, 20 deletions
diff --git a/core/src/mill/eval/Evaluator.scala b/core/src/mill/eval/Evaluator.scala index 3d6d253b..4afbe233 100644 --- a/core/src/mill/eval/Evaluator.scala +++ b/core/src/mill/eval/Evaluator.scala @@ -93,9 +93,12 @@ class Evaluator[T](val outPath: Path, } - val failing = new util.MultiBiMap.Mutable[Either[Task[_], Labelled[_]], Result.Failing] + val failing = new util.MultiBiMap.Mutable[Either[Task[_], Labelled[_]], Result.Failing[_]] for((k, vs) <- sortedGroups.items()){ - failing.addAll(k, vs.items.flatMap(results.get).collect{case f: Result.Failing => f}) + failing.addAll( + k, + vs.items.flatMap(results.get).collect{case f: Result.Failing[_] => f.map(_._1)} + ) } Evaluator.Results( goals.indexed.map(results(_).map(_._1)), @@ -177,6 +180,21 @@ class Evaluator[T](val outPath: Path, ) newResults(labelledNamedTask.task) match{ + case Result.Failure(_, Some((v, hashCode))) => + labelledNamedTask.task.asWorker match{ + case Some(w) => + workerCache(w.ctx.segments) = (inputsHash, v) + case None => + val terminalResult = labelledNamedTask + .writer + .asInstanceOf[Option[upickle.default.Writer[Any]]] + .map(_.write(v)) + + for(t <- terminalResult){ + write.over(paths.meta, upickle.default.write(inputsHash -> t, indent = 4)) + } + } + case Result.Success((v, hashCode)) => labelledNamedTask.task.asWorker match{ case Some(w) => @@ -335,7 +353,7 @@ object Evaluator{ case class Results(rawValues: Seq[Result[Any]], evaluated: Agg[Task[_]], transitive: Agg[Task[_]], - failing: MultiBiMap[Either[Task[_], Labelled[_]], Result.Failing], + failing: MultiBiMap[Either[Task[_], Labelled[_]], Result.Failing[_]], results: collection.Map[Task[_], Result[Any]]){ def values = rawValues.collect{case Result.Success(v) => v} } diff --git a/core/src/mill/eval/Result.scala b/core/src/mill/eval/Result.scala index f5293c8c..690c5d30 100644 --- a/core/src/mill/eval/Result.scala +++ b/core/src/mill/eval/Result.scala @@ -1,22 +1,28 @@ package mill.eval sealed trait Result[+T]{ - def map[V](f: T => V): Result[V] = this match{ - case Result.Success(v) => Result.Success(f(v)) - case f: Result.Failing => f - case Result.Skipped => Result.Skipped - } + def map[V](f: T => V): Result[V] } object Result{ implicit def create[T](t: => T): Result[T] = { try Success(t) catch { case e: Throwable => Exception(e, new OuterStack(new java.lang.Exception().getStackTrace)) } } - case class Success[T](value: T) extends Result[T] - case object Skipped extends Result[Nothing] - sealed trait Failing extends Result[Nothing] - case class Failure(msg: String) extends Failing - case class Exception(throwable: Throwable, outerStack: OuterStack) extends Failing + case class Success[T](value: T) extends Result[T]{ + def map[V](f: T => V) = Result.Success(f(value)) + } + case object Skipped extends Result[Nothing]{ + def map[V](f: Nothing => V) = this + } + sealed trait Failing[+T] extends Result[T]{ + def map[V](f: T => V): Failing[V] + } + case class Failure[T](msg: String, value: Option[T] = None) extends Failing[T]{ + def map[V](f: T => V) = Result.Failure(msg, value.map(f(_))) + } + case class Exception(throwable: Throwable, outerStack: OuterStack) extends Failing[Nothing]{ + def map[V](f: Nothing => V) = this + } class OuterStack(val value: Seq[StackTraceElement]){ override def hashCode() = value.hashCode() diff --git a/core/src/mill/main/ReplApplyHandler.scala b/core/src/mill/main/ReplApplyHandler.scala index 66f80630..33013e2d 100644 --- a/core/src/mill/main/ReplApplyHandler.scala +++ b/core/src/mill/main/ReplApplyHandler.scala @@ -51,7 +51,7 @@ class ReplApplyHandler(pprinter0: pprint.PPrinter, for(v <- vs){ v match{ - case Result.Failure(m) => msg.append(m + "\n") + case Result.Failure(m, _) => msg.append(m + "\n") case Result.Exception(t, outerStack) => msg.append( t.toString + diff --git a/core/src/mill/main/RunScript.scala b/core/src/mill/main/RunScript.scala index 4d74833e..fd969524 100644 --- a/core/src/mill/main/RunScript.scala +++ b/core/src/mill/main/RunScript.scala @@ -185,7 +185,7 @@ object RunScript{ case Result.Exception(t, outerStack) => t.toString + t.getStackTrace.dropRight(outerStack.value.length).map("\n " + _).mkString - case Result.Failure(t) => t + case Result.Failure(t, _) => t } s"$ks ${fss.mkString(", ")}" }).mkString("\n") diff --git a/core/test/src/mill/util/TestEvaluator.scala b/core/test/src/mill/util/TestEvaluator.scala index 3fdd7c63..92ce5b37 100644 --- a/core/test/src/mill/util/TestEvaluator.scala +++ b/core/test/src/mill/util/TestEvaluator.scala @@ -32,7 +32,7 @@ class TestEvaluator[T <: TestUtil.TestBuild](module: T) val logger = new PrintLogger(true, ammonite.util.Colors.Default, System.out, System.out, System.err) val evaluator = new Evaluator(outPath, TestEvaluator.externalOutPath, module, discover, logger) - def apply[T](t: Task[T]): Either[Result.Failing, (T, Int)] = { + def apply[T](t: Task[T]): Either[Result.Failing[T], (T, Int)] = { val evaluated = evaluator.evaluate(Agg(t)) if (evaluated.failing.keyCount == 0) { @@ -49,7 +49,9 @@ class TestEvaluator[T <: TestUtil.TestBuild](module: T) )) } else { Left( - evaluated.failing.lookupKey(evaluated.failing.keys().next).items.next()) + evaluated.failing.lookupKey(evaluated.failing.keys().next).items.next() + .asInstanceOf[Result.Failing[T]] + ) } } diff --git a/core/test/src/mill/util/TestUtil.scala b/core/test/src/mill/util/TestUtil.scala index 59ef74df..93ea5ad8 100644 --- a/core/test/src/mill/util/TestUtil.scala +++ b/core/test/src/mill/util/TestUtil.scala @@ -49,9 +49,9 @@ object TestUtil { var failure = Option.empty[String] var exception = Option.empty[Throwable] override def evaluate(args: Ctx) = { - failure.map(Result.Failure) orElse - exception.map(Result.Exception(_, new OuterStack(Nil))) getOrElse - Result.Success(counter + args.args.map(_.asInstanceOf[Int]).sum) + failure.map(Result.Failure(_)) orElse + exception.map(Result.Exception(_, new OuterStack(Nil))) getOrElse + Result.Success(counter + args.args.map(_.asInstanceOf[Int]).sum) } override def sideHash = counter + failure.hashCode() + exception.hashCode() } |