summaryrefslogtreecommitdiff
path: root/scalalib/api
diff options
context:
space:
mode:
authorLi Haoyi <haoyi.sg@gmail.com>2018-12-12 22:15:38 +0800
committerGitHub <noreply@github.com>2018-12-12 22:15:38 +0800
commitea7fceb6e56f53bde3517586dfc57e10a605a524 (patch)
treecf2e4b7a403f8bcbcf3d1c4c45a8abd315cbefe6 /scalalib/api
parentd0e1b572e88d311e1aee23d92e0384a81de4bcb6 (diff)
downloadmill-ea7fceb6e56f53bde3517586dfc57e10a605a524.tar.gz
mill-ea7fceb6e56f53bde3517586dfc57e10a605a524.tar.bz2
mill-ea7fceb6e56f53bde3517586dfc57e10a605a524.zip
First pass at splitting out worker-api from mill core. (#504)
This reduces the {scala,scalajs,scalanative}-worker dependency from the entirety of Mill to a much narrower `mill.api` module. This reduces the amount of classpath pollution within these workers, should mean they're much faster to download the first time, and reduces the amount of random junk they would pull in if they were to be used outside of the Mill project. The interactions between the various *Modules and their *WorkerImpls has been narrowed down to the `*.api` modules, which only depend on other `*.api` modules. A lot of things have been moved around; user code is unlikely to break, but it's possible some will if it references classes that have been moved around. Forwarders have been left for the few internal classes that Mill uses in it's own `build.sc`, to support bootstrapping. Third-party code which breaks should be a straightforward to fix just by updating imports The `*.api` modules have minimal dependencies (mostly uPickle and os-lib) and minimal code. There is still a bunch of implementation code in there: some of it defining data-types that are commonly sent across the module/worker interface (`Agg`, `PathRef`, ...), and some of it just general helper functions that are needed both in modules and workers. The latter code isn't strictly API definitions, but for now is small enough it's not worth splitting into it's own module
Diffstat (limited to 'scalalib/api')
-rw-r--r--scalalib/api/src/mill/scalalib/api/ZincWorkerApi.scala76
1 files changed, 76 insertions, 0 deletions
diff --git a/scalalib/api/src/mill/scalalib/api/ZincWorkerApi.scala b/scalalib/api/src/mill/scalalib/api/ZincWorkerApi.scala
new file mode 100644
index 00000000..c5230ec5
--- /dev/null
+++ b/scalalib/api/src/mill/scalalib/api/ZincWorkerApi.scala
@@ -0,0 +1,76 @@
+package mill.scalalib.api
+
+import mill.api.Loose.Agg
+import mill.api.PathRef
+import mill.api.JsonFormatters._
+
+trait ZincWorkerApi {
+ /** Compile a Java-only project */
+ def compileJava(upstreamCompileOutput: Seq[CompilationResult],
+ sources: Agg[os.Path],
+ compileClasspath: Agg[os.Path],
+ javacOptions: Seq[String])
+ (implicit ctx: mill.api.Ctx): mill.api.Result[CompilationResult]
+
+ /** Compile a mixed Scala/Java or Scala-only project */
+ def compileMixed(upstreamCompileOutput: Seq[CompilationResult],
+ sources: Agg[os.Path],
+ compileClasspath: Agg[os.Path],
+ javacOptions: Seq[String],
+ scalaVersion: String,
+ scalacOptions: Seq[String],
+ compilerBridgeSources: os.Path,
+ compilerClasspath: Agg[os.Path],
+ scalacPluginClasspath: Agg[os.Path])
+ (implicit ctx: mill.api.Ctx): mill.api.Result[CompilationResult]
+
+ def discoverMainClasses(compilationResult: CompilationResult)
+ (implicit ctx: mill.api.Ctx): Seq[String]
+
+ def docJar(scalaVersion: String,
+ compilerBridgeSources: os.Path,
+ compilerClasspath: Agg[os.Path],
+ scalacPluginClasspath: Agg[os.Path],
+ args: Seq[String])
+ (implicit ctx: mill.api.Ctx): Boolean
+}
+
+
+object CompilationResult {
+ implicit val jsonFormatter: upickle.default.ReadWriter[CompilationResult] = upickle.default.macroRW
+}
+
+// analysisFile is represented by os.Path, so we won't break caches after file changes
+case class CompilationResult(analysisFile: os.Path, classes: PathRef)
+
+object Util{
+ def isDotty(scalaVersion: String) =
+ scalaVersion.startsWith("0.")
+
+
+ def grepJar(classPath: Agg[os.Path], name: String, version: String, sources: Boolean = false) = {
+ val suffix = if (sources) "-sources" else ""
+ val mavenStylePath = s"$name-$version$suffix.jar"
+ val ivyStylePath = {
+ val dir = if (sources) "srcs" else "jars"
+ s"$version/$dir/$name$suffix.jar"
+ }
+
+ classPath
+ .find(p => p.toString.endsWith(mavenStylePath) || p.toString.endsWith(ivyStylePath))
+ .getOrElse(throw new Exception(s"Cannot find $mavenStylePath or $ivyStylePath"))
+ }
+
+ private val ReleaseVersion = raw"""(\d+)\.(\d+)\.(\d+)""".r
+ private val MinorSnapshotVersion = raw"""(\d+)\.(\d+)\.([1-9]\d*)-SNAPSHOT""".r
+ private val DottyVersion = raw"""0\.(\d+)\.(\d+).*""".r
+
+ def scalaBinaryVersion(scalaVersion: String) = {
+ scalaVersion match {
+ case ReleaseVersion(major, minor, _) => s"$major.$minor"
+ case MinorSnapshotVersion(major, minor, _) => s"$major.$minor"
+ case DottyVersion(minor, _) => s"0.$minor"
+ case _ => scalaVersion
+ }
+ }
+} \ No newline at end of file