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

Ignore empty directory layout in external classes dir #1348

Merged
merged 2 commits into from Jul 21, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 13 additions & 11 deletions backend/src/main/scala/bloop/BloopClassFileManager.scala
Expand Up @@ -217,14 +217,19 @@ final class BloopClassFileManager(
clientExternalClassesDir: AbsolutePath,
clientReporter: Reporter,
clientTracer: BraveTracer
) => {
clientTracer.traceTask("populate external classes dir as it's empty") { _ =>
Task {
if (!BloopPaths.isDirectoryEmpty(clientExternalClassesDir)) Task.unit
else {
if (BloopPaths.isDirectoryEmpty(outPaths.internalReadOnlyClassesDir)) {
Task.unit
} else {
) =>
Task.defer {
// Exclude dirs because process controlling external dir might have created empty dir layouts
val externalDirHasFiles =
!BloopPaths.isDirectoryEmpty(clientExternalClassesDir, excludeDirs = true)
val isInternalEmpty =
BloopPaths.isDirectoryEmpty(outPaths.internalReadOnlyClassesDir, excludeDirs = false)

if (externalDirHasFiles) Task.unit
else if (isInternalEmpty) Task.unit
else
clientTracer.traceTask("populate empty classes dir") {
_ =>
// Prepopulate external classes dir even though compilation failed
val config = ParallelOps.CopyConfiguration(1, CopyMode.NoReplace, Set.empty)
ParallelOps
Expand All @@ -236,11 +241,8 @@ final class BloopClassFileManager(
enableCancellation = false
)
.map(_ => ())
}
}
}.flatten
}
}
)
}
}
Expand Down
19 changes: 17 additions & 2 deletions config/.jvm/src/test/scala/bloop/config/TestPlatform.scala
@@ -1,6 +1,21 @@
package bloop.config

import java.io.InputStreamReader
import java.io.BufferedReader
import java.util.stream.Collectors

object TestPlatform {
def getResourceAsString(resource: String): String =
getClass.getClassLoader.getResourceAsStream(resource).readAllBytes().map(_.toChar).mkString
def getResourceAsString(resource: String): String = {
val stream = getClass.getClassLoader.getResourceAsStream(resource)
if (stream == null) sys.error(s"Missing resource $resource!")
else {
try {
val isr = new InputStreamReader(stream)
try {
val reader = new BufferedReader(isr)
reader.lines().collect(Collectors.joining(System.lineSeparator))
} finally (isr.close())
} finally stream.close()
}
}
}
4 changes: 2 additions & 2 deletions shared/src/main/scala/bloop/io/Paths.scala
Expand Up @@ -171,7 +171,7 @@ object Paths {
()
}

def isDirectoryEmpty(path: AbsolutePath): Boolean = {
def isDirectoryEmpty(path: AbsolutePath, excludeDirs: Boolean): Boolean = {
var isEmpty: Boolean = true
import java.nio.file.NoSuchFileException
try {
Expand All @@ -187,7 +187,7 @@ object Paths {
directory: Path,
attributes: BasicFileAttributes
): FileVisitResult = {
if (path.underlying == directory) FileVisitResult.CONTINUE
if (excludeDirs || path.underlying == directory) FileVisitResult.CONTINUE
else {
isEmpty = false
FileVisitResult.TERMINATE
Expand Down