From b9824967392e4b674881e5dcec4c4fbb05e6cd9b Mon Sep 17 00:00:00 2001 From: Guillaume Martres Date: Sun, 5 Aug 2018 23:23:12 +0900 Subject: Add support for Dotty projects (#397) * Abstract over the scala compiler organization * Support using a locally published compiler Publishing locally with sbt means publishing ivy-style, which uses a different naming convention than maven, we now handle both cases. * Add minimal support for Dotty projects * Rewrite scalalib.Dep, introduce scalalib.CrossVersion Instead of Dep being a trait with three cases (Java/Scala/Point), it is now a case class where the cross field is an instance of the CrossVersion trait which has three cases (Constant/Binary/Full). This is more versatile since it allows for non-empty constant suffixes which will be used to implement withDottyCompat in the next commit. It's also a cleaner separation of concerns. We also deduplicate various pieces of codes that computed the artifact name: this is now always handled in Dep and CrossVersion. * Add simple way to use Scala 2 deps in a Dotty project This is similar to the withDottyCompat method in the sbt-dotty plugin. * Turn off the Dotty test on Java >= 9 --- .../test/resources/hello-dotty/foo/src/Main.scala | 17 ++++++++++++++ .../test/src/mill/scalalib/HelloWorldTests.scala | 26 +++++++++++++++++----- 2 files changed, 38 insertions(+), 5 deletions(-) create mode 100644 scalalib/test/resources/hello-dotty/foo/src/Main.scala (limited to 'scalalib/test') diff --git a/scalalib/test/resources/hello-dotty/foo/src/Main.scala b/scalalib/test/resources/hello-dotty/foo/src/Main.scala new file mode 100644 index 00000000..3fe80342 --- /dev/null +++ b/scalalib/test/resources/hello-dotty/foo/src/Main.scala @@ -0,0 +1,17 @@ +import cats._, cats.data._, cats.implicits._ + +trait Context + +object Main { + def foo(f: implicit Int => Int): Int = { + implicit val x: Int = 1 + f + } + + def main(args: Array[String]): Unit = { + val x = Applicative[List].pure(1) + assert(x == List(1)) + val value = foo(implicit x => x + 1) + assert(value == 2) + } +} diff --git a/scalalib/test/src/mill/scalalib/HelloWorldTests.scala b/scalalib/test/src/mill/scalalib/HelloWorldTests.scala index 7a1dd6df..1a89a0e3 100644 --- a/scalalib/test/src/mill/scalalib/HelloWorldTests.scala +++ b/scalalib/test/src/mill/scalalib/HelloWorldTests.scala @@ -14,6 +14,7 @@ import utest._ import utest.framework.TestPath import scala.collection.JavaConverters._ +import scala.util.Properties.isJavaAtLeast object HelloWorldTests extends TestSuite { @@ -190,11 +191,7 @@ object HelloWorldTests extends TestSuite { object HelloWorldTypeLevel extends HelloBase{ object foo extends ScalaModule { def scalaVersion = "2.11.8" - override def mapDependencies = T.task{ d: coursier.Dependency => - val artifacts = Set("scala-library", "scala-compiler", "scala-reflect") - if (d.module.organization != "org.scala-lang" || !artifacts(d.module.name)) d - else d.copy(module = d.module.copy(organization = "org.typelevel")) - } + override def scalaOrganization = "org.typelevel" def ivyDeps = Agg( ivy"com.github.julien-truffaut::monocle-macro::1.4.0" @@ -238,6 +235,13 @@ object HelloWorldTests extends TestSuite { } } + object HelloDotty extends HelloBase{ + object foo extends ScalaModule { + def scalaVersion = "0.9.0-RC1" + def ivyDeps = Agg(ivy"org.typelevel::cats-core:1.2.0".withDottyCompat(scalaVersion())) + } + } + val resourcePath = pwd / 'scalalib / 'test / 'resources / "hello-world" def jarMainClass(jar: JarFile): Option[String] = { @@ -815,5 +819,17 @@ object HelloWorldTests extends TestSuite { ) } + 'dotty - workspaceTest( + HelloDotty, + resourcePath = pwd / 'scalalib / 'test / 'resources / "hello-dotty" + ){ eval => + if (isJavaAtLeast("9")) { + // Skip the test because Dotty does not support Java >= 9 yet + // (see https://github.com/lampepfl/dotty/pull/3138) + } else { + val Right((_, evalCount)) = eval.apply(HelloDotty.foo.run()) + assert(evalCount > 0) + } + } } } -- cgit v1.2.3