summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorLi Haoyi <haoyi.sg@gmail.com>2018-02-02 08:53:11 -0800
committerLi Haoyi <haoyi.sg@gmail.com>2018-02-02 08:54:16 -0800
commitf1153f8fff92be3711fd238cd2c7c06ac2a7a5bc (patch)
treea5cbc4d30abea88da2f774dcf210f8d5a5a2bb60 /core
parent5be2c5aea4527cf637948e6bf2e4c56e3273fbd9 (diff)
downloadmill-f1153f8fff92be3711fd238cd2c7c06ac2a7a5bc.tar.gz
mill-f1153f8fff92be3711fd238cd2c7c06ac2a7a5bc.tar.bz2
mill-f1153f8fff92be3711fd238cd2c7c06ac2a7a5bc.zip
Fix propagation of overriden `Module#basePath` and add a test to verify it's behavior
Diffstat (limited to 'core')
-rw-r--r--core/src/mill/define/Module.scala2
-rw-r--r--core/src/mill/main/MainRunner.scala5
-rw-r--r--core/test/src/mill/define/BasePathTests.scala19
3 files changed, 23 insertions, 3 deletions
diff --git a/core/src/mill/define/Module.scala b/core/src/mill/define/Module.scala
index dd451c9c..09e8e974 100644
--- a/core/src/mill/define/Module.scala
+++ b/core/src/mill/define/Module.scala
@@ -104,7 +104,7 @@ class BaseModule(basePath0: Path)
// 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
+ override implicit def millModuleBasePath: BasePath = BasePath(basePath)
implicit def millImplicitBaseModule: BaseModule.Implicit = BaseModule.Implicit(this)
} \ No newline at end of file
diff --git a/core/src/mill/main/MainRunner.scala b/core/src/mill/main/MainRunner.scala
index e098144f..06e1795f 100644
--- a/core/src/mill/main/MainRunner.scala
+++ b/core/src/mill/main/MainRunner.scala
@@ -84,13 +84,16 @@ class MainRunner(config: ammonite.main.Cli.Config,
object CustomCodeWrapper extends Preprocessor.CodeWrapper {
def top(pkgName: Seq[Name], imports: Imports, indexedWrapperName: Name) = {
val wrapName = indexedWrapperName.backticked
+ val literalPath = pprint.Util.literalize(config.wd.toString)
s"""
|package ${pkgName.head.encoded}
|package ${Util.encodeScalaSourcePath(pkgName.tail)}
|$imports
|import mill._
|
- |object $wrapName extends mill.define.BaseModule(ammonite.ops.Path(${pprint.Util.literalize(config.wd.toString)})) with $wrapName{
+ |object $wrapName
+ |extends mill.define.BaseModule(ammonite.ops.Path($literalPath))
+ |with $wrapName{
| // Stub to make sure Ammonite has something to call after it evaluates a script,
| // even if it does nothing...
| def $$main() = Iterator[String]()
diff --git a/core/test/src/mill/define/BasePathTests.scala b/core/test/src/mill/define/BasePathTests.scala
index a0be4762..62f84787 100644
--- a/core/test/src/mill/define/BasePathTests.scala
+++ b/core/test/src/mill/define/BasePathTests.scala
@@ -1,8 +1,9 @@
package mill.define
-import mill.util.TestGraphs
+import mill.util.{TestGraphs, TestUtil}
import utest._
import ammonite.ops._
+import mill.{Module, T}
object BasePathTests extends TestSuite{
val testGraphs = new TestGraphs
val tests = Tests{
@@ -44,6 +45,22 @@ object BasePathTests extends TestSuite{
"cross", "210", "cross2", "js"
)
}
+ 'overriden - {
+ object overridenBasePath extends TestUtil.BaseModule {
+ override def basePath = pwd / 'overridenBasePathRootValue
+ object nested extends Module{
+ override def basePath = super.basePath / 'overridenBasePathNested
+ object nested extends Module{
+ override def basePath = super.basePath / 'overridenBasePathDoubleNested
+ }
+ }
+ }
+ assert(
+ overridenBasePath.basePath == pwd / 'overridenBasePathRootValue,
+ overridenBasePath.nested.basePath == pwd / 'overridenBasePathRootValue / 'nested / 'overridenBasePathNested,
+ overridenBasePath.nested.nested.basePath == pwd / 'overridenBasePathRootValue / 'nested / 'overridenBasePathNested / 'nested / 'overridenBasePathDoubleNested
+ )
+ }
}
}