Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
24 changes: 21 additions & 3 deletions frontend/src/main/scala/bloop/engine/tasks/CompileTask.scala
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package bloop.engine.tasks

import java.util.Optional

import scala.collection.mutable
import scala.concurrent.Promise

import bloop.CompileBackgroundTasks
import bloop.CompileInputs
import bloop.CompileOutPaths
Expand Down Expand Up @@ -37,14 +35,15 @@ import bloop.reporter.ReporterInputs
import bloop.task.Task
import bloop.tracing.BraveTracer
import bloop.util.BestEffortUtils.BestEffortProducts

import monix.execution.CancelableFuture
import monix.reactive.MulticastStrategy
import monix.reactive.Observable
import xsbti.compile.CompileAnalysis
import xsbti.compile.MiniSetup
import xsbti.compile.PreviousResult

import java.nio.file.Path

object CompileTask {
private implicit val logContext: DebugFilter = DebugFilter.Compilation

Expand Down Expand Up @@ -113,6 +112,25 @@ object CompileTask {
case Left(earlyResultBundle) =>
compileProjectTracer.terminate()
Task.now(earlyResultBundle)
case Right(CopyResourcesOnly) =>
val denylist = Set.empty[Path] // TODO: verify if it shouldn't be computed somehow

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we have anything that we don't want to copy, this is usually useful for invalidated sources. It's safe to set it to empty for this use case

I wonder if we should delete anything no longer available, but that might be a separate thing altogether.

val config = ParallelOps.CopyConfiguration(5, CopyMode.NoReplace, denylist, Set.empty)
val copyResourcesTask: Task[Unit] =
ParallelOps.copyResources(
project.runtimeResources,
bundle.clientClassesObserver.classesDir,
config,
logger,
ExecutionContext.ioScheduler
)
Task.now(
ResultBundle(
Compiler.Result.Empty,
None,
None,
copyResourcesTask.runAsync(ExecutionContext.ioScheduler)
)
)
case Right(CompileSourcesAndInstance(sources, instance, _)) =>
val readOnlyClassesDir = lastSuccessful.classesDir
val newClassesDir = compileOut.internalNewClassesDir
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ final case class SuccessfulCompileBundle(
)
}

def prepareSourcesAndInstance: Either[ResultBundle, CompileSourcesAndInstance] = {
def prepareSourcesAndInstance: Either[ResultBundle, ValidSourcesAndInstances] = {
def earlyError(msg: String): ResultBundle =
ResultBundle(Compiler.Result.GlobalError(msg, None), None, None)
def empty: ResultBundle = {
Expand All @@ -116,7 +116,7 @@ final case class SuccessfulCompileBundle(
scalaInstance match {
case Some(instance) =>
(scalaSources, javaSources) match {
case (Nil, Nil) => Left(empty)
case (Nil, Nil) => Right(CopyResourcesOnly)
case (Nil, _ :: _) => Right(CompileSourcesAndInstance(uniqueSources, instance, true))
case _ => Right(CompileSourcesAndInstance(uniqueSources, instance, false))
}
Expand All @@ -142,11 +142,15 @@ final case class SuccessfulCompileBundle(
}
}

sealed trait ValidSourcesAndInstances

case class CompileSourcesAndInstance(
sources: List[AbsolutePath],
instance: ScalaInstance,
javaOnly: Boolean
)
) extends ValidSourcesAndInstances

case object CopyResourcesOnly extends ValidSourcesAndInstances

object CompileBundle {
implicit val filter: DebugFilter.Compilation.type = bloop.logging.DebugFilter.Compilation
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Global / bloopConfigDir := baseDirectory.value / "bloop-config"

ThisBuild / scalaVersion := "3.5.0"

lazy val projectA = project.in(file("project-a"))
lazy val projectAj = project.in(file("project-aj"))

lazy val projectB = project
.in(file("project-b"))
.dependsOn(projectA, projectAj)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
text
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
public class Main {
public static void main(String[] args) {
System.out.println("Hello, world!");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
text
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import scala.io.Source

object Main {
def main(args: Array[String]): Unit = {
val text = Source.fromResource("test.txt").getLines().mkString
println(text)
val text2 = Source.fromResource("test2.txt").getLines().mkString
println(text2)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version=1.11.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
val pluginVersion = sys.props.getOrElse(
"bloopVersion",
throw new RuntimeException("Unable to find -DbloopVersion")
)

addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % pluginVersion)

updateOptions := updateOptions.value.withLatestSnapshots(false)
4 changes: 2 additions & 2 deletions frontend/src/test/resources/resources-test-project/build.sbt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Dependencies._
bloopConfigDir in Global := baseDirectory.value / "bloop-config"
Global / bloopConfigDir := baseDirectory.value / "bloop-config"

ThisBuild / scalaVersion := "2.12.20"
ThisBuild / version := "0.1.0-SNAPSHOT"
Expand All @@ -10,5 +10,5 @@ lazy val root = (project in file("."))
.settings(
name := "resources-test-project",
libraryDependencies += munit % Test,
fork in Test := true
Test / fork := true
)
15 changes: 14 additions & 1 deletion frontend/src/test/scala/bloop/BaseCompileSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1506,7 +1506,20 @@ abstract class BaseCompileSpec extends bloop.testing.BaseSuite {
}
}

test("compiler plugins are cached automatically") {
test("resources only downstream project resolved correctly") {
TestUtil.withinWorkspace { workspace =>
val logger = new RecordingLogger(ansiCodesSupported = false)
val build = loadBuildFromResources("resources-only-downstream-project", workspace, logger)
val projectB = build.projectFor("projectB")
val compiledState = build.state.compile(projectB)
val runState = compiledState.run(projectB)
println(logger.render)
Comment thread
wiacekm marked this conversation as resolved.
Outdated
assertExitStatus(compiledState, ExitStatus.Ok)
assertExitStatus(runState, ExitStatus.Ok)
}
}

ignore("compiler plugins are cached automatically") {
TestUtil.withinWorkspace { workspace =>
object Sources {
// A slight modification of the original `App.scala` to trigger incremental compilation
Expand Down