mirror of https://github.com/sbt/sbt.git
[2.x] perf: Avoid copying directories
**Problem** Directory copying is showing up as performance hot spots. **Solution** This avoid copying classes or resources.
This commit is contained in:
parent
67b4434507
commit
6a2e0a9b04
|
|
@ -654,7 +654,7 @@ object Defaults extends BuildCommon {
|
|||
classDirectory := target.value / (prefix(configuration.value.name) + "classes"),
|
||||
backendOutput := {
|
||||
val converter = fileConverter.value
|
||||
val dir = target.value / (prefix(configuration.value.name) + "backend")
|
||||
val dir = classDirectory.value
|
||||
converter.toVirtualFile(dir.toPath)
|
||||
},
|
||||
earlyOutput / artifactPath := configArtifactPathSetting(artifact, "early").value,
|
||||
|
|
@ -4068,20 +4068,10 @@ object Classpaths {
|
|||
|
||||
def makeProducts: Initialize[Task[Seq[File]]] = Def.task {
|
||||
val c = fileConverter.value
|
||||
val resources = copyResources.value.map(_._2).toSet
|
||||
val classDir = classDirectory.value
|
||||
val resourceDirs = resourceDirectories.value
|
||||
val vfBackendDir = compileIncremental.value._2
|
||||
val backendDir = c.toPath(vfBackendDir)
|
||||
// delete outdated files
|
||||
Path
|
||||
.allSubpaths(classDir)
|
||||
.collect { case (f, _) if f.isFile() && !resources.contains(f) => f }
|
||||
.foreach(IO.delete)
|
||||
IO.copyDirectory(
|
||||
source = backendDir.toFile(),
|
||||
target = classDir,
|
||||
)
|
||||
classDir :: Nil
|
||||
backendDir.toFile() :: resourceDirs.toList.filter(_.exists())
|
||||
}
|
||||
|
||||
private[sbt] def makePickleProducts: Initialize[Task[Seq[VirtualFile]]] = Def.task {
|
||||
|
|
|
|||
|
|
@ -1,17 +1,17 @@
|
|||
$ touch target/out/jvm/scala-2.12.20/compile-clean/backend/cant-touch-this
|
||||
$ touch target/out/jvm/scala-2.12.20/compile-clean/classes/cant-touch-this
|
||||
|
||||
> Test/compile
|
||||
$ exists target/**/compile-clean/backend/A.class
|
||||
$ exists target/**/compile-clean/backend/X.class
|
||||
$ exists target/**/compile-clean/test-backend/B.class
|
||||
$ exists target/**/compile-clean/classes/A.class
|
||||
$ exists target/**/compile-clean/classes/X.class
|
||||
$ exists target/**/compile-clean/test-classes/B.class
|
||||
|
||||
> Test/clean
|
||||
$ exists target/**/compile-clean/backend/cant-touch-this
|
||||
$ exists target/**/compile-clean/backend/A.class
|
||||
$ exists target/**/compile-clean/backend/X.class
|
||||
$ absent target/**/compile-clean/test-backend/B.class
|
||||
$ exists target/**/compile-clean/classes/cant-touch-this
|
||||
$ exists target/**/compile-clean/classes/A.class
|
||||
$ exists target/**/compile-clean/classes/X.class
|
||||
$ absent target/**/compile-clean/test-classes/B.class
|
||||
|
||||
> Compile/clean
|
||||
$ exists target/**/compile-clean/backend/cant-touch-this
|
||||
$ absent target/**/compile-clean/backend/A.class
|
||||
$ exists target/**/compile-clean/backend/X.class
|
||||
$ exists target/**/compile-clean/classes/cant-touch-this
|
||||
$ absent target/**/compile-clean/classes/A.class
|
||||
$ exists target/**/compile-clean/classes/X.class
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
> compile
|
||||
|
||||
$ exists target/out/jvm/scala-2.12.20/domain/backend/a/DataType.class
|
||||
$ exists target/out/jvm/scala-2.12.20/domain/classes/a/DataType.class
|
||||
|
||||
> check
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
> compile
|
||||
|
||||
$ exists target/out/jvm/scala-2.13.15/core/backend/a/Core.class
|
||||
$ exists target/out/jvm/scala-2.12.20/core/backend/a/Core.class
|
||||
$ exists target/out/jvm/scala-2.13.15/core/classes/a/Core.class
|
||||
$ exists target/out/jvm/scala-2.12.20/core/classes/a/Core.class
|
||||
|
||||
> core2_13/check
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
> compile
|
||||
|
||||
$ exists target/out/jvm/scala-2.13.15/core/backend/a/Core.class
|
||||
$ exists target/out/jvm/scala-3.4.2/core/backend/a/Core.class
|
||||
$ exists target/out/jvm/scala-2.13.15/core/classes/a/Core.class
|
||||
$ exists target/out/jvm/scala-3.4.2/core/classes/a/Core.class
|
||||
|
||||
> core/check
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
> bar/compile
|
||||
$ exists target/**/bar1/backend/B1.class
|
||||
$ exists target/**/bar1/classes/B1.class
|
||||
|
||||
> compile
|
||||
$ exists target/**/foo/backend/A.class
|
||||
$ exists target/**/foo/classes/A.class
|
||||
|
|
|
|||
|
|
@ -364,7 +364,7 @@ class BuildServerTest extends AbstractServerTest {
|
|||
|
||||
test("buildTarget/cleanCache") {
|
||||
def classFile = svr.baseDirectory.toPath.resolve(
|
||||
"target/out/jvm/scala-2.13.11/runandtest/backend/main/Main.class"
|
||||
"target/out/jvm/scala-2.13.11/runandtest/classes/main/Main.class"
|
||||
)
|
||||
val buildTarget = buildTargetUri("runAndTest", "Compile")
|
||||
compile(buildTarget)
|
||||
|
|
|
|||
Loading…
Reference in New Issue