diff --git a/kermit-bugsnag-test/README.md b/kermit-bugsnag-test/README.md new file mode 100644 index 00000000..c3231f9c --- /dev/null +++ b/kermit-bugsnag-test/README.md @@ -0,0 +1,17 @@ +# kermit-bugsnag-test + +This is a stub library to use for testing if you are using `kermit-bugsnag` in your build and want to run Kotlin +tests. `kermit-bugsnag` defines the cinterop for Bugsnag, but does not provide the implementation. When you +build your final application, your final link will include Bugsnag definitions. That works if you don't run +Kotlin/Native tests. If you do, you'll get linker errors when those tests are being built. + +To avoid those errors, include `kermit-bugsnag-test` in your Kotlin/Native test dependencies. + +```kotlin +sourceSets["iosTest"].dependencies { + implementation("co.touchlab:kermit-bugsnag-test:x.y.z") +} +``` + +These stubs don't actually work, but they'll satisfy the linker so you can run your Kotlin build tests. When your +framework is built into an app, you'll need to supply the Bugsnag implementation. \ No newline at end of file diff --git a/kermit-bugsnag-test/build.gradle.kts b/kermit-bugsnag-test/build.gradle.kts new file mode 100644 index 00000000..1fa991f0 --- /dev/null +++ b/kermit-bugsnag-test/build.gradle.kts @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2021 Touchlab + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ + +plugins { + kotlin("multiplatform") + id("co.touchlab.cklib") +} + +kotlin { + macosX64() + macosArm64() + iosX64() + iosArm64() + iosArm32() + iosSimulatorArm64() + tvosArm64() + tvosSimulatorArm64() + tvosX64() + watchosArm32() + watchosArm64() + watchosSimulatorArm64() + watchosX86() + watchosX64() + + sourceSets { + val commonMain by getting { + dependencies { + implementation("org.jetbrains.kotlin:kotlin-stdlib-common") + } + } + + val commonTest by getting { + dependencies { + implementation("org.jetbrains.kotlin:kotlin-test-common") + implementation("org.jetbrains.kotlin:kotlin-test-annotations-common") + } + } + + val darwinMain by creating + darwinMain.dependsOn(commonMain) + + val darwinTest by creating + darwinTest.dependsOn(commonTest) + + targets.withType { + val main by compilations.getting + main.defaultSourceSet.dependsOn(darwinMain) + val test by compilations.getting + test.defaultSourceSet.dependsOn(darwinTest) + } + } +} + +cklib { + create("objcsample") { + language = co.touchlab.cklib.gradle.CompileToBitcode.Language.OBJC + compilerArgs.addAll( + listOf( + "-DKONAN_MI_MALLOC=1", "-DNS_FORMAT_ARGUMENT(A)=", "-D_Nullable_result=_Nullable" + ) + ) + } +} + +apply(from = "../gradle/gradle-mvn-mpp-push.gradle") diff --git a/kermit-bugsnag-test/src/commonMain/kotlin/co/touchlab/kermit/crashlytics/Dummy.kt b/kermit-bugsnag-test/src/commonMain/kotlin/co/touchlab/kermit/crashlytics/Dummy.kt new file mode 100644 index 00000000..069c73bb --- /dev/null +++ b/kermit-bugsnag-test/src/commonMain/kotlin/co/touchlab/kermit/crashlytics/Dummy.kt @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2021 Touchlab + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package co.touchlab.kermit.crashlytics + +class Dummy { +} \ No newline at end of file diff --git a/kermit-bugsnag-test/src/objcsample/cpp/Bugsnag.m b/kermit-bugsnag-test/src/objcsample/cpp/Bugsnag.m new file mode 100644 index 00000000..3b012b25 --- /dev/null +++ b/kermit-bugsnag-test/src/objcsample/cpp/Bugsnag.m @@ -0,0 +1,25 @@ +// +// Created by Kevin Galligan on 10/30/21. +// + +#import "Bugsnag.h" + + +@implementation Bugsnag +- (instancetype)init { + return nil; +} + ++ (void)notify:(NSException *)exception { + +} + ++ (void)leaveBreadcrumbWithMessage:(NSString *)message { + +} + ++ (void)leaveBreadcrumbWithMessage:(NSString *)message metadata:(NSDictionary *)metadata andType:(BSGBreadcrumbType)type { + +} + +@end \ No newline at end of file diff --git a/kermit-bugsnag-test/src/objcsample/headers/Bugsnag.h b/kermit-bugsnag-test/src/objcsample/headers/Bugsnag.h new file mode 100644 index 00000000..b6f80943 --- /dev/null +++ b/kermit-bugsnag-test/src/objcsample/headers/Bugsnag.h @@ -0,0 +1,116 @@ +// +// Bugsnag.h +// +// Created by Conrad Irwin on 2014-10-01. +// +// Copyright (c) 2014 Bugsnag, Inc. All rights reserved. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall remain in place +// in this source code. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// +#import + +/** + * Types of breadcrumbs + */ +typedef NS_ENUM(NSUInteger, BSGBreadcrumbType) { + /** + * Any breadcrumb sent via Bugsnag.leaveBreadcrumb() + */ + BSGBreadcrumbTypeManual, + /** + * A call to Bugsnag.notify() (internal use only) + */ + BSGBreadcrumbTypeError, + /** + * A log message + */ + BSGBreadcrumbTypeLog, + /** + * A navigation action, such as pushing a view controller or dismissing an alert + */ + BSGBreadcrumbTypeNavigation, + /** + * A background process, such performing a database query + */ + BSGBreadcrumbTypeProcess, + /** + * A network request + */ + BSGBreadcrumbTypeRequest, + /** + * Change in application or view state + */ + BSGBreadcrumbTypeState, + /** + * A user event, such as authentication or control events + */ + BSGBreadcrumbTypeUser, +}; + +/** + * Static access to a Bugsnag Client, the easiest way to use Bugsnag in your app. + */ +@interface Bugsnag : NSObject// + +/** + * All Bugsnag access is class-level. Prevent the creation of instances. + */ +- (instancetype _Nonnull )init NS_UNAVAILABLE NS_SWIFT_UNAVAILABLE("Use class methods to initialise Bugsnag."); + +// ============================================================================= +// MARK: - Notify +// ============================================================================= + +/** + * Send a custom or caught exception to Bugsnag. + * + * The exception will be sent to Bugsnag in the background allowing your + * app to continue running. + * + * @param exception The exception. + */ ++ (void)notify:(NSException *_Nonnull)exception; + +// ============================================================================= +// MARK: - Breadcrumbs +// ============================================================================= + +/** + * Leave a "breadcrumb" log message, representing an action that occurred + * in your app, to aid with debugging. + * + * @param message the log message to leave + */ ++ (void)leaveBreadcrumbWithMessage:(NSString *_Nonnull)message; + +/** + * Leave a "breadcrumb" log message, representing an action that occurred + * in your app, to aid with debugging, along with additional metadata and + * a type. + * + * @param message The log message to leave. + * @param metadata Diagnostic data relating to the breadcrumb. + * Values should be serializable to JSON with NSJSONSerialization. + * @param type A BSGBreadcrumbTypeValue denoting the type of breadcrumb. + */ ++ (void)leaveBreadcrumbWithMessage:(NSString *_Nonnull)message + metadata:(NSDictionary *_Nullable)metadata + andType:(BSGBreadcrumbType)type + NS_SWIFT_NAME(leaveBreadcrumb(_:metadata:type:)); +@end diff --git a/kermit-bugsnag/src/darwinMain/kotlin/co/touchlab/kermit/bugsnag/BugsnagLogWriter.kt b/kermit-bugsnag/src/darwinMain/kotlin/co/touchlab/kermit/bugsnag/BugsnagLogWriter.kt index dd2c2930..2039c484 100644 --- a/kermit-bugsnag/src/darwinMain/kotlin/co/touchlab/kermit/bugsnag/BugsnagLogWriter.kt +++ b/kermit-bugsnag/src/darwinMain/kotlin/co/touchlab/kermit/bugsnag/BugsnagLogWriter.kt @@ -54,7 +54,10 @@ actual class BugsnagLogWriter actual constructor( private class BugsnagNSException(stackTrace: List, exceptionType: String, message: String) : NSException(name = exceptionType, reason = message, userInfo = null) { private val _callStackReturnAddresses:List init { - _callStackReturnAddresses = stackTrace.map { it.convert() as NSNumber } + _callStackReturnAddresses = stackTrace.map { + @Suppress("CAST_NEVER_SUCCEEDS") + it.convert() as NSNumber + } } override fun callStackReturnAddresses(): List<*> { diff --git a/kermit-crashlytics-test/build.gradle.kts b/kermit-crashlytics-test/build.gradle.kts index 985a76b0..84a61279 100644 --- a/kermit-crashlytics-test/build.gradle.kts +++ b/kermit-crashlytics-test/build.gradle.kts @@ -26,7 +26,7 @@ kotlin { macosArm64() iosX64() iosArm64() -// iosArm32() + iosArm32() iosSimulatorArm64() tvosArm64() tvosSimulatorArm64() diff --git a/kermit/build.gradle.kts b/kermit/build.gradle.kts index 93a44f69..93c508c0 100644 --- a/kermit/build.gradle.kts +++ b/kermit/build.gradle.kts @@ -110,10 +110,6 @@ kotlin { testSourceSet.dependsOn(commonTest) } - commonMain.dependencies { - implementation("org.jetbrains.kotlin:kotlin-stdlib-common") - } - commonTest.dependencies { implementation("org.jetbrains.kotlin:kotlin-test-common") implementation("org.jetbrains.kotlin:kotlin-test-annotations-common") @@ -121,10 +117,6 @@ kotlin { implementation("co.touchlab:testhelp:0.5.5") } - androidMain.dependencies { - implementation("org.jetbrains.kotlin:kotlin-stdlib") - } - androidTest.dependencies { implementation("org.jetbrains.kotlin:kotlin-test") implementation("org.jetbrains.kotlin:kotlin-test-junit") @@ -132,10 +124,6 @@ kotlin { implementation("org.robolectric:robolectric:4.5.1") } - jvmMain.dependencies { - implementation("org.jetbrains.kotlin:kotlin-stdlib") - } - jvmTest.dependencies { implementation("org.jetbrains.kotlin:kotlin-test") implementation("org.jetbrains.kotlin:kotlin-test-junit") diff --git a/settings.gradle.kts b/settings.gradle.kts index 71066851..e8f28eda 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -15,6 +15,7 @@ include(":kermit") include(":kermit-crashlytics") include(":kermit-crashlytics-test") include(":kermit-bugsnag") +include(":kermit-bugsnag-test") include(":kermit-gradle-plugin") include(":kermit-ir-plugin")