Compare commits
101 Commits
Author | SHA1 | Date |
---|---|---|
renovate[bot] | 9c82a57cb1 | |
renovate[bot] | 62ffd333f4 | |
renovate[bot] | 7f359510c4 | |
renovate[bot] | 794b269673 | |
renovate[bot] | 3e18628994 | |
renovate[bot] | 7c7671be48 | |
renovate[bot] | 96a4ba1473 | |
renovate[bot] | 66d7a729a8 | |
renovate[bot] | ccd8ed65aa | |
renovate[bot] | 61b96c7457 | |
renovate[bot] | 47650c0f52 | |
renovate[bot] | 0d082f62a8 | |
renovate[bot] | 49081d99eb | |
renovate[bot] | 0800c8c991 | |
renovate[bot] | ad8056153e | |
renovate[bot] | c8e5499614 | |
renovate[bot] | bc832aef86 | |
renovate[bot] | 533738b0fc | |
renovate[bot] | 3bcf79bd7f | |
renovate[bot] | e6134ce457 | |
renovate[bot] | 781775052a | |
renovate[bot] | 91491709f5 | |
renovate[bot] | 2806836307 | |
renovate[bot] | 9038384337 | |
renovate[bot] | 9c0f35ab8c | |
renovate[bot] | 039a714f52 | |
renovate[bot] | eec5dbbba0 | |
renovate[bot] | adf6fdc1f6 | |
renovate[bot] | 2fc9e10428 | |
renovate[bot] | c7c6647599 | |
renovate[bot] | bf6a47c16a | |
renovate[bot] | bad82d6cc4 | |
renovate[bot] | 51e75f15cd | |
renovate[bot] | ababb56266 | |
renovate[bot] | e1b5f2cedb | |
renovate[bot] | 33dd3657ce | |
renovate[bot] | e8d8a55be9 | |
renovate[bot] | 37c182fc6c | |
renovate[bot] | 170f307b02 | |
renovate[bot] | 575f6ce328 | |
renovate[bot] | 907755866d | |
renovate[bot] | 7f25eaecdc | |
renovate[bot] | 34e45744e8 | |
renovate[bot] | fd2a594ba9 | |
renovate[bot] | 19c9345489 | |
renovate[bot] | 2ad953292d | |
renovate[bot] | 309078083d | |
renovate[bot] | 09324c4290 | |
renovate[bot] | a988b9154d | |
renovate[bot] | 8dcca4abef | |
renovate[bot] | f22cff890a | |
renovate[bot] | 43ac9253f8 | |
renovate[bot] | c4be78d082 | |
renovate[bot] | d759c6addb | |
renovate[bot] | 6d83fb151d | |
renovate[bot] | a1bb2a60bb | |
renovate[bot] | 88f7b103bc | |
renovate[bot] | 29bf7c83c9 | |
renovate[bot] | 8c323b5546 | |
renovate[bot] | 0b530fdb31 | |
renovate[bot] | 208435b4cc | |
renovate[bot] | 02cec35a69 | |
renovate[bot] | dd43e7a15e | |
renovate[bot] | c0ce021bd0 | |
renovate[bot] | 9f2461f4de | |
renovate[bot] | 33a54ed1e0 | |
renovate[bot] | f14d0164de | |
renovate[bot] | faec7eb697 | |
renovate[bot] | e9bbbd06e7 | |
renovate[bot] | 399f9bf019 | |
renovate[bot] | a149baf71a | |
renovate[bot] | 5912780717 | |
renovate[bot] | 8a007da8fe | |
renovate[bot] | 1b82638170 | |
renovate[bot] | 4a3d164d57 | |
renovate[bot] | e84bce1e4a | |
renovate[bot] | 8048f7f731 | |
renovate[bot] | 26efc9f4bc | |
renovate[bot] | 6ff81fe7c0 | |
renovate[bot] | 47058bb4a4 | |
renovate[bot] | 0f7b00dae5 | |
renovate[bot] | 3fb90ff996 | |
Harsh Shandilya | ebb597db59 | |
Harsh Shandilya | 7a28726a2a | |
Harsh Shandilya | a24d5102bf | |
Harsh Shandilya | 9013544898 | |
Harsh Shandilya | e19979d781 | |
Harsh Shandilya | 174f672291 | |
Harsh Shandilya | eb583b983c | |
Harsh Shandilya | 2913b1e92d | |
renovate[bot] | 72ede4b5f6 | |
renovate[bot] | 8f42f73da7 | |
Harsh Shandilya | e8648924b2 | |
Harsh Shandilya | 6b00666b7f | |
Harsh Shandilya | 621cb5d62a | |
Harsh Shandilya | b65e3432f4 | |
renovate[bot] | 0e9d320ef0 | |
Harsh Shandilya | 4465f3df1d | |
Harsh Shandilya | bea7990783 | |
Harsh Shandilya | 334dfe095b | |
Harsh Shandilya | c47e92ad9b |
|
@ -20,22 +20,22 @@ jobs:
|
|||
actions: read
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
|
||||
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
|
||||
|
||||
- name: Set up JDK
|
||||
uses: actions/setup-java@cd89f46ac9d01407894225f350157564c9c7cee2 # v3.12.0
|
||||
uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1
|
||||
with:
|
||||
distribution: temurin
|
||||
java-version: 18
|
||||
|
||||
- name: Cache Kotlin/Native compiler
|
||||
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
|
||||
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
|
||||
with:
|
||||
path: ~/.konan
|
||||
key: ${{ runner.os }}-gradle-${{ hashFiles('gradle/wrapper/gradle-wrapper.properties', 'gradle/libs.versions.toml') }}
|
||||
|
||||
- name: Setup Gradle caching
|
||||
uses: gradle/gradle-build-action@ef76a971e2fa3f867b617efd72f2fbd72cf6f8bc # v2.8.0
|
||||
uses: gradle/gradle-build-action@4c39dd82cd5e1ec7c6fa0173bb41b4b6bb3b86ff # v3.3.2
|
||||
with:
|
||||
gradle-home-cache-cleanup: true
|
||||
cache-read-only: ${{ github.ref != 'refs/heads/main' }}
|
||||
|
@ -50,28 +50,28 @@ jobs:
|
|||
if: "github.event_name == 'push' && github.event.ref == 'refs/heads/main'"
|
||||
needs:
|
||||
- "check"
|
||||
runs-on: macos-13
|
||||
runs-on: macos-14
|
||||
permissions:
|
||||
actions: read
|
||||
contents: write
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
|
||||
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
|
||||
|
||||
- name: Set up JDK
|
||||
uses: actions/setup-java@cd89f46ac9d01407894225f350157564c9c7cee2 # v3.12.0
|
||||
uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1
|
||||
with:
|
||||
distribution: temurin
|
||||
java-version: 18
|
||||
|
||||
- name: Cache Kotlin/Native compiler
|
||||
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
|
||||
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
|
||||
with:
|
||||
path: ~/.konan
|
||||
key: ${{ runner.os }}-gradle-${{ hashFiles('gradle/wrapper/gradle-wrapper.properties', 'gradle/libs.versions.toml') }}
|
||||
|
||||
- name: Setup Gradle caching
|
||||
uses: gradle/gradle-build-action@ef76a971e2fa3f867b617efd72f2fbd72cf6f8bc # v2.8.0
|
||||
uses: gradle/gradle-build-action@4c39dd82cd5e1ec7c6fa0173bb41b4b6bb3b86ff # v3.3.2
|
||||
with:
|
||||
gradle-home-cache-cleanup: true
|
||||
cache-read-only: ${{ github.ref != 'refs/heads/main' }}
|
||||
|
|
|
@ -20,26 +20,26 @@ jobs:
|
|||
description: ${{ github.repository }}/${{ github.workflow }}#${{ github.run_number }}
|
||||
|
||||
publish:
|
||||
runs-on: macos-13
|
||||
runs-on: macos-14
|
||||
needs: create_staging_repository
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
|
||||
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
|
||||
|
||||
- name: Set up JDK
|
||||
uses: actions/setup-java@cd89f46ac9d01407894225f350157564c9c7cee2 # v3.12.0
|
||||
uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1
|
||||
with:
|
||||
distribution: temurin
|
||||
java-version: 18
|
||||
|
||||
- name: Cache Kotlin/Native compiler
|
||||
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
|
||||
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
|
||||
with:
|
||||
path: ~/.konan
|
||||
key: ${{ runner.os }}-gradle-${{ hashFiles('gradle/wrapper/gradle-wrapper.properties', 'gradle/libs.versions.toml') }}
|
||||
|
||||
- name: Publish
|
||||
uses: gradle/gradle-build-action@ef76a971e2fa3f867b617efd72f2fbd72cf6f8bc # v2.8.0
|
||||
uses: gradle/gradle-build-action@4c39dd82cd5e1ec7c6fa0173bb41b4b6bb3b86ff # v3.3.2
|
||||
with:
|
||||
arguments: publish :gradle-plugin:publish
|
||||
env:
|
||||
|
|
47
README.md
47
README.md
|
@ -1,6 +1,39 @@
|
|||
# TraceLog
|
||||
# TraceLog ![Maven Central](https://img.shields.io/maven-central/v/dev.msfjarvis.tracelog/dev.msfjarvis.tracelog.gradle.plugin?style=flat-square&label=Latest%20version)
|
||||
|
||||
PoC Kotlin compiler plugin to emit [OpenTelemetry](https://opentelemetry.io/)-compatible logging metadata from Kotlin projects.
|
||||
Kotlin compiler plugin to automate `println` debugging, because debuggers are for people smarter than me.
|
||||
|
||||
## Installation
|
||||
|
||||
Apply the Gradle plugin to your Kotlin project
|
||||
|
||||
```kotlin
|
||||
plugins {
|
||||
id("dev.msfjarvis.tracelog") version "0.1.3"
|
||||
}
|
||||
```
|
||||
|
||||
Optionally configure the annotation class and logger method (defaults shown below)
|
||||
|
||||
```kotlin
|
||||
traceLog {
|
||||
loggerFunction.set("kotlin.io.println")
|
||||
annotationClass.set("dev/msfjarvis/tracelog/runtime/annotations/DebugLog")
|
||||
}
|
||||
```
|
||||
|
||||
The `loggerFunction` parameter must be a fully qualified to a static method with a single parameter of the type `Any?`.
|
||||
|
||||
```kotlin
|
||||
fun recordMessage() {} // Bad, no parameter
|
||||
fun recordMessage(p0: String, p1: Int) {} // Bad, multiple parameters and incorrect types
|
||||
fun recordMessage(p0: Any?) {} // Good, single parameter with correct type
|
||||
```
|
||||
|
||||
> [!NOTE]
|
||||
> Due to a limitation in how TraceLog resolves the logger function, you might need to add `@JvmStatic` on the method
|
||||
> for TraceLog to be able to find it. This will be fixed in a future release.
|
||||
|
||||
## Usage
|
||||
|
||||
Currently, this prints out a basic textual representation of the method's inputs and execution time. That is,
|
||||
given this code:
|
||||
|
@ -10,6 +43,10 @@ given this code:
|
|||
fun debuggableFunction(p0: String): String {
|
||||
return "Debugging is cool!"
|
||||
}
|
||||
|
||||
fun main() {
|
||||
debuggableFunction("First parameter")
|
||||
}
|
||||
```
|
||||
|
||||
The compiler plugin will generate code that writes the following messages
|
||||
|
@ -18,3 +55,9 @@ The compiler plugin will generate code that writes the following messages
|
|||
⇢ debuggableFunction(p0=First parameter)
|
||||
⇠ debuggableFunction [214.209us] = Debugging is cool!
|
||||
```
|
||||
|
||||
## Compatibility
|
||||
|
||||
| Kotlin Version | TraceLog Version |
|
||||
|----------------|------------------|
|
||||
| 1.9.0 | 0.1.x |
|
||||
|
|
|
@ -28,7 +28,7 @@ public class TracingCommandLineProcessor : CommandLineProcessor {
|
|||
optionName = "debugAnnotation",
|
||||
valueDescription = ArtifactInfo.DEFAULT_TRACELOG_ANNOTATION,
|
||||
description = ANNOTATION_NAME.toString(),
|
||||
required = true,
|
||||
required = false,
|
||||
allowMultipleOccurrences = false,
|
||||
)
|
||||
val OPTION_LOGGER_FUNCTION =
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package dev.msfjarvis.tracelog.compiler.plugin
|
||||
|
||||
import com.google.auto.service.AutoService
|
||||
import dev.msfjarvis.tracelog.ArtifactInfo
|
||||
import org.jetbrains.kotlin.backend.common.extensions.IrGenerationExtension
|
||||
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
|
||||
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
|
||||
|
@ -18,7 +19,7 @@ public class TracingCompilerPluginRegistrar : CompilerPluginRegistrar() {
|
|||
val messageCollector =
|
||||
configuration.get(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, MessageCollector.NONE)
|
||||
val loggerFunction = configuration[LOGGER_FUNCTION] ?: "kotlin.io.println"
|
||||
val annotationName = requireNotNull(configuration[ANNOTATION_NAME])
|
||||
val annotationName = configuration[ANNOTATION_NAME] ?: ArtifactInfo.DEFAULT_TRACELOG_ANNOTATION
|
||||
|
||||
IrGenerationExtension.registerExtension(
|
||||
TracingIrGenerationExtension(messageCollector, loggerFunction, annotationName)
|
||||
|
|
|
@ -8,7 +8,6 @@ import com.tschuchort.compiletesting.SourceFile.Companion.kotlin
|
|||
import org.jetbrains.kotlin.compiler.plugin.CliOption
|
||||
import org.jetbrains.kotlin.compiler.plugin.CommandLineProcessor
|
||||
import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
@OptIn(ExperimentalCompilerApi::class)
|
||||
|
@ -88,7 +87,7 @@ class DebugLogTransformerTest {
|
|||
messageOutputStream = System.out
|
||||
}
|
||||
.compile()
|
||||
assertEquals(ExitCode.OK, result.exitCode)
|
||||
assertThat(result.exitCode).isEqualTo(ExitCode.OK)
|
||||
|
||||
val kClazz = result.classLoader.loadClass("SourceFileKt")
|
||||
val transformableWithReturnValue =
|
||||
|
@ -107,6 +106,116 @@ class DebugLogTransformerTest {
|
|||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `nested logger function`() {
|
||||
val annotationSrcFile =
|
||||
kotlin(
|
||||
"DebugLog.kt",
|
||||
"""
|
||||
package dev.msfjarvis.annotation
|
||||
annotation class DebugLog
|
||||
"""
|
||||
.trimIndent()
|
||||
)
|
||||
val srcFile =
|
||||
kotlin(
|
||||
"SourceFile.kt",
|
||||
"""
|
||||
import dev.msfjarvis.annotation.DebugLog
|
||||
|
||||
@DebugLog
|
||||
fun transformable() {
|
||||
println("In a transformable function!")
|
||||
}
|
||||
|
||||
@DebugLog
|
||||
fun transformableWithReturnValue(): String {
|
||||
println("In a transformable function!")
|
||||
return "Return value!"
|
||||
}
|
||||
|
||||
fun nonTransformable() {
|
||||
println("Not in a transformable function!")
|
||||
}
|
||||
|
||||
class TracingTest {
|
||||
@DebugLog
|
||||
fun transformableInClass() {
|
||||
println("In a transformable function!")
|
||||
}
|
||||
|
||||
fun nonTransformable() {
|
||||
println("Not in a transformable function!")
|
||||
}
|
||||
}
|
||||
"""
|
||||
.trimIndent()
|
||||
)
|
||||
val loggerFile =
|
||||
kotlin(
|
||||
"Logger.kt",
|
||||
"""
|
||||
package com.example
|
||||
object Logger {
|
||||
val messages = mutableListOf<String>()
|
||||
|
||||
@JvmStatic
|
||||
fun recordMessage(message: Any?) {
|
||||
messages += message.toString()
|
||||
}
|
||||
}
|
||||
"""
|
||||
.trimIndent()
|
||||
)
|
||||
|
||||
val result =
|
||||
KotlinCompilation()
|
||||
.apply {
|
||||
val processor = TracingCommandLineProcessor()
|
||||
pluginOptions = buildList {
|
||||
add(
|
||||
processor.option(
|
||||
TracingCommandLineProcessor.OPTION_LOGGER_FUNCTION,
|
||||
"com.example.Logger.recordMessage"
|
||||
)
|
||||
)
|
||||
add(
|
||||
processor.option(
|
||||
TracingCommandLineProcessor.OPTION_ANNOTATION_NAME,
|
||||
"dev/msfjarvis/annotation/DebugLog"
|
||||
)
|
||||
)
|
||||
}
|
||||
sources = listOf(annotationSrcFile, srcFile, loggerFile)
|
||||
compilerPluginRegistrars = listOf(TracingCompilerPluginRegistrar())
|
||||
commandLineProcessors = listOf(processor)
|
||||
noOptimize = true
|
||||
|
||||
inheritClassPath = true
|
||||
messageOutputStream = System.out
|
||||
}
|
||||
.compile()
|
||||
assertThat(result.exitCode).isEqualTo(ExitCode.OK)
|
||||
|
||||
val kClazz = result.classLoader.loadClass("SourceFileKt")
|
||||
val transformableWithReturnValue =
|
||||
kClazz.declaredMethods.first { it.name == "transformableWithReturnValue" }
|
||||
val retVal = transformableWithReturnValue.invoke(null)
|
||||
assertThat(retVal).isInstanceOf(String::class.java)
|
||||
assertThat(retVal).isEqualTo("Return value!")
|
||||
|
||||
val loggerClazz = result.classLoader.loadClass("com.example.Logger")
|
||||
val msgField = loggerClazz.declaredFields.first { it.name == "messages" }
|
||||
msgField.isAccessible = true
|
||||
val messages = msgField.get(null) as? List<*>
|
||||
assertThat(messages).isNotNull()
|
||||
assertThat(messages).contains("⇢ transformableWithReturnValue()")
|
||||
assertThat((messages?.last() as? String)?.replace("\\[.*]".toRegex(), "[]"))
|
||||
.isEqualTo(
|
||||
"⇠ transformableWithReturnValue [] = Return value!",
|
||||
)
|
||||
}
|
||||
|
||||
private fun CommandLineProcessor.option(key: CliOption, value: Any?): PluginOption {
|
||||
return PluginOption(pluginId, key.optionName, value.toString())
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
@file:Suppress("UnstableApiUsage")
|
||||
|
||||
pluginManagement {
|
||||
plugins { id("org.gradle.toolchains.foojay-resolver-convention") version "0.7.0" }
|
||||
plugins { id("org.gradle.toolchains.foojay-resolver-convention") version "0.8.0" }
|
||||
repositories {
|
||||
includeBuild("../build-logic")
|
||||
mavenCentral()
|
||||
|
|
|
@ -32,7 +32,7 @@ public class TraceLogGradlePlugin : KotlinCompilerPluginSupportPlugin {
|
|||
if (useLocal) {
|
||||
it.project(":runtime")
|
||||
} else {
|
||||
"dev.msfjarvis.tracelog:runtime:1.0.0-SNAPSHOT"
|
||||
"${ArtifactInfo.GROUP}:${ArtifactInfo.RUNTIME_ARTIFACT}:${ArtifactInfo.VERSION}"
|
||||
}
|
||||
else -> null
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ org.gradle.jvmargs=-Xmx2048m
|
|||
kotlin.code.style=official
|
||||
# Library Information
|
||||
GROUP=dev.msfjarvis.tracelog
|
||||
VERSION_NAME=0.1.2
|
||||
VERSION_NAME=0.2.0-SNAPSHOT
|
||||
# Maven central
|
||||
POM_INCEPTION_YEAR=2023
|
||||
RELEASE_SIGNING_ENABLED=true
|
||||
|
|
|
@ -1,30 +1,31 @@
|
|||
[versions]
|
||||
kotlin = "1.9.0"
|
||||
junit = "5.10.0"
|
||||
junit = "5.10.2"
|
||||
|
||||
[plugins]
|
||||
android-library = { id = "com.android.library", version = "8.1.1" }
|
||||
buildconfig = "com.github.gmazzo.buildconfig:4.1.2"
|
||||
dokka = { id = "org.jetbrains.dokka", version = "1.8.20" }
|
||||
android-library = { id = "com.android.library", version = "8.4.1" }
|
||||
buildconfig = "com.github.gmazzo.buildconfig:5.3.5"
|
||||
dokka = { id = "org.jetbrains.dokka", version = "1.9.20" }
|
||||
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
|
||||
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
|
||||
kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
|
||||
kotlinx-binaryCompatibilityValidator = { id = "org.jetbrains.kotlinx.binary-compatibility-validator", version = "0.13.2" }
|
||||
kotlinx-binaryCompatibilityValidator = { id = "org.jetbrains.kotlinx.binary-compatibility-validator", version = "0.14.0" }
|
||||
ksp = "com.google.devtools.ksp:1.9.0-1.0.13"
|
||||
mavenPublish = { id = "com.vanniktech.maven.publish", version = "0.25.3" }
|
||||
spotless = "com.diffplug.spotless:6.21.0"
|
||||
mavenPublish = { id = "com.vanniktech.maven.publish", version = "0.27.0" }
|
||||
shadow = "com.github.johnrengelman.shadow:8.1.1"
|
||||
spotless = "com.diffplug.spotless:6.25.0"
|
||||
|
||||
[libraries]
|
||||
android-gradle-plugin = "com.android.tools.build:gradle:8.1.1"
|
||||
android-gradle-plugin = "com.android.tools.build:gradle:8.4.1"
|
||||
auto-annotations = "com.google.auto.service:auto-service-annotations:1.1.1"
|
||||
auto-ksp = "dev.zacsweers.autoservice:auto-service-ksp:1.1.0"
|
||||
junit-jupiter-api = { module = "org.junit.jupiter:junit-jupiter-api", version.ref = "junit" }
|
||||
junit-jupiter-engine = { module = "org.junit.jupiter:junit-jupiter-engine", version.ref = "junit" }
|
||||
junit-legacy = "junit:junit:4.13.2"
|
||||
kct = "dev.zacsweers.kctfork:core:0.3.2"
|
||||
kct = "dev.zacsweers.kctfork:core:0.4.1"
|
||||
kotlin-compiler = { module = "org.jetbrains.kotlin:kotlin-compiler-embeddable", version.ref = "kotlin" }
|
||||
kotlin-gradlePlugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
|
||||
kotlin-gradlePlugin-api = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin-api", version.ref = "kotlin" }
|
||||
kotlin-stdlib = { module = "org.jetbrains.kotlin:kotlin-stdlib", version.ref = "kotlin" }
|
||||
mordant = "com.github.ajalt.mordant:mordant:2.1.0"
|
||||
truth = "com.google.truth:truth:1.1.5"
|
||||
mordant = "com.github.ajalt.mordant:mordant:2.6.0"
|
||||
truth = "com.google.truth:truth:1.4.2"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionSha256Sum=591855b517fc635b9e04de1d05d5e76ada3f89f5fc76f87978d1b245b4f69225
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip
|
||||
distributionSha256Sum=a4b4158601f8636cdeeab09bd76afb640030bb5b144aafe261a5e8af027dc612
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
|
||||
networkTimeout=10000
|
||||
validateDistributionUrl=true
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
|
|
|
@ -1,16 +1,26 @@
|
|||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
|
||||
plugins {
|
||||
alias(libs.plugins.kotlin.jvm)
|
||||
id("dev.msfjarvis.tracelog")
|
||||
alias(libs.plugins.shadow)
|
||||
application
|
||||
}
|
||||
|
||||
kotlin.jvmToolchain(11)
|
||||
|
||||
traceLog { loggerFunction.set("dev.msfjarvis.tracelog.sample.recordMessage") }
|
||||
tasks.withType<KotlinCompile>().configureEach {
|
||||
compilerOptions.freeCompilerArgs.addAll(
|
||||
"-P",
|
||||
"plugin:dev.msfjarvis.tracelog:loggerFunction=dev.msfjarvis.tracelog.sample.recordMessage",
|
||||
"-P",
|
||||
"plugin:dev.msfjarvis.tracelog:debugAnnotation=dev/msfjarvis/tracelog/runtime/annotations/DebugLog",
|
||||
)
|
||||
}
|
||||
|
||||
application { mainClass.set("dev.msfjarvis.tracelog.sample.MainKt") }
|
||||
|
||||
dependencies {
|
||||
kotlinCompilerPluginClasspath(projects.compilerPlugin)
|
||||
implementation(projects.runtime)
|
||||
implementation(libs.mordant)
|
||||
}
|
||||
|
|
|
@ -66,6 +66,7 @@ public fun recordMessage(message: Any?) {
|
|||
|
||||
/** An example of an annotated method which will be transformed by the compiler plugin. */
|
||||
@DebugLog
|
||||
@Suppress("UNUSED_PARAMETER")
|
||||
public fun debuggableFunction(p0: String, p1: String = "Bar"): String {
|
||||
return "Debugging is cool!"
|
||||
}
|
||||
|
|
|
@ -1,11 +1,17 @@
|
|||
import org.jetbrains.kotlin.gradle.dsl.KotlinCommonOptions
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinCompile
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTargetWithHostTests
|
||||
|
||||
plugins {
|
||||
alias(libs.plugins.kotlin.multiplatform)
|
||||
id("dev.msfjarvis.tracelog")
|
||||
}
|
||||
plugins { alias(libs.plugins.kotlin.multiplatform) }
|
||||
|
||||
traceLog { loggerFunction.set("recordMessage") }
|
||||
tasks.withType<KotlinCompile<KotlinCommonOptions>>().configureEach {
|
||||
kotlinOptions.options.freeCompilerArgs.addAll(
|
||||
"-P",
|
||||
"plugin:dev.msfjarvis.tracelog:loggerFunction=recordMessage",
|
||||
"-P",
|
||||
"plugin:dev.msfjarvis.tracelog:debugAnnotation=dev/msfjarvis/tracelog/runtime/annotations/DebugLog",
|
||||
)
|
||||
}
|
||||
|
||||
fun KotlinNativeTargetWithHostTests.configureTarget() = binaries {
|
||||
executable { entryPoint = "main" }
|
||||
|
@ -17,6 +23,8 @@ kotlin {
|
|||
macosX64 { configureTarget() }
|
||||
|
||||
dependencies {
|
||||
kotlinCompilerPluginClasspath(projects.compilerPlugin)
|
||||
kotlinNativeCompilerPluginClasspath(projects.compilerPlugin)
|
||||
commonMainImplementation(projects.runtime)
|
||||
commonMainImplementation(libs.mordant)
|
||||
}
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
import com.github.ajalt.mordant.rendering.TextColors.*
|
||||
import com.github.ajalt.mordant.terminal.Terminal
|
||||
|
||||
object LogPrinter {
|
||||
private val messages = arrayListOf<String>()
|
||||
|
||||
private const val MATCH_ARROW = "arrow"
|
||||
private const val MATCH_IDENTIFIER = "identifier"
|
||||
private const val MATCH_PARAMS = "params"
|
||||
private const val MATCH_TIME = "time"
|
||||
private const val MATCH_RETURN = "retval"
|
||||
|
||||
private val ENTER_REGEX =
|
||||
"(?<$MATCH_ARROW>⇢) (?<$MATCH_IDENTIFIER>[a-zA-Z].*)\\((?<$MATCH_PARAMS>.*)\\)".toRegex()
|
||||
private val EXIT_REGEX =
|
||||
"(?<$MATCH_ARROW>⇠) (?<$MATCH_IDENTIFIER>[a-zA-Z].*) \\[(?<$MATCH_TIME>.*)] = (?<$MATCH_RETURN>.*)"
|
||||
.toRegex()
|
||||
|
||||
private fun MatchResult.getMatch(groupName: String): String {
|
||||
return groups[groupName]!!.value
|
||||
}
|
||||
|
||||
fun submitLog(message: String) {
|
||||
messages += message
|
||||
}
|
||||
|
||||
fun printLogs() {
|
||||
val t = Terminal()
|
||||
messages.forEach { msg ->
|
||||
var matches = ENTER_REGEX.find(msg)
|
||||
if (matches != null) {
|
||||
val params =
|
||||
matches.getMatch(MATCH_PARAMS).split(", ").joinToString(", ") {
|
||||
val split = it.split("=")
|
||||
if (split.size == 1) {
|
||||
""
|
||||
} else {
|
||||
val (name, value) = (split[0] to split[1])
|
||||
"${brightYellow(name)}=${brightBlue(value)}"
|
||||
}
|
||||
}
|
||||
t.println(
|
||||
"""
|
||||
${red(matches.getMatch(MATCH_ARROW))} ${green(matches.getMatch(MATCH_IDENTIFIER))}($params)
|
||||
"""
|
||||
.trimIndent()
|
||||
)
|
||||
} else {
|
||||
matches = EXIT_REGEX.matchEntire(msg)
|
||||
if (matches != null) {
|
||||
t.println(
|
||||
"""
|
||||
${red(matches.getMatch(MATCH_ARROW))} ${green(matches.getMatch(MATCH_IDENTIFIER))} [${blue(matches.getMatch(
|
||||
MATCH_TIME))}] = ${brightWhite(matches.getMatch(MATCH_RETURN))}
|
||||
"""
|
||||
.trimIndent()
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,69 +1,27 @@
|
|||
import com.github.ajalt.mordant.rendering.TextColors.*
|
||||
import com.github.ajalt.mordant.terminal.Terminal
|
||||
import dev.msfjarvis.tracelog.runtime.annotations.DebugLog
|
||||
|
||||
private val messages = arrayListOf<String>()
|
||||
|
||||
private const val MATCH_ARROW = "arrow"
|
||||
private const val MATCH_IDENTIFIER = "identifier"
|
||||
private const val MATCH_PARAMS = "params"
|
||||
private const val MATCH_TIME = "time"
|
||||
private const val MATCH_RETURN = "retval"
|
||||
|
||||
private val ENTER_REGEX =
|
||||
"(?<$MATCH_ARROW>⇢) (?<$MATCH_IDENTIFIER>[a-zA-Z].*)\\((?<$MATCH_PARAMS>.*)\\)".toRegex()
|
||||
private val EXIT_REGEX =
|
||||
"(?<$MATCH_ARROW>⇠) (?<$MATCH_IDENTIFIER>[a-zA-Z].*) \\[(?<$MATCH_TIME>.*)] = (?<$MATCH_RETURN>.*)"
|
||||
.toRegex()
|
||||
|
||||
private fun MatchResult.getMatch(groupName: String): String {
|
||||
return groups[groupName]!!.value
|
||||
}
|
||||
|
||||
fun main() {
|
||||
debuggableFunction("First parameter")
|
||||
val t = Terminal()
|
||||
messages.forEach { msg ->
|
||||
var matches = ENTER_REGEX.find(msg)
|
||||
if (matches != null) {
|
||||
val params =
|
||||
matches
|
||||
.getMatch(MATCH_PARAMS)
|
||||
.split(", ")
|
||||
.map {
|
||||
val split = it.split("=")
|
||||
(split[0] to split[1])
|
||||
}
|
||||
.joinToString(", ") { (name, value) -> "${brightYellow(name)}=${brightBlue(value)}" }
|
||||
t.println(
|
||||
"""
|
||||
${red(matches.getMatch(MATCH_ARROW))} ${green(matches.getMatch(MATCH_IDENTIFIER))}($params)
|
||||
"""
|
||||
.trimIndent()
|
||||
)
|
||||
} else {
|
||||
matches = EXIT_REGEX.matchEntire(msg)
|
||||
if (matches != null) {
|
||||
t.println(
|
||||
"""
|
||||
${red(matches.getMatch(MATCH_ARROW))} ${green(matches.getMatch(MATCH_IDENTIFIER))} [${blue(matches.getMatch(
|
||||
MATCH_TIME))}] = ${brightWhite(matches.getMatch(MATCH_RETURN))}
|
||||
"""
|
||||
.trimIndent()
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
try {
|
||||
throwingFunction()
|
||||
} catch (_: Exception) {}
|
||||
LogPrinter.printLogs()
|
||||
}
|
||||
|
||||
/** Custom implementation of a logger function for use by the compiler plugin. */
|
||||
@Suppress("Unused") // Used by the generated bytecode
|
||||
fun recordMessage(message: Any?) {
|
||||
messages += message.toString()
|
||||
LogPrinter.submitLog(message.toString())
|
||||
}
|
||||
|
||||
/** An example of an annotated method which will be transformed by the compiler plugin. */
|
||||
@DebugLog
|
||||
@Suppress("UNUSED_PARAMETER")
|
||||
fun debuggableFunction(p0: String, p1: String = "Bar"): String {
|
||||
return "Debugging is cool!"
|
||||
}
|
||||
|
||||
@DebugLog
|
||||
fun throwingFunction() {
|
||||
throw Exception("This code is throwing!")
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
@file:Suppress("UnstableApiUsage")
|
||||
|
||||
pluginManagement {
|
||||
plugins { id("org.gradle.toolchains.foojay-resolver-convention") version "0.7.0" }
|
||||
plugins { id("org.gradle.toolchains.foojay-resolver-convention") version "0.8.0" }
|
||||
repositories {
|
||||
includeBuild("build-logic")
|
||||
includeBuild("gradle-plugin")
|
||||
|
@ -41,6 +41,11 @@ pluginManagement {
|
|||
"com.github.gmazzo.buildconfig",
|
||||
"com.github.gmazzo.buildconfig.gradle.plugin"
|
||||
)
|
||||
includeModule("com.github.johnrengelman", "shadow")
|
||||
includeModule(
|
||||
"com.github.johnrengelman.shadow",
|
||||
"com.github.johnrengelman.shadow.gradle.plugin"
|
||||
)
|
||||
includeModule("com.github.gmazzo.buildconfig", "plugin")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue