From 7cd18fd936b95410274be031a8231e5a3d9866a4 Mon Sep 17 00:00:00 2001 From: Li Haoyi Date: Sat, 6 Jan 2018 23:25:29 -0800 Subject: 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 --- scalalib/src/main/scala/mill/scalalib/Module.scala | 4 +--- .../src/test/scala/mill/scalalib/HelloWorldTests.scala | 16 ++++++++-------- 2 files changed, 9 insertions(+), 11 deletions(-) (limited to 'scalalib/src') diff --git a/scalalib/src/main/scala/mill/scalalib/Module.scala b/scalalib/src/main/scala/mill/scalalib/Module.scala index c6fcfb4d..6cc47176 100644 --- a/scalalib/src/main/scala/mill/scalalib/Module.scala +++ b/scalalib/src/main/scala/mill/scalalib/Module.scala @@ -75,7 +75,6 @@ trait Module extends mill.Module with TaskModule { outer => def compileIvyDeps = T{ Seq[Dep]() } def scalacPluginIvyDeps = T{ Seq[Dep]() } def runIvyDeps = T{ Seq[Dep]() } - def basePath: Path def scalacOptions = T{ Seq.empty[String] } def javacOptions = T{ Seq.empty[String] } @@ -360,11 +359,10 @@ trait PublishModule extends Module { outer => } trait SbtModule extends Module { outer => - def basePath: Path override def sources = T.source{ basePath / 'src / 'main / 'scala } override def resources = T.source{ basePath / 'src / 'main / 'resources } trait Tests extends super.Tests{ - def basePath = outer.basePath + override def basePath = outer.basePath override def sources = T.source{ basePath / 'src / 'test / 'scala } override def resources = T.source{ basePath / 'src / 'test / 'resources } } diff --git a/scalalib/src/test/scala/mill/scalalib/HelloWorldTests.scala b/scalalib/src/test/scala/mill/scalalib/HelloWorldTests.scala index 4cd1d58d..c9419d07 100644 --- a/scalalib/src/test/scala/mill/scalalib/HelloWorldTests.scala +++ b/scalalib/src/test/scala/mill/scalalib/HelloWorldTests.scala @@ -9,7 +9,7 @@ import mill.define.{Cross, Target} import mill.discover.Discovered import mill.eval.{Evaluator, Result} import mill.scalalib.publish._ -import mill.util.TestEvaluator +import mill.util.{TestEvaluator, TestUtil} import sbt.internal.inc.CompileFailed import utest._ @@ -20,8 +20,8 @@ trait HelloWorldModule extends scalalib.Module { def basePath = HelloWorldTests.workingSrcPath } -object HelloWorld extends HelloWorldModule -object CrossHelloWorld extends mill.Module{ +object HelloWorld extends TestUtil.BaseModule with HelloWorldModule +object CrossHelloWorld extends TestUtil.BaseModule { val cross = for(v <- Cross("2.10.6", "2.11.11", "2.12.3", "2.12.4")) yield new HelloWorldModule { @@ -29,19 +29,19 @@ object CrossHelloWorld extends mill.Module{ } } -object HelloWorldWithMain extends HelloWorldModule { +object HelloWorldWithMain extends TestUtil.BaseModule with HelloWorldModule { def mainClass = Some("Main") } -object HelloWorldWarnUnused extends HelloWorldModule { +object HelloWorldWarnUnused extends TestUtil.BaseModule with HelloWorldModule { def scalacOptions = T(Seq("-Ywarn-unused")) } -object HelloWorldFatalWarnings extends HelloWorldModule { +object HelloWorldFatalWarnings extends TestUtil.BaseModule with HelloWorldModule { def scalacOptions = T(Seq("-Ywarn-unused", "-Xfatal-warnings")) } -object HelloWorldWithPublish extends HelloWorldModule with PublishModule { +object HelloWorldWithPublish extends TestUtil.BaseModule with HelloWorldModule with PublishModule { def artifactName = "hello-world" def publishVersion = "0.0.1" @@ -60,7 +60,7 @@ object HelloWorldWithPublish extends HelloWorldModule with PublishModule { Seq(Developer("lihaoyi", "Li Haoyi", "https://github.com/lihaoyi")) ) } -object HelloWorldScalaOverride extends HelloWorldModule { +object HelloWorldScalaOverride extends TestUtil.BaseModule with HelloWorldModule { override def scalaVersion: Target[String] = "2.11.11" } object HelloWorldTests extends TestSuite { -- cgit v1.2.3