Skip to content

Commit

Permalink
remove all KSP logic
Browse files Browse the repository at this point in the history
We aren't currently planning on pursuing KSP (see
[#1075](#1075)).
  • Loading branch information
RBusarow committed Dec 9, 2024
1 parent 2259b47 commit 268bed9
Show file tree
Hide file tree
Showing 66 changed files with 118 additions and 2,779 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ jobs:
# Expressions in Github actions are limited. If there would be an if expression, then we
# wouldn't need to duplicate the next step and depending on the OS enable / disable them.
- name: Test on Windows
run: ./gradlew.bat assemble test --no-build-cache --no-daemon --stacktrace -Doverride_config-fullTestRun=false -Doverride_config-includeKspTests=false
run: ./gradlew.bat assemble test --no-build-cache --no-daemon --stacktrace -Doverride_config-fullTestRun=false

- name: Upload Test Results
uses: actions/upload-artifact@0b2256b8c012f0828dc542b3febcab082c67f72b # v4
Expand Down
2 changes: 0 additions & 2 deletions compiler-api/api/compiler-api.api
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
public final class com/squareup/anvil/compiler/api/AnalysisBackend : java/lang/Enum {
public static final field EMBEDDED Lcom/squareup/anvil/compiler/api/AnalysisBackend;
public static final field KSP Lcom/squareup/anvil/compiler/api/AnalysisBackend;
public static fun getEntries ()Lkotlin/enums/EnumEntries;
public static fun valueOf (Ljava/lang/String;)Lcom/squareup/anvil/compiler/api/AnalysisBackend;
public static fun values ()[Lcom/squareup/anvil/compiler/api/AnalysisBackend;
Expand Down Expand Up @@ -60,7 +59,6 @@ public final class com/squareup/anvil/compiler/api/CodeGeneratorKt {

public final class com/squareup/anvil/compiler/api/ComponentMergingBackend : java/lang/Enum {
public static final field IR Lcom/squareup/anvil/compiler/api/ComponentMergingBackend;
public static final field KSP Lcom/squareup/anvil/compiler/api/ComponentMergingBackend;
public static fun getEntries ()Lkotlin/enums/EnumEntries;
public static fun valueOf (Ljava/lang/String;)Lcom/squareup/anvil/compiler/api/ComponentMergingBackend;
public static fun values ()[Lcom/squareup/anvil/compiler/api/ComponentMergingBackend;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,4 @@ package com.squareup.anvil.compiler.api
public enum class AnalysisBackend {
/** Anvil runs as a direct compiler plugin inside compileKotlin tasks. */
EMBEDDED,

/** Anvil runs as a Kotlin Symbol Processor (KSP). */
KSP,
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ public interface AnvilContext {
* These models could be generated by any of:
* - Anvil via the [generateFactories] option
* - Dagger via KAPT
* - Dagger via KSP
*/
public val willHaveDaggerFactories: Boolean

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,4 @@ package com.squareup.anvil.compiler.api
public enum class ComponentMergingBackend {
/** Component merging runs as an IR plugin during kapt stub generation. */
IR,

/** Component merging runs as a Kotlin Symbol Processor (KSP) with dagger KSP. */
KSP,
}
2 changes: 0 additions & 2 deletions compiler-utils/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ dependencies {
implementation(libs.inject)

testFixturesApi(libs.kotlin.compileTesting)
testFixturesApi(libs.kotlin.compileTesting.ksp)
testFixturesImplementation(project(":compiler"))
testFixturesImplementation(libs.dagger2.compiler)
testFixturesImplementation(libs.dagger2)
Expand All @@ -48,7 +47,6 @@ dependencies {
compileOnly(libs.dagger2.compiler)
compileOnly(libs.junit)
compileOnly(libs.kotlin.compileTesting)
compileOnly(libs.kotlin.compileTesting.ksp)
compileOnly(libs.truth)
}
}
9 changes: 3 additions & 6 deletions compiler-utils/dependencies/testFixturesRuntimeClasspath.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ com.google.code.findbugs:jsr305:3.0.2
com.google.dagger:dagger-compiler:2.52
com.google.dagger:dagger-spi:2.52
com.google.dagger:dagger:2.52
com.google.devtools.ksp:symbol-processing-aa-embeddable:2.0.0-1.0.22
com.google.devtools.ksp:symbol-processing-api:2.0.0-1.0.22
com.google.devtools.ksp:symbol-processing-common-deps:2.0.0-1.0.22
com.google.devtools.ksp:symbol-processing:2.0.0-1.0.22
com.google.devtools.ksp:symbol-processing-api:1.9.24-1.0.20
com.google.errorprone:error_prone_annotations:2.28.0
com.google.errorprone:javac-shaded:9-dev-r4023-3
com.google.googlejavaformat:google-java-format:1.5
Expand All @@ -20,10 +17,8 @@ com.squareup.okio:okio-jvm:3.9.0
com.squareup.okio:okio:3.9.0
com.squareup:javapoet:1.13.0
com.squareup:kotlinpoet-jvm:1.18.1
com.squareup:kotlinpoet-ksp:1.18.1
com.squareup:kotlinpoet:1.18.1
dev.zacsweers.kctfork:core:0.5.1
dev.zacsweers.kctfork:ksp:0.5.1
io.github.classgraph:classgraph:4.8.174
jakarta.inject:jakarta.inject-api:2.0.1
javax.annotation:jsr250-api:1.0
Expand All @@ -41,6 +36,8 @@ org.jetbrains.kotlin:kotlin-compiler-embeddable:2.0.21
org.jetbrains.kotlin:kotlin-daemon-embeddable:2.0.21
org.jetbrains.kotlin:kotlin-reflect:2.0.21
org.jetbrains.kotlin:kotlin-script-runtime:2.0.21
org.jetbrains.kotlin:kotlin-stdlib-jdk7:2.0.21
org.jetbrains.kotlin:kotlin-stdlib-jdk8:2.0.21
org.jetbrains.kotlin:kotlin-stdlib:2.0.21
org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.6.4
org.jetbrains:annotations:13.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,22 @@ package com.squareup.anvil.compiler.internal.testing

import com.google.auto.value.processor.AutoAnnotationProcessor
import com.google.common.truth.Truth.assertWithMessage
import com.google.devtools.ksp.processing.SymbolProcessorProvider
import com.squareup.anvil.annotations.ExperimentalAnvilApi
import com.squareup.anvil.compiler.AnvilCommandLineProcessor
import com.squareup.anvil.compiler.AnvilComponentRegistrar
import com.squareup.anvil.compiler.internal.testing.AnvilCompilationMode.Embedded
import com.squareup.anvil.compiler.internal.testing.AnvilCompilationMode.Ksp
import com.tschuchort.compiletesting.JvmCompilationResult
import com.tschuchort.compiletesting.KotlinCompilation
import com.tschuchort.compiletesting.PluginOption
import com.tschuchort.compiletesting.SourceFile
import com.tschuchort.compiletesting.addPreviousResultToClasspath
import com.tschuchort.compiletesting.kspProcessorOptions
import com.tschuchort.compiletesting.kspWithCompilation
import com.tschuchort.compiletesting.symbolProcessorProviders
import dagger.internal.codegen.ComponentProcessor
import dagger.internal.codegen.KspComponentProcessor
import org.intellij.lang.annotations.Language
import org.jetbrains.kotlin.config.JvmTarget
import org.jetbrains.kotlin.config.LanguageVersion
import java.io.File
import java.io.OutputStream
import java.nio.file.Files
import java.util.Locale
import java.util.ServiceLoader

/**
* A simple API over a [KotlinCompilation] with extra configuration support for Anvil.
Expand Down Expand Up @@ -78,11 +70,6 @@ public class AnvilCompilation internal constructor(
optionName = "disable-component-merging",
optionValue = disableComponentMerging.toString(),
),
PluginOption(
pluginId = anvilCommandLineProcessor.pluginId,
optionName = "analysis-backend",
optionValue = mode.analysisBackend.name.lowercase(Locale.US),
),
PluginOption(
pluginId = anvilCommandLineProcessor.pluginId,
optionName = "ir-merges-file",
Expand Down Expand Up @@ -137,29 +124,6 @@ public class AnvilCompilation internal constructor(
),
)
}

is Ksp -> {
symbolProcessorProviders += buildList {
addAll(
ServiceLoader.load(
SymbolProcessorProvider::class.java,
SymbolProcessorProvider::class.java.classLoader,
)
// TODO for now, we don't want to run the dagger KSP processor while we're testing
// KSP. This will change when we start supporting dagger-KSP, at which point we can
// change this filter to be based on https://github.com/square/anvil/pull/713
.filterNot { it is KspComponentProcessor.Provider },
)
addAll(mode.symbolProcessorProviders)
}
// Run KSP embedded directly within this kotlinc invocation
kspWithCompilation = true
kspProcessorOptions["will-have-dagger-factories"] = generateDaggerFactories.toString()
kspProcessorOptions["generate-dagger-factories"] = generateDaggerFactories.toString()
kspProcessorOptions["generate-dagger-factories-only"] =
generateDaggerFactoriesOnly.toString()
kspProcessorOptions["disable-component-merging"] = disableComponentMerging.toString()
}
}

if (enableExperimentalAnvilApis) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
package com.squareup.anvil.compiler.internal.testing

import com.google.devtools.ksp.processing.SymbolProcessorProvider
import com.squareup.anvil.compiler.api.AnalysisBackend
import com.squareup.anvil.compiler.api.AnalysisBackend.EMBEDDED
import com.squareup.anvil.compiler.api.AnalysisBackend.KSP
import com.squareup.anvil.compiler.api.CodeGenerator

// TODO: Repurpose this as a way to pass a spec into `compile(...)` in tests,
// instead of individual flags.
// This is left in place for now because it's already wired up everywhere.
public sealed class AnvilCompilationMode(public val analysisBackend: AnalysisBackend) {
public data class Embedded(
val codeGenerators: List<CodeGenerator> = emptyList(),
) : AnvilCompilationMode(EMBEDDED)
public data class Ksp(
val symbolProcessorProviders: List<SymbolProcessorProvider> = emptyList(),
) : AnvilCompilationMode(KSP)
}
4 changes: 1 addition & 3 deletions compiler/api/compiler.api
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ public final class com/squareup/anvil/compiler/AnvilComponentRegistrar : org/jet

public final class com/squareup/anvil/compiler/CommandLineOptions {
public static final field Companion Lcom/squareup/anvil/compiler/CommandLineOptions$Companion;
public synthetic fun <init> (ZZZZZLcom/squareup/anvil/compiler/api/AnalysisBackend;Lcom/squareup/anvil/compiler/api/ComponentMergingBackend;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun getBackend ()Lcom/squareup/anvil/compiler/api/AnalysisBackend;
public final fun getComponentMergingBackend ()Lcom/squareup/anvil/compiler/api/ComponentMergingBackend;
public synthetic fun <init> (ZZZZZLkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun getDisableComponentMerging ()Z
public final fun getGenerateFactories ()Z
public final fun getGenerateFactoriesOnly ()Z
Expand Down
6 changes: 0 additions & 6 deletions compiler/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ buildConfig {
useKotlinOutput { topLevelConstants = true }

buildConfigField("boolean", "FULL_TEST_RUN", libs.versions.config.fullTestRun.get())
buildConfigField("boolean", "INCLUDE_KSP_TESTS", libs.versions.config.includeKspTests.get())
}

conventions {
Expand Down Expand Up @@ -41,12 +40,9 @@ dependencies {
implementation(libs.dagger2)
implementation(libs.jsr250)
implementation(libs.kotlinpoet)
implementation(libs.kotlinpoet.ksp)

compileOnly(libs.auto.service.annotations)
compileOnly(libs.kotlin.compiler)
compileOnly(libs.ksp.compilerPlugin)
compileOnly(libs.ksp.api)

kapt(libs.auto.service.processor)

Expand All @@ -58,11 +54,9 @@ dependencies {
testImplementation(libs.kotest.assertions.core.jvm)
testImplementation(libs.kotlin.annotationProcessingEmbeddable)
testImplementation(libs.kotlin.compileTesting)
testImplementation(libs.kotlin.compileTesting.ksp)
testImplementation(libs.kotlin.compiler)
testImplementation(libs.kotlin.test)
testImplementation(libs.kotlin.reflect)
testImplementation(libs.ksp.compilerPlugin)
testImplementation(libs.truth)

testRuntimeOnly(libs.kotest.assertions.core.jvm)
Expand Down
1 change: 0 additions & 1 deletion compiler/dependencies/runtimeClasspath.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
com.google.dagger:dagger:2.52
com.squareup:kotlinpoet-jvm:1.18.1
com.squareup:kotlinpoet-ksp:1.18.1
com.squareup:kotlinpoet:1.18.1
jakarta.inject:jakarta.inject-api:2.0.1
javax.annotation:jsr250-api:1.0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.squareup.anvil.compiler

import com.google.auto.service.AutoService
import com.squareup.anvil.compiler.api.AnalysisBackend
import com.squareup.anvil.compiler.api.ComponentMergingBackend
import org.jetbrains.kotlin.compiler.plugin.AbstractCliOption
import org.jetbrains.kotlin.compiler.plugin.CliOption
import org.jetbrains.kotlin.compiler.plugin.CommandLineProcessor
Expand Down Expand Up @@ -49,14 +47,6 @@ internal const val willHaveDaggerFactoriesName = "will-have-dagger-factories"
internal val willHaveDaggerFactoriesKey =
CompilerConfigurationKey.create<Boolean>("anvil $willHaveDaggerFactoriesName")

internal const val analysisBackendName = "analysis-backend"
internal val analysisBackendKey =
CompilerConfigurationKey.create<String>("anvil $analysisBackendName")

internal const val mergingBackendName = "merging-backend"
internal val mergingBackendKey =
CompilerConfigurationKey.create<String>("anvil $mergingBackendName")

/**
* Parses arguments from the Gradle plugin for the compiler plugin.
*/
Expand Down Expand Up @@ -141,20 +131,6 @@ public class AnvilCommandLineProcessor : CommandLineProcessor {
required = false,
allowMultipleOccurrences = false,
),
CliOption(
optionName = analysisBackendName,
valueDescription = AnalysisBackend.entries.joinToString("|", "<", ">"),
description = "Controls whether Anvil analysis is running as an embedded plugin or as KSP.",
required = false,
allowMultipleOccurrences = false,
),
CliOption(
optionName = mergingBackendName,
valueDescription = ComponentMergingBackend.entries.joinToString("|", "<", ">"),
description = "Controls whether module merging is running as an IR plugin or as KSP.",
required = false,
allowMultipleOccurrences = false,
),
)

override fun processOption(
Expand Down Expand Up @@ -183,8 +159,6 @@ public class AnvilCommandLineProcessor : CommandLineProcessor {

trackSourceFilesName ->
configuration.put(trackSourceFilesKey, value.toBoolean())

analysisBackendName -> configuration.put(analysisBackendKey, value)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ package com.squareup.anvil.compiler
import com.google.auto.service.AutoService
import com.squareup.anvil.annotations.ExperimentalAnvilApi
import com.squareup.anvil.compiler.CommandLineOptions.Companion.commandLineOptions
import com.squareup.anvil.compiler.api.AnalysisBackend
import com.squareup.anvil.compiler.api.CodeGenerator
import com.squareup.anvil.compiler.api.ComponentMergingBackend
import com.squareup.anvil.compiler.codegen.CodeGenerationExtension
import com.squareup.anvil.compiler.codegen.ContributesSubcomponentHandlerGenerator
import com.squareup.anvil.compiler.codegen.incremental.BaseDir
Expand Down Expand Up @@ -50,25 +48,15 @@ public class AnvilComponentRegistrar : ComponentRegistrar {
val mergingEnabled =
!commandLineOptions.generateFactoriesOnly && !commandLineOptions.disableComponentMerging
if (mergingEnabled) {
if (commandLineOptions.componentMergingBackend == ComponentMergingBackend.IR) {
IrGenerationExtension.registerExtension(
project,
IrContributionMerger(
classScanner = scanner,
moduleDescriptorFactory = moduleDescriptorFactory,
trackSourceFiles = trackSourceFiles,
irMergesFile = irMergesFile,
),
)
} else {
// TODO in dagger-ksp support
}
}

// Everything below this point is only when running in embedded compilation mode. If running in
// KSP, there's nothing else to do.
if (commandLineOptions.backend != AnalysisBackend.EMBEDDED) {
return
IrGenerationExtension.registerExtension(
project,
IrContributionMerger(
classScanner = scanner,
moduleDescriptorFactory = moduleDescriptorFactory,
trackSourceFiles = trackSourceFiles,
irMergesFile = irMergesFile,
),
)
}

val sourceGenFolder = configuration.getNotNull(srcGenDirKey)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
package com.squareup.anvil.compiler

import com.squareup.anvil.compiler.api.AnalysisBackend
import com.squareup.anvil.compiler.api.ComponentMergingBackend
import org.jetbrains.kotlin.config.CompilerConfiguration
import java.util.Locale

public class CommandLineOptions private constructor(
public val generateFactories: Boolean,
public val generateFactoriesOnly: Boolean,
public val disableComponentMerging: Boolean,
public val trackSourceFiles: Boolean,
public val willHaveDaggerFactories: Boolean,
public val backend: AnalysisBackend,
public val componentMergingBackend: ComponentMergingBackend,
) {
public companion object {
public val CompilerConfiguration.commandLineOptions: CommandLineOptions
Expand All @@ -22,24 +17,6 @@ public class CommandLineOptions private constructor(
disableComponentMerging = get(disableComponentMergingKey, false),
trackSourceFiles = get(trackSourceFilesKey, true),
willHaveDaggerFactories = get(willHaveDaggerFactoriesKey, false),
backend = parseBackend(),
componentMergingBackend = parseComponentMergingBackend(),
)

private fun CompilerConfiguration.parseBackend(): AnalysisBackend {
val config = get(analysisBackendKey, AnalysisBackend.EMBEDDED.name)
return config
.uppercase(Locale.US)
.let { value -> AnalysisBackend.entries.find { it.name == value } }
?: error("Unknown backend option: '$config'")
}

private fun CompilerConfiguration.parseComponentMergingBackend(): ComponentMergingBackend {
val config = get(mergingBackendKey, ComponentMergingBackend.IR.name)
return config
.uppercase(Locale.US)
.let { value -> ComponentMergingBackend.entries.find { it.name == value } }
?: error("Unknown backend option: '$config'")
}
}
}
Loading

0 comments on commit 268bed9

Please sign in to comment.