From 82e370b4cbe80f454ace02360b401981176a717b Mon Sep 17 00:00:00 2001 From: MkDev11 Date: Wed, 14 Jan 2026 00:10:23 -0500 Subject: [PATCH] [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. --- .../scala/sbt/internal/FileChangesMacro.scala | 5 +---- .../sbt-test/nio/nested-task-scope/build.sbt | 20 +++++++++++++++++++ .../nio/nested-task-scope/src/test.txt | 1 + .../src/sbt-test/nio/nested-task-scope/test | 3 +++ 4 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 sbt-app/src/sbt-test/nio/nested-task-scope/build.sbt create mode 100644 sbt-app/src/sbt-test/nio/nested-task-scope/src/test.txt create mode 100644 sbt-app/src/sbt-test/nio/nested-task-scope/test 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