From 6878fb6cdbbdf038b97120d7242f782698df6763 Mon Sep 17 00:00:00 2001 From: Eugene Yokota Date: Sat, 8 Jun 2019 17:49:06 +0200 Subject: [PATCH] turbo mode This creates a performance mode that enables experimental or advanced features that might require some debugging by the build user when it doesn't work. Initially we are putting the layered ClassLoader (`ClassLoaderLayeringStrategy.AllLibraryJars`) behind this flag. --- main/src/main/scala/sbt/Defaults.scala | 12 ++++++++---- main/src/main/scala/sbt/Keys.scala | 1 + main/src/main/scala/sbt/internal/SysProp.scala | 2 ++ .../classloader-cache/akka-actor-system/build.sbt | 2 ++ sbt/src/sbt-test/classloader-cache/jni/build.sbt | 2 ++ .../classloader-cache/library-mismatch/build.sbt | 2 ++ .../sbt-test/classloader-cache/resources/build.sbt | 2 ++ .../sbt-test/classloader-cache/snapshot/build.sbt | 2 ++ sbt/src/sbt-test/classloader-cache/utest/build.sbt | 2 ++ 9 files changed, 23 insertions(+), 4 deletions(-) diff --git a/main/src/main/scala/sbt/Defaults.scala b/main/src/main/scala/sbt/Defaults.scala index 40c33e08e..12d8cc4e1 100755 --- a/main/src/main/scala/sbt/Defaults.scala +++ b/main/src/main/scala/sbt/Defaults.scala @@ -164,7 +164,6 @@ object Defaults extends BuildCommon { private[sbt] lazy val globalJvmCore: Seq[Setting[_]] = Seq( compilerCache := state.value get Keys.stateCompilerCache getOrElse CompilerCache.fresh, - classLoaderLayeringStrategy :== ClassLoaderLayeringStrategy.AllLibraryJars, sourcesInBase :== true, autoAPIMappings := false, apiMappings := Map.empty, @@ -285,6 +284,7 @@ object Defaults extends BuildCommon { val tempDirectory = taskTemporaryDirectory.value () => Clean.deleteContents(tempDirectory, _ => false) }, + turbo :== SysProp.turbo, useSuperShell := { if (insideCI.value) false else SysProp.supershell }, progressReports := { val progress = useSuperShell.value @@ -1049,7 +1049,7 @@ object Defaults extends BuildCommon { cp, forkedParallelExecution = false, javaOptions = Nil, - strategy = ClassLoaderLayeringStrategy.AllLibraryJars, + strategy = ClassLoaderLayeringStrategy.ScalaLibrary, projectId = "", ) } @@ -1072,7 +1072,7 @@ object Defaults extends BuildCommon { cp, forkedParallelExecution, javaOptions = Nil, - strategy = ClassLoaderLayeringStrategy.AllLibraryJars, + strategy = ClassLoaderLayeringStrategy.ScalaLibrary, projectId = "", ) } @@ -1886,7 +1886,11 @@ object Defaults extends BuildCommon { } val base = ModuleID(id.groupID, id.name, sv).withCrossVersion(cross) CrossVersion(scalaV, binVersion)(base).withCrossVersion(Disabled()) - } + }, + classLoaderLayeringStrategy := { + if (turbo.value) ClassLoaderLayeringStrategy.AllLibraryJars + else ClassLoaderLayeringStrategy.ScalaLibrary + }, ) // build.sbt is treated a Scala source of metabuild, so to enable deprecation flag on build.sbt we set the option here. lazy val deprecationSettings: Seq[Setting[_]] = diff --git a/main/src/main/scala/sbt/Keys.scala b/main/src/main/scala/sbt/Keys.scala index a38f143c3..001db1bf8 100644 --- a/main/src/main/scala/sbt/Keys.scala +++ b/main/src/main/scala/sbt/Keys.scala @@ -474,6 +474,7 @@ object Keys { def apply(progress: ExecuteProgress[Task]): TaskProgress = new TaskProgress(progress) } val useSuperShell = settingKey[Boolean]("Enables (true) or disables the super shell.") + val turbo = settingKey[Boolean]("Enables (true) or disables optional performance features.") // This key can be used to add custom ExecuteProgress instances val progressReports = settingKey[Seq[TaskProgress]]("A function that returns a list of progress reporters.").withRank(DTask) private[sbt] val postProgressReports = settingKey[Unit]("Internally used to modify logger.").withRank(DTask) diff --git a/main/src/main/scala/sbt/internal/SysProp.scala b/main/src/main/scala/sbt/internal/SysProp.scala index 0379f28be..c5dd716f0 100644 --- a/main/src/main/scala/sbt/internal/SysProp.scala +++ b/main/src/main/scala/sbt/internal/SysProp.scala @@ -93,6 +93,8 @@ object SysProp { coursierOpt.orElse(notIvyOpt).getOrElse(true) } + def turbo: Boolean = getOrFalse("sbt.turbo") + def taskTimings: Boolean = getOrFalse("sbt.task.timings") def taskTimingsOnShutdown: Boolean = getOrFalse("sbt.task.timings.on.shutdown") def taskTimingsThreshold: Long = long("sbt.task.timings.threshold", 0L) diff --git a/sbt/src/sbt-test/classloader-cache/akka-actor-system/build.sbt b/sbt/src/sbt-test/classloader-cache/akka-actor-system/build.sbt index 9be9015dc..7d5b0fbd5 100644 --- a/sbt/src/sbt-test/classloader-cache/akka-actor-system/build.sbt +++ b/sbt/src/sbt-test/classloader-cache/akka-actor-system/build.sbt @@ -1,3 +1,5 @@ +ThisBuild / turbo := true + val akkaTest = (project in file(".")).settings( name := "akka-test", scalaVersion := "2.12.8", diff --git a/sbt/src/sbt-test/classloader-cache/jni/build.sbt b/sbt/src/sbt-test/classloader-cache/jni/build.sbt index e12fc74f2..63e0131ab 100644 --- a/sbt/src/sbt-test/classloader-cache/jni/build.sbt +++ b/sbt/src/sbt-test/classloader-cache/jni/build.sbt @@ -10,6 +10,8 @@ val wrappedTest = taskKey[Unit]("Test with modified java.library.path") def wrap(task: InputKey[Unit]): Def.Initialize[Task[Unit]] = Def.sequential(appendToLibraryPath, task.toTask(""), dropLibraryPath) +ThisBuild / turbo := true + val root = (project in file(".")).settings( scalaVersion := "2.12.8", javacOptions ++= Seq("-source", "1.8", "-target", "1.8", "-h", diff --git a/sbt/src/sbt-test/classloader-cache/library-mismatch/build.sbt b/sbt/src/sbt-test/classloader-cache/library-mismatch/build.sbt index fefcd86a2..460c9f175 100644 --- a/sbt/src/sbt-test/classloader-cache/library-mismatch/build.sbt +++ b/sbt/src/sbt-test/classloader-cache/library-mismatch/build.sbt @@ -1,3 +1,5 @@ +ThisBuild / turbo := true + val snapshot = (project in file(".")).settings( name := "mismatched-libraries", scalaVersion := "2.12.8", diff --git a/sbt/src/sbt-test/classloader-cache/resources/build.sbt b/sbt/src/sbt-test/classloader-cache/resources/build.sbt index fbc057785..bf5ab6486 100644 --- a/sbt/src/sbt-test/classloader-cache/resources/build.sbt +++ b/sbt/src/sbt-test/classloader-cache/resources/build.sbt @@ -1,3 +1,5 @@ +ThisBuild / turbo := true + resolvers += "Local Maven" at (baseDirectory.value / "libraries" / "foo" / "ivy").toURI.toURL.toString libraryDependencies += "sbt" %% "foo-lib" % "0.1.0" diff --git a/sbt/src/sbt-test/classloader-cache/snapshot/build.sbt b/sbt/src/sbt-test/classloader-cache/snapshot/build.sbt index a43dd3048..28eeb6222 100644 --- a/sbt/src/sbt-test/classloader-cache/snapshot/build.sbt +++ b/sbt/src/sbt-test/classloader-cache/snapshot/build.sbt @@ -1,3 +1,5 @@ +ThisBuild / turbo := true + import java.nio.file.Files import java.nio.file.attribute.FileTime import scala.collection.JavaConverters._ diff --git a/sbt/src/sbt-test/classloader-cache/utest/build.sbt b/sbt/src/sbt-test/classloader-cache/utest/build.sbt index b0d82f379..c64105efb 100644 --- a/sbt/src/sbt-test/classloader-cache/utest/build.sbt +++ b/sbt/src/sbt-test/classloader-cache/utest/build.sbt @@ -1,3 +1,5 @@ +ThisBuild / turbo := true + val utestTest = (project in file(".")).settings( name := "utest-test", scalaVersion := "2.12.8",