Skip to content

Commit

Permalink
Support kotlin.native.useEmbeddableCompilerJar=false
Browse files Browse the repository at this point in the history
(cherry picked from commit 38ecdb1)
  • Loading branch information
ting-yuan authored and KSP Auto Pick committed Jan 18, 2023
1 parent e8ea2ac commit a3fc613
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) =
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,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))
Expand Down

0 comments on commit a3fc613

Please sign in to comment.