[2.x] fix: inputFileChanges with nested task scopes (#8516)

Fixes #7489

When using nested task scopes like otherTask / testTask, the
inputFileChanges macro was returning the wrong scope. It checked
if the scope already had a task axis and returned it as-is, but
this meant it would use otherTask's scope instead of testTask's.

The fix always sets the task axis to the key being queried,
ensuring fileInputs settings are found at the correct scope.
This commit is contained in:
MkDev11 2026-01-14 00:10:23 -05:00 committed by GitHub
parent e16298521b
commit 82e370b4cb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 25 additions and 4 deletions

View File

@ -98,8 +98,5 @@ object FileChangesMacro:
'{ rescope[Seq[NioPath]]($ts, allOutputFiles).value }
private def getTaskScope[A: Type](in: Expr[TaskKey[A]])(using Quotes): Expr[sbt.Scope] =
'{
if $in.scope.task.toOption.isDefined then $in.scope
else $in.scope.copy(task = Select($in.key))
}
'{ $in.scope.copy(task = Select($in.key)) }
end FileChangesMacro

View File

@ -0,0 +1,20 @@
import sbt.nio.Keys._
import sbt.internal.FileChangesMacro._
val testTask = taskKey[Unit]("test task")
val otherTask = taskKey[Unit]("dummy task")
// Set fileInputs at nested task scope: otherTask / testTask
otherTask / testTask / fileInputs := Seq(
baseDirectory.value.toGlob / "src" / "*.txt"
)
// Create a scoped task key to use with the inputFileChanges macro
val scopedTestTask = otherTask / testTask
// Test that inputFileChanges works with nested task scopes (fixes #7489)
val checkChanges = taskKey[Unit]("check that file changes are detected")
checkChanges := {
val files = scopedTestTask.inputFiles
assert(files.nonEmpty, s"inputFiles should not be empty, got: $files")
}

View File

@ -0,0 +1 @@
initial content

View File

@ -0,0 +1,3 @@
# Test that inputFileChanges works with nested task scopes (fixes #7489)
> checkChanges