Skip to content

Commit

Permalink
Merge branch 'release-2.4.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
lupuuss committed Oct 6, 2024
2 parents 623e8ae + 8aed1c0 commit f8537ea
Show file tree
Hide file tree
Showing 44 changed files with 301 additions and 149 deletions.
14 changes: 14 additions & 0 deletions build-mokkery/src/main/kotlin/MokkeryAttributes.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
object MokkeryAttributes {

const val GitBase = "github.com/lupuuss/Mokkery"
const val GitHttpsUrl = "https://$GitBase"
const val GitVscUrl = "${GitHttpsUrl}.git"
const val GitConnectionUrl = "scm:git:git://$GitBase.git"
const val GitDevConnectionUrl = "scm:git:ssh://git@$GitBase.git"
const val GitIssuesUrl = "$GitHttpsUrl/issues"

const val WebsiteUrl = "https://mokkery.dev"

const val DisplayName = "Mokkery"
const val Description = "Mokkery is a mocking library for Kotlin Multiplatform, easy to use, boilerplate-free and compiler plugin driven."
}
9 changes: 0 additions & 9 deletions build-mokkery/src/main/kotlin/MokkeryUrls.kt

This file was deleted.

7 changes: 6 additions & 1 deletion build-mokkery/src/main/kotlin/Utils.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

import org.gradle.api.Project
import org.gradle.kotlin.dsl.extra
import org.jetbrains.dokka.gradle.DokkaTaskPartial
import java.util.*

fun Project.loadLocalProperties() {
Expand All @@ -16,4 +17,8 @@ fun Project.loadLocalProperties() {
}
}

