Skip to content

Commit

Permalink
Don't force discoveredSbtPlugins when bloopInstall
Browse files Browse the repository at this point in the history
Adds support to elide `discoveredSbtPlugins` for all sbt versions if
either `bloopInstall` or `bloopGenerate` are under execution.

This makes the process faster (exporting the bloop build takes now 11
seconds!).
  • Loading branch information
jvican committed Jun 12, 2018
1 parent ecd5a8b commit 58e69e6
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 32 deletions.
10 changes: 6 additions & 4 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ val benchmarkBridge = project
.disablePlugins(ScriptedPlugin)
.settings(
releaseEarly := { () },
skip in publish := true
skip in publish := true,
bloopGenerate in Compile := None,
bloopGenerate in Test := None,
)

/***************************************************************************************************/
Expand Down Expand Up @@ -171,18 +173,18 @@ lazy val jsBridge06 = project
.settings(testSettings)
.settings(
name := "bloop-js-bridge-0.6",
target := (file("bridges") / "scalajs" / "target" / "0.6").getAbsoluteFile,
libraryDependencies += Dependencies.scalaJsTools06
)

lazy val jsBridge10 = project
.dependsOn(frontend % Provided, frontend % "test->test")
.in(file("bridges") / "scalajs" / "target" / "scalajs-1.0")
.in(file("bridges") / "scalajs")
.disablePlugins(ScriptedPlugin)
.settings(testSettings)
.settings(
name := "bloop-js-bridge-1.0",
sourceDirectories in Compile += file("bridges") / "scalajs" / "src" / "main" / "scala",
sourceDirectories in Test += file("bridges") / "scalajs" / "src" / "test" / "scala",
target := (file("bridges") / "scalajs" / "target" / "1.0").getAbsoluteFile,
libraryDependencies += Dependencies.scalaJsTools10
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ object Compat {

implicit def fileToRichFile(file: File): sbt.RichFile = new sbt.RichFile(file)

def currentCommandFromState(s: sbt.State): Option[String] = Some(s.history.current)

def generateCacheFile(s: sbt.Keys.TaskStreams, id: String) = s.cacheDirectory / id

def toBloopArtifact(a: Artifact, f: File): Config.Artifact = {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ object Compat {
def ivyScala: SettingKey[Option[ScalaModuleInfo]] = keys.scalaModuleInfo
}

def currentCommandFromState(s: sbt.State): Option[String] =
s.currentCommand.map(_.commandLine)

implicit def execToString(e: Exec): String = e.commandLine

implicit def fileToRichFile(file: File): sbt.RichFile = new sbt.RichFile(file)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ object BloopDefaults {
BloopKeys.bloopResourceManaged := BloopKeys.bloopTargetDir.value / "resource_managed",
BloopKeys.bloopGenerate := bloopGenerate.value,
BloopKeys.bloopAnalysisOut := None
) ++ DiscoveredSbtPlugins.settings
) ++ discoveredSbtPluginsSettings

lazy val projectSettings: Seq[Def.Setting[_]] = {
sbt.inConfig(Compile)(configSettings) ++
Expand Down Expand Up @@ -161,6 +161,29 @@ object BloopDefaults {
)
}

/**
* Replace the implementation of discovered sbt plugins so that we don't run it
* when we `bloopGenerate` or `bloopInstall`. This is important because when there
* are sbt plugins in the build they trigger the compilation of all the modules.
* We do no-op when there is indeed an sbt plugin in the build. */
lazy val discoveredSbtPluginsSettings: Seq[Def.Setting[_]] = List(
Keys.discoveredSbtPlugins := (Def.taskDyn {
if (Keys.sbtPlugin.value) Def.task(PluginDiscovery.emptyDiscoveredNames)
else {
currentCommandFromState(Keys.state.value) match {
case Some(userCommand) =>
if (userCommand.endsWith(BloopKeys.bloopGenerate.key.label) ||
userCommand.endsWith(BloopKeys.bloopInstall.key.label)) {
Def.task(PluginDiscovery.emptyDiscoveredNames)
} else {
Def.task(PluginDiscovery.discoverSourceAll(Keys.compile.value))
}
case None => Def.task(PluginDiscovery.discoverSourceAll(Keys.compile.value))
}
}
}).value
)

private final val ScalaNativePluginLabel = "scala.scalanative.sbtplugin.ScalaNativePlugin"
private final val ScalaJsPluginLabel = "org.scalajs.sbtplugin.ScalaJSPlugin"

Expand Down
2 changes: 1 addition & 1 deletion project/BuildPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import sbt.librarymanagement.syntax.stringToOrganization
import sbt.util.FileFunction
import sbtassembly.PathList
import sbtdynver.GitDescribeOutput

import ch.epfl.scala.sbt.release.ReleaseEarlyPlugin.{autoImport => ReleaseEarlyKeys}
import sbt.internal.PluginDiscovery

object BuildPlugin extends AutoPlugin {
import sbt.plugins.JvmPlugin
Expand Down
6 changes: 5 additions & 1 deletion project/MavenPluginIntegration.scala
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,11 @@ object MavenPluginImplementation {
}

val resourceGenerators: Def.Initialize[Task[Seq[File]]] = Def.taskDyn {
if (!MavenPluginKeys.mavenPlugin.value) Def.task(Nil)
// Let's protect this so that we don't run it when we do `bloopInstall`
val state = Keys.state.value.currentCommand
val isBloopInstall = state.exists(e =>
e.commandLine.contains("bloopInstall") || e.commandLine.contains("bloopGenerate"))
if (!MavenPluginKeys.mavenPlugin.value || isBloopInstall) Def.task(Nil)
else {
val task = Def.task {
val BloopGoal = "bloopInstall"
Expand Down

0 comments on commit 58e69e6

Please sign in to comment.