In-source zinc's LM integration code

This commit is contained in:
Dale Wijnand 2019-04-18 08:14:04 +01:00
parent b9b520f79e
commit e978357e47
No known key found for this signature in database
GPG Key ID: 4F256E3D151DF5EF
14 changed files with 125 additions and 55 deletions

View File

@ -89,15 +89,18 @@ def baseSettings: Seq[Setting[_]] =
def testedBaseSettings: Seq[Setting[_]] =
baseSettings ++ testDependencies
val mimaSettings = Def settings (
mimaPreviousArtifacts := {
Seq(
def sbt10Plus = Seq(
"1.0.0", "1.0.1", "1.0.2", "1.0.3", "1.0.4",
"1.1.0", "1.1.1", "1.1.2", "1.1.3", "1.1.4", "1.1.5", "1.1.6",
"1.2.0", "1.2.1", "1.2.3"
).map { v =>
organization.value % moduleName.value % v cross (if (crossPaths.value) CrossVersion.binary else CrossVersion.disabled)
}.toSet
"1.2.0", "1.2.1", /*DOA,*/ "1.2.3", "1.2.4", /*DOA,*/ "1.2.6", "1.2.7", "1.2.8",
) ++ sbt13Plus
def sbt13Plus = Seq() // Add sbt 1.3+ stable versions when released
def mimaSettings = mimaSettingsSince(sbt10Plus)
def mimaSettingsSince(versions: Seq[String]) = Def settings (
mimaPreviousArtifacts := {
val crossVersion = if (crossPaths.value) CrossVersion.binary else CrossVersion.disabled
versions.map(v => organization.value % moduleName.value % v cross crossVersion).toSet
},
mimaBinaryIssueFilters ++= Seq(
// Changes in the internal package
@ -425,7 +428,6 @@ lazy val actionsProj = (project in file("main-actions"))
addSbtCompilerClasspath,
addSbtCompilerApiInfo,
addSbtLmCore,
addSbtCompilerIvyIntegration,
addSbtZinc
)
@ -576,11 +578,25 @@ lazy val mainSettingsProj = (project in file("main-settings"))
addSbtLmCore
)
lazy val zincLmIntegrationProj = (project in file("zinc-lm-integration"))
.enablePlugins(BuildInfoPlugin)
.settings(
name := "Zinc LM Integration",
testedBaseSettings,
buildInfo in Compile := Nil, // Only generate build info for tests
BuildInfoPlugin.buildInfoScopedSettings(Test),
buildInfoPackage in Test := "sbt.internal.inc",
buildInfoObject in Test := "ZincLmIntegrationBuildInfo",
buildInfoKeys in Test := List[BuildInfoKey]("zincVersion" -> zincVersion),
mimaSettingsSince(sbt13Plus),
)
.configure(addSbtZincCompileCore, addSbtLmCore, addSbtLmIvyTest)
// The main integration project for sbt. It brings all of the projects together, configures them, and provides for overriding conventions.
lazy val mainProj = (project in file("main"))
.enablePlugins(ContrabandPlugin)
.dependsOn(logicProj, actionsProj, mainSettingsProj, runProj, commandProj, collectionProj,
scriptedSbtReduxProj, scriptedPluginProj)
scriptedSbtReduxProj, scriptedPluginProj, zincLmIntegrationProj)
.settings(
testedBaseSettings,
name := "Main",
@ -798,6 +814,7 @@ def allProjects =
actionsProj,
commandProj,
mainSettingsProj,
zincLmIntegrationProj,
mainProj,
sbtProj,
bundledLauncherProj,

View File

@ -28,7 +28,7 @@ import sbt.Scope.{ GlobalScope, ThisScope, fillTaskAxis }
import sbt.internal.CommandStrings.ExportStream
import sbt.internal._
import sbt.internal.inc.JavaInterfaceUtil._
import sbt.internal.inc.ZincUtil
import sbt.internal.inc.{ ZincLmUtil, ZincUtil }
import sbt.internal.io.{ Source, WatchState }
import sbt.internal.librarymanagement.{ CustomHttp => _, _ }
import sbt.internal.librarymanagement.mavenint.{
@ -470,7 +470,7 @@ object Defaults extends BuildCommon {
IvyActions.cleanCachedResolutionCache(ivyModule.value, streams.value.log)
},
scalaCompilerBridgeBinaryJar := None,
scalaCompilerBridgeSource := ZincUtil.getDefaultBridgeModule(scalaVersion.value),
scalaCompilerBridgeSource := ZincLmUtil.getDefaultBridgeModule(scalaVersion.value),
)
// must be a val: duplication detected by object identity
private[this] lazy val compileBaseGlobal: Seq[Setting[_]] = globalDefaults(
@ -532,7 +532,7 @@ object Defaults extends BuildCommon {
compilerBridgeJar = jar
)
case _ =>
ZincUtil.scalaCompiler(
ZincLmUtil.scalaCompiler(
scalaInstance = scalaInstance.value,
classpathOptions = classpathOptions.value,
globalLock = launcher.globalLock,

View File

@ -10,7 +10,7 @@ package internal
import sbt.util.Logger
import sbt.internal.util.JLine
import sbt.internal.inc.{ ScalaInstance, ZincUtil }
import sbt.internal.inc.{ ScalaInstance, ZincLmUtil, ZincUtil }
import xsbti.compile.ClasspathOptionsUtil
object ConsoleProject {
@ -41,7 +41,7 @@ object ConsoleProject {
compilerBridgeJar = jar
)
case None =>
ZincUtil.scalaCompiler(
ZincLmUtil.scalaCompiler(
scalaInstance = scalaInstance,
classpathOptions = ClasspathOptionsUtil.repl,
globalLock = launcher.globalLock,

View File

@ -37,7 +37,7 @@ import Keys.{
import Project.inScope
import sbt.internal.inc.classpath.ClasspathUtilities
import sbt.librarymanagement.ivy.{ InlineIvyConfiguration, IvyDependencyResolution, IvyPaths }
import sbt.internal.inc.{ ZincUtil, ScalaInstance }
import sbt.internal.inc.{ ZincLmUtil, ZincUtil, ScalaInstance }
import sbt.internal.util.Attributed.data
import sbt.internal.util.Types.const
import sbt.internal.util.{ Attributed, Settings, ~> }
@ -93,14 +93,14 @@ private[sbt] object Load {
val si = ScalaInstance(scalaProvider.version, scalaProvider.launcher)
val zincDir = BuildPaths.getZincDirectory(state, globalBase)
val classpathOptions = ClasspathOptionsUtil.boot
val scalac = ZincUtil.scalaCompiler(
val scalac = ZincLmUtil.scalaCompiler(
scalaInstance = si,
classpathOptions = classpathOptions,
globalLock = launcher.globalLock,
componentProvider = app.provider.components,
secondaryCacheDir = Option(zincDir),
dependencyResolution = dependencyResolution,
compilerBridgeSource = ZincUtil.getDefaultBridgeModule(scalaProvider.version),
compilerBridgeSource = ZincLmUtil.getDefaultBridgeModule(scalaProvider.version),
scalaJarsTarget = zincDir,
log = log
)

View File

@ -16,7 +16,7 @@ object Dependencies {
case Some(version) => version
case _ => "1.3.0-M3"
}
private val zincVersion = "1.3.0-M3"
val zincVersion = "1.3.0-M3"
private val sbtIO = "org.scala-sbt" %% "io" % ioVersion
@ -29,6 +29,7 @@ object Dependencies {
private val utilScripted = "org.scala-sbt" %% "util-scripted" % utilVersion
private val libraryManagementCore = "org.scala-sbt" %% "librarymanagement-core" % lmVersion
private val libraryManagementIvy = "org.scala-sbt" %% "librarymanagement-ivy" % lmVersion
private val libraryManagementImpl = {
val lmOrganization =
@ -56,9 +57,9 @@ object Dependencies {
private val compilerClasspath = "org.scala-sbt" %% "zinc-classpath" % zincVersion
private val compilerApiInfo = "org.scala-sbt" %% "zinc-apiinfo" % zincVersion
private val compilerBridge = "org.scala-sbt" %% "compiler-bridge" % zincVersion
private val compilerIvyIntegration = "org.scala-sbt" %% "zinc-ivy-integration" % zincVersion
private val zinc = "org.scala-sbt" %% "zinc" % zincVersion
private val zincCompile = "org.scala-sbt" %% "zinc-compile" % zincVersion
private val zincCompileCore = "org.scala-sbt" %% "zinc-compile-core" % zincVersion
def getSbtModulePath(key: String, name: String) = {
val localProps = new java.util.Properties()
@ -73,11 +74,19 @@ object Dependencies {
lazy val sbtLmPath = getSbtModulePath("sbtlm.path", "sbt/lm")
lazy val sbtZincPath = getSbtModulePath("sbtzinc.path", "sbt/zinc")
def addSbtModule(p: Project, path: Option[String], projectName: String, m: ModuleID) =
def addSbtModule(
p: Project,
path: Option[String],
projectName: String,
moduleId: ModuleID,
c: Option[Configuration] = None
) = {
val m = moduleId.withConfigurations(c.map(_.name))
path match {
case Some(f) => p dependsOn ProjectRef(file(f), projectName)
case Some(f) => p dependsOn ClasspathDependency(ProjectRef(file(f), projectName), c.map(_.name))
case None => p settings (libraryDependencies += m, dependencyOverrides += m)
}
}
def addSbtIO(p: Project): Project = addSbtModule(p, sbtIoPath, "io", sbtIO)
@ -100,6 +109,8 @@ object Dependencies {
addSbtModule(p, sbtLmPath, "lmCore", libraryManagementCore)
def addSbtLmImpl(p: Project): Project =
addSbtModule(p, sbtLmPath, "lmImpl", libraryManagementImpl)
def addSbtLmIvyTest(p: Project): Project =
addSbtModule(p, sbtLmPath, "lmIvy", libraryManagementIvy, Some(Test))
def addSbtCompilerInterface(p: Project): Project =
addSbtModule(p, sbtZincPath, "compilerInterface212", compilerInterface)
@ -109,11 +120,11 @@ object Dependencies {
addSbtModule(p, sbtZincPath, "zincApiInfo212", compilerApiInfo)
def addSbtCompilerBridge(p: Project): Project =
addSbtModule(p, sbtZincPath, "compilerBridge212", compilerBridge)
def addSbtCompilerIvyIntegration(p: Project): Project =
addSbtModule(p, sbtZincPath, "zincIvyIntegration", compilerIvyIntegration)
def addSbtZinc(p: Project): Project = addSbtModule(p, sbtZincPath, "zinc", zinc)
def addSbtZincCompile(p: Project): Project =
addSbtModule(p, sbtZincPath, "zincCompile", zincCompile)
def addSbtZincCompileCore(p: Project): Project =
addSbtModule(p, sbtZincPath, "zincCompileCore", zincCompileCore)
val sjsonNewScalaJson = Def.setting {
"com.eed3si9n" %% "sjson-new-scalajson" % contrabandSjsonNewVersion.value

View File

@ -1,8 +1,8 @@
/*
* Zinc - The incremental compiler for Scala.
* Copyright 2011 - 2017, Lightbend, Inc.
* sbt
* Copyright 2011 - 2018, Lightbend, Inc.
* Copyright 2008 - 2010, Mark Harrah
* This software is released under the terms written in LICENSE.
* Licensed under Apache License 2.0 (see LICENSE)
*/
package xsbti.compile;

View File

@ -1,8 +1,8 @@
/*
* Zinc - The incremental compiler for Scala.
* Copyright 2011 - 2017, Lightbend, Inc.
* sbt
* Copyright 2011 - 2018, Lightbend, Inc.
* Copyright 2008 - 2010, Mark Harrah
* This software is released under the terms written in LICENSE.
* Licensed under Apache License 2.0 (see LICENSE)
*/
package sbt.internal.inc

View File

@ -1,8 +1,8 @@
/*
* Zinc - The incremental compiler for Scala.
* Copyright 2011 - 2017, Lightbend, Inc.
* sbt
* Copyright 2011 - 2018, Lightbend, Inc.
* Copyright 2008 - 2010, Mark Harrah
* This software is released under the terms written in LICENSE.
* Licensed under Apache License 2.0 (see LICENSE)
*/
package sbt.internal.inc

View File

@ -1,8 +1,8 @@
/*
* Zinc - The incremental compiler for Scala.
* Copyright 2011 - 2017, Lightbend, Inc.
* sbt
* Copyright 2011 - 2018, Lightbend, Inc.
* Copyright 2008 - 2010, Mark Harrah
* This software is released under the terms written in LICENSE.
* Licensed under Apache License 2.0 (see LICENSE)
*/
package sbt.internal.inc

View File

@ -1,8 +1,8 @@
/*
* Zinc - The incremental compiler for Scala.
* Copyright 2011 - 2017, Lightbend, Inc.
* sbt
* Copyright 2011 - 2018, Lightbend, Inc.
* Copyright 2008 - 2010, Mark Harrah
* This software is released under the terms written in LICENSE.
* Licensed under Apache License 2.0 (see LICENSE)
*/
package sbt
@ -44,6 +44,9 @@ private[sbt] object ZincComponentCompiler {
case sc if (sc startsWith "2.11.") => "compiler-bridge_2.11"
case sc if (sc startsWith "2.12.") => "compiler-bridge_2.12"
case "2.13.0-M1" => "compiler-bridge_2.12"
case sc if (sc startsWith "2.13.0-pre-") => "compiler-bridge_2.13.0-M5"
case sc if (sc startsWith "2.13.0-M") => "compiler-bridge_2.13.0-M5"
case sc if (sc startsWith "2.13.0-RC") => "compiler-bridge_2.13.0-M5"
case _ => "compiler-bridge_2.13"
}
}

View File

@ -1,8 +1,8 @@
/*
* Zinc - The incremental compiler for Scala.
* Copyright 2011 - 2017, Lightbend, Inc.
* sbt
* Copyright 2011 - 2018, Lightbend, Inc.
* Copyright 2008 - 2010, Mark Harrah
* This software is released under the terms written in LICENSE.
* Licensed under Apache License 2.0 (see LICENSE)
*/
package sbt

View File

@ -1,8 +1,8 @@
/*
* Zinc - The incremental compiler for Scala.
* Copyright 2011 - 2017, Lightbend, Inc.
* sbt
* Copyright 2011 - 2018, Lightbend, Inc.
* Copyright 2008 - 2010, Mark Harrah
* This software is released under the terms written in LICENSE.
* Licensed under Apache License 2.0 (see LICENSE)
*/
package sbt.internal.inc

View File

@ -1,19 +1,28 @@
/*
* sbt
* Copyright 2011 - 2018, Lightbend, Inc.
* Copyright 2008 - 2010, Mark Harrah
* Licensed under Apache License 2.0 (see LICENSE)
*/
package sbt.internal.inc
import java.io.File
import sbt.io.IO
import sbt.io.syntax._
import sbt.librarymanagement._
import sbt.librarymanagement.ivy._
import sbt.util.Logger
import xsbti.compile.CompilerBridgeProvider
import org.scalatest._
/**
* Base class for test suites that must be able to fetch and compile the compiler bridge.
*
* This is a very good example on how to instantiate the compiler bridge provider.
*/
abstract class IvyBridgeProviderSpecification extends UnitSpec with AbstractBridgeProviderTestkit {
abstract class IvyBridgeProviderSpecification extends FlatSpec with Matchers {
def currentBase: File = new File(".")
def currentTarget: File = currentBase / "target" / "ivyhome"
def currentManaged: File = currentBase / "target" / "lib_managed"
@ -24,7 +33,8 @@ abstract class IvyBridgeProviderSpecification extends UnitSpec with AbstractBrid
MavenRepository("scala-integration",
"https://scala-ci.typesafe.com/artifactory/scala-integration/")
)
private val ivyConfiguration =
private def ivyConfiguration(log: Logger) =
getDefaultConfiguration(currentBase, currentTarget, resolvers, log)
def secondaryCacheDirectory: File = {
@ -32,13 +42,28 @@ abstract class IvyBridgeProviderSpecification extends UnitSpec with AbstractBrid
target / "zinc-components"
}
def getZincProvider(targetDir: File, log: Logger): CompilerBridgeProvider = {
def getZincProvider(bridge: ModuleID, targetDir: File, log: Logger): CompilerBridgeProvider = {
val lock = ZincComponentCompiler.getDefaultLock
val secondaryCache = Some(secondaryCacheDirectory)
val componentProvider = ZincComponentCompiler.getDefaultComponentProvider(targetDir)
val manager = new ZincComponentManager(lock, componentProvider, secondaryCache, log)
val dependencyResolution = IvyDependencyResolution(ivyConfiguration)
ZincComponentCompiler.interfaceProvider(manager, dependencyResolution, currentManaged)
val dependencyResolution = IvyDependencyResolution(ivyConfiguration(log))
ZincComponentCompiler.interfaceProvider(bridge, manager, dependencyResolution, currentManaged)
}
def getCompilerBridge(targetDir: File, log: Logger, scalaVersion: String): File = {
val bridge0 = ZincComponentCompiler.getDefaultBridgeModule(scalaVersion)
// redefine the compiler bridge version
// using the version of zinc used during testing
// this way when building with zinc as a source dependency
// these specs don't go looking for some SHA-suffixed compiler bridge
val bridge1 = bridge0.withRevision(ZincLmIntegrationBuildInfo.zincVersion)
val provider = getZincProvider(bridge1, targetDir, log)
val scalaInstance = provider.fetchScalaInstance(scalaVersion, log)
val bridge = provider.fetchCompiledBridge(scalaInstance, log)
val target = targetDir / s"target-bridge-$scalaVersion.jar"
IO.copyFile(bridge, target)
target
}
private def getDefaultConfiguration(baseDirectory: File,

View File

@ -1,3 +1,10 @@
/*
* sbt
* Copyright 2011 - 2018, Lightbend, Inc.
* Copyright 2008 - 2010, Mark Harrah
* Licensed under Apache License 2.0 (see LICENSE)
*/
package sbt.internal.inc
import sbt.internal.util.ConsoleLogger
@ -11,10 +18,13 @@ class ZincComponentCompilerSpec extends IvyBridgeProviderSpecification {
val scala2121 = "2.12.1"
val scala2122 = "2.12.2"
val scala2123 = "2.12.3"
val scala2130M2 = "2.13.0-M2"
val scala2130RC1 = "2.13.0-RC1"
def isJava8: Boolean = sys.props("java.specification.version") == "1.8"
val logger = ConsoleLogger()
it should "compile the bridge for Scala 2.10.5 and 2.10.6" in {
if (isJava8) {
IO.withTemporaryDirectory(t => getCompilerBridge(t, logger, scala2105) should exist)
@ -35,6 +45,10 @@ class ZincComponentCompilerSpec extends IvyBridgeProviderSpecification {
IO.withTemporaryDirectory(t => getCompilerBridge(t, logger, scala2123) should exist)
}
it should "compile the bridge for Scala 2.13.0-M2" in {
IO.withTemporaryDirectory(t => getCompilerBridge(t, logger, scala2130M2) should exist)
}
it should "compile the bridge for Scala 2.13.0-RC1" in {
IO.withTemporaryDirectory(t => getCompilerBridge(t, logger, scala2130RC1) should exist)
}