fun Project.extraString(name: String) = if (extra.has(name)) extra.get(name) as String else null
fun Project.excludeFromApiDocs() {
tasks.withType(DokkaTaskPartial::class.java) {
enabled = false
}
}
64 changes: 0 additions & 64 deletions build-mokkery/src/main/kotlin/mokkery-coroutines.gradle.kts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ kotlin {
tvosSimulatorArm64()

watchosX64()
watchosArm32()
watchosArm64()
watchosSimulatorArm64()
watchosDeviceArm64()
Expand Down
28 changes: 16 additions & 12 deletions build-mokkery/src/main/kotlin/mokkery-publish.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
import MokkeryUrls.GitConnection
import MokkeryUrls.GitDevConnection
import MokkeryUrls.GitHttp
import MokkeryUrls.Website
import MokkeryAttributes.GitConnectionUrl
import MokkeryAttributes.GitDevConnectionUrl
import MokkeryAttributes.GitHttpsUrl
import MokkeryAttributes.GitIssuesUrl
import MokkeryAttributes.WebsiteUrl
import com.vanniktech.maven.publish.SonatypeHost

plugins {
id("com.vanniktech.maven.publish")
id("org.jetbrains.dokka")
}

loadLocalProperties()

mavenPublishing {
coordinates(project.group.toString(), project.name, project.version.toString())
signAllPublications()
publishToMavenCentral(SonatypeHost.S01, automaticRelease = false)
pom {
name.set(project.name)
description.set(
"Mokkery is a mocking library for Kotlin Multiplatform, easy to use, boilerplate-free and compiler plugin driven."
)
url.set(Website)
description.set(MokkeryAttributes.Description)
url.set(WebsiteUrl)
licenses {
license {
name.set("The Apache Software License, Version 2.0")
Expand All @@ -33,9 +34,12 @@ mavenPublishing {
}
}
scm {
url.set(GitHttp)
connection.set(GitConnection)
developerConnection.set(GitDevConnection)
url.set(GitHttpsUrl)
connection.set(GitConnectionUrl)
developerConnection.set(GitDevConnectionUrl)
}
issueManagement {
url.set(GitIssuesUrl)
}
}
}
}
8 changes: 4 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@ buildscript {

dependencies {
classpath(":build-mokkery")
classpath(libs.gradle.plugin.kotlinx.atomicfu)
classpath(libs.dokka.base)
}
}


rootProject.version = libs.versions.mokkery.get()
rootProject.group = "dev.mokkery"

rootProject.ext["pluginId"] = "dev.mokkery"

allprojects {
group = rootProject.group
version = rootProject.version
tasks.withType<DokkaTask> {
onlyIf { "SNAPSHOT" !in version.toString() }
}
afterEvaluate {
extensions.findByType<JavaPluginExtension>()?.apply {
toolchain.languageVersion.set(JavaLanguageVersion.of(8))
Expand All @@ -42,7 +42,7 @@ allprojects {

val dokkaHtmlMultiModule by tasks.getting(DokkaMultiModuleTask::class) {
moduleName.set("Mokkery")
moduleVersion.set(libs.versions.mokkery.get())
moduleVersion.set(rootProject.version.toString())
pluginConfiguration<DokkaBase, DokkaBaseConfiguration> {
customAssets += rootProject.layout.projectDirectory.file("website/static/img/logo-icon.svg").asFile
}
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ kotlin.code.style=official
kotlin.suppressGradlePluginWarnings=IncorrectCompileOnlyDependencyWarning
kotlin.native.ignoreDisabledTargets=true
org.gradle.jvmargs=-Xmx3g
version=2.4.0-SNAPSHOT
10 changes: 5 additions & 5 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
[versions]
mokkery = "2.3.0"
kotlin = "2.0.20"
kotlinx-coroutines = "1.8.1"
kotlinx-coroutines = "1.9.0"
buildconfig = "4.0.4"
google-autoservice = "1.0.1"
atomicfu = "0.24.0"
atomicfu = "0.25.0"
dokka = "1.9.20"
poko = "0.17.0"
vanniktech-publish-plugin = "0.29.0"
objensis = "3.4"
bytebuddy = "1.14.19"
gradle-portal-publish = "1.2.1"

[plugins]
dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" }
poko = { id = "dev.drewhamilton.poko", version.ref = "poko" }
kotlinx-atomicfu = { id = "org.jetbrains.kotlinx.atomicfu", version.ref = "atomicfu" }
gradle-portal-publish = { id = "com.gradle.plugin-publish", version.ref = "gradle-portal-publish" }

[libraries]
kotlin-plugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
Expand All @@ -31,7 +33,5 @@ kotlin-compiler-embeddable = { module = "org.jetbrains.kotlin:kotlin-compiler-em
google-autoservice = { module = "com.google.auto.service:auto-service", version.ref = "google-autoservice"}
google-autoservice-annotations = { module = "com.google.auto.service:auto-service-annotations", version.ref = "google-autoservice"}

gradle-plugin-kotlinx-atomicfu = { module = "org.jetbrains.kotlinx:atomicfu-gradle-plugin", version.ref = "atomicfu" }

objenesis = { module = "org.objenesis:objenesis", version.ref = "objensis" }
bytebuddy = { module = "net.bytebuddy:byte-buddy", version.ref = "bytebuddy" }
2 changes: 1 addition & 1 deletion mokkery-coroutines/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id("mokkery-publish")
id("mokkery-coroutines") // TODO replace and remove when all targets being supported by Kotlinx Coroutines
id("mokkery-multiplatform")
alias(libs.plugins.poko)
}

Expand Down
10 changes: 5 additions & 5 deletions mokkery-gradle/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
plugins {
kotlin("jvm")
id("mokkery-publish")
id("com.gradle.plugin-publish") version "1.1.0"
alias(libs.plugins.gradle.portal.publish)
}

dependencies {
Expand Down Expand Up @@ -44,13 +44,13 @@ val functionalTest by testing.suites.creating(JvmTestSuite::class) {
tasks.check { dependsOn(functionalTest) }

gradlePlugin {
website.set(MokkeryUrls.Website)
vcsUrl.set("${MokkeryUrls.GitHttp}.git")
website.set(MokkeryAttributes.WebsiteUrl)
vcsUrl.set(MokkeryAttributes.GitVscUrl)
plugins {
create(rootProject.name) {
id = rootProject.extra["pluginId"] as String
displayName = "Mokkery"
description = "Mokkery is a mocking library for Kotlin Multiplatform, easy to use, boilerplate-free and compiler plugin driven."
displayName = MokkeryAttributes.DisplayName
description = MokkeryAttributes.Description
version = project.version
implementationClass = "${project.group}.gradle.MokkeryGradlePlugin"
tags.set(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,10 @@ public fun interface ApplicationRule {
* It means that it is automatically applied to tests in Multiplatform, JVM and Android projects.
*/
public val AllTests: ApplicationRule = ApplicationRule { it.name.contains("Test") || it.name == "test" }

/**
* Results in Mokkery being applied to all source sets in this project.
*/
public val All: ApplicationRule = ApplicationRule { true }
}
}
6 changes: 1 addition & 5 deletions mokkery-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import org.jetbrains.dokka.gradle.DokkaTaskPartial

plugins {
id("mokkery-publish")
kotlin("jvm")
Expand All @@ -15,9 +13,7 @@ kotlin.sourceSets.all {
}
}

tasks.withType(DokkaTaskPartial::class) {
enabled = false
}
excludeFromApiDocs()

dependencies {
kapt(libs.google.autoservice)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ abstract class CoreTransformer(
compilerPluginScope: CompilerPluginScope
) : TransformerScope, IrElementTransformerVoid() {
final override lateinit var currentFile: IrFile
private set
override val classes = mutableMapOf<ClassResolver, IrClass>()
override val functions = mutableMapOf<FunctionResolver, IrSimpleFunction>()
override val compilerConfig: CompilerConfiguration = compilerPluginScope.compilerConfig
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ object Mokkery {
val internalEverySuspend by dev_mokkery_internal.function
val internalVerify by dev_mokkery_internal.function
val internalVerifySuspend by dev_mokkery_internal.function
val callIgnoringClassCastException by dev_mokkery_internal.function

val TemplatingScope by dev_mokkery_internal_templating.function
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ class MokkeryTransformer(compilerPluginScope: CompilerPluginScope) : CoreTransfo
irBlock {
val variable = createTmpVariable(irCall(getFunction(Mokkery.Function.TemplatingScope)))
val transformer = TemplatingScopeCallsTransformer(this@MokkeryTransformer, variable)
transformer.currentFile = currentFile
block.transformChildren(transformer, null)
+irCall(function) {
block as IrFunctionExpression
Expand All @@ -165,6 +166,7 @@ class MokkeryTransformer(compilerPluginScope: CompilerPluginScope) : CoreTransfo
compilerPluginScope = this@MokkeryTransformer,
templatingScope = variable
)
transformer.currentFile = currentFile
block.transformChildren(transformer, null)
+irCall(function) {
putValueArgument(0, irGet(variable))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ import dev.mokkery.plugin.core.CoreTransformer
import dev.mokkery.plugin.core.Mokkery
import dev.mokkery.plugin.core.declarationIrBuilder
import dev.mokkery.plugin.core.getClass
import dev.mokkery.plugin.core.getFunction
import dev.mokkery.plugin.core.messageCollector
import dev.mokkery.plugin.core.mokkeryErrorAt
import dev.mokkery.plugin.ir.irCall
import dev.mokkery.plugin.ir.irLambda
import dev.mokkery.plugin.ir.kClassReference
import dev.mokkery.plugin.logAt
import org.jetbrains.kotlin.backend.common.lower.DeclarationIrBuilder
import org.jetbrains.kotlin.ir.IrStatement
import org.jetbrains.kotlin.ir.backend.js.utils.valueArguments
Expand All @@ -30,13 +34,15 @@ import org.jetbrains.kotlin.ir.expressions.IrSpreadElement
import org.jetbrains.kotlin.ir.expressions.IrVararg
import org.jetbrains.kotlin.ir.expressions.putElement
import org.jetbrains.kotlin.ir.symbols.IrSymbol
import org.jetbrains.kotlin.ir.types.IrType
import org.jetbrains.kotlin.ir.types.getClass
import org.jetbrains.kotlin.ir.types.isNothing
import org.jetbrains.kotlin.ir.types.isPrimitiveType
import org.jetbrains.kotlin.ir.types.makeNullable
import org.jetbrains.kotlin.ir.util.defaultType
import org.jetbrains.kotlin.ir.util.getSimpleFunction
import org.jetbrains.kotlin.ir.util.isFinalClass
import org.jetbrains.kotlin.ir.util.isSuspend
import org.jetbrains.kotlin.ir.util.isTypeParameter
import org.jetbrains.kotlin.platform.konan.isNative

Expand Down Expand Up @@ -78,13 +84,28 @@ class TemplatingScopeCallsTransformer(
+irGet(tmp)
}
}
if (isNativePlatform && !returnType.isPrimitiveType(nullable = false) && !returnType.isNothing()) {
// make return type nullable to avoid runtime checks on non-primitive types (K/N to work)
expression.type = pluginContext.irBuiltIns.anyNType
}
interceptAllArgsOf(expression)
token++
return expression
return when {
isNativePlatform -> workaroundNativeChecks(expression, returnType)
else -> expression
}
}

private fun workaroundNativeChecks(expression: IrCall, returnType: IrType): IrCall {
if (returnType.isPrimitiveType(nullable = false) || returnType.isNothing()) return expression
expression.apply { type = pluginContext.irBuiltIns.anyNType }
if (!expression.isSuspend || expression.valueArguments.all { it != null }) return expression
val callIgnoringClassCastExceptionFun = getFunction(Mokkery.Function.callIgnoringClassCastException)
return declarationIrBuilder(expression) {
irCall(callIgnoringClassCastExceptionFun) {
val blockParamType = callIgnoringClassCastExceptionFun.valueParameters[1].type
val lambda = irLambda(pluginContext.irBuiltIns.anyNType, blockParamType, currentFile) { +expression }
putValueArgument(0, irGet(templatingScope))
putValueArgument(1, lambda)
putTypeArgument(0, pluginContext.irBuiltIns.anyNType)
}
}
}

private fun interceptAllArgsOf(expression: IrCall) {
Expand Down
Loading

0 comments on commit f8537ea

Please sign in to comment.