Skip to content

Commit

Permalink
Remove custom best effort directory path
Browse files Browse the repository at this point in the history
  • Loading branch information
jchyb committed Aug 7, 2023
1 parent d67ada9 commit 8723208
Show file tree
Hide file tree
Showing 16 changed files with 79 additions and 138 deletions.
37 changes: 27 additions & 10 deletions backend/src/main/scala/bloop/BloopClassFileManager.scala
Original file line number Diff line number Diff line change
Expand Up @@ -214,17 +214,34 @@ final class BloopClassFileManager(
) => {
clientTracer.traceTaskVerbose("copy new products to external classes dir") { _ =>
val config = ParallelOps.CopyConfiguration(5, CopyMode.ReplaceExisting, Set.empty)
ParallelOps
.copyDirectories(config)(
newClassesDir,
clientExternalClassesDir.underlying,
inputs.ioScheduler,
enableCancellation = false
)
.map { walked =>
readOnlyCopyDenylist.++=(walked.target)
val clientExternalBestEffortDir =
clientExternalClassesDir.underlying.resolve("META-INF/best-effort")

// Deletes all previous best-effort artifacts to get rid of all of the outdated ones.
// Since best effort compilation is not affected by incremental compilation,
// all relevant files are always produced by the compiler. Because of this,
// we can always delete all previous files and copy newly created ones
// without losing anything in the process.
val deleteClientExternalBestEffortDir =
Task {
if (Files.exists(clientExternalBestEffortDir)) {
BloopPaths.delete(AbsolutePath(clientExternalBestEffortDir))
}
()
}
}.memoize

deleteClientExternalBestEffortDir *>
ParallelOps
.copyDirectories(config)(
newClassesDir,
clientExternalClassesDir.underlying,
inputs.ioScheduler,
enableCancellation = false
)
.map { walked =>
readOnlyCopyDenylist.++=(walked.target)
()
}
}
}
)
Expand Down
1 change: 0 additions & 1 deletion backend/src/main/scala/bloop/CompileProducts.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import xsbti.compile.PreviousResult
case class CompileProducts(
readOnlyClassesDir: Path,
newClassesDir: Path,
bestEffortDepDir: Option[Path],
resultForDependentCompilationsInSameRun: PreviousResult,
resultForFutureCompilationRuns: PreviousResult,
invalidatedCompileProducts: Set[File],
Expand Down
105 changes: 27 additions & 78 deletions backend/src/main/scala/bloop/Compiler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import bloop.reporter.ZincReporter
import bloop.task.Task
import bloop.tracing.BraveTracer
import bloop.util.AnalysisUtils
import bloop.util.BestEffortDirs
import bloop.util.CacheHashCode
import bloop.util.UUIDUtil

Expand Down Expand Up @@ -71,7 +70,6 @@ case class CompileOutPaths(
analysisOut: AbsolutePath,
genericClassesDir: AbsolutePath,
externalClassesDir: AbsolutePath,
bestEffortDirs: Option[BestEffortDirs],
internalReadOnlyClassesDir: AbsolutePath
) {
// Don't change the internals of this method without updating how they are cleaned up
Expand Down Expand Up @@ -229,7 +227,7 @@ object Compiler {
compileInputs: CompileInputs,
isBestEffortMode: Boolean,
isBestEffortDep: Boolean
): Task[Result] = { // TODO improve
): Task[Result] = {
val logger = compileInputs.logger
val tracer = compileInputs.tracer
val compileOut = compileInputs.out
Expand All @@ -240,9 +238,6 @@ object Compiler {
val readOnlyClassesDirPath = readOnlyClassesDir.toString
val newClassesDir = compileOut.internalNewClassesDir.underlying
val newClassesDirPath = newClassesDir.toString
val bestEffortBuildDir = compileOut.bestEffortDirs.map(_.buildDir.underlying)
val bestEffortDepDir = compileOut.bestEffortDirs.map(_.depDir.underlying)
bestEffortBuildDir.foreach(dir => if (!Files.exists(dir)) Files.createDirectories(dir))

logger.debug(s"External classes directory ${externalClassesDirPath}")
logger.debug(s"Read-only classes directory ${readOnlyClassesDirPath}")
Expand Down Expand Up @@ -385,7 +380,7 @@ object Compiler {
clientTracer.traceTaskVerbose(descriptionMsg) { _ =>
Task.defer {
clientLogger.debug(descriptionMsg)
val denyList =
val denyList =
if (invalidate) {
val invalidatedClassFiles =
allInvalidatedClassFilesForProject.iterator.map(_.toPath).toSet
Expand Down Expand Up @@ -446,7 +441,7 @@ object Compiler {
.doOnCancel(Task(cancel()))
.map {
case Success(_) if cancelPromise.isCompleted => handleCancellation
case Success(result) if isBestEffortMode && isBestEffortDep =>
case Success(_) if isBestEffortMode && isBestEffortDep =>
handleBestEffortSuccess(
compileInputs,
compileOut,
Expand All @@ -462,7 +457,8 @@ object Compiler {
None
)
case Failure(cause: xsbti.CompileFailed) if isBestEffortMode =>
// copies required files to a bsp directory !!!
// Copies required files to a bsp directory.
// For the Success case this is done by the enclosing method
fileManager.complete(true)
handleBestEffortSuccess(
compileInputs,
Expand Down Expand Up @@ -515,7 +511,6 @@ object Compiler {
val products = CompileProducts(
readOnlyClassesDir,
readOnlyClassesDir,
bestEffortDepDir,
noOpPreviousResult,
noOpPreviousResult,
Set(),
Expand All @@ -531,7 +526,12 @@ object Compiler {
): Task[Unit] = Task.defer {
clientLogger.debug(s"Triggering background tasks for $clientClassesDir")
val updateClientState =
updateExternalClassesDirWithReadOnly(clientClassesDir, clientTracer, clientLogger, true)
updateExternalClassesDirWithReadOnly(
clientClassesDir,
clientTracer,
clientLogger,
true
)

val writeAnalysisIfMissing = {
if (compileOut.analysisOut.exists) Task.unit
Expand All @@ -544,16 +544,7 @@ object Compiler {
}

val deleteNewClassesDir = Task(BloopPaths.delete(AbsolutePath(newClassesDir)))
val deleteBestEffortDirsTasks = compileOut.bestEffortDirs match {
case Some(BestEffortDirs(buildDir, depDir)) =>
List(Task(BloopPaths.delete(buildDir)), Task(BloopPaths.delete(depDir)))
case None => List(Task.unit)
}
val allTasks = List(
deleteNewClassesDir,
updateClientState,
writeAnalysisIfMissing
) ++ deleteBestEffortDirsTasks
val allTasks = List(deleteNewClassesDir, updateClientState, writeAnalysisIfMissing)
Task
.gatherUnordered(allTasks)
.map(_ => ())
Expand Down Expand Up @@ -633,14 +624,8 @@ object Compiler {
}
}
}
val deleteBestEffortDirsTasks =
compileOut.bestEffortDirs match { // TODO duplicate
case Some(BestEffortDirs(buildDir, depDir)) =>
List(Task(BloopPaths.delete(buildDir)), Task(BloopPaths.delete(depDir)))
case None => List(Task.unit)
}
Task
.gatherUnordered(List(firstTask, secondTask) ++ deleteBestEffortDirsTasks)
.gatherUnordered(List(firstTask, secondTask))
.map(_ => ())
}

Expand All @@ -651,7 +636,6 @@ object Compiler {
val products = CompileProducts(
readOnlyClassesDir,
newClassesDir,
bestEffortDepDir,
resultForDependentCompilationsInSameRun,
resultForFutureCompilationRuns,
allInvalidated.toSet,
Expand Down Expand Up @@ -681,13 +665,6 @@ object Compiler {
toBackgroundTasks(backgroundTasksForFailedCompilation.toList)
Result.Failed(failedProblems, None, elapsed, backgroundTasks, None)
case t: Throwable =>
compileOut.bestEffortDirs.foreach {
case BestEffortDirs(buildDir, _) =>
logger.info(
"Unsuccessful best effort compilation. No best effort artifacts were created."
)
BloopPaths.delete(buildDir)
}
t.printStackTrace()
val backgroundTasks =
toBackgroundTasks(backgroundTasksForFailedCompilation.toList)
Expand All @@ -698,7 +675,7 @@ object Compiler {

/**
* Handles successful Best Effort compilation.
* Does not persist incrementalCompilation analysis.
* Does not persist incremental compilation analysis.
*/
def handleBestEffortSuccess(
compileInputs: CompileInputs,
Expand All @@ -720,7 +697,6 @@ object Compiler {
val readOnlyClassesDir = compileOut.internalReadOnlyClassesDir.underlying
val readOnlyClassesDirPath = readOnlyClassesDir.toString
val newClassesDir = compileOut.internalNewClassesDir.underlying
val bestEffortBuildDir = compileOut.bestEffortDirs.map(_.buildDir.underlying)
val sourcesWithFatal = reporter.getSourceFilesWithFatalWarnings
val reportedFatalWarnings = isFatalWarningsEnabled && sourcesWithFatal.nonEmpty
val code = if (reportedFatalWarnings) bsp.StatusCode.Error else bsp.StatusCode.Ok
Expand All @@ -732,47 +708,20 @@ object Compiler {
Some(compileOut.analysisOut)
)

// TODO remove
val products = compileOut.bestEffortDirs.map {
case BestEffortDirs(buildDir, depDir) =>
// For Best Effort, delete previous dep directory contents and update with new ones
if (Files.exists(depDir.underlying)) BloopPaths.delete(depDir)
if (!Files.exists(depDir.underlying)) Files.createDirectories(depDir.underlying)
java.nio.file.Files
.walk(buildDir.underlying)
.forEach { srcFile =>
val targetFile =
depDir.underlying.resolve(buildDir.underlying.relativize(srcFile))
if (Files.isDirectory(srcFile)) {
logger.info("copying " + srcFile)
Files.createDirectories(targetFile)
} else if (Files.isRegularFile(srcFile)) {
logger.info("copying file " + srcFile)
Files.copy(
srcFile,
targetFile,
java.nio.file.StandardCopyOption.REPLACE_EXISTING
)
}
}
BloopPaths.delete(buildDir)

val noOpPreviousResult =
updatePreviousResultWithRecentClasspathHashes(
compileInputs.previousResult,
uniqueInputs
)
val noOpPreviousResult =
updatePreviousResultWithRecentClasspathHashes(
compileInputs.previousResult,
uniqueInputs
)

CompileProducts(
readOnlyClassesDir,
newClassesDir,
bestEffortBuildDir,
noOpPreviousResult,
noOpPreviousResult,
Set.empty,
Map.empty
)
}.get
val products = CompileProducts(
readOnlyClassesDir,
newClassesDir,
noOpPreviousResult,
noOpPreviousResult,
Set.empty,
Map.empty
)

// Delete all those class files that were invalidated in the external classes dir
val allInvalidated =
Expand Down
8 changes: 0 additions & 8 deletions backend/src/main/scala/bloop/util/BestEffortDirs.scala

This file was deleted.

2 changes: 1 addition & 1 deletion frontend/src/it/scala/bloop/CommunityBuild.scala
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ abstract class CommunityBuild(val buildpressHomeDir: AbsolutePath) {
resources = Nil,
compileSetup = Config.CompileSetup.empty,
genericClassesDir = dummyClassesDir,
bestEffortDirs = None,
isBestEffort = false,
scalacOptions = Nil,
javacOptions = Nil,
sources = Nil,
Expand Down
8 changes: 2 additions & 6 deletions frontend/src/main/scala/bloop/bsp/BloopBspServices.scala
Original file line number Diff line number Diff line change
Expand Up @@ -793,8 +793,7 @@ final class BloopBspServices(
fullClasspath.toList,
javaOptions,
workingDirectory,
environmentVariables,
None
environmentVariables
)
}).toList
Task.now((state, Right(environmentEntries)))
Expand Down Expand Up @@ -1261,10 +1260,7 @@ final class BloopBspServices(
target = target,
options = project.scalacOptions.toList,
classpath = classpath,
classDirectory = classesDir,
bestEffortDirectory = project.bestEffortDirs.map(bestEffortDirs =>
bsp.Uri(bestEffortDirs.depDir.toBspUri)
)
classDirectory = classesDir
)
}.toList
)
Expand Down
18 changes: 6 additions & 12 deletions frontend/src/main/scala/bloop/data/Project.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import bloop.io.ByteHasher
import bloop.logging.DebugFilter
import bloop.logging.Logger
import bloop.task.Task
import bloop.util.BestEffortDirs

import com.typesafe.config.ConfigException
import com.typesafe.config.ConfigFactory
Expand All @@ -44,7 +43,7 @@ final case class Project(
resources: List[AbsolutePath],
compileSetup: Config.CompileSetup,
genericClassesDir: AbsolutePath,
bestEffortDirs: Option[BestEffortDirs],
isBestEffort: Boolean,
scalacOptions: List[String],
javacOptions: List[String],
sources: List[AbsolutePath],
Expand Down Expand Up @@ -378,7 +377,7 @@ object Project {
compileResources,
setup,
AbsolutePath(project.classesDir),
None,
false,
scala.map(_.options).getOrElse(Nil),
project.java.map(_.options).getOrElse(Nil),
project.sources.map(AbsolutePath.apply),
Expand Down Expand Up @@ -441,9 +440,6 @@ object Project {
logger: Logger
): Project = {
val workspaceDir = project.workspaceDirectory.getOrElse(configDir.getParent)
val bestEffortBaseDir = project.genericClassesDir.getParent.resolve("best-effort")
val bestEffortBuildDir = bestEffortBaseDir.resolve("build")
val bestEffortDepDir = bestEffortBaseDir.resolve("dep")
val isDotty = project.scalaInstance.exists(_.isDotty)

def isAtLeastScala3M3(version: String) = {
Expand All @@ -457,13 +453,11 @@ object Project {
}

def enableBestEffortFlag(options: List[String]): List[String] = {
val bestEffortDirOpt = "-Ybest-effort-dir"
val bestEffortOpt = "-Ybest-effort"
val withBETastyOpt = "-Ywith-best-effort-tasty"
if (!Files.exists(bestEffortBaseDir.underlying))
Files.createDirectories(bestEffortBaseDir.underlying)
val optsWithDir =
if (options.exists(opt => opt.startsWith(bestEffortDirOpt))) options
else options ++ List(bestEffortDirOpt, bestEffortBuildDir.toString)
if (options.contains(bestEffortOpt)) options
else options :+ bestEffortOpt
val optsWithBETasty =
if (optsWithDir.contains(withBETastyOpt)) optsWithDir
else options :+ withBETastyOpt
Expand Down Expand Up @@ -576,7 +570,7 @@ object Project {
val options = enableBestEffortFlag(withEnabledJavaSemanticDb.scalacOptions)

project.copy(
bestEffortDirs = Some(BestEffortDirs(bestEffortBuildDir, bestEffortDepDir)),
isBestEffort = true,
scalacOptions = options
)
} else withEnabledJavaSemanticDb
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,6 @@ object ResultsCache {
CompileProducts(
classesDir,
classesDir,
p.bestEffortDirs.map(_.buildDir.underlying),
r,
r,
Set.empty,
Expand Down

0 comments on commit 8723208

Please sign in to comment.