diff options
author | Li Haoyi <haoyi.sg@gmail.com> | 2018-01-06 23:25:29 -0800 |
---|---|---|
committer | Li Haoyi <haoyi.sg@gmail.com> | 2018-01-07 00:21:37 -0800 |
commit | 7cd18fd936b95410274be031a8231e5a3d9866a4 (patch) | |
tree | c3d9a1f4a110dc5f25824eb9f118ea8ebfcd2b37 /core/src/main/scala/mill/main/MainRunner.scala | |
parent | a6febe05a5650274110301a09bb97e4770ea0400 (diff) | |
download | mill-7cd18fd936b95410274be031a8231e5a3d9866a4.tar.gz mill-7cd18fd936b95410274be031a8231e5a3d9866a4.tar.bz2 mill-7cd18fd936b95410274be031a8231e5a3d9866a4.zip |
First pass at implicitly propagating a `def basePath: Path` up the `Module` hierarchy, which each module receives and extends.
One constraint is that now must define your abstract modules as `trait`s rather than `class`es, or otherwise add an implicit `ctx: ModuleCtx` parameter to your class definition.
So far this lets us remove some explicit `basePath` definitions in `build.sc`. Proper handling of `basePath` in `CrossModule`s is future work
Diffstat (limited to 'core/src/main/scala/mill/main/MainRunner.scala')
-rw-r--r-- | core/src/main/scala/mill/main/MainRunner.scala | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/core/src/main/scala/mill/main/MainRunner.scala b/core/src/main/scala/mill/main/MainRunner.scala index 76e2d069..322795ea 100644 --- a/core/src/main/scala/mill/main/MainRunner.scala +++ b/core/src/main/scala/mill/main/MainRunner.scala @@ -75,15 +75,12 @@ class MainRunner(config: ammonite.main.Cli.Config, } override def initMain(isRepl: Boolean) = { super.initMain(isRepl).copy( - scriptCodeWrapper = mill.main.MainRunner.CustomCodeWrapper, + scriptCodeWrapper = CustomCodeWrapper, // Ammonite does not properly forward the wd from CliConfig to Main, so // force forward it outselves wd = config.wd ) } -} - -object MainRunner{ object CustomCodeWrapper extends Preprocessor.CodeWrapper { def top(pkgName: Seq[Name], imports: Imports, indexedWrapperName: Name) = { val wrapName = indexedWrapperName.backticked @@ -93,14 +90,17 @@ object MainRunner{ |$imports |import mill._ | - |object $wrapName extends $wrapName{ + |object $wrapName extends mill.define.Task.BaseModule(ammonite.ops.Path(${pprint.Util.literalize(config.wd.toString)})) with $wrapName{ + | // Make sure we don't include the `build` wrapper-object's name in + | // the `basePath`s of our build + | override def basePath = super.basePath / ammonite.ops.up | // Stub to make sure Ammonite has something to call after it evaluates a script, | // even if it does nothing... | def $$main() = Iterator[String]() | lazy val mapping = mill.discover.Discovered.make[$wrapName].mapping(this) |} | - |sealed abstract class $wrapName extends mill.Module{ + |sealed trait $wrapName extends mill.Module{ |""".stripMargin } @@ -112,4 +112,4 @@ object MainRunner{ "\n}" } } -}
\ No newline at end of file +} |