Upgrade build from sbt 0.13.17 to 1.2.3

This commit is contained in:
Seth Tisue 2018-09-26 14:56:08 +02:00 committed by Adriaan Moors
parent 2e82444401
commit 705ac90e17
17 changed files with 53 additions and 114 deletions

View File

@ -138,8 +138,6 @@ Note that sbt's incremental compilation is often too coarse for the Scala compil
codebase and re-compiles too many files, resulting in long build times (check
[sbt#1104](https://github.com/sbt/sbt/issues/1104) for progress on that front). In the
meantime you can:
- Enable "Ant mode" in which sbt only re-compiles source files that were modified.
Create a file `local.sbt` containing the line `antStyle := true`.
- Use IntelliJ IDEA for incremental compiles (see [IDE Setup](#ide-setup) below) - its
incremental compiler is a bit less conservative, but usually correct.

View File

@ -67,7 +67,7 @@ lazy val publishSettings : Seq[Setting[_]] = Seq(
else Nil
},
// Add a "default" Ivy configuration because sbt expects the Scala distribution to have one:
ivyConfigurations += Configuration("default", "Default", true, List(Configurations.Runtime), true),
ivyConfigurations += Configuration.of("Default", "default", "Default", true, Vector(Configurations.Runtime), true),
publishMavenStyle := true
)
@ -97,20 +97,17 @@ lazy val instanceSettings = Seq[Setting[_]](
// sbt claims that s.isManagedVersion is false even though s was resolved by Ivy
// We create a managed copy to prevent sbt from putting it on the classpath where we don't want it
if(s.isManagedVersion) s else {
val jars = s.jars
val libraryJar = jars.find(_.getName contains "-library").get
val compilerJar = jars.find(_.getName contains "-compiler").get
val extraJars = jars.filter(f => (f ne libraryJar) && (f ne compilerJar))
val s2 = new ScalaInstance(s.version, s.loader, libraryJar, compilerJar, extraJars, Some(s.actualVersion))
import sbt.internal.inc.ScalaInstance
val s2 = new ScalaInstance(s.version, s.loader, s.libraryJar, s.compilerJar, s.allJars, Some(s.actualVersion))
assert(s2.isManagedVersion)
s2
}
},
// As of sbt 0.13.12 (sbt/sbt#2634) sbt endeavours to align both scalaOrganization and scalaVersion
// sbt endeavours to align both scalaOrganization and scalaVersion
// in the Scala artefacts, for example scala-library and scala-compiler.
// This doesn't work in the scala/scala build because the version of scala-library and the scalaVersion of
// scala-library are correct to be different. So disable overriding.
ivyScala ~= (_ map (_ copy (overrideScalaVersion = false))),
scalaModuleInfo ~= (_ map (_ withOverrideScalaVersion false)),
Quiet.silenceScalaBinaryVersionWarning
)
@ -137,25 +134,6 @@ lazy val commonSettings = instanceSettings ++ clearSourceAndResourceDirectories
// to make sure they are being cleaned properly
cleanFiles += (classDirectory in Compile).value,
cleanFiles += (target in Compile in doc).value,
// SBT 0.13.17+ doesn't seem to respect `cleanFiles` anymore: https://github.com/sbt/sbt/pull/3834/files#r172686677
// Let's override `cleanFilesTask`.
cleanFilesTask := {
val filesAndDirs = (Vector(managedDirectory.value, target.value) ++ cleanFiles.value).distinct
// START: Copy/pasted from SBT
val preserve = cleanKeepFiles.value
val (dirs, fs) = filesAndDirs.filter(_.exists).partition(_.isDirectory)
val preserveSet = preserve.filter(_.exists).toSet
// performance reasons, only the direct items under `filesAndDirs` are allowed to be preserved.
val dirItems = dirs flatMap { _.*("*").get }
(preserveSet diff dirItems.toSet) match {
case xs if xs.isEmpty => ()
case xs => sys.error(s"cleanKeepFiles contains directory/file that are not directly under cleanFiles: $xs")
}
val toClean = (dirItems filterNot { preserveSet(_) }) ++ fs
toClean
// END: Copy/pasted from SBT
},
fork in run := true,
//scalacOptions in Compile += "-Xlint:-nullary-override,-inaccessible,-nonlocal-return,_",
//scalacOptions ++= Seq("-Xmaxerrs", "5", "-Xmaxwarns", "5"),
@ -363,7 +341,7 @@ lazy val library = configureAsSubproject(project)
// Include *.txt files in source JAR:
mappings in Compile in packageSrc ++= {
val base = (unmanagedResourceDirectories in Compile).value
base ** "*.txt" pair relativeTo(base)
base ** "*.txt" pair Path.relativeTo(base)
},
Osgi.headers += "Import-Package" -> "sun.misc;resolution:=optional, *",
Osgi.jarlist := true,
@ -455,7 +433,7 @@ lazy val compiler = configureAsSubproject(project)
(unmanagedResourceDirectories in Compile in LocalProject("interactive")).value ++
(unmanagedResourceDirectories in Compile in LocalProject("scaladoc")).value ++
(unmanagedResourceDirectories in Compile in LocalProject("repl")).value
base ** ((includeFilter in unmanagedResources in Compile).value || "*.scala" || "*.psd" || "*.ai" || "*.java") pair relativeTo(base)
base ** ((includeFilter in unmanagedResources in Compile).value || "*.scala" || "*.psd" || "*.ai" || "*.java") pair Path.relativeTo(base)
},
// Include the additional projects in the scaladoc JAR:
sources in Compile in doc ++= {
@ -702,7 +680,7 @@ def osgiTestProject(p: Project, framework: ModuleID) = p
val mappings = ((mkPack in dist).value / "lib").listFiles.collect {
case f if f.getName.startsWith("scala-") && f.getName.endsWith(".jar") => (f, targetDir / f.getName)
}
IO.copy(mappings, overwrite = true)
IO.copy(mappings, CopyOptions() withOverwrite true)
targetDir
},
cleanFiles += (buildDirectory in ThisBuild).value / "osgi"
@ -750,12 +728,15 @@ lazy val test = project
testFrameworks += new TestFramework("scala.tools.partest.sbt.Framework"),
testOptions in IntegrationTest += Tests.Argument("-Dpartest.java_opts=-Xmx1024M -Xms64M"),
testOptions in IntegrationTest += Tests.Argument("-Dpartest.scalac_opts=" + (scalacOptions in Compile).value.mkString(" ")),
testOptions in IntegrationTest += Tests.Setup { () =>
testOptions in IntegrationTest += {
val cp = (dependencyClasspath in Test).value
val baseDir = (baseDirectory in ThisBuild).value
// Copy code.jar (resolved in the otherwise unused scope "test") and instrumented.jar (from specLib) to the location where partest expects them
copyBootstrapJar(cp, baseDir, "test/files/codelib", "code")
IO.copyFile((packagedArtifact in (LocalProject("specLib"), Compile, packageBin)).value._2, baseDir / "test/files/speclib/instrumented.jar")
val instrumentedJar = (packagedArtifact in (LocalProject("specLib"), Compile, packageBin)).value._2
Tests.Setup { () =>
// Copy code.jar (resolved in the otherwise unused scope "test") and instrumented.jar (from specLib)to the location where partest expects them
copyBootstrapJar(cp, baseDir, "test/files/codelib", "code")
IO.copyFile(instrumentedJar, baseDir / "test/files/speclib/instrumented.jar")
}
},
definedTests in IntegrationTest += new sbt.TestDefinition(
"partest",
@ -767,12 +748,13 @@ lazy val test = project
}, true, Array()
),
executeTests in IntegrationTest := {
val log = streams.value.log
val result = (executeTests in IntegrationTest).value
val result2 = (executeTests in Test).value
if (result.overall != TestResult.Error && result.events.isEmpty) {
// workaround for https://github.com/sbt/sbt/issues/2722
val result = (executeTests in Test).value
(streams.value.log.error("No test events found"))
result.copy(overall = TestResult.Error)
log.error("No test events found")
result2.copy(overall = TestResult.Error)
}
else result
},
@ -793,13 +775,13 @@ lazy val scalaDist = Project("scala-dist", file(".") / "target" / "scala-dist-di
.settings(
mappings in Compile in packageBin ++= {
val binBaseDir = buildDirectory.value / "pack"
val binMappings = (mkBin in dist).value.pair(relativeTo(binBaseDir), errorIfNone = false)
val binMappings = (mkBin in dist).value.pair(Path.relativeTo(binBaseDir), errorIfNone = false)
// With the way the resource files are spread out over the project sources we can't just add
// an unmanagedResourceDirectory, so we generate the mappings manually:
val docBaseDir = (baseDirectory in ThisBuild).value
val docMappings = (docBaseDir / "doc").*** pair relativeTo(docBaseDir)
val docMappings = (docBaseDir / "doc").allPaths pair Path.relativeTo(docBaseDir)
val resBaseDir = (baseDirectory in ThisBuild).value / "src/manual/scala/tools/docutil/resources"
val resMappings = resBaseDir ** ("*.html" | "*.css" | "*.gif" | "*.png") pair (p => relativeTo(resBaseDir)(p).map("doc/tools/" + _))
val resMappings = resBaseDir ** ("*.html" | "*.css" | "*.gif" | "*.png") pair (p => Path.relativeTo(resBaseDir)(p).map("doc/tools/" + _))
docMappings ++ resMappings ++ binMappings
},
resourceGenerators in Compile += Def.task {
@ -812,8 +794,8 @@ lazy val scalaDist = Project("scala-dist", file(".") / "target" / "scala-dist-di
runner.value.run("scala.tools.docutil.ManMaker",
(fullClasspath in Compile in manual).value.files,
Seq(command, htmlOut.getAbsolutePath, manOut.getAbsolutePath),
streams.value.log).foreach(sys.error)
(manOut ** "*.1" pair rebase(manOut, fixedManOut)).foreach { case (in, out) =>
streams.value.log).failed foreach (sys error _.getMessage)
(manOut ** "*.1" pair Path.rebase(manOut, fixedManOut)).foreach { case (in, out) =>
// Generated manpages should always use LF only. There doesn't seem to be a good reason
// for generating them with the platform EOL first and then converting them but that's
// what the old Ant build did.
@ -893,9 +875,9 @@ lazy val root: Project = (project in file("."))
doc in Compile in scalap
).result map (_ -> "doc")
)).value
val log = streams.value.log
val failed = results.collect { case (Inc(i), d) => (i, d) }
if (failed.nonEmpty) {
val log = streams.value.log
def showScopedKey(k: Def.ScopedKey[_]): String =
Vector(
k.scope.project.toOption.map {
@ -933,11 +915,9 @@ lazy val root: Project = (project in file("."))
throw new RuntimeException
}
},
antStyle := false,
incOptions := {
incOptions.value
.withNameHashing(!antStyle.value).withAntStyle(antStyle.value)
.withRecompileOnMacroDef(false) // // macros in library+reflect are hard-wired to implementations with `FastTrack`.
.withRecompileOnMacroDef(Some(Boolean box false).asJava) // macros in library+reflect are hard-wired to implementations with `FastTrack`.
}
)
.aggregate(library, reflect, compiler, compilerOptionsExporter, interactive, repl, replFrontend,
@ -969,7 +949,7 @@ lazy val dist = (project in file("dist"))
val targetDir = (buildDirectory in ThisBuild).value / "pack" / "lib"
val jlineJAR = findJar((dependencyClasspath in Compile).value, jlineDep).get.data
val mappings = Seq((jlineJAR, targetDir / "jline.jar"))
IO.copy(mappings, overwrite = true)
IO.copy(mappings, CopyOptions() withOverwrite true)
targetDir
},
cleanFiles += (buildDirectory in ThisBuild).value / "quick",
@ -1104,6 +1084,7 @@ intellij := {
import xml.transform._
val s = streams.value
val compilerScalaInstance = (scalaInstance in LocalProject("compiler")).value
val modules: List[(String, Seq[File])] = {
// for the sbt build module, the dependencies are fetched from the project's build using sbt-buildinfo
@ -1187,20 +1168,20 @@ intellij := {
if (!ipr.exists) {
scala.Console.print(s"Could not find src/intellij/scala.ipr. Create new project files from src/intellij/*.SAMPLE (y/N)? ")
scala.Console.flush()
if (scala.Console.readLine() == "y") {
if (scala.io.StdIn.readLine() == "y") {
intellijCreateFromSample((baseDirectory in ThisBuild).value)
continue = true
}
} else {
scala.Console.print("Update library classpaths in the current src/intellij/scala.ipr (y/N)? ")
scala.Console.flush()
continue = scala.Console.readLine() == "y"
continue = scala.io.StdIn.readLine() == "y"
}
if (continue) {
s.log.info("Updating library classpaths in src/intellij/scala.ipr.")
val content = XML.loadFile(ipr)
val newStarr = replaceLibrary(content, "starr", Some("Scala"), starrDep((scalaInstance in LocalProject("compiler")).value.jars))
val newStarr = replaceLibrary(content, "starr", Some("Scala"), starrDep(compilerScalaInstance.allJars))
val newModules = modules.foldLeft(newStarr)({
case (res, (modName, jars)) =>
if (jars.isEmpty) res // modules without dependencies
@ -1219,7 +1200,7 @@ intellijFromSample := {
val s = streams.value
scala.Console.print(s"Create new project files from src/intellij/*.SAMPLE (y/N)? ")
scala.Console.flush()
if (scala.Console.readLine() == "y")
if (scala.io.StdIn.readLine() == "y")
intellijCreateFromSample((baseDirectory in ThisBuild).value)
else
s.log.info("Aborting.")
@ -1228,7 +1209,7 @@ intellijFromSample := {
def intellijCreateFromSample(basedir: File): Unit = {
val files = basedir / "src/intellij" * "*.SAMPLE"
val copies = files.get.map(f => (f, new File(f.getAbsolutePath.stripSuffix(".SAMPLE"))))
IO.copy(copies, overwrite = true)
IO.copy(copies, CopyOptions() withOverwrite true)
}
lazy val intellijToSample = taskKey[Unit]("Update src/intellij/*.SAMPLE using the current IntelliJ project files.")
@ -1237,7 +1218,7 @@ intellijToSample := {
val s = streams.value
scala.Console.print(s"Update src/intellij/*.SAMPLE using the current IntelliJ project files (y/N)? ")
scala.Console.flush()
if (scala.Console.readLine() == "y") {
if (scala.io.StdIn.readLine() == "y") {
val basedir = (baseDirectory in ThisBuild).value
val existing = basedir / "src/intellij" * "*.SAMPLE"
IO.delete(existing.get)

View File

@ -5,7 +5,6 @@ import sbt._
/** This object defines keys that should be visible with an unqualified name in all .sbt files and the command line */
object BuildSettings extends AutoPlugin {
object autoImport {
lazy val antStyle = settingKey[Boolean]("Use ant-style incremental builds instead of name-hashing")
lazy val baseVersion = settingKey[String]("The base version number from which all others are derived")
lazy val baseVersionSuffix = settingKey[String]("Identifies the kind of version to build")
lazy val mimaReferenceVersion = settingKey[Option[String]]("Scala version number to run MiMa against")

View File

@ -2,7 +2,6 @@ package scala.build
import aQute.bnd.osgi.Builder
import aQute.bnd.osgi.Constants._
import java.util.Properties
import java.util.jar.Attributes
import sbt._
import sbt.Keys._

View File

@ -5,6 +5,7 @@ import java.util.concurrent.TimeUnit
import sbt.testing.{SuiteSelector, TestSelector}
import sbt.{JUnitXmlTestsListener, TestEvent, TestResult, TestsListener, _}
import sbt.internal.util.EscHelpers.removeEscapeSequences
// The default JUnitXMLListener doesn't play well with partest: we end up clobbering the one-and-only partest.xml
// file on group of tests run by `testAll`, and the test names in the XML file don't seem to show the path to the
@ -21,9 +22,9 @@ class PartestTestListener(target: File) extends TestsListener {
val skipStatus = EnumSet.of(TStatus.Skipped, TStatus.Ignored)
override def doInit(): Unit = ()
override def doComplete(finalResult: TestResult.Value): Unit = ()
override def doComplete(finalResult: TestResult): Unit = ()
override def endGroup(name: String, t: Throwable): Unit = ()
override def endGroup(name: String, result: TestResult.Value): Unit = ()
override def endGroup(name: String, result: TestResult): Unit = ()
override def testEvent(event: TestEvent): Unit = {
// E.g "test.files.pos" or "test.scaladoc.run"
def groupOf(e: sbt.testing.Event) = {
@ -62,7 +63,7 @@ class PartestTestListener(target: File) extends TestsListener {
val writer = new PrintWriter(stringWriter)
e.throwable.get.printStackTrace(writer)
writer.flush()
ConsoleLogger.removeEscapeSequences(stringWriter.toString)
removeEscapeSequences(stringWriter.toString)
} else {
""
}
@ -70,13 +71,13 @@ class PartestTestListener(target: File) extends TestsListener {
<testcase classname={group} name={testOf(e)} time={(1.0 * e.duration() / 1000).toString}>
{e.status match {
case TStatus.Error if e.throwable.isDefined =>
<error message={ConsoleLogger.removeEscapeSequences(e.throwable.get.getMessage)} type={e.throwable.get.getClass.getName}>
<error message={removeEscapeSequences(e.throwable.get.getMessage)} type={e.throwable.get.getClass.getName}>
{trace}
</error>
case TStatus.Error =>
<error message={"No Exception or message provided"}/>
case TStatus.Failure if e.throwable.isDefined =>
<failure message={ConsoleLogger.removeEscapeSequences(e.throwable.get.getMessage)} type={e.throwable.get.getClass.getName}>
<failure message={removeEscapeSequences(e.throwable.get.getMessage)} type={e.throwable.get.getClass.getName}>
{trace}
</failure>
case TStatus.Failure =>

View File

@ -10,7 +10,7 @@ object PartestUtil {
private def testCaseFinder = (testBase / srcPath).*(AllPassFilter).*(testCaseFilter)
private val basePaths = allTestCases.map(_._2.split('/').take(3).mkString("/") + "/").distinct
def allTestCases = testCaseFinder.pair(relativeTo(globalBase))
def allTestCases = testCaseFinder.pair(io.Path.relativeTo(globalBase))
def basePathExamples = new FixedSetExamples(basePaths)
private def equiv(f1: File, f2: File) = f1.getCanonicalFile == f2.getCanonicalFile
def parentChain(f: File): Iterator[File] =

View File

@ -2,32 +2,13 @@ package scala.build
import sbt._
import Keys._
import java.util.function.Supplier
object Quiet {
// Workaround sbt issue described:
//
// https://github.com/scala/scala-dev/issues/100
def silenceScalaBinaryVersionWarning = ivyConfiguration := {
ivyConfiguration.value match {
case c: InlineIvyConfiguration =>
val delegate = c.log
val logger = new Logger {
override def trace(t: => Throwable): Unit = delegate.trace(t)
override def log(level: sbt.Level.Value, message: => String): Unit = {
level match {
case sbt.Level.Warn =>
val message0 = message
val newLevel = if (message.contains("differs from Scala binary version in project"))
delegate.log(sbt.Level.Debug, message)
else
delegate.log(level, message)
case _ => delegate.log(level, message)
}
}
override def success(message: => String): Unit = delegate.success(message)
}
new InlineIvyConfiguration(c.paths, c.resolvers, c.otherResolvers, c.moduleConfigurations, c.localOnly, c.lock, c.checksums, c.resolutionCacheDir, c.updateOptions, logger)
case x => x
}
ivyConfiguration.value // TODO: Needs revisiting in sbt 1
}
}

View File

@ -99,14 +99,7 @@ object ScriptCommands {
def enableOptimizerCommand = setup("enableOptimizer")(_ => enableOptimizer)
private[this] def setup(name: String)(f: Seq[String] => Seq[Setting[_]]) = Command.args(name, name) { case (state, seq) =>
// `Project.extract(state).append(f(seq), state)` would be simpler, but it
// takes the project's initial state and discards all changes that were made in the sbt console.
val session = Project.session(state)
val extracted = Project.extract(state)
val settings = f(seq)
val appendSettings = Load.transformSettings(Load.projectScope(extracted.currentRef), extracted.currentRef.build, extracted.rootProject, settings)
val newStructure = Load.reapply(session.mergeSettings ++ appendSettings, extracted.structure)(extracted.showKey)
Project.setProject(session, newStructure, state)
Project.extract(state).appendWithSession(f(seq), state)
}
private[this] val enableOptimizer = Seq(

View File

@ -8,7 +8,7 @@ object TestJDeps {
val reflectJar = (packageBin in Compile in LocalProject("reflect")).value
// jdeps -s -P build/pack/lib/scala-{library,reflect}.jar | grep -v build/pack | perl -pe 's/.*\((.*)\)$/$1/' | sort -u
val jdepsOut = Process("jdeps", Seq("-s", "-P", libraryJar.getPath, reflectJar.getPath)).lines
val jdepsOut = scala.sys.process.Process("jdeps", Seq("-s", "-P", libraryJar.getPath, reflectJar.getPath)).lineStream
val profilePart = ".*\\((.*)\\)$".r
val profiles = jdepsOut.collect {

View File

@ -1,6 +1,6 @@
package scala.build
import sbt.{stringToProcess => _, _}
import sbt._
import Keys._
import java.util.{Date, Locale, Properties, TimeZone}
import java.io.{File, FileInputStream}
@ -109,7 +109,6 @@ object VersionUtil {
* suffix is used for releases. All other suffix values are treated as RC / milestone builds. The special suffix
* value "SPLIT" is used to split the real suffix off from `baseVersion` instead and then apply the usual logic. */
private lazy val versionPropertiesImpl: Def.Initialize[Versions] = Def.setting {
val log = sLog.value
val (date, sha) = (gitProperties.value.date, gitProperties.value.sha)
val (base, suffix) = {

View File

@ -1 +1 @@
sbt.version=0.13.17
sbt.version=1.2.3

View File

@ -1,5 +1,5 @@
scalacOptions ++= Seq("-unchecked", "-feature", /*"-deprecation",*/
"-Xlint" /*, "-Xfatal-warnings"*/)
/* "-Xlint" */ /*, "-Xfatal-warnings"*/)
libraryDependencies += "org.apache.commons" % "commons-lang3" % "3.3.2"

View File

@ -1 +1 @@
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.6.1")
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.7.0")

View File

@ -11,7 +11,7 @@ else
fi
SBT_CMD=${SBT_CMD-sbt}
SBT_CMD="$SBT_CMD -sbt-version 0.13.17"
SBT_CMD="$SBT_CMD -sbt-version 1.2.3"
# repo to publish builds
integrationRepoUrl=${integrationRepoUrl-"https://scala-ci.typesafe.com/artifactory/scala-integration/"}

View File

@ -1,15 +1 @@
/project/project/
/project/target/
/target/
# what appears to be a Scala IDE-generated file
.cache-main
# standard Eclipse output directory
/bin/
.idea
# sbteclipse-generated Eclipse files
/.classpath
/.project
/.settings/
target/

View File

@ -0,0 +1 @@
sbt.version=1.1.4

View File

@ -0,0 +1 @@
addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.2.27")