diff options
author | Guillaume Martres <smarter@ubuntu.com> | 2018-08-05 23:23:12 +0900 |
---|---|---|
committer | Li Haoyi <haoyi.sg@gmail.com> | 2018-08-05 22:23:12 +0800 |
commit | b9824967392e4b674881e5dcec4c4fbb05e6cd9b (patch) | |
tree | 40c67dff4ffb26f085ef52b1ec3e2341f33d27be /scalalib/src/mill/scalalib/ScalaModule.scala | |
parent | 66c133a2ff58823c43ddfa7643fb74b8cf2bd0a6 (diff) | |
download | mill-b9824967392e4b674881e5dcec4c4fbb05e6cd9b.tar.gz mill-b9824967392e4b674881e5dcec4c4fbb05e6cd9b.tar.bz2 mill-b9824967392e4b674881e5dcec4c4fbb05e6cd9b.zip |
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
Diffstat (limited to 'scalalib/src/mill/scalalib/ScalaModule.scala')
-rw-r--r-- | scalalib/src/mill/scalalib/ScalaModule.scala | 50 |
1 files changed, 42 insertions, 8 deletions
diff --git a/scalalib/src/mill/scalalib/ScalaModule.scala b/scalalib/src/mill/scalalib/ScalaModule.scala index 3cea7fab..1899ee14 100644 --- a/scalalib/src/mill/scalalib/ScalaModule.scala +++ b/scalalib/src/mill/scalalib/ScalaModule.scala @@ -8,6 +8,7 @@ import mill.define.TaskModule import mill.eval.{PathRef, Result} import mill.modules.Jvm import mill.modules.Jvm.{createJar, subprocess} +import Dep.isDotty import Lib._ import mill.util.Loose.Agg import mill.util.DummyInputStream @@ -17,6 +18,7 @@ import mill.util.DummyInputStream */ trait ScalaModule extends JavaModule { outer => trait Tests extends TestModule with ScalaModule{ + override def scalaOrganization = outer.scalaOrganization() def scalaVersion = outer.scalaVersion() override def repositories = outer.repositories override def scalacPluginIvyDeps = outer.scalacPluginIvyDeps @@ -25,12 +27,24 @@ trait ScalaModule extends JavaModule { outer => override def scalaWorker = outer.scalaWorker override def moduleDeps: Seq[JavaModule] = Seq(outer) } + + def scalaOrganization: T[String] = T { + if (isDotty(scalaVersion())) + "ch.epfl.lamp" + else + "org.scala-lang" + } + def scalaVersion: T[String] 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(version = scalaVersion()) + val artifacts = + if (isDotty(scalaVersion())) + Set("dotty-library", "dotty-compiler") + else + Set("scala-library", "scala-compiler", "scala-reflect") + if (!artifacts(d.module.name)) d + else d.copy(module = d.module.copy(organization = scalaOrganization()), version = scalaVersion()) } override def resolveCoursierDependency: Task[Dep => coursier.Dependency] = T.task{ @@ -77,25 +91,41 @@ trait ScalaModule extends JavaModule { outer => case _ => (scalaVersion(), Lib.scalaBinaryVersion(scalaVersion())) } + val (bridgeDep, bridgeName, bridgeVersion) = + if (isDotty(scalaVersion0)) { + val org = scalaOrganization() + val name = "dotty-sbt-bridge" + val version = scalaVersion() + (ivy"$org:$name:$version", name, version) + } else { + val org = "org.scala-sbt" + val name = "compiler-bridge" + val version = Versions.zinc + (ivy"$org::$name:$version", s"${name}_$scalaBinaryVersion0", version) + } + resolveDependencies( repositories, Lib.depToDependency(_, scalaVersion0, platformSuffix()), - Seq(ivy"org.scala-sbt::compiler-bridge:${Versions.zinc}"), + Seq(bridgeDep), sources = true - ).map(_.find(_.path.last == s"compiler-bridge_${scalaBinaryVersion0}-${Versions.zinc}-sources.jar").map(_.path).get) + ).map(deps => + grepJar(deps.map(_.path), bridgeName, s"$bridgeVersion-sources") + ) } def scalacPluginClasspath: T[Agg[PathRef]] = T { resolveDeps(scalacPluginIvyDeps)() } - def scalaLibraryIvyDeps = T{ scalaRuntimeIvyDeps(scalaVersion()) } + def scalaLibraryIvyDeps = T{ scalaRuntimeIvyDeps(scalaOrganization(), scalaVersion()) } /** * Classpath of the Scala Compiler & any compiler plugins */ def scalaCompilerClasspath: T[Agg[PathRef]] = T{ resolveDeps( - T.task{scalaCompilerIvyDeps(scalaVersion()) ++ scalaRuntimeIvyDeps(scalaVersion())} + T.task{scalaCompilerIvyDeps(scalaOrganization(), scalaVersion()) ++ + scalaRuntimeIvyDeps(scalaOrganization(), scalaVersion())} )() } override def compileClasspath = T{ @@ -155,7 +185,11 @@ trait ScalaModule extends JavaModule { outer => Result.Failure("repl needs to be run with the -i/--interactive flag") }else{ Jvm.interactiveSubprocess( - mainClass = "scala.tools.nsc.MainGenericRunner", + mainClass = + if (isDotty(scalaVersion())) + "dotty.tools.repl.Main" + else + "scala.tools.nsc.MainGenericRunner", classPath = runClasspath().map(_.path) ++ scalaCompilerClasspath().map(_.path), mainArgs = Seq("-usejavacp"), workingDir = pwd |