-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RUM-8582: Add kotlin compiler plugin environment
- Loading branch information
1 parent
d5346cd
commit 6bba719
Showing
5 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
...roid-gradle-plugin/src/main/kotlin/com/datadog/gradle/plugin/kcp/ComposeTagTransformer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.datadog.gradle.plugin.kcp | ||
|
||
import org.jetbrains.kotlin.backend.common.IrElementTransformerVoidWithContext | ||
import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext | ||
import org.jetbrains.kotlin.cli.common.messages.MessageCollector | ||
|
||
@Suppress("UnusedPrivateProperty") | ||
|
||
class ComposeTagTransformer( | ||
private val messageCollector: MessageCollector, | ||
private val pluginContext: IrPluginContext | ||
) : IrElementTransformerVoidWithContext() |
20 changes: 20 additions & 0 deletions
20
...android-gradle-plugin/src/main/kotlin/com/datadog/gradle/plugin/kcp/DatadogIrExtension.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.datadog.gradle.plugin.kcp | ||
|
||
import org.jetbrains.kotlin.backend.common.extensions.FirIncompatiblePluginAPI | ||
import org.jetbrains.kotlin.backend.common.extensions.IrGenerationExtension | ||
import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext | ||
import org.jetbrains.kotlin.cli.common.messages.MessageCollector | ||
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment | ||
|
||
/** | ||
* The extension registers all the visitors that need to explore the code being compiled | ||
*/ | ||
@FirIncompatiblePluginAPI | ||
class DatadogIrExtension(private val messageCollector: MessageCollector) : IrGenerationExtension { | ||
|
||
override fun generate(moduleFragment: IrModuleFragment, pluginContext: IrPluginContext) { | ||
val composeTagTransformer = ComposeTagTransformer(messageCollector, pluginContext) | ||
|
||
moduleFragment.accept(composeTagTransformer, null) | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...oid-gradle-plugin/src/main/kotlin/com/datadog/gradle/plugin/kcp/DatadogPluginRegistrar.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.datadog.gradle.plugin.kcp | ||
|
||
import com.google.auto.service.AutoService | ||
import org.jetbrains.kotlin.backend.common.extensions.FirIncompatiblePluginAPI | ||
import org.jetbrains.kotlin.backend.common.extensions.IrGenerationExtension | ||
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys | ||
import org.jetbrains.kotlin.cli.common.messages.MessageCollector | ||
import org.jetbrains.kotlin.compiler.plugin.CompilerPluginRegistrar | ||
import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi | ||
import org.jetbrains.kotlin.config.CommonConfigurationKeys | ||
import org.jetbrains.kotlin.config.CompilerConfiguration | ||
|
||
/** | ||
* The Registrar makes the plugin visible to the Kotlin Compiler, and provides the extensions to use. | ||
*/ | ||
@OptIn(ExperimentalCompilerApi::class) | ||
@AutoService(CompilerPluginRegistrar::class) | ||
class DatadogPluginRegistrar : CompilerPluginRegistrar() { | ||
|
||
// Supports Kotlin 2.x compiler | ||
override val supportsK2 = true | ||
|
||
@OptIn(FirIncompatiblePluginAPI::class) | ||
override fun ExtensionStorage.registerExtensions(configuration: CompilerConfiguration) { | ||
val messageCollector = configuration.get(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, MessageCollector.NONE) | ||
val useFir = configuration.getBoolean(CommonConfigurationKeys.USE_FIR) | ||
|
||
if (!useFir) { | ||
IrGenerationExtension.registerExtension(DatadogIrExtension(messageCollector)) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters