Skip to content

Commit f54199b

Browse files
committed
[compiler] Instruct the JavaBuilder to not run without outright disabling it
#SCL-22172 fixed - By providing a unique Java compiler id that does not match any Java compiler implementation in the platform, we are able to tell the JPS JavaBuilder to not run in Zinc Scala projects, without disabling it. - This also prevents the disabling of the KotlinBuilder in Zinc Scala projects, although, we need to do a bit more work to make this fully supported, as Zinc does not guarantee incremental compilation support for Scala and Kotlin. - This change prevents the disabling of the GradleResourcesBuilder in gradle Scala projects that use the Zinc incremental compiler.
1 parent e5d2170 commit f54199b

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

scala/compiler-jps/src/org/jetbrains/jps/incremental/scala/InitialScalaBuilder.scala

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import org.jetbrains.jps.builders.DirtyFilesHolder
77
import org.jetbrains.jps.builders.java.{JavaBuilderUtil, JavaSourceRootDescriptor}
88
import org.jetbrains.jps.builders.storage.BuildDataCorruptedException
99
import org.jetbrains.jps.incremental._
10+
import org.jetbrains.jps.model.java.JpsJavaExtensionService
1011
import org.jetbrains.jps.model.module.JpsModule
1112
import org.jetbrains.plugins.scala.compiler.data.IncrementalityType
1213

@@ -31,6 +32,21 @@ class InitialScalaBuilder extends ModuleLevelBuilder(BuilderCategory.INITIAL) {
3132
val previousIncrementalityType = readIncrementalityType(context)
3233
val incrementalityType = ScalaBuilder.projectSettings(context).getIncrementalityType
3334

35+
if (incrementalityType == IncrementalityType.SBT) {
36+
// The project uses the Zinc incremental compiler. The Zinc incremental compiler compiles both Scala and Java
37+
// sources. For that reason, it is important that the JavaBuilder does not run for our project. However,
38+
// disabling the JavaBuilder through the JavaBuilder.IS_ENABLED global key is not ideal. There are other
39+
// JPS builders who are also implicitly disabled by this action, such as the KotlinBuilder and the
40+
// GradleResourcesBuilder. Thus, we want to instruct the JavaBuilder to not run for our project, but keep it
41+
// enabled, such that the other builders can run. This can be achieved through the Java Compiler ID mechanism.
42+
// We set the Java Compiler ID to our custom Zinc ID, an ID which is unique to the Scala plugin and for which
43+
// a compiler does not exist in the IDEA Platform. In this case, the JavaBuilder will not have a compiler
44+
// instance to run, and therefore it will not do anything in our project, but remain officially enabled.
45+
val project = context.getProjectDescriptor.getProject
46+
val configuration = JpsJavaExtensionService.getInstance().getCompilerConfiguration(project)
47+
configuration.setJavaCompilerId(ZincCompilerId)
48+
}
49+
3450
previousIncrementalityType match {
3551
case _ if JavaBuilderUtil.isForcedRecompilationAllJavaModules(context) =>
3652
// Forced rebuild, save current incremental compiler setting to disk and continue.
@@ -156,4 +172,10 @@ object InitialScalaBuilder {
156172
storeScalaModules(context, result)
157173
result
158174
}
175+
176+
/**
177+
* A unique compiler id (in the IntelliJ Platform), which does not match any other Java compiler implementation
178+
* provided by the platform.
179+
*/
180+
private final val ZincCompilerId = "scala_Zinc"
159181
}

scala/compiler-jps/src/org/jetbrains/jps/incremental/scala/SbtBuilder.scala

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import org.jetbrains.jps.incremental.ModuleLevelBuilder.{ExitCode => JpsExitCode
88

99
import java.io.File
1010
import org.jetbrains.jps.incremental._
11-
import org.jetbrains.jps.incremental.java.JavaBuilder
1211
import org.jetbrains.jps.incremental.messages.ProgressMessage
1312
import org.jetbrains.jps.incremental.scala.InitialScalaBuilder.isScalaProject
1413
import org.jetbrains.jps.incremental.scala.SbtBuilder._
@@ -24,12 +23,6 @@ import _root_.scala.jdk.CollectionConverters._
2423
class SbtBuilder extends ModuleLevelBuilder(BuilderCategory.TRANSLATOR) {
2524
override def getPresentableName: String = JpsBundle.message("sbt.builder.presentable.name")
2625

27-
override def buildStarted(context: CompileContext): Unit = {
28-
if (isEnabled(context)) {
29-
JavaBuilder.IS_ENABLED.set(context, false)
30-
}
31-
}
32-
3326
override def build(context: CompileContext,
3427
chunk: ModuleChunk,
3528
dirtyFilesHolder: DirtyFilesHolder,

0 commit comments

Comments
 (0)