Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

inputFileChanges cannot be scoped to a task scoped to another task #7489

Open
johnhungerford opened this issue Feb 2, 2024 · 1 comment
Open
Labels

Comments

@johnhungerford
Copy link

steps

add to build.sbt:

lazy val testTask = taskKey[Unit]("test task")

lazy val otherTask = taskKey[Unit]("dummy task")

otherTask / testTask / fileInputs := Seq(
	Glob(file("src").getAbsoluteFile, RelativeGlob.**)
)

otherTask / testTask := {
	if ((otherTask / testTask).inputFileChanges.hasChanges) {
		println("CHANGED")
	} else println("NOT CHANGED")
}

in the sbt console run > otherTask / testTask, change a file in src, and run > otherTask / testTask, and > otherTask / testTask again.

The output will be NOT CHANGED in all three cases

problem

fileInputs does not seem to track file changes within the scope of otherTask.

expectation

We should see CHANGED, CHANGED, NOT CHANGED

notes

@johnhungerford
Copy link
Author

As a workaround, it's pretty easy to implement the logic from the macro directly in build.sbt:

lazy val testTask = taskKey[Unit]("test task")

lazy val otherTask = taskKey[Unit]("dummy task")

otherTask / testTask / fileInputs := Seq(
    Glob(file("src").getAbsoluteFile, RelativeGlob.**)
)

otherTask / testTask := {
    val changes = (otherTask / testTask / changedInputFiles).value
    val current = (otherTask / testTask / allInputFiles).value
    val previous = Previous.runtimeInEnclosingTask(otherTask / testTask / inputFileStamps).value
    val fileChanges = previous.map(changes).getOrElse(FileChanges.noPrevious(current))
    if ((otherTask / testTask).inputFileChanges.hasChanges) {
	println("CHANGED")
    } else println("NOT CHANGED")
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant