Skip to content

Commit 4576f2c

Browse files
Iveta Jurčíkováfacebook-github-bot
Iveta Jurčíková
authored andcommitted
Do not check for jvm_abi_gen_working_dir if the plugin is not used
Summary: ### Context We are exploring the integration of the Kotlin Incremental Compiler into Buck for the incremental compilation of Kotlin source files. The goal is to improve build speed by only recompiling modified source files within a target, rather than rebuilding the entire target as is currently done. Recently, I started noticing a continuous increase in compiler non-incremental fallbacks due to the absence of jvmAbiGenWorkingDir. This directory is an output of the jvm-abi-gen plugin, which is used solely for class ABI. Therefore, when the source-only ABI was set as the abi_generation_mode, this directory was never created, leading to a forced non-incremental mode. ### This Diff This diff checks for jvm_abi_gen_working_dir only if the plugin is being used. ---- ### Internal [Doc](https://docs.google.com/document/d/1-zhGPkmt3I2os-kcIaFk9SvT6odt2AJWswSY-J_6AWs/edit?usp=sharing)|[Unidash](https://fburl.com/unidash/m84c5935)|[Code pointer](https://www.internalfb.com/code/fbsource/[adb2a0b14b76]/fbcode/buck2/prelude/kotlin/kotlincd_jar_creator.bzl?lines=98-107) Differential Revision: D71127908 fbshipit-source-id: ad7b2337bf22d8d9ef97fb085ba8e7d849229b0f
1 parent 6eb8ab4 commit 4576f2c

File tree

4 files changed

+32
-12
lines changed

4 files changed

+32
-12
lines changed

toolchains/android/src/com/facebook/buck/jvm/kotlin/KotlincModeFactory.java

+13-6
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import com.facebook.buck.jvm.kotlin.kotlinc.incremental.KotlincMode;
1818
import com.google.common.collect.ImmutableList;
1919
import java.util.Optional;
20+
import javax.annotation.Nullable;
2021

2122
public class KotlincModeFactory {
2223
private static final Logger LOG = Logger.get(KotlincModeFactory.class);
@@ -52,11 +53,6 @@ public static KotlincMode create(
5253
() ->
5354
new IllegalStateException(
5455
"incremental_state_dir/kotlinc_working_dir is not created"));
55-
AbsPath jvmAbiGenWorkingDir =
56-
extraParams
57-
.getJvmAbiGenWorkingDir()
58-
.orElseThrow(
59-
() -> new IllegalStateException("jvm_abi_gen_working_dir is not created"));
6056
ActionMetadata metadata =
6157
actionMetadata.orElseThrow(
6258
() -> new IllegalStateException("actionMetadata is not created"));
@@ -69,7 +65,18 @@ public static KotlincMode create(
6965
KotlinSourceChangesFactory.create(),
7066
ClasspathChangesFactory.create(metadata, classpathSnapshots),
7167
incrementalStateDir.resolve(kotlinClassUsageFile.getFileName()),
72-
jvmAbiGenWorkingDir);
68+
getJvmAbiGenWorkingDir(
69+
extraParams.getShouldUseJvmAbiGen(), extraParams.getJvmAbiGenWorkingDir()));
70+
}
71+
}
72+
73+
private static @Nullable AbsPath getJvmAbiGenWorkingDir(
74+
boolean shouldUseJvmAbiGen, Optional<AbsPath> jvmAbiGenWorkingDir) {
75+
if (!shouldUseJvmAbiGen) {
76+
return null;
7377
}
78+
79+
return jvmAbiGenWorkingDir.orElseThrow(
80+
() -> new IllegalStateException("jvm_abi_gen_working_dir is not created"));
7481
}
7582
}

toolchains/android/src/com/facebook/buck/jvm/kotlin/buildtools/JvmCompilationConfigurationFactory.kt

+7-3
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,16 @@ internal class JvmCompilationConfigurationFactory(
5959
forceNonIncrementalMode(true)
6060
}
6161

62-
if (mode.jvmAbiGenWorkingDir.toFile().exists().not()) {
62+
// targets with abi_generation_mode = "source_only" do not use jvm-abi-gen for
63+
// class abi generation so the directory is never created
64+
val jvmAbiGenWorkingDir = mode.jvmAbiGenWorkingDir
65+
if (jvmAbiGenWorkingDir != null &&
66+
jvmAbiGenWorkingDir.toFile().exists().not()) {
6367
LOG.info(
64-
"Non-incremental compilation will be performed: ${mode.jvmAbiGenWorkingDir.fileName} not found")
68+
"Non-incremental compilation will be performed: ${jvmAbiGenWorkingDir.fileName} not found")
6569
kotlinCDLoggingContext.addExtras(
6670
JvmCompilationConfigurationFactory::class.java.simpleName,
67-
"Non-incremental compilation will be performed: ${mode.jvmAbiGenWorkingDir.fileName} not found")
71+
"Non-incremental compilation will be performed: ${jvmAbiGenWorkingDir.fileName} not found")
6872
forceNonIncrementalMode(true)
6973
}
7074

toolchains/android/src/com/facebook/buck/jvm/kotlin/kotlinc/incremental/KotlincMode.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ sealed interface KotlincMode {
2222
val kotlinSourceChanges: KotlinSourceChanges,
2323
val classpathChanges: ClasspathChanges,
2424
val kotlinClassUsageFile: AbsPath,
25-
val jvmAbiGenWorkingDir: AbsPath
25+
val jvmAbiGenWorkingDir: AbsPath?
2626
) : KotlincMode
2727
}

toolchains/android/test/com/facebook/buck/jvm/kotlin/buildtools/JvmCompilationConfigurationFactoryTest.kt

+11-2
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ internal class JvmCompilationConfigurationFactoryTest {
163163
}
164164

165165
@Test
166-
fun `when classpath changes can not be detected, incremental mode is forced`() {
166+
fun `when classpath changes can not be detected, non-incremental mode is forced`() {
167167
jvmCompilationConfigurationFactory.create(
168168
createFakeIncrementalKotlincMode(ClasspathChanges.Unknown))
169169

@@ -184,6 +184,15 @@ internal class JvmCompilationConfigurationFactoryTest {
184184
.forceNonIncrementalMode(true)
185185
}
186186

187+
@Test
188+
fun `when jvmAbiGen output is null, non-incremental mode is forced`() {
189+
jvmCompilationConfigurationFactory.create(
190+
createFakeIncrementalKotlincMode(jvmAbiGenWorkingDir = null))
191+
192+
verify(classpathSnapshotBasedIncrementalJvmCompilationConfiguration, never())
193+
.forceNonIncrementalMode(true)
194+
}
195+
187196
@Test
188197
fun `when jvmAbiGen working directory does not exist, non-incremental mode is forced`() {
189198
val noExistingFile = createNonExistingFileMock()
@@ -206,7 +215,7 @@ internal class JvmCompilationConfigurationFactoryTest {
206215
private fun createFakeIncrementalKotlincMode(
207216
classpathChanges: ClasspathChanges = createFakeClasspathChanges(),
208217
kotlinDepFile: AbsPath = createExistingFileMock(),
209-
jvmAbiGenWorkingDir: AbsPath = createExistingFileMock()
218+
jvmAbiGenWorkingDir: AbsPath? = createExistingFileMock()
210219
): KotlincMode.Incremental {
211220
val rootProjectDir = AbsPath.get("/home/root")
212221
val buildDir = AbsPath.get("/home/root/buildDir")

0 commit comments

Comments
 (0)