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"),
|
classDirectory := target.value / (prefix(configuration.value.name) + "classes"),
|
||||||
backendOutput := {
|
backendOutput := {
|
||||||
val converter = fileConverter.value
|
val converter = fileConverter.value
|
||||||
val dir = target.value / (prefix(configuration.value.name) + "backend")
|
val dir = classDirectory.value
|
||||||
converter.toVirtualFile(dir.toPath)
|
converter.toVirtualFile(dir.toPath)
|
||||||
},
|
},
|
||||||
earlyOutput / artifactPath := configArtifactPathSetting(artifact, "early").value,
|
earlyOutput / artifactPath := configArtifactPathSetting(artifact, "early").value,
|
||||||
|
|
@ -4068,20 +4068,10 @@ object Classpaths {
|
||||||
|
|
||||||
def makeProducts: Initialize[Task[Seq[File]]] = Def.task {
|
def makeProducts: Initialize[Task[Seq[File]]] = Def.task {
|
||||||
val c = fileConverter.value
|
val c = fileConverter.value
|
||||||
val resources = copyResources.value.map(_._2).toSet
|
val resourceDirs = resourceDirectories.value
|
||||||
val classDir = classDirectory.value
|
|
||||||
val vfBackendDir = compileIncremental.value._2
|
val vfBackendDir = compileIncremental.value._2
|
||||||
val backendDir = c.toPath(vfBackendDir)
|
val backendDir = c.toPath(vfBackendDir)
|
||||||
// delete outdated files
|
backendDir.toFile() :: resourceDirs.toList.filter(_.exists())
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private[sbt] def makePickleProducts: Initialize[Task[Seq[VirtualFile]]] = Def.task {
|
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
|
> Test/compile
|
||||||
$ exists target/**/compile-clean/backend/A.class
|
$ exists target/**/compile-clean/classes/A.class
|
||||||
$ exists target/**/compile-clean/backend/X.class
|
$ exists target/**/compile-clean/classes/X.class
|
||||||
$ exists target/**/compile-clean/test-backend/B.class
|
$ exists target/**/compile-clean/test-classes/B.class
|
||||||
|
|
||||||
> Test/clean
|
> Test/clean
|
||||||
$ exists target/**/compile-clean/backend/cant-touch-this
|
$ exists target/**/compile-clean/classes/cant-touch-this
|
||||||
$ exists target/**/compile-clean/backend/A.class
|
$ exists target/**/compile-clean/classes/A.class
|
||||||
$ exists target/**/compile-clean/backend/X.class
|
$ exists target/**/compile-clean/classes/X.class
|
||||||
$ absent target/**/compile-clean/test-backend/B.class
|
$ absent target/**/compile-clean/test-classes/B.class
|
||||||
|
|
||||||
> Compile/clean
|
> Compile/clean
|
||||||
$ exists target/**/compile-clean/backend/cant-touch-this
|
$ exists target/**/compile-clean/classes/cant-touch-this
|
||||||
$ absent target/**/compile-clean/backend/A.class
|
$ absent target/**/compile-clean/classes/A.class
|
||||||
$ exists target/**/compile-clean/backend/X.class
|
$ exists target/**/compile-clean/classes/X.class
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
> compile
|
> 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
|
> check
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
> compile
|
> compile
|
||||||
|
|
||||||
$ exists target/out/jvm/scala-2.13.15/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/backend/a/Core.class
|
$ exists target/out/jvm/scala-2.12.20/core/classes/a/Core.class
|
||||||
|
|
||||||
> core2_13/check
|
> core2_13/check
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
> compile
|
> compile
|
||||||
|
|
||||||
$ exists target/out/jvm/scala-2.13.15/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/backend/a/Core.class
|
$ exists target/out/jvm/scala-3.4.2/core/classes/a/Core.class
|
||||||
|
|
||||||
> core/check
|
> core/check
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
> bar/compile
|
> bar/compile
|
||||||
$ exists target/**/bar1/backend/B1.class
|
$ exists target/**/bar1/classes/B1.class
|
||||||
|
|
||||||
> compile
|
> compile
|
||||||
$ exists target/**/foo/backend/A.class
|
$ exists target/**/foo/classes/A.class
|
||||||
|
|
|
||||||
|
|
@ -364,7 +364,7 @@ class BuildServerTest extends AbstractServerTest {
|
||||||
|
|
||||||
test("buildTarget/cleanCache") {
|
test("buildTarget/cleanCache") {
|
||||||
def classFile = svr.baseDirectory.toPath.resolve(
|
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")
|
val buildTarget = buildTargetUri("runAndTest", "Compile")
|
||||||
compile(buildTarget)
|
compile(buildTarget)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue