Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ZacSweers/kotlin-compile-testing
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 0.3.2
Choose a base ref
...
head repository: ZacSweers/kotlin-compile-testing
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 0.4.0
Choose a head ref
  • 16 commits
  • 14 files changed
  • 4 contributors

Commits on Aug 2, 2023

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    20fc546 View commit details

Commits on Sep 16, 2023

  1. Update dependency com.squareup.okio:okio to v3.5.0 (#173)

    Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
    renovate[bot] authored Sep 16, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    7b5f355 View commit details
  2. Update ksp to v1.9.10-1.0.13 (#174)

    Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
    renovate[bot] authored Sep 16, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    0038002 View commit details
  3. Update dependency io.github.classgraph:classgraph to v4.8.162 (#175)

    Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
    renovate[bot] authored Sep 16, 2023
    Copy the full SHA
    b17892e View commit details
  4. Update dependency gradle to v8.3 (#178)

    Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
    renovate[bot] authored Sep 16, 2023
    Copy the full SHA
    a8fcd8e View commit details
  5. Update dependency org.mockito:mockito-core to v5.5.0 (#180)

    Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
    renovate[bot] authored Sep 16, 2023
    Copy the full SHA
    088472b View commit details
  6. Update plugin dokka to v1.9.0 (#181)

    Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
    renovate[bot] authored Sep 16, 2023
    Copy the full SHA
    085abe3 View commit details
  7. Update actions/checkout action to v4 (#182)

    Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
    renovate[bot] authored Sep 16, 2023
    Copy the full SHA
    7975fd3 View commit details
  8. Update kotlin monorepo to v1.9.10 (#179)

    * Update kotlin monorepo to v1.9.30-station-874
    
    * Update gradle/libs.versions.toml
    
    ---------
    
    Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
    Co-authored-by: Zac Sweers <pandanomic@gmail.com>
    renovate[bot] and ZacSweers authored Sep 16, 2023
    Copy the full SHA
    ba6c603 View commit details

Commits on Oct 24, 2023

  1. Update dependency org.mockito:mockito-core to v5.6.0 (#187)

    Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
    renovate[bot] authored Oct 24, 2023
    Copy the full SHA
    39d7ca7 View commit details
  2. Update actions/checkout digest to b4ffde6 (#185)

    Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
    renovate[bot] authored Oct 24, 2023
    Copy the full SHA
    747c923 View commit details
  3. Update dependency gradle to v8.4 (#186)

    Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
    renovate[bot] authored Oct 24, 2023
    Copy the full SHA
    4439e50 View commit details
  4. Create parent directories of SourceFile (#189)

    Currently, createNewFile() fails if you have a SourceFile in a directory,
    since it can't create the owning directory.
    
    Co-authored-by: Pranjal Vachaspati <pranjal.vachaspati@toasttab.com>
    BraisGabin and pranjalvachaspati-toast authored Oct 24, 2023
    Copy the full SHA
    fdaa9da View commit details

Commits on Oct 31, 2023

  1. Prepare for Kotlin 1.9.20 (#184)

    * Update kotlin to 1.9.20-Beta
    
    * Update deps
    
    * Remove old JS test
    
    * Add support for disabling scripting compiler support
    
    This seems broken in K2
    
    * Update test
    
    * Update to final
    ZacSweers authored Oct 31, 2023
    Copy the full SHA
    aeec55b View commit details
  2. Okio 3.6.0

    ZacSweers committed Oct 31, 2023
    Copy the full SHA
    073722d View commit details
  3. Prepare for release 0.4.0.

    ZacSweers committed Oct 31, 2023
    Copy the full SHA
    91af63b View commit details
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ jobs:
matrix:
platform: [ 'windows-latest', 'ubuntu-latest' ]
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4

- uses: gradle/wrapper-validation-action@v1

13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
Changelog
=========

0.4.0
-----

_2023-10-31_

- **Enhancement**: Create parent directories of `SourceFile` in compilations.
- Update to Kotlin `1.9.20`.
- Update to KSP `1.9.20-1.0.13`.
- Update to ClassGraph `4.8.162`.
- Update to Okio `3.6.0`.

Special thanks to [@BraisGabin](https://github.com/BraisGabin) for contributing to this release!

0.3.2
-----

7 changes: 3 additions & 4 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -28,12 +28,11 @@ dependencies {
implementation(libs.okio)
implementation(libs.classgraph)

// This dependency is only needed as a "sample" compiler plugin to test that
// These dependencies are only needed as a "sample" compiler plugin to test that
// running compiler plugins passed via the pluginClasspath CLI option works
testRuntimeOnly(libs.kotlin.scriptingCompiler)

// Include Kotlin/JS standard library in test classpath for auto loading
testRuntimeOnly(libs.kotlin.stdlibJs)
testRuntimeOnly(libs.intellij.core)
testRuntimeOnly(libs.intellij.util)

// The Kotlin compiler should be near the end of the list because its .jar file includes
// an obsolete version of Guava
Original file line number Diff line number Diff line change
@@ -59,7 +59,7 @@ abstract class AbstractKotlinCompilation<A : CommonCompilerArguments> internal c
/**
* Legacy [ComponentRegistrar] plugins that should be added to the compilation.
*/
@Deprecated("Migrate to ComponentPluginRegistrar and use componentPluginRegistrars instead")
@Deprecated("Migrate to ComponentPluginRegistrar and use compilerPluginRegistrars instead")
var componentRegistrars: List<ComponentRegistrar> = emptyList()

/**
@@ -128,6 +128,9 @@ abstract class AbstractKotlinCompilation<A : CommonCompilerArguments> internal c
/** Enable support for the new K2 compiler. */
var supportsK2 = false

/** Disables compiler scripting support. */
var disableStandardScript = false

// Directory for input source files
protected val sourcesDir get() = workingDir.resolve("sources")

Original file line number Diff line number Diff line change
@@ -32,12 +32,14 @@ import org.jetbrains.kotlin.config.Services
import org.jetbrains.kotlin.kapt3.base.incremental.DeclaredProcType
import org.jetbrains.kotlin.kapt3.base.incremental.IncrementalProcessor
import org.jetbrains.kotlin.kapt3.util.MessageCollectorBackedKaptLogger
import java.io.*
import java.lang.RuntimeException
import java.io.File
import java.io.OutputStreamWriter
import java.net.URLClassLoader
import java.nio.file.Path
import javax.annotation.processing.Processor
import javax.tools.*
import javax.tools.Diagnostic
import javax.tools.DiagnosticCollector
import javax.tools.JavaFileObject

data class PluginOption(val pluginId: PluginId, val optionName: OptionName, val optionValue: OptionValue)

@@ -72,9 +74,6 @@ class KotlinCompilation : AbstractKotlinCompilation<K2JVMCompilerArguments>() {
/** Generate metadata for Java 1.8 reflection on method parameters */
var javaParameters: Boolean = false

/** Use the IR backend */
var useIR: Boolean = true

/** Use the old JVM backend */
var useOldBackend: Boolean = false

@@ -294,7 +293,6 @@ class KotlinCompilation : AbstractKotlinCompilation<K2JVMCompilerArguments>() {

args.jvmTarget = jvmTarget
args.javaParameters = javaParameters
args.useIR = useIR
args.useOldBackend = useOldBackend

if(javaModulePath != null)
@@ -337,6 +335,7 @@ class KotlinCompilation : AbstractKotlinCompilation<K2JVMCompilerArguments>() {

args.javaPackagePrefix = javaPackagePrefix
args.suppressMissingBuiltinsError = suppressMissingBuiltinsError
args.disableStandardScript = disableStandardScript
}

/** Performs the 1st and 2nd compilation step to generate stubs and run annotation processors */
Original file line number Diff line number Diff line change
@@ -36,6 +36,7 @@ abstract class SourceFile {
fun new(name: String, contents: String) = object : SourceFile() {
override fun writeIfNeeded(dir: File): File {
val file = dir.resolve(name)
file.parentFile.mkdirs()
file.createNewFile()

file.sink().buffer().use {
Original file line number Diff line number Diff line change
@@ -71,19 +71,5 @@ class CompilerPluginsTest {

assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.OK)
}

@Test
fun `when JS compiler plugins are added they get executed`() {
val mockPlugin = Mockito.mock(ComponentRegistrar::class.java)

val result = defaultJsCompilerConfig().apply {
sources = listOf(SourceFile.new("emptyKotlinFile.kt", ""))
componentRegistrars = listOf(mockPlugin)
inheritClassPath = true
}.compile()

verify(mockPlugin, atLeastOnce()).registerProjectComponents(any(), any())
assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.OK)
}
}

Original file line number Diff line number Diff line change
@@ -7,7 +7,6 @@ import org.assertj.core.api.Assertions.assertThat
import org.jetbrains.kotlin.compiler.plugin.AbstractCliOption
import org.jetbrains.kotlin.compiler.plugin.CliOption
import org.jetbrains.kotlin.compiler.plugin.CommandLineProcessor
import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi
import org.junit.Ignore
import org.junit.Rule
import org.junit.Test
@@ -92,6 +91,18 @@ class KotlinCompilationTests {
assertClassLoadable(result, "b.KSource")
}

@Test
fun `runs with sources in directory`() {
val result = defaultCompilerConfig().apply {
sources = listOf(SourceFile.kotlin("com/foo/bar/kSource.kt", """
package com.foo.bar
class KSource"""))
}.compile()

assertThat(result.exitCode).isEqualTo(ExitCode.OK)
assertClassLoadable(result, "com.foo.bar.KSource")
}

@Test
fun `Kotlin can access JDK`() {
val source = SourceFile.kotlin("kSource.kt", """
@@ -912,6 +923,8 @@ class KotlinCompilationTests {
componentRegistrars = emptyList()
pluginClasspaths = emptyList()
languageVersion = "2.0"
inheritClassPath = true
disableStandardScript = true
}.compile()

assertThat(result.exitCode).isEqualTo(ExitCode.OK)
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ kotlin.incremental=false
kapt.include.compile.classpath=false

GROUP=dev.zacsweers.kctfork
VERSION_NAME=0.3.2
VERSION_NAME=0.4.0
POM_DESCRIPTION=A library that enables testing of Kotlin annotation processors, compiler plugins and code generation.
POM_INCEPTION_YEAR=2019
POM_URL=https\://github.com/zacsweers/kotlin-compile-testing
17 changes: 10 additions & 7 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
[versions]
kotlin = "1.9.0"
ksp = "1.9.0-1.0.12"
idea = "222.4459.24" # Flamingo | 2022.2.1 (see https://plugins.jetbrains.com/docs/intellij/android-studio-releases-list.html)
kotlin = "1.9.20"
ksp = "1.9.20-1.0.13"

[plugins]
buildconfig = { id = "com.github.gmazzo.buildconfig", version = "3.1.0" }
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
dokka = { id = "org.jetbrains.dokka", version = "1.8.20" }
dokka = { id = "org.jetbrains.dokka", version = "1.9.10" }
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
mavenPublish = { id = "com.vanniktech.maven.publish", version = "0.25.3" }

[libraries]
autoService = "com.google.auto.service:auto-service-annotations:1.1.1"
autoService-ksp = "dev.zacsweers.autoservice:auto-service-ksp:1.1.0"

classgraph = "io.github.classgraph:classgraph:4.8.161"
classgraph = "io.github.classgraph:classgraph:4.8.162"

intellij-core = { module = "com.jetbrains.intellij.platform:core", version.ref = "idea" }
intellij-util = { module = "com.jetbrains.intellij.platform:util", version.ref = "idea" }

javapoet = "com.squareup:javapoet:1.13.0"

kotlin-compilerEmbeddable = { module = "org.jetbrains.kotlin:kotlin-compiler-embeddable", version.ref = "kotlin" }
kotlin-annotationProcessingEmbeddable = { module = "org.jetbrains.kotlin:kotlin-annotation-processing-embeddable", version.ref = "kotlin" }
kotlin-scriptingCompiler = { module = "org.jetbrains.kotlin:kotlin-scripting-compiler", version.ref = "kotlin" }
kotlin-stdlibJs = { module = "org.jetbrains.kotlin:kotlin-stdlib-js", version.ref = "kotlin" }
kotlin-reflect = { module = "org.jetbrains.kotlin:kotlin-reflect", version.ref = "kotlin" }
kotlin-junit = { module = "org.jetbrains.kotlin:kotlin-test-junit", version.ref = "kotlin" }

@@ -29,10 +32,10 @@ kotlinpoet = "com.squareup:kotlinpoet:1.14.2"
ksp = { module = "com.google.devtools.ksp:symbol-processing", version.ref = "ksp" }
ksp-api = { module = "com.google.devtools.ksp:symbol-processing-api", version.ref = "ksp" }

okio = "com.squareup.okio:okio:3.4.0"
okio = "com.squareup.okio:okio:3.6.0"

truth = { module = "com.google.truth:truth", version = "1.1.5" }
junit = "junit:junit:4.13.2"
mockito = "org.mockito:mockito-core:5.4.0"
mockito = "org.mockito:mockito-core:5.6.0"
mockitoKotlin = "com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0"
assertJ = "org.assertj:assertj-core:3.24.2"
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
17 changes: 9 additions & 8 deletions gradlew
Original file line number Diff line number Diff line change
@@ -83,7 +83,8 @@ done
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
@@ -144,15 +145,15 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC2039,SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC2039,SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
@@ -201,11 +202,11 @@ fi
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
# double quotes to make sure that they get re-expanded; and
# * put everything else in single quotes, so that it's not re-expanded.
# Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.

set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
10 changes: 9 additions & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -37,7 +37,7 @@ dependencyResolutionManagement {

google()

// Kotlin bootstrap repository, useful for testing against Kotlin dev builds. Usually only tested on CI shadow jobs
// Kotlin dev repository, useful for testing against Kotlin dev builds. Usually only tested on CI shadow jobs
// https://kotlinlang.slack.com/archives/C0KLZSCHF/p1616514468003200?thread_ts=1616509748.001400&cid=C0KLZSCHF
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev/") {
name = "Kotlin-Dev"
@@ -46,6 +46,14 @@ dependencyResolutionManagement {
includeGroupByRegex("org\\.jetbrains.*")
}
}

maven("https://www.jetbrains.com/intellij-repository/releases") {
name = "Intellij"
}

maven("https://cache-redirector.jetbrains.com/intellij-dependencies") {
name = "Intellij"
}
}
}