This commit is contained in:
carlos4s 2026-04-13 14:42:33 +00:00 committed by GitHub
commit 567c04648b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 17 additions and 3 deletions

View File

@ -167,10 +167,9 @@ private[sbt] object Clean {
})
.flatMapTask { case scope =>
Def.task {
val targetDir = (scope / target).value.toPath
val baseDir = (scope / baseDirectory).value.toPath
val filter = cleanFilter(scope).value
// We do not want to inadvertently delete files that are not in the target directory.
val excludeFilter: Path => Boolean = path => !path.startsWith(targetDir) || filter(path)
val excludeFilter: Path => Boolean = path => !path.startsWith(baseDir) || filter(path)
val delete = cleanDelete(scope).value
val st = (scope / streams).value
taskKey.previous.foreach(_.toSeqPath.foreach(p => if (!excludeFilter(p)) delete(p)))

View File

@ -0,0 +1,8 @@
name := "clean-managed-outside-target"
scalaVersion := "3.3.1"
Compile / sourceManaged := baseDirectory.value / "src_managed"
Compile / sourceGenerators += Def.task {
val file = (Compile / sourceManaged).value / "demo" / "Test.scala"
IO.write(file, """object Test extends App { println("Hi") }""")
Seq(file)
}.taskValue

View File

@ -0,0 +1,7 @@
# Test that managedSourcePaths / clean removes managed sources outside target
> compile
$ exists src_managed/demo/Test.scala
> Compile / managedSourcePaths
> Compile / managedSourcePaths / clean
$ absent src_managed/demo/Test.scala