Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix: Also copy resources on noop #2579

Merged
merged 1 commit into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 8 additions & 29 deletions backend/src/main/scala/bloop/BloopClassFileManager.scala
Original file line number Diff line number Diff line change
Expand Up @@ -201,34 +201,6 @@ final class BloopClassFileManager(

}

private def copyResources(
resources: List[AbsolutePath],
copyTo: AbsolutePath,
config: ParallelOps.CopyConfiguration
): Task[Unit] = {
val (singleFiles, classpathEntries) =
resources.partition(path => path.exists && path.isFile)

val singleFilesToCopy =
for (file <- singleFiles)
yield file.underlying -> copyTo.underlying.resolve(file.underlying.toFile().getName())

val classpathEntriesCopy =
for (entry <- classpathEntries) yield {
ParallelOps
.copyDirectories(config)(
entry.underlying,
copyTo.underlying,
inputs.ioScheduler,
enableCancellation = false,
inputs.logger,
singleFilesToCopy
)
}

Task.gatherUnordered(classpathEntriesCopy).map(_ => ())
}

def complete(success: Boolean): Unit = {

val deleteAfterCompilation = Task { BloopPaths.delete(AbsolutePath(backupDir)) }
Expand Down Expand Up @@ -262,11 +234,18 @@ final class BloopClassFileManager(
}
.flatMap(_ => deleteAfterCompilation)

val copyResources = ParallelOps.copyResources(
inputs.resources,
clientExternalClassesDir,
config,
inputs.logger,
inputs.ioScheduler
)
Task
.gatherUnordered(
List(
copyClassFiles,
copyResources(inputs.resources, clientExternalClassesDir, config)
copyResources
)
)
.map(_ => ())
Expand Down
10 changes: 9 additions & 1 deletion backend/src/main/scala/bloop/Compiler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,14 @@ object Compiler {
val denyDir = Set(readOnlyClassesDir.resolve("META-INF/best-effort"))
val config =
ParallelOps.CopyConfiguration(5, CopyMode.ReplaceIfMetadataMismatch, denyList, denyDir)

val copyResources = ParallelOps.copyResources(
compileInputs.resources,
clientClassesDir,
config,
compileInputs.logger,
compileInputs.ioScheduler
)
val lastCopy = ParallelOps.copyDirectories(config)(
readOnlyClassesDir,
clientClassesDir.underlying,
Expand All @@ -812,7 +820,7 @@ object Compiler {
compileInputs.logger
)

lastCopy.map { _ =>
Task.gatherUnordered(List(copyResources, lastCopy)).map { _ =>
clientLogger.debug(
s"Finished copying classes from $readOnlyClassesDir to $clientClassesDir"
)
Expand Down
33 changes: 33 additions & 0 deletions backend/src/main/scala/bloop/io/ParallelOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,39 @@ object ParallelOps {

private[this] val takenByOtherCopyProcess = new ConcurrentHashMap[Path, Promise[Unit]]()

/**
* Copies the resources in `resources` to the directory `copyTo` ,
*/
def copyResources(
resources: List[AbsolutePath],
copyTo: AbsolutePath,
config: ParallelOps.CopyConfiguration,
logger: Logger,
scheduler: Scheduler
): Task[Unit] = {
val (singleFiles, classpathEntries) =
resources.partition(path => path.exists && path.isFile)

val singleFilesToCopy =
for (file <- singleFiles)
yield file.underlying -> copyTo.underlying.resolve(file.underlying.toFile().getName())

val classpathEntriesCopy =
for (entry <- classpathEntries) yield {
ParallelOps
.copyDirectories(config)(
entry.underlying,
copyTo.underlying,
scheduler,
enableCancellation = false,
logger,
singleFilesToCopy
)
}

Task.gatherUnordered(classpathEntriesCopy).map(_ => ())
}

/**
* Copies files from [[origin]] to [[target]] with the provided copy
* configuration in parallel on the scheduler [[scheduler]].
Expand Down
7 changes: 7 additions & 0 deletions frontend/src/test/scala/bloop/RunSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,13 @@ class RunSpec extends BloopHelpers {
val state = loadState(workspace, projects, logger)
val runState = state.run(`A`)
assertEquals(ExitStatus.Ok, runState.status)

// Remove to make sure we copy on noop
state.getClientExternalDir(A).resolve("resource.txt").toFile.delete()

val state2 = loadState(workspace, projects, logger)
val runState2 = state2.run(`A`)
assertEquals(ExitStatus.Ok, runState2.status)
}
}

Expand Down
Loading