diff options
author | Ting-Yuan Huang <laszio@google.com> | 2023-01-18 02:08:16 -0800 |
---|---|---|
committer | KSP Auto Pick <kotlin-symbol-processing@google.com> | 2023-01-18 20:48:01 +0000 |
commit | a3fc613b7928a5908e5bdefbdc01e5155899d666 (patch) | |
tree | 5c64f18bf5ed5660526e1417495b01019db36d54 | |
parent | e8ea2ac285fc2d1ab8726b0f46d5a827cf5bf9d1 (diff) | |
download | ksp-a3fc613b7928a5908e5bdefbdc01e5155899d666.tar.gz |
Support kotlin.native.useEmbeddableCompilerJar=false
(cherry picked from commit 38ecdb108fc8a049097a473ec0ac6e4b4c46d332)
-rw-r--r-- | gradle-plugin/src/main/kotlin/com/google/devtools/ksp/gradle/KspSubplugin.kt | 28 | ||||
-rw-r--r-- | integration-tests/src/test/kotlin/com/google/devtools/ksp/test/KMPImplementedIT.kt | 23 |
2 files changed, 47 insertions, 4 deletions
diff --git a/gradle-plugin/src/main/kotlin/com/google/devtools/ksp/gradle/KspSubplugin.kt b/gradle-plugin/src/main/kotlin/com/google/devtools/ksp/gradle/KspSubplugin.kt index 4841a7ae..3b923674 100644 --- a/gradle-plugin/src/main/kotlin/com/google/devtools/ksp/gradle/KspSubplugin.kt +++ b/gradle-plugin/src/main/kotlin/com/google/devtools/ksp/gradle/KspSubplugin.kt @@ -79,8 +79,10 @@ class KspGradleSubplugin @Inject internal constructor(private val registry: Tool const val KSP_PLUGIN_ID = "com.google.devtools.ksp.symbol-processing" const val KSP_API_ID = "symbol-processing-api" const val KSP_COMPILER_PLUGIN_ID = "symbol-processing" + const val KSP_COMPILER_PLUGIN_ID_NON_EMBEDDABLE = "symbol-processing-cmdline" const val KSP_GROUP_ID = "com.google.devtools.ksp" const val KSP_PLUGIN_CLASSPATH_CONFIGURATION_NAME = "kspPluginClasspath" + const val KSP_PLUGIN_CLASSPATH_CONFIGURATION_NAME_NON_EMBEDDABLE = "kspPluginClasspathNonEmbeddable" @JvmStatic fun getKspOutputDir(project: Project, sourceSetName: String, target: String) = @@ -233,10 +235,21 @@ class KspGradleSubplugin @Inject internal constructor(private val registry: Tool ) project.dependencies.add( KSP_PLUGIN_CLASSPATH_CONFIGURATION_NAME, - "$KSP_GROUP_ID:$KSP_COMPILER_PLUGIN_ID:$KSP_VERSION" ) + val kspClasspathCfgNonEmbeddable = project.configurations.maybeCreate( + KSP_PLUGIN_CLASSPATH_CONFIGURATION_NAME_NON_EMBEDDABLE + ) + project.dependencies.add( + KSP_PLUGIN_CLASSPATH_CONFIGURATION_NAME_NON_EMBEDDABLE, + "$KSP_GROUP_ID:$KSP_API_ID:$KSP_VERSION" + ) + project.dependencies.add( + KSP_PLUGIN_CLASSPATH_CONFIGURATION_NAME_NON_EMBEDDABLE, + "$KSP_GROUP_ID:$KSP_COMPILER_PLUGIN_ID_NON_EMBEDDABLE:$KSP_VERSION" + ) + findJavaTaskForKotlinCompilation(kotlinCompilation)?.configure { javaCompile -> val generatedJavaSources = javaCompile.project.fileTree(javaOutputDir) generatedJavaSources.include("**/*.java") @@ -488,12 +501,19 @@ class KspGradleSubplugin @Inject internal constructor(private val registry: Tool configureAsKspTask(kspTask, false) configureAsAbstractKotlinCompileTool(kspTask) + val useEmbeddable = project.findProperty("kotlin.native.useEmbeddableCompilerJar") + ?.toString()?.toBoolean() ?: true + val classpathCfg = if (useEmbeddable) { + kspClasspathCfg + } else { + kspClasspathCfgNonEmbeddable + } // KotlinNativeCompile computes -Xplugin=... from compilerPluginClasspath. if (kspExtension.blockOtherCompilerPlugins) { - kspTask.compilerPluginClasspath = kspClasspathCfg + kspTask.compilerPluginClasspath = classpathCfg } else { kspTask.compilerPluginClasspath = - kspClasspathCfg + kotlinCompileTask.compilerPluginClasspath!! + classpathCfg + kotlinCompileTask.compilerPluginClasspath!! kspTask.compilerPluginOptions.addPluginArgument(kotlinCompileTask.compilerPluginOptions) } kspTask.commonSources.from(kotlinCompileTask.commonSources) @@ -555,7 +575,7 @@ class KspGradleSubplugin @Inject internal constructor(private val registry: Tool override fun getPluginArtifactForNative(): SubpluginArtifact? = SubpluginArtifact( groupId = "com.google.devtools.ksp", - artifactId = KSP_COMPILER_PLUGIN_ID, + artifactId = KSP_COMPILER_PLUGIN_ID_NON_EMBEDDABLE, version = KSP_VERSION ) } diff --git a/integration-tests/src/test/kotlin/com/google/devtools/ksp/test/KMPImplementedIT.kt b/integration-tests/src/test/kotlin/com/google/devtools/ksp/test/KMPImplementedIT.kt index cee259e4..7c9c2dcd 100644 --- a/integration-tests/src/test/kotlin/com/google/devtools/ksp/test/KMPImplementedIT.kt +++ b/integration-tests/src/test/kotlin/com/google/devtools/ksp/test/KMPImplementedIT.kt @@ -222,6 +222,29 @@ class KMPImplementedIT { } @Test + fun testNonEmbeddableArtifact() { + Assume.assumeFalse(System.getProperty("os.name").startsWith("Windows", ignoreCase = true)) + val gradleRunner = GradleRunner.create().withProjectDir(project.root) + + gradleRunner.withArguments( + "--configuration-cache-problems=warn", + "-Pkotlin.native.useEmbeddableCompilerJar=false", + ":workload-linuxX64:kspTestKotlinLinuxX64" + ).build() + + gradleRunner.withArguments( + "--configuration-cache-problems=warn", + "-Pkotlin.native.useEmbeddableCompilerJar=true", + ":workload-linuxX64:kspTestKotlinLinuxX64" + ).build() + + gradleRunner.withArguments( + "--configuration-cache-problems=warn", + ":workload-linuxX64:kspTestKotlinLinuxX64" + ).build() + } + + @Test fun testLinuxX64ErrorLog() { Assume.assumeFalse(System.getProperty("os.name").startsWith("Windows", ignoreCase = true)) val gradleRunner = GradleRunner.create().withProjectDir(project.root) |