Merge pull request #7215 from dragos/expose/external-hooks-public

Expose RunProfiler to the build
This commit is contained in:
eugene yokota 2023-04-25 11:49:28 -04:00 committed by GitHub
commit df738abbbd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 61 additions and 2 deletions

View File

@ -946,11 +946,16 @@ object Defaults extends BuildCommon {
compileAnalysisTargetRoot.value / compileAnalysisFilename.value
},
externalHooks := IncOptions.defaultExternal,
zincCompilationListeners := Seq.empty,
incOptions := {
val old = incOptions.value
val extHooks = externalHooks.value
val newExtHooks = extHooks.withInvalidationProfiler(
() => new DefaultRunProfiler(zincCompilationListeners.value)
)
old
.withAuxiliaryClassFiles(auxiliaryClassFiles.value.toArray)
.withExternalHooks(externalHooks.value)
.withExternalHooks(newExtHooks)
.withClassfileManagerType(
Option(
TransactionalManagerType

View File

@ -249,6 +249,7 @@ object Keys {
val aggregate = settingKey[Boolean]("Configures task aggregation.").withRank(BMinusSetting)
val sourcePositionMappers = taskKey[Seq[xsbti.Position => Option[xsbti.Position]]]("Maps positions in generated source files to the original source it was generated from").withRank(DTask)
private[sbt] val externalHooks = taskKey[ExternalHooks]("The external hooks used by zinc.")
val zincCompilationListeners = settingKey[Seq[RunProfiler]]("Listeners that receive information about incremental compiler decisions.").withRank(DSetting)
val auxiliaryClassFiles = taskKey[Seq[AuxiliaryClassFiles]]("The auxiliary class files that must be managed by Zinc (for instance the TASTy files)")
val fileConverter = settingKey[FileConverter]("The file converter used to convert between Path and VirtualFile")
val allowMachinePath = settingKey[Boolean]("Allow machine-specific paths during conversion.")
@ -426,7 +427,7 @@ object Keys {
val bspBuildTargetJVMRunEnvironment = inputKey[Unit]("Corresponds to the buildTarget/jvmRunEnvironment request").withRank(DTask)
val bspBuildTargetJVMTestEnvironment = inputKey[Unit]("Corresponds to the buildTarget/jvmTestEnvironment request").withRank(DTask)
val bspBuildTargetJvmEnvironmentItem = taskKey[JvmEnvironmentItem]("Computes JVM environment item").withRank(DTask)
val bspScalaTestClasses = inputKey[Unit]("Corresponds to buildTarget/scalaTestClasses request").withRank(DTask)
val bspScalaTestClassesItem = taskKey[Seq[ScalaTestClassesItem]]("").withRank(DTask)
val bspScalaMainClasses = inputKey[Unit]("Corresponds to buildTarget/scalaMainClasses request").withRank(DTask)

View File

@ -0,0 +1,53 @@
/*
* sbt
* Copyright 2011 - 2018, Lightbend, Inc.
* Copyright 2008 - 2010, Mark Harrah
* Licensed under Apache License 2.0 (see LICENSE)
*/
package sbt.internal
import xsbti.VirtualFileRef
import xsbti.compile.{ APIChange, InitialChanges, RunProfiler }
class DefaultRunProfiler(profilers: Seq[RunProfiler]) extends RunProfiler {
override def timeCompilation(startNanos: Long, durationNanos: Long): Unit =
profilers.foreach(_.timeCompilation(startNanos, durationNanos))
override def registerInitial(changes: InitialChanges): Unit =
profilers.foreach(_.registerInitial(changes))
override def registerEvent(
kind: String,
inputs: Array[String],
outputs: Array[String],
reason: String
): Unit =
profilers.foreach(_.registerEvent(kind, inputs, outputs, reason))
override def registerCycle(
invalidatedClasses: Array[String],
invalidatedPackageObjects: Array[String],
initialSources: Array[VirtualFileRef],
invalidatedSources: Array[VirtualFileRef],
recompiledClasses: Array[String],
changesAfterRecompilation: Array[APIChange],
nextInvalidations: Array[String],
shouldCompileIncrementally: Boolean
): Unit =
profilers.foreach(
_.registerCycle(
invalidatedClasses,
invalidatedPackageObjects,
initialSources,
invalidatedSources,
recompiledClasses,
changesAfterRecompilation,
nextInvalidations,
shouldCompileIncrementally
)
)
override def registerRun(): Unit =
profilers.foreach(_.registerRun())
}