Add scalaCompilerBridgeBinaryJar task

The end goal is to rewrite Dotty's compiler-bridge in Java (this is easy
since the zinc-specific phases are in the compiler itself) to simplify
the bootstrapping process.
This commit is contained in:
Guillaume Martres 2018-08-27 19:16:15 +09:00 committed by Eugene Yokota
parent 73b69022ab
commit 7eab02fff3
6 changed files with 67 additions and 25 deletions

View File

@ -450,7 +450,8 @@ object Defaults extends BuildCommon {
val _ = clean.value val _ = clean.value
IvyActions.cleanCachedResolutionCache(ivyModule.value, streams.value.log) IvyActions.cleanCachedResolutionCache(ivyModule.value, streams.value.log)
}, },
scalaCompilerBridgeSource := ZincUtil.getDefaultBridgeModule(scalaVersion.value) scalaCompilerBridgeBinaryJar := None,
scalaCompilerBridgeSource := ZincUtil.getDefaultBridgeModule(scalaVersion.value),
) )
// must be a val: duplication detected by object identity // must be a val: duplication detected by object identity
private[this] lazy val compileBaseGlobal: Seq[Setting[_]] = globalDefaults( private[this] lazy val compileBaseGlobal: Seq[Setting[_]] = globalDefaults(
@ -503,17 +504,27 @@ object Defaults extends BuildCommon {
val zincDir = BuildPaths.getZincDirectory(st, g) val zincDir = BuildPaths.getZincDirectory(st, g)
val app = appConfiguration.value val app = appConfiguration.value
val launcher = app.provider.scalaProvider.launcher val launcher = app.provider.scalaProvider.launcher
val scalac = ZincUtil.scalaCompiler( val scalac =
scalaInstance = scalaInstance.value, scalaCompilerBridgeBinaryJar.value match {
classpathOptions = classpathOptions.value, case Some(jar) =>
globalLock = launcher.globalLock, ZincUtil.scalaCompiler(
componentProvider = app.provider.components, scalaInstance = scalaInstance.value,
secondaryCacheDir = Option(zincDir), classpathOptions = classpathOptions.value,
dependencyResolution = dependencyResolution.value, compilerBridgeJar = jar
compilerBridgeSource = scalaCompilerBridgeSource.value, )
scalaJarsTarget = zincDir, case _ =>
log = streams.value.log ZincUtil.scalaCompiler(
) scalaInstance = scalaInstance.value,
classpathOptions = classpathOptions.value,
globalLock = launcher.globalLock,
componentProvider = app.provider.components,
secondaryCacheDir = Option(zincDir),
dependencyResolution = dependencyResolution.value,
compilerBridgeSource = scalaCompilerBridgeSource.value,
scalaJarsTarget = zincDir,
log = streams.value.log
)
}
val compilers = ZincUtil.compilers( val compilers = ZincUtil.compilers(
instance = scalaInstance.value, instance = scalaInstance.value,
classpathOptions = classpathOptions.value, classpathOptions = classpathOptions.value,

View File

@ -220,7 +220,8 @@ object Keys {
val crossSbtVersions = settingKey[Seq[String]]("The versions of Sbt used when cross-building an sbt plugin.") val crossSbtVersions = settingKey[Seq[String]]("The versions of Sbt used when cross-building an sbt plugin.")
val printWarnings = taskKey[Unit]("Shows warnings from compilation, including ones that weren't printed initially.").withRank(BPlusTask) val printWarnings = taskKey[Unit]("Shows warnings from compilation, including ones that weren't printed initially.").withRank(BPlusTask)
val fileInputOptions = settingKey[Seq[String]]("Options that take file input, which may invalidate the cache.").withRank(CSetting) val fileInputOptions = settingKey[Seq[String]]("Options that take file input, which may invalidate the cache.").withRank(CSetting)
val scalaCompilerBridgeSource = settingKey[ModuleID]("Configures the module ID of the sources of the compiler bridge.").withRank(CSetting) val scalaCompilerBridgeBinaryJar = taskKey[Option[File]]("Optionally, the jar of the compiler bridge. When not None, this takes precedence over scalaCompilerBridgeSource").withRank(CSetting)
val scalaCompilerBridgeSource = settingKey[ModuleID]("Configures the module ID of the sources of the compiler bridge when scalaCompilerBridgeBinaryJar is None").withRank(CSetting)
val scalaArtifacts = settingKey[Seq[String]]("Configures the list of artifacts which should match the Scala binary version").withRank(CSetting) val scalaArtifacts = settingKey[Seq[String]]("Configures the list of artifacts which should match the Scala binary version").withRank(CSetting)
val enableBinaryCompileAnalysis = settingKey[Boolean]("Writes the analysis file in binary format") val enableBinaryCompileAnalysis = settingKey[Boolean]("Writes the analysis file in binary format")
val crossJavaVersions = settingKey[Seq[String]]("The java versions used during JDK cross testing").withRank(BPlusSetting) val crossJavaVersions = settingKey[Seq[String]]("The java versions used during JDK cross testing").withRank(BPlusSetting)

View File

@ -21,7 +21,10 @@ object ConsoleProject {
val cpImports = new Imports(extracted, state) val cpImports = new Imports(extracted, state)
val bindings = ("currentState" -> state) :: ("extracted" -> extracted) :: ("cpHelpers" -> cpImports) :: Nil val bindings = ("currentState" -> state) :: ("extracted" -> extracted) :: ("cpHelpers" -> cpImports) :: Nil
val unit = extracted.currentUnit val unit = extracted.currentUnit
val (_, dependencyResolution) = extracted.runTask(Keys.dependencyResolution, state) val (state1, dependencyResolution) =
extracted.runTask(Keys.dependencyResolution, state)
val (_, scalaCompilerBridgeBinaryJar) =
extracted.runTask(Keys.scalaCompilerBridgeBinaryJar, state1)
val scalaInstance = { val scalaInstance = {
val scalaProvider = state.configuration.provider.scalaProvider val scalaProvider = state.configuration.provider.scalaProvider
ScalaInstance(scalaProvider.version, scalaProvider.launcher) ScalaInstance(scalaProvider.version, scalaProvider.launcher)
@ -30,17 +33,26 @@ object ConsoleProject {
val zincDir = BuildPaths.getZincDirectory(state, g) val zincDir = BuildPaths.getZincDirectory(state, g)
val app = state.configuration val app = state.configuration
val launcher = app.provider.scalaProvider.launcher val launcher = app.provider.scalaProvider.launcher
val compiler = ZincUtil.scalaCompiler( val compiler = scalaCompilerBridgeBinaryJar match {
scalaInstance = scalaInstance, case Some(jar) =>
classpathOptions = ClasspathOptionsUtil.repl, ZincUtil.scalaCompiler(
globalLock = launcher.globalLock, scalaInstance = scalaInstance,
componentProvider = app.provider.components, classpathOptions = ClasspathOptionsUtil.repl,
secondaryCacheDir = Option(zincDir), compilerBridgeJar = jar
dependencyResolution = dependencyResolution, )
compilerBridgeSource = extracted.get(Keys.scalaCompilerBridgeSource), case None =>
scalaJarsTarget = zincDir, ZincUtil.scalaCompiler(
log = log scalaInstance = scalaInstance,
) classpathOptions = ClasspathOptionsUtil.repl,
globalLock = launcher.globalLock,
componentProvider = app.provider.components,
secondaryCacheDir = Option(zincDir),
dependencyResolution = dependencyResolution,
compilerBridgeSource = extracted.get(Keys.scalaCompilerBridgeSource),
scalaJarsTarget = zincDir,
log = log
)
}
val imports = BuildUtil.getImports(unit.unit) ++ BuildUtil.importAll(bindings.map(_._1)) val imports = BuildUtil.getImports(unit.unit) ++ BuildUtil.importAll(bindings.map(_._1))
val importString = imports.mkString("", ";\n", ";\n\n") val importString = imports.mkString("", ";\n", ";\n\n")
val initCommands = importString + extra val initCommands = importString + extra

View File

@ -0,0 +1 @@
object A

View File

@ -0,0 +1,16 @@
scalaVersion := "2.12.6"
// We can't use "%%" here without breaking the "== bridgeModule" check below
val bridgeModule = "org.scala-sbt" % s"compiler-bridge_2.12" % "1.2.1"
libraryDependencies += bridgeModule % Configurations.ScalaTool
scalaCompilerBridgeSource := "shouldnotbeused" % "dummy" % "dummy"
scalaCompilerBridgeBinaryJar := {
for {
toolReport <- update.value.configuration(Configurations.ScalaTool)
m <- toolReport.modules.find(m => m.module == bridgeModule)
(_, file) <- m.artifacts.find(art => art._1.`type` == Artifact.DefaultType)
} yield file
}

View File

@ -0,0 +1 @@
> compile