mirror of https://github.com/sbt/sbt.git
Only trigger reload if sources have changed
Running a `~` command in a local build off the latest develop branch will cause the build to reload even if the build sources were only touched and not actually modified.
This commit is contained in:
parent
de1423d662
commit
d826e93ddf
|
|
@ -218,7 +218,7 @@ object MainLoop {
|
||||||
}
|
}
|
||||||
state.get(CheckBuildSourcesKey) match {
|
state.get(CheckBuildSourcesKey) match {
|
||||||
case Some(cbs) =>
|
case Some(cbs) =>
|
||||||
if (!cbs.needsReload(state, exec.commandLine)) process()
|
if (!cbs.needsReload(state, state.globalLogging.full, exec.commandLine)) process()
|
||||||
else {
|
else {
|
||||||
if (exec.commandLine.startsWith(SetTerminal))
|
if (exec.commandLine.startsWith(SetTerminal))
|
||||||
exec +: Exec("reload", None, None) +: state.remove(CheckBuildSourcesKey)
|
exec +: Exec("reload", None, None) +: state.remove(CheckBuildSourcesKey)
|
||||||
|
|
|
||||||
|
|
@ -526,7 +526,14 @@ private[sbt] object Continuous extends DeprecatedContinuous {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buildGlobs.exists(_.matches(path))) {
|
if (buildGlobs.exists(_.matches(path))) {
|
||||||
getWatchEvent(forceTrigger = false).map(e => e -> Watch.Reload).toSeq
|
getWatchEvent(forceTrigger = false).flatMap { e =>
|
||||||
|
state.get(CheckBuildSources.CheckBuildSourcesKey) match {
|
||||||
|
case Some(cbs) =>
|
||||||
|
if (cbs.needsReload(state, logger, "")) Some(e -> Watch.Reload) else None
|
||||||
|
case None =>
|
||||||
|
Some(e -> Watch.Reload)
|
||||||
|
}
|
||||||
|
}.toSeq
|
||||||
} else {
|
} else {
|
||||||
val acceptedConfigParameters = configs.flatMap { config =>
|
val acceptedConfigParameters = configs.flatMap { config =>
|
||||||
config.inputs().flatMap {
|
config.inputs().flatMap {
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ import sbt.nio.Keys._
|
||||||
import sbt.nio.file.{ FileAttributes, FileTreeView, Glob, ** }
|
import sbt.nio.file.{ FileAttributes, FileTreeView, Glob, ** }
|
||||||
import sbt.nio.file.syntax._
|
import sbt.nio.file.syntax._
|
||||||
import sbt.nio.Settings
|
import sbt.nio.Settings
|
||||||
|
import sbt.util.Logger
|
||||||
|
|
||||||
import scala.annotation.tailrec
|
import scala.annotation.tailrec
|
||||||
import scala.concurrent.duration.{ Deadline => SDeadline, _ }
|
import scala.concurrent.duration.{ Deadline => SDeadline, _ }
|
||||||
|
|
@ -102,11 +103,10 @@ private[sbt] class CheckBuildSources extends AutoCloseable {
|
||||||
!resetState
|
!resetState
|
||||||
}
|
}
|
||||||
@inline private def forceCheck = fileTreeRepository.isEmpty
|
@inline private def forceCheck = fileTreeRepository.isEmpty
|
||||||
private[sbt] def needsReload(state: State, cmd: String) = {
|
private[sbt] def needsReload(state: State, logger: Logger, cmd: String) = {
|
||||||
(needCheck(state, cmd) && (forceCheck || needUpdate.compareAndSet(true, false))) && {
|
(needCheck(state, cmd) && (forceCheck || needUpdate.compareAndSet(true, false))) && {
|
||||||
val extracted = Project.extract(state)
|
val extracted = Project.extract(state)
|
||||||
val onChanges = extracted.get(Global / onChangedBuildSource)
|
val onChanges = extracted.get(Global / onChangedBuildSource)
|
||||||
val logger = state.globalLogging.full
|
|
||||||
val current = getStamps(force = false)
|
val current = getStamps(force = false)
|
||||||
val previous = previousStamps.getAndSet(current)
|
val previous = previousStamps.getAndSet(current)
|
||||||
Settings.changedFiles(previous, current) match {
|
Settings.changedFiles(previous, current) match {
|
||||||
|
|
@ -160,8 +160,9 @@ private[sbt] object CheckBuildSources {
|
||||||
private[sbt] def needReloadImpl: Def.Initialize[Task[StateTransform]] = Def.task {
|
private[sbt] def needReloadImpl: Def.Initialize[Task[StateTransform]] = Def.task {
|
||||||
val st = state.value
|
val st = state.value
|
||||||
st.get(CheckBuildSourcesKey) match {
|
st.get(CheckBuildSourcesKey) match {
|
||||||
case Some(cbs) if (cbs.needsReload(st, "")) => StateTransform("reload" :: (_: State))
|
case Some(cbs) if (cbs.needsReload(st, st.globalLogging.full, "")) =>
|
||||||
case _ => StateTransform(identity)
|
StateTransform("reload" :: (_: State))
|
||||||
|
case _ => StateTransform(identity)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private[sbt] def buildSourceFileInputs: Def.Initialize[Seq[Glob]] = Def.setting {
|
private[sbt] def buildSourceFileInputs: Def.Initialize[Seq[Glob]] = Def.setting {
|
||||||
|
|
|
||||||
|
|
@ -16,4 +16,11 @@ failingTask := {
|
||||||
throw new IllegalStateException("failed")
|
throw new IllegalStateException("failed")
|
||||||
}
|
}
|
||||||
|
|
||||||
onChangedBuildSource := ReloadOnSourceChanges
|
watchOnIteration := { (count, project, commands) =>
|
||||||
|
val extra = baseDirectory.value / "extra.sbt"
|
||||||
|
IO.copyFile(baseDirectory.value / "changes" / "extra.sbt", extra, CopyOptions().withOverwrite(true))
|
||||||
|
Watch.defaultStartWatch(count, project, commands).foreach(_.linesIterator.foreach(l => println(s"[info] $l")))
|
||||||
|
Watch.Ignore
|
||||||
|
}
|
||||||
|
|
||||||
|
Global / onChangedBuildSource := ReloadOnSourceChanges
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
Compile / compile := {
|
Compile / compile := {
|
||||||
Count.increment()
|
Count.increment()
|
||||||
// Trigger a new build by updating the last modified time
|
// Trigger a new build by updating the last modified time
|
||||||
val extra = baseDirectory.value / "extra.sbt"
|
|
||||||
IO.copyFile(baseDirectory.value / "changes" / "extra.sbt", extra, CopyOptions().withOverwrite(true))
|
|
||||||
(Compile / compile).value
|
(Compile / compile).value
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue