Skip to content

Commit

Permalink
introduce common-deps module for classpath isolation
Browse files Browse the repository at this point in the history
  • Loading branch information
neetopia committed Oct 11, 2023
1 parent ed8d94b commit c3de1a5
Show file tree
Hide file tree
Showing 12 changed files with 90 additions and 13 deletions.
10 changes: 10 additions & 0 deletions api/src/main/kotlin/com/google/devtools/ksp/processing/ExitCode.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.google.devtools.ksp.processing

enum class ExitCode(code: Int) {
OK(0),

// Whenever there are some error messages.
PROCESSING_ERROR(1),

// Let exceptions pop through to the caller. Don't catch and convert them to, e.g., INTERNAL_ERROR.
}
59 changes: 59 additions & 0 deletions common-deps/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

description = "Kotlin Symbol Processor"

val kotlinBaseVersion: String by project
val junitVersion: String by project
val googleTruthVersion: String by project
val agpBaseVersion: String by project
val signingKey: String? by project
val signingPassword: String? by project

tasks.withType<KotlinCompile> {
compilerOptions.freeCompilerArgs.add("-Xjvm-default=all-compatibility")
}

plugins {
kotlin("jvm")
`maven-publish`
signing
id("org.jetbrains.dokka")
}

dependencies {
compileOnly(project(":api"))
}

tasks {
val sourcesJar by creating(Jar::class) {
archiveClassifier.set("sources")
from(project.sourceSets.main.get().allSource)
}
}

val dokkaJavadocJar by tasks.register<Jar>("dokkaJavadocJar") {
dependsOn(tasks.dokkaJavadoc)
from(tasks.dokkaJavadoc.flatMap { it.outputDirectory })
archiveClassifier.set("javadoc")
}

publishing {
publications {
create<MavenPublication>("default") {
artifactId = "symbol-processing-common-deps"
from(components["java"])
artifact(tasks["sourcesJar"])
artifact(tasks["dokkaJavadocJar"])
pom {
name.set("com.google.devtools.ksp:symbol-processing-common-deps")
description.set("Kotlin Symbol processing Gradle Utils")
}
}
}
}

signing {
isRequired = hasProperty("signingKey")
useInMemoryPgpKeys(signingKey, signingPassword)
sign(extensions.getByType<PublishingExtension>().publications)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.google.devtools.ksp.impl
package com.google.devtools.ksp.processing

import java.io.File
import java.io.Serializable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.devtools.ksp.impl
package com.google.devtools.ksp.processing

import com.google.devtools.ksp.processing.KSPLogger
import com.google.devtools.ksp.symbol.KSNode

class KspGradleLogger(val loglevel: Int) : KSPLogger {
Expand Down
6 changes: 3 additions & 3 deletions gradle-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@ dependencies {
// replace AGP dependency w/ gradle-api when we have source registering API available.
compileOnly("com.android.tools.build:gradle:$agpBaseVersion")
compileOnly(gradleApi())
implementation(project(":kotlin-analysis-api")) {
isTransitive = false
}
compileOnly(project(":kotlin-analysis-api"))
implementation(project(":api"))
implementation(project(":common-deps"))
testImplementation(gradleApi())
testImplementation(project(":api"))
testImplementation(project(":common-util"))
Expand Down Expand Up @@ -141,6 +140,7 @@ tasks.named("processTestResources").configure {

tasks.named<Test>("test").configure {
dependsOn(":api:publishAllPublicationsToTestRepository")
dependsOn(":common-deps:publishAllPublicationsToTestRepository")
dependsOn(":gradle-plugin:publishAllPublicationsToTestRepository")
dependsOn(":symbol-processing:publishAllPublicationsToTestRepository")
dependsOn(":kotlin-analysis-api:publishAllPublicationsToTestRepository")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.google.devtools.ksp.gradle

import com.google.devtools.ksp.impl.KSPJvmConfig
import com.google.devtools.ksp.impl.KSPLoader
import com.google.devtools.ksp.impl.KotlinSymbolProcessing
import com.google.devtools.ksp.impl.KspGradleLogger
import com.google.devtools.ksp.processing.ExitCode
import com.google.devtools.ksp.processing.KSPJvmConfig
import com.google.devtools.ksp.processing.KspGradleLogger
import org.gradle.api.DefaultTask
import org.gradle.api.artifacts.Configuration
import org.gradle.api.file.ConfigurableFileCollection
Expand Down Expand Up @@ -80,6 +80,9 @@ abstract class KspAATask @Inject constructor(
val kspTaskName = kotlinCompileProvider.name.replaceFirst("compile", "ksp")
val kspAADepCfg = project.configurations.detachedConfiguration(
project.dependencies.create("${KspGradleSubplugin.KSP_GROUP_ID}:symbol-processing-aa:$KSP_VERSION"),
project.dependencies.create(
"${KspGradleSubplugin.KSP_GROUP_ID}:symbol-processing-common-deps:$KSP_VERSION"
),
project.dependencies.create("org.jetbrains.intellij.deps:trove4j:1.0.20200330"),
).apply {
isTransitive = false
Expand Down Expand Up @@ -327,7 +330,7 @@ abstract class KspAAWorkerAction : WorkAction<KspAAWorkParameter> {
objectOutputStream.writeObject(kspConfig)

val exitCode = try {
val kspLoaderClass = isolatedClassLoader.loadClass(KSPLoader::class.java.canonicalName)
val kspLoaderClass = isolatedClassLoader.loadClass("com.google.devtools.ksp.impl.KSPLoader")
val runMethod = kspLoaderClass.getMethod(
"loadAndRunKSP",
ByteArray::class.java,
Expand All @@ -340,14 +343,14 @@ abstract class KspAAWorkerAction : WorkAction<KspAAWorkParameter> {
processorProviders,
gradleCfg.logLevel.get().ordinal
) as Int
KotlinSymbolProcessing.ExitCode.values()[returnCode]
ExitCode.values()[returnCode]
} catch (e: Exception) {
require(e is InvocationTargetException)
kspGradleLogger.exception(e.targetException)
throw e.targetException
}

if (exitCode != KotlinSymbolProcessing.ExitCode.OK) {
if (exitCode != ExitCode.OK) {
throw Exception("KSP failed with exit code: $exitCode")
}
}
Expand Down
1 change: 1 addition & 0 deletions integration-tests/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ tasks.withType<Test> {
jvmArgumentProviders.add(RelativizingInternalPathProvider("testRepo", File(rootProject.buildDir, "repos/test")))
dependsOn(":api:publishAllPublicationsToTestRepository")
dependsOn(":gradle-plugin:publishAllPublicationsToTestRepository")
dependsOn(":common-deps:publishAllPublicationsToTestRepository")
dependsOn(":symbol-processing:publishAllPublicationsToTestRepository")
dependsOn(":symbol-processing-cmdline:publishAllPublicationsToTestRepository")
dependsOn(":kotlin-analysis-api:publishAllPublicationsToTestRepository")
Expand Down
1 change: 1 addition & 0 deletions kotlin-analysis-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ dependencies {
implementation("org.jetbrains.intellij.deps:asm-all:$aaAsmVersion")
implementation("org.codehaus.woodstox:stax2-api:$aaStax2Version") { isTransitive = false }
implementation("com.fasterxml:aalto-xml:$aaAaltoXmlVersion") { isTransitive = false }
compileOnly(project(":common-deps"))

implementation(project(":api"))
implementation(project(":common-util"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
package com.google.devtools.ksp.impl

import com.google.devtools.ksp.processing.KSPJvmConfig
import com.google.devtools.ksp.processing.KspGradleLogger
import com.google.devtools.ksp.processing.SymbolProcessorProvider
import java.io.ByteArrayInputStream
import java.io.ObjectInputStream
Expand Down
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pluginManagement {

include("api")
include("gradle-plugin")
include("common-deps")
include("common-util")
include("test-utils")
include("compiler-plugin")
Expand Down
1 change: 1 addition & 0 deletions test-utils/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ dependencies {
runtimeOnly("org.junit.platform:junit-platform-suite:$junitPlatformVersion")

implementation(kotlin("stdlib", kotlinBaseVersion))
implementation(project(":common-deps"))
implementation("org.jetbrains.kotlin:kotlin-compiler:$kotlinBaseVersion")
implementation("org.jetbrains.kotlin:kotlin-compiler-internal-test-framework:$kotlinBaseVersion")
implementation("org.jetbrains.kotlin:kotlin-scripting-compiler:$kotlinBaseVersion")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
package com.google.devtools.ksp.test

import com.google.devtools.ksp.impl.CommandLineKSPLogger
import com.google.devtools.ksp.impl.KSPJvmConfig
import com.google.devtools.ksp.impl.KotlinSymbolProcessing
import com.google.devtools.ksp.processing.KSPJvmConfig
import com.google.devtools.ksp.processor.AbstractTestProcessor
import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler
import org.jetbrains.kotlin.cli.jvm.config.jvmClasspathRoots
Expand Down

0 comments on commit c3de1a5

Please sign in to comment.