diff options
author | Li Haoyi <haoyi.sg@gmail.com> | 2018-01-15 12:16:15 -0800 |
---|---|---|
committer | Li Haoyi <haoyi.sg@gmail.com> | 2018-01-15 12:57:56 -0800 |
commit | 5e9d809c6eb566e8452bbe2f3a986f31c57e5438 (patch) | |
tree | 6e7c3bc9bee712d66a2575a4b8dfd18eae917b0a | |
parent | e5c313e12faf3ccf90aa7f69eb2eb16f8add782f (diff) | |
download | mill-5e9d809c6eb566e8452bbe2f3a986f31c57e5438.tar.gz mill-5e9d809c6eb566e8452bbe2f3a986f31c57e5438.tar.bz2 mill-5e9d809c6eb566e8452bbe2f3a986f31c57e5438.zip |
- Collapse `Ctx#segments` and `Ctx#segments0` into one field, instead doing the prefix-stripping up-front in `BaseModule`
-rw-r--r-- | build.sbt | 5 | ||||
-rw-r--r-- | core/src/main/scala/mill/define/Cross.scala | 2 | ||||
-rw-r--r-- | core/src/main/scala/mill/define/Ctx.scala | 7 | ||||
-rw-r--r-- | core/src/main/scala/mill/define/Module.scala | 15 | ||||
-rw-r--r-- | core/src/main/scala/mill/define/Task.scala | 6 | ||||
-rw-r--r-- | core/src/test/scala/mill/define/BasePathTests.scala | 26 | ||||
-rw-r--r-- | core/src/test/scala/mill/util/TestUtil.scala | 14 | ||||
-rw-r--r-- | scalajslib/src/test/scala/mill/scalajslib/HelloJSWorldTests.scala | 6 |
8 files changed, 41 insertions, 40 deletions
@@ -14,7 +14,10 @@ val sharedSettings = Seq( resolvers += Resolver.sonatypeRepo("releases"), scalacOptions += "-P:acyclic:force", autoCompilerPlugins := true, - addCompilerPlugin("com.lihaoyi" %% "acyclic" % "0.1.7") + addCompilerPlugin("com.lihaoyi" %% "acyclic" % "0.1.7"), + + libraryDependencies += "com.lihaoyi" % "ammonite" % "1.0.3-21-05b5d32" cross CrossVersion.full, + mainClass in Test := Some("ammonite.Main") ) diff --git a/core/src/main/scala/mill/define/Cross.scala b/core/src/main/scala/mill/define/Cross.scala index 8af8e2e3..0d799f19 100644 --- a/core/src/main/scala/mill/define/Cross.scala +++ b/core/src/main/scala/mill/define/Cross.scala @@ -63,7 +63,7 @@ class Cross[T](cases: Any*) val sub = ci.make( c, ctx.copy( - segments0 = ctx.segments0 ++ Seq(ctx.segment), + segments = ctx.segments ++ Seq(ctx.segment), basePath = ctx.basePath / relPath, segment = Segment.Cross(crossValues) ) diff --git a/core/src/main/scala/mill/define/Ctx.scala b/core/src/main/scala/mill/define/Ctx.scala index fc8bf85a..308c50ef 100644 --- a/core/src/main/scala/mill/define/Ctx.scala +++ b/core/src/main/scala/mill/define/Ctx.scala @@ -41,10 +41,9 @@ case class Ctx(enclosing: String, lineNum: Int, segment: Segment, basePath: Path, - segments0: Segments, - overrides: Int){ - def segments = Segments(segments0.value.drop(1):_*) -} + segments: Segments, + overrides: Int) + object Ctx{ implicit def make(implicit millModuleEnclosing0: sourcecode.Enclosing, millModuleLine0: sourcecode.Line, diff --git a/core/src/main/scala/mill/define/Module.scala b/core/src/main/scala/mill/define/Module.scala index 3d3bb87c..f7c84b6d 100644 --- a/core/src/main/scala/mill/define/Module.scala +++ b/core/src/main/scala/mill/define/Module.scala @@ -30,7 +30,7 @@ class Module(implicit outerCtx0: mill.define.Ctx) extends mill.moduledefs.Cacher }) implicit def millModuleBasePath: BasePath = BasePath(basePath) implicit def millModuleSegments: Segments = { - millOuterCtx.segments0 ++ Seq(millOuterCtx.segment) + millOuterCtx.segments ++ Seq(millOuterCtx.segment) } } @@ -90,11 +90,18 @@ trait TaskModule extends Module { def defaultCommandName(): String } -class BaseModule(basePath: Path) +class BaseModule(basePath0: Path) (implicit millModuleEnclosing0: sourcecode.Enclosing, millModuleLine0: sourcecode.Line, millName0: sourcecode.Name, overrides0: Overrides) extends Module()( - mill.define.Ctx.make(implicitly, implicitly, implicitly, BasePath(basePath), Segments(), implicitly) - )
\ No newline at end of file + mill.define.Ctx.make(implicitly, implicitly, implicitly, BasePath(basePath0), Segments(), implicitly) + ){ + // A BaseModule should provide an empty Segments list to it's children, since + // it is the root of the module tree, and thus must not include it's own + // sourcecode.Name as part of the list, + override implicit def millModuleSegments: Segments = Segments() + override implicit def millModuleBasePath: BasePath = BasePath(millOuterCtx.basePath) + override def basePath = millOuterCtx.basePath +}
\ No newline at end of file diff --git a/core/src/main/scala/mill/define/Task.scala b/core/src/main/scala/mill/define/Task.scala index c0892743..90908e4e 100644 --- a/core/src/main/scala/mill/define/Task.scala +++ b/core/src/main/scala/mill/define/Task.scala @@ -229,7 +229,7 @@ object Caller { class TargetImpl[+T](t: Task[T], ctx0: mill.define.Ctx, val readWrite: RW[_]) extends Target[T] { - val ctx = ctx0.copy(segments0 = ctx0.segments0 ++ Seq(ctx0.segment)) + val ctx = ctx0.copy(segments = ctx0.segments ++ Seq(ctx0.segment)) val inputs = Seq(t) def evaluate(args: mill.util.Ctx) = args[T](0) override def toString = ctx.enclosing + "@" + Integer.toHexString(System.identityHashCode(this)) @@ -237,7 +237,7 @@ class TargetImpl[+T](t: Task[T], class Command[+T](t: Task[T], ctx0: mill.define.Ctx, val writer: W[_]) extends NamedTask[T] { - val ctx = ctx0.copy(segments0 = ctx0.segments0 ++ Seq(ctx0.segment)) + val ctx = ctx0.copy(segments = ctx0.segments ++ Seq(ctx0.segment)) val inputs = Seq(t) def evaluate(args: mill.util.Ctx) = args[T](0) override def asCommand = Some(this) @@ -253,7 +253,7 @@ class Persistent[+T](t: Task[T], class Input[T](t: Task[T], ctx0: mill.define.Ctx, val readWrite: RW[_]) extends Target[T]{ - val ctx = ctx0.copy(segments0 = ctx0.segments0 ++ Seq(ctx0.segment)) + val ctx = ctx0.copy(segments = ctx0.segments ++ Seq(ctx0.segment)) val inputs = Seq(t) def evaluate(args: mill.util.Ctx) = args[T](0) override def sideHash = util.Random.nextInt() diff --git a/core/src/test/scala/mill/define/BasePathTests.scala b/core/src/test/scala/mill/define/BasePathTests.scala index 577b89c8..a0be4762 100644 --- a/core/src/test/scala/mill/define/BasePathTests.scala +++ b/core/src/test/scala/mill/define/BasePathTests.scala @@ -11,37 +11,37 @@ object BasePathTests extends TestSuite{ assert(remaining == segments) } 'singleton - { - check(testGraphs.singleton, "singleton") + check(testGraphs.singleton) } 'separateGroups - { - check(TestGraphs.triangleTask, "triangleTask") + check(TestGraphs.triangleTask) } 'TraitWithModuleObject - { check(TestGraphs.TraitWithModuleObject.TraitModule, - "TraitWithModuleObject", "TraitModule" + "TraitModule" ) } 'nestedModuleNested - { - check(TestGraphs.nestedModule.nested, "nestedModule", "nested") + check(TestGraphs.nestedModule.nested, "nested") } 'nestedModuleInstance - { - check(TestGraphs.nestedModule.classInstance, "nestedModule", "classInstance") + check(TestGraphs.nestedModule.classInstance, "classInstance") } 'singleCross - { - check(TestGraphs.singleCross.cross, "singleCross", "cross") - check(TestGraphs.singleCross.cross("210"), "singleCross", "cross", "210") - check(TestGraphs.singleCross.cross("211"), "singleCross", "cross", "211") + check(TestGraphs.singleCross.cross, "cross") + check(TestGraphs.singleCross.cross("210"), "cross", "210") + check(TestGraphs.singleCross.cross("211"), "cross", "211") } 'doubleCross - { - check(TestGraphs.doubleCross.cross, "doubleCross", "cross") - check(TestGraphs.doubleCross.cross("210", "jvm"), "doubleCross", "cross", "210", "jvm") - check(TestGraphs.doubleCross.cross("212", "js"), "doubleCross", "cross", "212", "js") + check(TestGraphs.doubleCross.cross, "cross") + check(TestGraphs.doubleCross.cross("210", "jvm"), "cross", "210", "jvm") + check(TestGraphs.doubleCross.cross("212", "js"), "cross", "212", "js") } 'nestedCrosses - { - check(TestGraphs.nestedCrosses.cross, "nestedCrosses", "cross") + check(TestGraphs.nestedCrosses.cross, "cross") check( TestGraphs.nestedCrosses.cross("210").cross2("js"), - "nestedCrosses", "cross", "210", "cross2", "js" + "cross", "210", "cross2", "js" ) } diff --git a/core/src/test/scala/mill/util/TestUtil.scala b/core/src/test/scala/mill/util/TestUtil.scala index c0985c97..1af12a74 100644 --- a/core/src/test/scala/mill/util/TestUtil.scala +++ b/core/src/test/scala/mill/util/TestUtil.scala @@ -12,16 +12,8 @@ object TestUtil { millModuleLine0: sourcecode.Line, millName0: sourcecode.Name, overrides: Overrides) - extends Module()( - mill.define.Ctx.make( - implicitly, - implicitly, - implicitly, - BasePath(ammonite.ops.pwd / millModuleEnclosing0.value), - Segments(), - implicitly - ) - ) + extends mill.define.BaseModule(ammonite.ops.pwd / millModuleEnclosing0.value) + object test{ def anon(inputs: Task[Int]*) = new Test(inputs) @@ -51,7 +43,7 @@ object TestUtil { val pure: Boolean) (implicit ctx0: mill.define.Ctx) extends Test(inputs) with Target[Int]{ - val ctx = ctx0.copy(segments0 = ctx0.segments0 ++ Seq(ctx0.segment)) + val ctx = ctx0.copy(segments = ctx0.segments ++ Seq(ctx0.segment)) val readWrite = upickle.default.IntRW diff --git a/scalajslib/src/test/scala/mill/scalajslib/HelloJSWorldTests.scala b/scalajslib/src/test/scala/mill/scalajslib/HelloJSWorldTests.scala index ca580d71..2094687b 100644 --- a/scalajslib/src/test/scala/mill/scalajslib/HelloJSWorldTests.scala +++ b/scalajslib/src/test/scala/mill/scalajslib/HelloJSWorldTests.scala @@ -24,13 +24,13 @@ object HelloJSWorldTests extends TestSuite { object HelloJSWorld extends TestUtil.BaseModule { val matrix = for { - scalaJS <- Seq("0.6.20", "0.6.21", "1.0.0-M2") scala <- Seq("2.11.8", "2.12.3", "2.12.4") - } yield (scalaJS, scala) + scalaJS <- Seq("0.6.20", "0.6.21", "1.0.0-M2") + } yield (scala, scalaJS) object build extends Cross[BuildModule](matrix:_*) - class BuildModule(sjsVersion0: String, scalaVersion0: String) extends HelloJSWorldModule { + class BuildModule(scalaVersion0: String, sjsVersion0: String) extends HelloJSWorldModule { def scalaVersion = scalaVersion0 def scalaJSVersion = sjsVersion0 def pomSettings = PomSettings( |