mirror of https://github.com/sbt/sbt.git
[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:
parent
e16298521b
commit
82e370b4cb
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
initial content
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
# Test that inputFileChanges works with nested task scopes (fixes #7489)
|
||||
|
||||
> checkChanges
|
||||
Loading…
Reference in New Issue