mirror of https://github.com/sbt/sbt.git
Fix clean task to delete managed sources located outside the target directory
This commit is contained in:
parent
730f4a525d
commit
d028427067
|
|
@ -1965,18 +1965,7 @@ object Defaults extends BuildCommon with DefExtra {
|
|||
}
|
||||
|
||||
/** Implements `cleanFiles` task. */
|
||||
private[sbt] def cleanFilesTask: Initialize[Task[Vector[File]]] = {
|
||||
import ScopeFilter.Make.*
|
||||
val allConfigs = ScopeFilter(configurations = inAnyConfiguration)
|
||||
Def.task {
|
||||
val targetDir = target.value.toPath
|
||||
val managedSrcDirs = managedSourceDirectories.?.all(allConfigs).value.flatten.flatten
|
||||
val managedRscDirs = managedResourceDirectories.?.all(allConfigs).value.flatten.flatten
|
||||
(managedSrcDirs ++ managedRscDirs)
|
||||
.filter(d => !d.toPath.startsWith(targetDir))
|
||||
.toVector
|
||||
}
|
||||
}
|
||||
private[sbt] def cleanFilesTask: Initialize[Task[Vector[File]]] = Def.task { Vector.empty[File] }
|
||||
|
||||
def runMainTask(
|
||||
classpath: Initialize[Task[Classpath]],
|
||||
|
|
|
|||
|
|
@ -107,7 +107,6 @@ private[sbt] object Clean {
|
|||
val excludeFilter = cleanFilter(scope).value
|
||||
val delete = cleanDelete(scope).value
|
||||
val targetDir = (scope / target).?.value.map(_.toPath)
|
||||
val baseDir = (scope / baseDirectory).?.value.map(_.toPath)
|
||||
|
||||
targetDir.withFilter(_ => full).foreach(deleteContents(_, excludeFilter, view, delete))
|
||||
(scope / cleanFiles).?.value.getOrElse(Nil).foreach { x =>
|
||||
|
|
@ -124,10 +123,8 @@ private[sbt] object Clean {
|
|||
val streamsGlobs =
|
||||
(streamsKey.toSeq ++ stampsKey)
|
||||
.map(k => manager(k).cacheDirectory.toPath.toGlob / **)
|
||||
// Use baseDirectory instead of target so that file outputs outside the
|
||||
// target directory but within the project root are also cleaned.
|
||||
((scope / fileOutputs).value.filter { g =>
|
||||
baseDir.fold(true)(g.base.startsWith)
|
||||
targetDir.fold(true)(g.base.startsWith)
|
||||
} ++ streamsGlobs)
|
||||
.foreach { g =>
|
||||
val filter: Path => Boolean = { path =>
|
||||
|
|
|
|||
|
|
@ -5,10 +5,3 @@ $ exists src_managed/demo/Test.scala
|
|||
> Compile / managedSourcePaths
|
||||
> Compile / managedSourcePaths / clean
|
||||
$ absent src_managed/demo/Test.scala
|
||||
|
||||
# Test that clean also removes managed sources outside target
|
||||
> compile
|
||||
$ exists src_managed/demo/Test.scala
|
||||
|
||||
> clean
|
||||
$ absent src_managed/demo/Test.scala
|
||||
|
|
|
|||
Loading…
Reference in New Issue