diff --git a/CHANGELOG.md b/CHANGELOG.md index ae82af54..f841d24d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## Unreleased + +### Features + +- Add stubs/no-op support for unsupported targets ([#426](https://github.com/getsentry/sentry-kotlin-multiplatform/pull/426)) + ## 0.16.0 Potentially breaking: this release bumps the used Kotlin version to `2.1.21`. diff --git a/build.gradle.kts b/build.gradle.kts index 28338309..a2b388c7 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -2,6 +2,7 @@ import com.diffplug.spotless.LineEnding import com.vanniktech.maven.publish.MavenPublishPlugin import com.vanniktech.maven.publish.MavenPublishPluginExtension import io.gitlab.arturbosch.detekt.Detekt +import org.jetbrains.dokka.gradle.DokkaTask import java.util.zip.ZipFile plugins { @@ -161,6 +162,13 @@ private fun Project.validateKotlinMultiplatformCoreArtifacts() { subprojects { if (project.name.contains("sentry-kotlin-multiplatform")) { + tasks.withType().configureEach { + dokkaSourceSets.configureEach { + if (name.endsWith("Test")) { + suppress.set(true) + } + } + } apply(plugin = Config.dokka) } } diff --git a/buildSrc/src/main/java/Publication.kt b/buildSrc/src/main/java/Publication.kt index fea3d5ce..96bb9f88 100644 --- a/buildSrc/src/main/java/Publication.kt +++ b/buildSrc/src/main/java/Publication.kt @@ -26,7 +26,12 @@ fun DistributionContainer.configureForMultiplatform(project: Project, buildPubli "watchosarm32" to "$projectName-watchosarm32", "watchosarm64" to "$projectName-watchosarm64", "watchossimulatorarm64" to "$projectName-watchossimulatorarm64", - "watchosx64" to "$projectName-watchosx64" + "watchosx64" to "$projectName-watchosx64", + "js" to "$projectName-js", + "wasm-js" to "$projectName-wasm-js", + "mingwx64" to "$projectName-mingwx64", + "linuxarm64" to "$projectName-linuxarm64", + "linuxx64" to "$projectName-linuxx64" ) platforms.forEach { (distName, projectName) -> diff --git a/sentry-kotlin-multiplatform/build.gradle.kts b/sentry-kotlin-multiplatform/build.gradle.kts index 7b246d0d..a4951ec1 100644 --- a/sentry-kotlin-multiplatform/build.gradle.kts +++ b/sentry-kotlin-multiplatform/build.gradle.kts @@ -1,5 +1,9 @@ +@file:OptIn(ExperimentalWasmDsl::class) + import com.codingfeline.buildkonfig.compiler.FieldSpec.Type.STRING import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi +import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl +import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget import org.jetbrains.kotlin.gradle.tasks.KotlinCompile @@ -63,6 +67,7 @@ kotlin { tvosX64() macosX64() macosArm64() + addNoOpTargets() sourceSets { @OptIn(ExperimentalKotlinGradlePluginApi::class) @@ -185,8 +190,10 @@ kotlin { // workaround for https://youtrack.jetbrains.com/issue/KT-41709 due to having "Meta" in the class name // if we need to use this class, we'd need to find a better way to work it out - targets.withType().all { - compilations["main"].cinterops["Sentry"].extraOpts( + targets.withType().matching { + it.konanTarget.family.isAppleFamily + }.forEach { target -> + target.compilations["main"].cinterops["Sentry"].extraOpts( "-compiler-option", "-DSentryMechanismMeta=SentryMechanismMetaUnavailable", "-compiler-option", @@ -195,6 +202,14 @@ kotlin { "-DSentryMetricsAPIDelegate=SentryMetricsAPIDelegateUnavailable" ) } + + val commonStub by creating { + dependsOn(commonMain.get()) + } + jsMain.get().dependsOn(commonStub) + wasmJsMain.get().dependsOn(commonStub) + linuxMain.get().dependsOn(commonStub) + mingwMain.get().dependsOn(commonStub) } } @@ -216,3 +231,25 @@ buildkonfig { buildConfigField(STRING, "SENTRY_COCOA_VERSION", Config.Libs.sentryCocoaVersion) } } + +private fun KotlinMultiplatformExtension.addNoOpTargets() { + js(IR) { + browser() + binaries.library() + compilations.remove(compilations.getByName("test")) + } + wasmJs { + browser() + binaries.library() + compilations.remove(compilations.getByName("test")) + } + mingwX64 { + compilations.remove(compilations.getByName("test")) + } + linuxArm64 { + compilations.remove(compilations.getByName("test")) + } + linuxX64 { + compilations.remove(compilations.getByName("test")) + } +} diff --git a/sentry-kotlin-multiplatform/sentry_kotlin_multiplatform.podspec b/sentry-kotlin-multiplatform/sentry_kotlin_multiplatform.podspec index 145c2127..126f6651 100644 --- a/sentry-kotlin-multiplatform/sentry_kotlin_multiplatform.podspec +++ b/sentry-kotlin-multiplatform/sentry_kotlin_multiplatform.podspec @@ -54,4 +54,4 @@ Pod::Spec.new do |spec| } ] -end +end \ No newline at end of file diff --git a/sentry-kotlin-multiplatform/src/commonStub/kotlin/io/sentry/kotlin/multiplatform/Attachment.commonStub.kt b/sentry-kotlin-multiplatform/src/commonStub/kotlin/io/sentry/kotlin/multiplatform/Attachment.commonStub.kt new file mode 100644 index 00000000..84d0bf2d --- /dev/null +++ b/sentry-kotlin-multiplatform/src/commonStub/kotlin/io/sentry/kotlin/multiplatform/Attachment.commonStub.kt @@ -0,0 +1,49 @@ +package io.sentry.kotlin.multiplatform + +public actual class Attachment { + + public actual val bytes: ByteArray? + public actual val contentType: String? + public actual val pathname: String? + public actual val filename: String + + public actual companion object { + public actual fun fromScreenshot(screenshotBytes: ByteArray): Attachment = + Attachment(screenshotBytes, "screenshot.png", "image/png") + } + + public actual constructor(bytes: ByteArray, filename: String) { + this.bytes = null + this.pathname = null + this.filename = "" + this.contentType = null + } + + public actual constructor(bytes: ByteArray, filename: String, contentType: String?) { + this.bytes = null + this.pathname = null + this.filename = "" + this.contentType = null + } + + public actual constructor(pathname: String) { + this.bytes = null + this.pathname = null + this.filename = "" + this.contentType = null + } + + public actual constructor(pathname: String, filename: String) { + this.bytes = null + this.pathname = null + this.filename = "" + this.contentType = null + } + + public actual constructor(pathname: String, filename: String, contentType: String?) { + this.bytes = null + this.pathname = null + this.filename = "" + this.contentType = null + } +} diff --git a/sentry-kotlin-multiplatform/src/commonStub/kotlin/io/sentry/kotlin/multiplatform/Context.commonStub.kt b/sentry-kotlin-multiplatform/src/commonStub/kotlin/io/sentry/kotlin/multiplatform/Context.commonStub.kt new file mode 100644 index 00000000..4e98d1e3 --- /dev/null +++ b/sentry-kotlin-multiplatform/src/commonStub/kotlin/io/sentry/kotlin/multiplatform/Context.commonStub.kt @@ -0,0 +1,3 @@ +package io.sentry.kotlin.multiplatform + +public actual abstract class Context diff --git a/sentry-kotlin-multiplatform/src/commonStub/kotlin/io/sentry/kotlin/multiplatform/SentryBridge.commonStub.kt b/sentry-kotlin-multiplatform/src/commonStub/kotlin/io/sentry/kotlin/multiplatform/SentryBridge.commonStub.kt new file mode 100644 index 00000000..1700b36b --- /dev/null +++ b/sentry-kotlin-multiplatform/src/commonStub/kotlin/io/sentry/kotlin/multiplatform/SentryBridge.commonStub.kt @@ -0,0 +1,67 @@ +package io.sentry.kotlin.multiplatform + +import io.sentry.kotlin.multiplatform.protocol.Breadcrumb +import io.sentry.kotlin.multiplatform.protocol.SentryId +import io.sentry.kotlin.multiplatform.protocol.User +import io.sentry.kotlin.multiplatform.protocol.UserFeedback + +@Suppress("UnusedPrivateMember") +internal actual class SentryBridge actual constructor( + private val sentryInstance: SentryInstance +) { + actual fun init(context: Context, configuration: OptionsConfiguration) { + // No-op + } + + actual fun init(configuration: OptionsConfiguration) { + // No-op + } + + actual fun initWithPlatformOptions(configuration: PlatformOptionsConfiguration) { + // No-op + } + + actual fun captureMessage(message: String): SentryId { + return SentryId.EMPTY_ID + } + + actual fun captureMessage(message: String, scopeCallback: ScopeCallback): SentryId { + return SentryId.EMPTY_ID + } + + actual fun captureException(throwable: Throwable): SentryId { + return SentryId.EMPTY_ID + } + + actual fun captureException(throwable: Throwable, scopeCallback: ScopeCallback): SentryId { + return SentryId.EMPTY_ID + } + + actual fun configureScope(scopeCallback: ScopeCallback) { + // No-op + } + + actual fun captureUserFeedback(userFeedback: UserFeedback) { + // No-op + } + + actual fun addBreadcrumb(breadcrumb: Breadcrumb) { + // No-op + } + + actual fun setUser(user: User?) { + // No-op + } + + actual fun isCrashedLastRun(): Boolean { + return false + } + + actual fun isEnabled(): Boolean { + return false + } + + actual fun close() { + // No-op + } +} diff --git a/sentry-kotlin-multiplatform/src/commonStub/kotlin/io/sentry/kotlin/multiplatform/SentryEvent.commonStub.kt b/sentry-kotlin-multiplatform/src/commonStub/kotlin/io/sentry/kotlin/multiplatform/SentryEvent.commonStub.kt new file mode 100644 index 00000000..f41b517d --- /dev/null +++ b/sentry-kotlin-multiplatform/src/commonStub/kotlin/io/sentry/kotlin/multiplatform/SentryEvent.commonStub.kt @@ -0,0 +1,12 @@ +package io.sentry.kotlin.multiplatform + +import io.sentry.kotlin.multiplatform.protocol.Message +import io.sentry.kotlin.multiplatform.protocol.SentryException + +public actual class SentryEvent actual constructor() : SentryBaseEvent() { + public actual var message: Message? = null + public actual var logger: String? = null + public actual var level: SentryLevel? = null + public actual var fingerprint: MutableList = mutableListOf() + public actual var exceptions: MutableList = mutableListOf() +} diff --git a/sentry-kotlin-multiplatform/src/commonStub/kotlin/io/sentry/kotlin/multiplatform/SentryPlatformInstance.commonStub.kt b/sentry-kotlin-multiplatform/src/commonStub/kotlin/io/sentry/kotlin/multiplatform/SentryPlatformInstance.commonStub.kt new file mode 100644 index 00000000..3e2f4d5d --- /dev/null +++ b/sentry-kotlin-multiplatform/src/commonStub/kotlin/io/sentry/kotlin/multiplatform/SentryPlatformInstance.commonStub.kt @@ -0,0 +1,7 @@ +package io.sentry.kotlin.multiplatform + +internal actual class SentryPlatformInstance : SentryInstance { + actual override fun init(configuration: PlatformOptionsConfiguration) { + // No-op + } +} diff --git a/sentry-kotlin-multiplatform/src/commonStub/kotlin/io/sentry/kotlin/multiplatform/SentryPlatformOptions.commonStub.kt b/sentry-kotlin-multiplatform/src/commonStub/kotlin/io/sentry/kotlin/multiplatform/SentryPlatformOptions.commonStub.kt new file mode 100644 index 00000000..09a6f960 --- /dev/null +++ b/sentry-kotlin-multiplatform/src/commonStub/kotlin/io/sentry/kotlin/multiplatform/SentryPlatformOptions.commonStub.kt @@ -0,0 +1,12 @@ +package io.sentry.kotlin.multiplatform + +public actual class SentryPlatformOptions + +internal actual fun SentryPlatformOptions.prepareForInit() { + // No-op +} + +internal actual fun SentryOptions.toPlatformOptionsConfiguration(): PlatformOptionsConfiguration = + { + // No-op + } diff --git a/sentry-kotlin-multiplatform/src/commonStub/kotlin/io/sentry/kotlin/multiplatform/protocol/SentryId.commonStub.kt b/sentry-kotlin-multiplatform/src/commonStub/kotlin/io/sentry/kotlin/multiplatform/protocol/SentryId.commonStub.kt new file mode 100644 index 00000000..da302990 --- /dev/null +++ b/sentry-kotlin-multiplatform/src/commonStub/kotlin/io/sentry/kotlin/multiplatform/protocol/SentryId.commonStub.kt @@ -0,0 +1,9 @@ +package io.sentry.kotlin.multiplatform.protocol + +public actual data class SentryId actual constructor(private val sentryIdString: String) { + public actual companion object { + public actual val EMPTY_ID: SentryId = SentryId("") + } + + actual override fun toString(): String = sentryIdString +} diff --git a/sentry-kotlin-multiplatform/src/commonTest/kotlin/io/sentry/kotlin/multiplatform/BreadcrumbTestConverter.kt b/sentry-kotlin-multiplatform/src/commonTest/kotlin/io/sentry/kotlin/multiplatform/BreadcrumbTestConverter.kt index 42682423..5dbdc4b3 100644 --- a/sentry-kotlin-multiplatform/src/commonTest/kotlin/io/sentry/kotlin/multiplatform/BreadcrumbTestConverter.kt +++ b/sentry-kotlin-multiplatform/src/commonTest/kotlin/io/sentry/kotlin/multiplatform/BreadcrumbTestConverter.kt @@ -3,7 +3,6 @@ package io.sentry.kotlin.multiplatform import io.sentry.kotlin.multiplatform.protocol.Breadcrumb expect class BreadcrumbTestConverter(breadcrumb: Breadcrumb) { - fun getType(): String? fun getCategory(): String? fun getMessage(): String?