Merge pull request #8374 from eed3si9n/wip/copy-directory

[2.x] perf: Avoid copying directories
This commit is contained in:
eugene yokota 2025-11-18 01:12:41 -05:00 committed by GitHub
commit 17d54e1985
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 27 additions and 37 deletions

View File

@ -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 {

View File

@ -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

View File

@ -1,4 +1,4 @@
ThisBuild / scalaVersion := "2.12.20"
ThisBuild / scalaVersion := "3.7.4"
name := "hello"
enablePlugins(JavaAppPackaging)
@ -6,7 +6,7 @@ enablePlugins(JavaAppPackaging)
lazy val check = taskKey[Unit]("")
check := {
val cmd = "target/universal/stage/bin/hello"
val cmd = "target/out/jvm/scala-3.7.4/hello/universal/stage/bin/hello"
val cmd0 =
if (sys.props("os.name").toLowerCase(java.util.Locale.ROOT).contains("windows"))
cmd + ".bat"

View File

@ -1,3 +1,4 @@
ThisBuild / libraryDependencySchemes += "org.scala-lang.modules" %% "scala-xml" % VersionScheme.Always
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.3.20")
// addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.3.20")
libraryDependencies += Defaults.sbtPluginExtra("com.github.sbt" % "sbt-native-packager" % "1.11.4", "2", "3.7.3")

View File

@ -1,6 +1,5 @@
import java.io.File
import java.nio.file.Files
object Main extends App {
@main def hello() =
Files.write(new File("output").toPath, "OK".getBytes("UTF-8"))
}

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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)