diff --git a/main/src/main/scala/sbt/internal/FileChangesMacro.scala b/main/src/main/scala/sbt/internal/FileChangesMacro.scala index d78bb88ef..29d0b8ce0 100644 --- a/main/src/main/scala/sbt/internal/FileChangesMacro.scala +++ b/main/src/main/scala/sbt/internal/FileChangesMacro.scala @@ -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 diff --git a/sbt-app/src/sbt-test/nio/nested-task-scope/build.sbt b/sbt-app/src/sbt-test/nio/nested-task-scope/build.sbt new file mode 100644 index 000000000..0a0fbaa9f --- /dev/null +++ b/sbt-app/src/sbt-test/nio/nested-task-scope/build.sbt @@ -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") +} diff --git a/sbt-app/src/sbt-test/nio/nested-task-scope/src/test.txt b/sbt-app/src/sbt-test/nio/nested-task-scope/src/test.txt new file mode 100644 index 000000000..f2376e2ba --- /dev/null +++ b/sbt-app/src/sbt-test/nio/nested-task-scope/src/test.txt @@ -0,0 +1 @@ +initial content diff --git a/sbt-app/src/sbt-test/nio/nested-task-scope/test b/sbt-app/src/sbt-test/nio/nested-task-scope/test new file mode 100644 index 000000000..5c92ac474 --- /dev/null +++ b/sbt-app/src/sbt-test/nio/nested-task-scope/test @@ -0,0 +1,3 @@ +# Test that inputFileChanges works with nested task scopes (fixes #7489) + +> checkChanges