diff options
author | Li Haoyi <haoyi.sg@gmail.com> | 2017-12-29 01:59:51 -0800 |
---|---|---|
committer | Li Haoyi <haoyi.sg@gmail.com> | 2017-12-29 01:59:51 -0800 |
commit | 23cef1eccce3030166a6731823fc78d67b345261 (patch) | |
tree | c4042dd49359ebc74428730c0bbecefca5af416e /core/src | |
parent | 7250a28ac4c14f57cfdbaff1339bfcefca5f0525 (diff) | |
download | mill-23cef1eccce3030166a6731823fc78d67b345261.tar.gz mill-23cef1eccce3030166a6731823fc78d67b345261.tar.bz2 mill-23cef1eccce3030166a6731823fc78d67b345261.zip |
Kill old `LabelledTarget` classes
Diffstat (limited to 'core/src')
-rw-r--r-- | core/src/main/scala/mill/discover/Discovered.scala | 53 | ||||
-rw-r--r-- | core/src/main/scala/mill/discover/Mirror.scala | 30 | ||||
-rw-r--r-- | core/src/main/scala/mill/eval/Evaluator.scala | 17 | ||||
-rw-r--r-- | core/src/main/scala/mill/main/RunScript.scala | 2 | ||||
-rw-r--r-- | core/src/test/scala/mill/define/GraphTests.scala | 2 | ||||
-rw-r--r-- | core/src/test/scala/mill/discover/CrossModuleTests.scala | 25 | ||||
-rw-r--r-- | core/src/test/scala/mill/discover/DiscoveredTests.scala | 10 | ||||
-rw-r--r-- | core/src/test/scala/mill/discover/LabelingTests.scala | 2 | ||||
-rw-r--r-- | core/src/test/scala/mill/eval/JavaCompileJarTests.scala | 4 | ||||
-rw-r--r-- | core/src/test/scala/mill/util/TestGraphs.scala | 15 |
10 files changed, 65 insertions, 95 deletions
diff --git a/core/src/main/scala/mill/discover/Discovered.scala b/core/src/main/scala/mill/discover/Discovered.scala index 8824a341..6e819d75 100644 --- a/core/src/main/scala/mill/discover/Discovered.scala +++ b/core/src/main/scala/mill/discover/Discovered.scala @@ -2,9 +2,8 @@ package mill.discover import mill.define.Task.Module import mill.define.{Cross, Target, Task} -import mill.discover.Mirror.LabelledTarget import ammonite.main.Router -import ammonite.main.Router.{EntryPoint, Result} +import mill.discover.Mirror.{Segment, TargetPoint} import mill.util.Ctx.Loader import scala.language.experimental.macros @@ -14,16 +13,7 @@ import scala.reflect.macros.blackbox.Context * Allows you to implicitly summon up a build [[Mirror]] for arbitrary types */ class Discovered[T](val mirror: Mirror[T, T]){ - def targets(obj: T) = Mirror.traverse(obj, mirror) { (h, p) => - h.labelled(obj, p) - } - def mapping(t: T) = { - Discovered.Mapping( - targets(t).map(x => x.target -> x).toMap[Task[Any], LabelledTarget[_]], - mirror, - t - ) - } + def mapping(t: T) = Discovered.Mapping(mirror, t) } object Discovered { @@ -31,17 +21,36 @@ object Discovered { // Magically injected by the `Evaluator`, rather than being constructed here def make() = ??? } - case class Mapping[T](value: Map[Task[Any], LabelledTarget[_]], - mirror: Mirror[T, T], - base: T) + case class Mapping[T](mirror: Mirror[T, T], + base: T){ + val modules = Mirror.traverse(base, mirror){ (mirror, segmentsRev) => + val resolvedNode = mirror.node( + base, + segmentsRev.reverse.map{case Mirror.Segment.Cross(vs) => vs.toList case _ => Nil}.toList + ) + Seq(resolvedNode -> segmentsRev.reverse) + }.toMap + val targets = Mirror.traverse(base, mirror){ (mirror, segmentsRev) => + val resolvedNode = mirror.node( + base, + segmentsRev.reverse.map{case Mirror.Segment.Cross(vs) => vs.toList case _ => Nil}.toList + ) + for(target <- mirror.targets) yield { + + target.asInstanceOf[TargetPoint[Any, Any]].run(resolvedNode) -> (segmentsRev.reverse :+ Segment.Label(target.label)) + } + + }.toMap + + } def consistencyCheck[T](mapping: Discovered.Mapping[T]) = { - val d = new Discovered(mapping.mirror) - val inconsistent = for{ - (t1, t2) <- d.targets(mapping.base).zip(d.targets(mapping.base)) - if t1.target ne t2.target - } yield t1.segments - inconsistent + val mapping2 = Discovered.Mapping(mapping.mirror, mapping.base) + + for{ + (t1, t2) <- mapping2.targets.zip(mapping.targets) + if t1._1 ne t2._1 + } yield t1._2 } @@ -70,7 +79,7 @@ object Discovered { m.isPublic } yield { val x = Ident(TermName(c.freshName())) - val t = q"""mill.discover.Mirror.makeTargetPoint( + val t = q"""mill.discover.Mirror.TargetPoint( ${m.name.toString}, ($x: ${m.typeSignature.resultType}) => $x.${m.name.toTermName} )""" diff --git a/core/src/main/scala/mill/discover/Mirror.scala b/core/src/main/scala/mill/discover/Mirror.scala index 7fa9736b..42339fd7 100644 --- a/core/src/main/scala/mill/discover/Mirror.scala +++ b/core/src/main/scala/mill/discover/Mirror.scala @@ -17,12 +17,7 @@ case class Mirror[-T, V](node: (T, List[List[Any]]) => V, commands: Seq[EntryPoint[V]], targets: Seq[Mirror.TargetPoint[V, _]], children: List[(String, Mirror[T, _])], - crossChildren: Option[(V => List[List[Any]], Mirror[T, _])]){ - def labelled(obj: T, p: Seq[Mirror.Segment]) = { - val crossValues = p.map{case Mirror.Segment.Cross(vs) => vs case _ => Nil}.toList - targets.map(t => t.labelled(node(obj, crossValues.reverse.map(_.toList)), p.reverse)) - } -} + crossChildren: Option[(V => List[List[Any]], Mirror[T, _])]) object Mirror{ def renderSelector(selector: Seq[Mirror.Segment]) = { @@ -58,29 +53,8 @@ object Mirror{ /** - * A target after being materialized in a concrete build - */ - case class LabelledTarget[V](target: Task[V], - format: upickle.default.ReadWriter[V], - segments: Seq[Segment]) - - /** * Represents metadata about a particular target, before the target is * materialized for a concrete build */ - case class TargetPoint[T, V](label: String, - format: upickle.default.ReadWriter[V], - run: T => Target[V]) { - def labelled(t: T, segments: Seq[Segment]) = { - LabelledTarget(run(t), format, segments :+ Segment.Label(label)) - } - } - - def makeTargetPoint[T, V](label: String, func: T => Target[V]) - (implicit f1: upickle.default.Reader[V], - f2: upickle.default.Writer[V]) = { - - val f = upickle.default.ReadWriter(f2.write, f1.read) - TargetPoint(label, f, func) - } + case class TargetPoint[T, V](label: String, run: T => Target[V]) } diff --git a/core/src/main/scala/mill/eval/Evaluator.scala b/core/src/main/scala/mill/eval/Evaluator.scala index 130dbcbc..110747a1 100644 --- a/core/src/main/scala/mill/eval/Evaluator.scala +++ b/core/src/main/scala/mill/eval/Evaluator.scala @@ -6,7 +6,7 @@ import ammonite.ops._ import ammonite.runtime.SpecialClassLoader import mill.define._ import mill.discover.{Discovered, Mirror} -import mill.discover.Mirror.{LabelledTarget, Segment} +import mill.discover.Mirror.Segment import mill.util import mill.util._ @@ -20,31 +20,23 @@ class Evaluator[T](val workspacePath: Path, val classLoaderSig: Seq[(Path, Long)] = Evaluator.classLoaderSig){ - val moduleMapping = Mirror.traverse(mapping.base, mapping.mirror){ (mirror, segmentsRev) => - val resolvedNode = mirror.node( - mapping.base, - segmentsRev.reverse.map{case Mirror.Segment.Cross(vs) => vs.toList case _ => Nil}.toList - ) - Seq(resolvedNode -> segmentsRev.reverse) - }.toMap val workerCache = mutable.Map.empty[Ctx.Loader[_], Any] workerCache(Discovered.Mapping) = mapping def evaluate(goals: OSet[Task[_]]): Evaluator.Results = { mkdir(workspacePath) - LabelledTarget val transitive = Graph.transitiveTargets(goals) val topoSorted = Graph.topoSorted(transitive) val sortedGroups = Graph.groupAroundImportantTargets(topoSorted){ - case t: NamedTask[Any] if moduleMapping.contains(t.owner) => + case t: NamedTask[Any] if mapping.modules.contains(t.owner) => Right(Labelled( t, t match{ case t: Target[Any] => Some(t.readWrite.asInstanceOf[upickle.default.ReadWriter[Any]]) case _ => None }, - moduleMapping(t.owner) :+ Segment.Label(t.name) + mapping.modules(t.owner) :+ Segment.Label(t.name) )) case t if goals.contains(t) => Left(t) } @@ -224,9 +216,6 @@ class Evaluator[T](val workspacePath: Path, object Evaluator{ - def resolveDestPaths(workspacePath: Path, t: LabelledTarget[_]): (Path, Path) = { - resolveDestPaths(workspacePath, t.segments) - } def resolveDestPaths(workspacePath: Path, t: Labelled[_]): (Path, Path) = { resolveDestPaths(workspacePath, t.segments) } diff --git a/core/src/main/scala/mill/main/RunScript.scala b/core/src/main/scala/mill/main/RunScript.scala index 3d41be2c..7ea96b2b 100644 --- a/core/src/main/scala/mill/main/RunScript.scala +++ b/core/src/main/scala/mill/main/RunScript.scala @@ -142,7 +142,7 @@ object RunScript{ val json = for(t <- Seq(target)) yield { t match { case t: mill.define.Target[_] => - for (segments <- evaluator.moduleMapping.get(t.owner)) yield { + for (segments <- evaluator.mapping.modules.get(t.owner)) yield { val jsonFile = Evaluator.resolveDestPaths(evaluator.workspacePath, segments :+ Segment.Label(t.name))._2 val metadata = upickle.json.read(jsonFile.toIO) metadata(1) diff --git a/core/src/test/scala/mill/define/GraphTests.scala b/core/src/test/scala/mill/define/GraphTests.scala index 9442f9ab..d17f125f 100644 --- a/core/src/test/scala/mill/define/GraphTests.scala +++ b/core/src/test/scala/mill/define/GraphTests.scala @@ -157,7 +157,7 @@ object GraphTests extends TestSuite{ Graph.transitiveTargets(OSet.from(goals)) ) val grouped = Graph.groupAroundImportantTargets(topoSorted) { - case t: Target[_] if mapping.value.contains(t) || goals.contains(t) => t + case t: NamedTask[Any] if mapping.modules.contains(t.owner) => t case t if goals.contains(t) => t } grouped.keyCount diff --git a/core/src/test/scala/mill/discover/CrossModuleTests.scala b/core/src/test/scala/mill/discover/CrossModuleTests.scala index 135d76e3..99d33800 100644 --- a/core/src/test/scala/mill/discover/CrossModuleTests.scala +++ b/core/src/test/scala/mill/discover/CrossModuleTests.scala @@ -2,7 +2,7 @@ package mill.discover import mill.{Module, T} import mill.define.Cross -import mill.discover.Mirror.{LabelledTarget, Segment} +import mill.discover.Mirror.Segment import mill.discover.Mirror.Segment.Label import mill.util.TestUtil.test import utest._ @@ -75,17 +75,17 @@ object CrossModuleTests extends TestSuite{ } 'crossTargetDiscovery - { - val discovered = Discovered.make[singleCross.type].targets(singleCross) + val discovered = Discovered.mapping(singleCross) - val segments = discovered.map(_.segments) - val expectedSegments = List( + val segments = discovered.targets.values.toSet + val expectedSegments = Set( List(Label("cross"), Segment.Cross(List("210")), Label("suffix")), List(Label("cross"), Segment.Cross(List("211")), Label("suffix")), List(Label("cross"), Segment.Cross(List("212")), Label("suffix")) ) assert(segments == expectedSegments) - val targets = discovered.map(_.target) - val expected = List( + val targets = discovered.targets.keys.toSet + val expected = Set( singleCross.cross("210").suffix, singleCross.cross("211").suffix, singleCross.cross("212").suffix @@ -94,25 +94,24 @@ object CrossModuleTests extends TestSuite{ } 'doubleCrossTargetDiscovery - { - val discovered = Discovered.make[doubleCross.type] - val targets = discovered.targets(doubleCross).map(_.target) + val discovered = Discovered.mapping(doubleCross) + val targets = discovered.targets.keys.toSet - val expected = List( + val expected = Set( doubleCross.cross("jvm", "210").suffix, doubleCross.cross("js", "210").suffix, doubleCross.cross("jvm", "211").suffix, doubleCross.cross("js", "211").suffix, doubleCross.cross("jvm", "212").suffix, doubleCross.cross("js", "212").suffix, - doubleCross.cross("native", "212").suffix, - + doubleCross.cross("native", "212").suffix ) assert(targets == expected) } 'nestedCrosses - { - val discovered = Discovered.make[nestedCrosses.type].targets(nestedCrosses) - assert(discovered.length == 9) + val discovered = Discovered.mapping(nestedCrosses).targets + assert(discovered.size == 9) } } } diff --git a/core/src/test/scala/mill/discover/DiscoveredTests.scala b/core/src/test/scala/mill/discover/DiscoveredTests.scala index 31d6119e..b2d14080 100644 --- a/core/src/test/scala/mill/discover/DiscoveredTests.scala +++ b/core/src/test/scala/mill/discover/DiscoveredTests.scala @@ -12,7 +12,7 @@ object DiscoveredTests extends TestSuite{ val tests = Tests{ 'targets - { - val discovered = Discovered.make[nestedModule.type] + val discovered = Discovered.mapping(nestedModule) def flatten(h: Mirror[nestedModule.type, _]): Seq[Any] = { h.node(nestedModule, Nil) :: h.children.flatMap{case (label, c) => flatten(c)} @@ -26,7 +26,7 @@ object DiscoveredTests extends TestSuite{ ) assert(flattenedHierarchy == expectedHierarchy) - val mapped = discovered.targets(nestedModule).map(x => x.segments -> x.target) + val mapped = discovered.targets.map(_.swap) val expected = Seq( (List(Label("classInstance"), Label("single")), nestedModule.classInstance.single), @@ -37,9 +37,9 @@ object DiscoveredTests extends TestSuite{ } 'traitWithModule - { - val discovered = Discovered.make[TraitWithModuleObject.type] - val mapped = discovered.targets(TraitWithModuleObject).map(x => x.segments -> x.target) - val expected = Seq( + val discovered = Discovered.mapping(TraitWithModuleObject) + val mapped = discovered.targets.map(_.swap) + val expected = Map( ( List(Label("TraitModule"), Label("testFramework")), TraitWithModuleObject.TraitModule.testFramework diff --git a/core/src/test/scala/mill/discover/LabelingTests.scala b/core/src/test/scala/mill/discover/LabelingTests.scala index fa417373..71c6a6bf 100644 --- a/core/src/test/scala/mill/discover/LabelingTests.scala +++ b/core/src/test/scala/mill/discover/LabelingTests.scala @@ -16,7 +16,7 @@ object LabelingTests extends TestSuite{ def check(mapping: Discovered.Mapping[_], t: Task[_], relPath: Option[String]) = { - val names: Seq[(Task[_], Seq[Mirror.Segment])] = mapping.value.mapValues(_.segments).toSeq + val names: Seq[(Task[_], Seq[Mirror.Segment])] = mapping.targets.toSeq val nameMap = names.toMap val targetLabel = nameMap.get(t).map(_.map{case Label(v) => v}.mkString(".")) diff --git a/core/src/test/scala/mill/eval/JavaCompileJarTests.scala b/core/src/test/scala/mill/eval/JavaCompileJarTests.scala index 7587b3d9..2b5bcb58 100644 --- a/core/src/test/scala/mill/eval/JavaCompileJarTests.scala +++ b/core/src/test/scala/mill/eval/JavaCompileJarTests.scala @@ -58,7 +58,7 @@ object JavaCompileJarTests extends TestSuite{ Right(Tuple2( evaluated.rawValues(0).asInstanceOf[Result.Success[T]].value, evaluated.evaluated.collect{ - case t: Target[_] if mapping.value.contains(t) => t + case t: Target[_] if mapping.targets.contains(t) => t case t: mill.define.Command[_] => t }.size )) @@ -73,7 +73,7 @@ object JavaCompileJarTests extends TestSuite{ val evaluated = evaluator.evaluate(targets) .evaluated .flatMap(_.asTarget) - .filter(mapping.value.contains) + .filter(mapping.targets.contains) assert(evaluated == expected) } diff --git a/core/src/test/scala/mill/util/TestGraphs.scala b/core/src/test/scala/mill/util/TestGraphs.scala index 86d331bb..46ca9ff9 100644 --- a/core/src/test/scala/mill/util/TestGraphs.scala +++ b/core/src/test/scala/mill/util/TestGraphs.scala @@ -187,14 +187,13 @@ object TestGraphs{ } } object doubleCross{ - val cross = - for{ - scalaVersion <- mill.define.Cross("210", "211", "212") - platform <- mill.define.Cross("jvm", "js", "native") - if !(platform == "native" && scalaVersion != "212") - } yield new Module{ - def suffix = T{ scalaVersion + "_" + platform } - } + val cross = for{ + scalaVersion <- mill.define.Cross("210", "211", "212") + platform <- mill.define.Cross("jvm", "js", "native") + if !(platform == "native" && scalaVersion != "212") + } yield new Module{ + def suffix = T{ scalaVersion + "_" + platform } + } } object indirectNestedCrosses{ |