Merge pull request #9031 from eed3si9n/bport2/metabuild

[2.0.x] fix: Fixes metabuild reloading
This commit is contained in:
eugene yokota 2026-04-05 22:27:20 -04:00 committed by GitHub
commit 372b945651
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 75 additions and 9 deletions

View File

@ -420,6 +420,7 @@ object Defaults extends BuildCommon {
terminal := Def.uncached(state.value.get(terminalKey).getOrElse(Terminal(ITerminal.get))),
InstallSbtn.installSbtn := InstallSbtn.installSbtnImpl.evaluated,
InstallSbtn.installSbtn / aggregate := false,
checkBuildSources / pollInterval :== CheckBuildSources.defaultPollInterval,
) ++ LintUnused.lintSettings
++ DefaultBackgroundJobService.backgroundJobServiceSettings
++ RemoteCache.globalSettings
@ -555,8 +556,6 @@ object Defaults extends BuildCommon {
sourceManaged := target.value / "src_managed",
resourceManaged := target.value / "resource_managed",
// Adds subproject build.sbt files to the global list of build files to monitor
Scope.Global / checkBuildSources / pollInterval :==
new FiniteDuration(Int.MinValue, TimeUnit.MILLISECONDS),
Scope.Global / checkBuildSources / fileInputs ++= {
if ((Scope.Global / onChangedBuildSource).value != IgnoreSourceChanges)
Seq(baseDirectory.value.toGlob / "*.sbt")

View File

@ -73,10 +73,10 @@ private[sbt] object Load {
val launcher = scalaProvider.launcher
val stagingDirectory = getStagingDirectory(state, globalBase).getCanonicalFile
val javaHome = Util.javaHome
val out = baseDirectory.toPath.resolve("target").resolve("out")
val out = app.baseDirectory.toPath.resolve("target").resolve("out")
val rootPaths = Map(
"OUT" -> out,
"BASE" -> baseDirectory.toPath,
"BASE" -> app.baseDirectory.toPath,
"SBT_BOOT" -> launcher.bootDirectory.toPath,
"IVY_HOME" -> launcher.ivyHome.toPath,
"JAVA_HOME" -> javaHome,
@ -119,7 +119,9 @@ private[sbt] object Load {
)
val evalPluginDef: (BuildStructure, State) => PluginData = EvaluateTask.evalPluginDef
val delegates = defaultDelegates
val pluginMgmt = PluginManagement(loader)
import sbt.ProjectExtra.projectReturn
val pluginContext = PluginManagement.Context(false, Project.projectReturn(state).size - 1)
val pluginMgmt = PluginManagement(loader, pluginContext)
val inject = InjectSettings(injectGlobal(state), Nil, const(Nil))
SysProp.setSwovalTempDir()
SysProp.setIpcSocketTempDir()

View File

@ -54,12 +54,15 @@ object PluginManagement {
val emptyContext: Context = Context(false, 0)
def apply(initialLoader: ClassLoader): PluginManagement =
PluginManagement(initialLoader, emptyContext)
def apply(initialLoader: ClassLoader, context: Context): PluginManagement =
PluginManagement(
Set.empty,
Set.empty,
new PluginClassLoader(initialLoader),
initialLoader,
emptyContext
context
)
def extractOverrides(classpath: Classpath): Set[ModuleID] =

View File

@ -10,6 +10,7 @@ package sbt
package internal.nio
import java.nio.file.Path
import java.util.concurrent.TimeUnit
import java.util.concurrent.atomic.{ AtomicBoolean, AtomicReference }
import sbt.BasicCommandStrings.{ RebootCommand, Shutdown, TerminateAction }
import sbt.Keys.{ baseDirectory, pollInterval, state }
@ -65,7 +66,9 @@ private[sbt] class CheckBuildSources extends AutoCloseable {
}
private def reset(state: State): Unit = {
val extracted = Project.extract(state)
val interval = extracted.get(checkBuildSources / pollInterval)
val interval = extracted
.getOpt(checkBuildSources / pollInterval)
.getOrElse(CheckBuildSources.defaultPollInterval)
val newSources = extracted.get(Global / checkBuildSources / fileInputs).distinct
if (interval >= 0.seconds || "polling" == SysProp.watchMode) {
Option(repository.getAndSet(null)).foreach(_.close())
@ -174,7 +177,9 @@ private[sbt] class CheckBuildSources extends AutoCloseable {
override def close(): Unit = {}
}
private[sbt] object CheckBuildSources {
private[sbt] object CheckBuildSources:
val defaultPollInterval: FiniteDuration = FiniteDuration(Int.MinValue, TimeUnit.MILLISECONDS)
private[sbt] val CheckBuildSourcesKey =
AttributeKey[CheckBuildSources]("check-build-source", "", KeyRanks.Invisible)
/*
@ -219,4 +224,4 @@ private[sbt] object CheckBuildSources {
projectGlobs(projectDir, baseDir.toGlob / "*.sbt" :: Nil)
} else Nil
}
}
end CheckBuildSources

View File

@ -0,0 +1,24 @@
package example
import sbt.*
import Keys.*
import complete.DefaultParsers.{ *, given }
object FooPlugin extends AutoPlugin:
override def requires = empty
override def trigger = allRequirements
lazy object autoImport:
@transient
lazy val foo = taskKey[Unit]("foo")
lazy val check = inputKey[Unit]("check")
import autoImport.*
override def projectSettings: Seq[Def.Setting[?]] = Seq(
foo := println("foo"),
check := {
val args = spaceDelimited("<arg>").parsed
assert(name.value.endsWith(args.head), s"${name.value} does not end with ${args.head}")
},
)
end FooPlugin

View File

@ -0,0 +1,24 @@
package example
import sbt.*
import Keys.*
import complete.DefaultParsers.{ *, given }
object FooPlugin extends AutoPlugin:
override def requires = empty
override def trigger = allRequirements
lazy object autoImport:
@transient
lazy val foo = taskKey[Unit]("foo")
lazy val check = inputKey[Unit]("check")
import autoImport.*
override def projectSettings: Seq[Def.Setting[?]] = Seq(
foo := println("foo"),
check := {
val args = spaceDelimited("<arg>").parsed
assert(name.value.endsWith(args.head), s"${name.value} does not end with ${args.head}")
},
)
end FooPlugin

View File

@ -0,0 +1,9 @@
> foo
> reload plugins
> check -build
> foo
> reload plugins
> reload return
> reload return
> compile
> foo