From 561641394c882b853f9cdf795e0d6151aac16267 Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Thu, 25 Apr 2024 01:48:07 +0200 Subject: [PATCH 01/78] Add raw working impl --- buildSrc/src/main/java/Config.kt | 4 +- plugin-build/build.gradle.kts | 51 +++++++++++ plugin-build/gradle.properties | 8 ++ plugin-build/gradle/libs.versions.toml | 16 ++++ plugin-build/plugin/build.gradle.kts | 60 +++++++++++++ .../template/plugin/TemplateExampleTask.kt | 46 ++++++++++ .../template/plugin/TemplateExtension.kt | 28 ++++++ .../gradle/template/plugin/TemplatePlugin.kt | 87 +++++++++++++++++++ .../template/plugin/TemplatePluginTest.kt | 43 +++++++++ plugin-build/settings.gradle.kts | 30 +++++++ .../xcshareddata/swiftpm/Package.resolved | 14 +++ .../kmp-app-spm/shared/build.gradle.kts | 1 + .../src/commonTest/kotlin/CompilationTest.kt | 8 ++ settings.gradle.kts | 1 + 14 files changed, 395 insertions(+), 2 deletions(-) create mode 100644 plugin-build/build.gradle.kts create mode 100644 plugin-build/gradle.properties create mode 100644 plugin-build/gradle/libs.versions.toml create mode 100644 plugin-build/plugin/build.gradle.kts create mode 100644 plugin-build/plugin/src/main/java/com/ncorti/kotlin/gradle/template/plugin/TemplateExampleTask.kt create mode 100644 plugin-build/plugin/src/main/java/com/ncorti/kotlin/gradle/template/plugin/TemplateExtension.kt create mode 100644 plugin-build/plugin/src/main/java/com/ncorti/kotlin/gradle/template/plugin/TemplatePlugin.kt create mode 100644 plugin-build/plugin/src/test/java/com/ncorti/kotlin/gradle/template/plugin/TemplatePluginTest.kt create mode 100644 plugin-build/settings.gradle.kts create mode 100644 sentry-samples/kmp-app-cocoapods/iosApp/iosApp.xcworkspace/xcshareddata/swiftpm/Package.resolved create mode 100644 sentry-samples/kmp-app-spm/shared/src/commonTest/kotlin/CompilationTest.kt diff --git a/buildSrc/src/main/java/Config.kt b/buildSrc/src/main/java/Config.kt index 792b8884..cbce6d75 100644 --- a/buildSrc/src/main/java/Config.kt +++ b/buildSrc/src/main/java/Config.kt @@ -1,7 +1,7 @@ object Config { val agpVersion = "7.4.2" - val kotlinVersion = "1.9.21" - val composeVersion = "1.5.11" + val kotlinVersion = "1.9.23" + val composeVersion = "1.6.1" val gradleMavenPublishPluginVersion = "0.18.0" val multiplatform = "multiplatform" diff --git a/plugin-build/build.gradle.kts b/plugin-build/build.gradle.kts new file mode 100644 index 00000000..908ab692 --- /dev/null +++ b/plugin-build/build.gradle.kts @@ -0,0 +1,51 @@ +import io.gitlab.arturbosch.detekt.Detekt + +plugins { + alias(libs.plugins.kotlin) apply false + alias(libs.plugins.pluginPublish) apply false + alias(libs.plugins.detekt) + alias(libs.plugins.ktlint) + alias(libs.plugins.versionCheck) +} + +allprojects { + group = property("GROUP").toString() + version = property("VERSION").toString() + + apply { + plugin(rootProject.libs.plugins.detekt.get().pluginId) + plugin(rootProject.libs.plugins.ktlint.get().pluginId) + } + + ktlint { + debug.set(false) + verbose.set(true) + android.set(false) + outputToConsole.set(true) + ignoreFailures.set(false) + enableExperimentalRules.set(true) + filter { + exclude("**/generated/**") + include("**/kotlin/**") + } + } + + detekt { + config.setFrom(rootProject.files("../config/detekt/detekt.yml")) + } +} + +tasks.withType().configureEach { + reports { + html.required.set(true) + html.outputLocation.set(file("build/reports/detekt.html")) + } +} + +tasks.register("clean", Delete::class.java) { + delete(rootProject.layout.buildDirectory) +} + +tasks.wrapper { + distributionType = Wrapper.DistributionType.ALL +} diff --git a/plugin-build/gradle.properties b/plugin-build/gradle.properties new file mode 100644 index 00000000..3e4ac7f7 --- /dev/null +++ b/plugin-build/gradle.properties @@ -0,0 +1,8 @@ +ID=com.ncorti.kotlin.gradle.template.plugin +VERSION=1.0.0 +GROUP=com.ncorti.kotlin.gradle.template +DISPLAY_NAME=An empty Gradle Plugin from a template +DESCRIPTION=An empty Gradle plugin created from a template +WEBSITE=https://github.com/cortinico/kotlin-gradle-plugin-template +VCS_URL=https://github.com/cortinico/kotlin-gradle-plugin-template +IMPLEMENTATION_CLASS=com.ncorti.kotlin.gradle.template.plugin.TemplatePlugin diff --git a/plugin-build/gradle/libs.versions.toml b/plugin-build/gradle/libs.versions.toml new file mode 100644 index 00000000..dc4894dd --- /dev/null +++ b/plugin-build/gradle/libs.versions.toml @@ -0,0 +1,16 @@ +[versions] +detekt = "1.23.6" +kotlin = "1.9.23" +ktlintGradle = "12.1.0" +pluginPublish = "1.2.1" +versionCheck = "0.51.0" + +[plugins] +detekt = { id = "io.gitlab.arturbosch.detekt", version.ref = "detekt"} +kotlin = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin"} +ktlint = { id = "org.jlleitschuh.gradle.ktlint", version.ref = "ktlintGradle"} +pluginPublish = { id = "com.gradle.plugin-publish", version.ref = "pluginPublish"} +versionCheck = { id = "com.github.ben-manes.versions", version.ref = "versionCheck"} + +[libraries] +junit = "junit:junit:4.13.2" diff --git a/plugin-build/plugin/build.gradle.kts b/plugin-build/plugin/build.gradle.kts new file mode 100644 index 00000000..3687159b --- /dev/null +++ b/plugin-build/plugin/build.gradle.kts @@ -0,0 +1,60 @@ +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +plugins { + kotlin("jvm") + `java-gradle-plugin` + alias(libs.plugins.pluginPublish) + id("de.undercouch.download") version "5.6.0" +} + +dependencies { + implementation(kotlin("stdlib")) + implementation(gradleApi()) + implementation(kotlin("gradle-plugin")) + implementation("com.squareup.okhttp3:okhttp:4.9.0") + + testImplementation(libs.junit) +} + +java { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 +} + +tasks.withType { + kotlinOptions { + jvmTarget = JavaVersion.VERSION_1_8.toString() + } +} + +gradlePlugin { + plugins { + create(property("ID").toString()) { + id = property("ID").toString() + implementationClass = property("IMPLEMENTATION_CLASS").toString() + version = property("VERSION").toString() + description = property("DESCRIPTION").toString() + displayName = property("DISPLAY_NAME").toString() + tags.set(listOf("plugin", "gradle", "sample", "template")) + } + } +} + +gradlePlugin { + website.set(property("WEBSITE").toString()) + vcsUrl.set(property("VCS_URL").toString()) +} + +tasks.create("setupPluginUploadFromEnvironment") { + doLast { + val key = System.getenv("GRADLE_PUBLISH_KEY") + val secret = System.getenv("GRADLE_PUBLISH_SECRET") + + if (key == null || secret == null) { + throw GradleException("gradlePublishKey and/or gradlePublishSecret are not defined environment variables") + } + + System.setProperty("gradle.publish.key", key) + System.setProperty("gradle.publish.secret", secret) + } +} diff --git a/plugin-build/plugin/src/main/java/com/ncorti/kotlin/gradle/template/plugin/TemplateExampleTask.kt b/plugin-build/plugin/src/main/java/com/ncorti/kotlin/gradle/template/plugin/TemplateExampleTask.kt new file mode 100644 index 00000000..0ddd20fc --- /dev/null +++ b/plugin-build/plugin/src/main/java/com/ncorti/kotlin/gradle/template/plugin/TemplateExampleTask.kt @@ -0,0 +1,46 @@ +package com.ncorti.kotlin.gradle.template.plugin + +import org.gradle.api.DefaultTask +import org.gradle.api.file.RegularFileProperty +import org.gradle.api.provider.Property +import org.gradle.api.tasks.Input +import org.gradle.api.tasks.Optional +import org.gradle.api.tasks.OutputFile +import org.gradle.api.tasks.TaskAction +import org.gradle.api.tasks.options.Option + +abstract class TemplateExampleTask : DefaultTask() { + init { + description = "Just a sample template task" + + // Don't forget to set the group here. + // group = BasePlugin.BUILD_GROUP + } + + @get:Input + @get:Option(option = "message2", description = "A message to be printed in the output file") + abstract val message2: Property + + @get:Input + @get:Option(option = "message", description = "A message to be printed in the output file") + abstract val message: Property + + @get:Input + @get:Option(option = "tag", description = "A Tag to be used for debug and in the output file") + @get:Optional + abstract val tag: Property + + @get:OutputFile + abstract val outputFile: RegularFileProperty + + @TaskAction + fun sampleAction() { + val prettyTag = tag.orNull?.let { "[$it]" } ?: "" + + logger.lifecycle("$prettyTag message is: ${message.orNull}") + logger.lifecycle("$prettyTag tag is: ${tag.orNull}") + logger.lifecycle("$prettyTag outputFile is: ${outputFile.orNull}") + + outputFile.get().asFile.writeText("$prettyTag ${message.get()}") + } +} diff --git a/plugin-build/plugin/src/main/java/com/ncorti/kotlin/gradle/template/plugin/TemplateExtension.kt b/plugin-build/plugin/src/main/java/com/ncorti/kotlin/gradle/template/plugin/TemplateExtension.kt new file mode 100644 index 00000000..7a8bec3b --- /dev/null +++ b/plugin-build/plugin/src/main/java/com/ncorti/kotlin/gradle/template/plugin/TemplateExtension.kt @@ -0,0 +1,28 @@ +package com.ncorti.kotlin.gradle.template.plugin + +import org.gradle.api.Project +import org.gradle.api.file.RegularFileProperty +import org.gradle.api.provider.Property +import javax.inject.Inject + +const val DEFAULT_OUTPUT_FILE = "template-example.txt" + +@Suppress("UnnecessaryAbstractClass") +abstract class TemplateExtension + @Inject + constructor(project: Project) { + private val objects = project.objects + + // Example of a property that is mandatory. The task will + // fail if this property is not set as is annotated with @Optional. + val message: Property = objects.property(String::class.java) + + // Example of a property that is optional. + val tag: Property = objects.property(String::class.java) + + // Example of a property with a default set with .convention + val outputFile: RegularFileProperty = + objects.fileProperty().convention( + project.layout.buildDirectory.file(DEFAULT_OUTPUT_FILE), + ) + } diff --git a/plugin-build/plugin/src/main/java/com/ncorti/kotlin/gradle/template/plugin/TemplatePlugin.kt b/plugin-build/plugin/src/main/java/com/ncorti/kotlin/gradle/template/plugin/TemplatePlugin.kt new file mode 100644 index 00000000..d6965f48 --- /dev/null +++ b/plugin-build/plugin/src/main/java/com/ncorti/kotlin/gradle/template/plugin/TemplatePlugin.kt @@ -0,0 +1,87 @@ +package com.ncorti.kotlin.gradle.template.plugin + +import okhttp3.OkHttpClient +import okhttp3.Request +import org.gradle.api.Plugin +import org.gradle.api.Project +import org.gradle.api.tasks.Copy +import org.jetbrains.kotlin.de.undercouch.gradle.tasks.download.Download +import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension +import org.jetbrains.kotlin.gradle.dsl.kotlinExtension +import org.jetbrains.kotlin.gradle.kpm.external.project +import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType +import java.io.File +import java.io.FileOutputStream +import java.io.IOException + +const val EXTENSION_NAME = "templateExampleConfig" +const val TASK_NAME = "templateExample" + +@Suppress("unused") +class TemplatePlugin : Plugin { + override fun apply(project: Project): Unit = with(project) { + afterEvaluate { + val extension = project.extensions.findByName("kotlin") + if (extension is KotlinMultiplatformExtension) { + extension.targets.withType(org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget::class.java).forEach { + it.compilations.all { + if (it.compilationName == "test" && it.target.platformType == KotlinPlatformType.native) { + it.compilerOptions.configure { + freeCompilerArgs.add("-linker-options") + val path = "${project.buildDir}/sentry-temp/Carthage/Build/Sentry.xcframework/ios-arm64_x86_64-simulator/" + print(path) + freeCompilerArgs.add("-F$path") + } + } + } + } + it.tasks.register("downloadSentry", Download::class.java) { download -> + // TODO: only if it doesn't exist or give the option to overwrite + val sentryVersion = project.findProperty("sentryVersion") as String? ?: "8.21.0" + val downloadPath = "${project.layout.buildDirectory.asFile.get().path}/sentry-temp" + val zipFile = "$downloadPath/Sentry.xcframework.zip" + + println(downloadPath) + download.src("https://github.com/getsentry/sentry-cocoa/releases/download/$sentryVersion/Sentry.xcframework.zip") + download.dest(File(zipFile)) + download.overwrite(true) + + println("finished downloading Sentry") + } + + it.tasks.register("setupSentry", Copy::class.java) { copy -> + copy.dependsOn("downloadSentry") + val zipFile = "${project.buildDir}/sentry-temp/Sentry.xcframework.zip" + copy.from(zipTree(zipFile)) + copy.into("${project.buildDir}/sentry-temp") + + copy.from(project.fileTree("${project.buildDir}/sentry-temp/Carthage/Build/Sentry.xcframework/ios-arm64_x86_64-simulator/Sentry.framework")) + copy.into("${project.buildDir}/bin/iosSimulatorArm64/debugTest/frameworks/Sentry.framework") + } + + project.tasks.named("linkDebugTestIosSimulatorArm64").configure { task -> + task.dependsOn("setupSentry") + } + } + } + } +} + +private fun KotlinMultiplatformExtension.downloadAndSetupSentry() { + targets.withType(org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget::class.java).forEach { + } +} + +private fun configureDownloadTask(project: Project) { + val sentryVersion = project.findProperty("sentryVersion") as String? ?: "8.21.0" + val downloadPath = "${project.layout.buildDirectory.asFile.get().path}/sentry-temp" + val zipFile = "$downloadPath/Sentry.xcframework.zip" + +// project.tasks.register("downloadSentry") { +// group = "build setup" +// description = "Download Sentry framework." +// src("https://github.com/getsentry/sentry-cocoa/releases/download/$sentryVersion/Sentry.xcframework.zip") +// dest(File(zipFile)) +// overwrite(true) +// } +} diff --git a/plugin-build/plugin/src/test/java/com/ncorti/kotlin/gradle/template/plugin/TemplatePluginTest.kt b/plugin-build/plugin/src/test/java/com/ncorti/kotlin/gradle/template/plugin/TemplatePluginTest.kt new file mode 100644 index 00000000..9b45d64d --- /dev/null +++ b/plugin-build/plugin/src/test/java/com/ncorti/kotlin/gradle/template/plugin/TemplatePluginTest.kt @@ -0,0 +1,43 @@ +package com.ncorti.kotlin.gradle.template.plugin + +import org.gradle.testfixtures.ProjectBuilder +import org.junit.Assert.assertEquals +import org.junit.Assert.assertNotNull +import org.junit.Test +import java.io.File + +class TemplatePluginTest { + @Test + fun `plugin is applied correctly to the project`() { + val project = ProjectBuilder.builder().build() + project.pluginManager.apply("com.ncorti.kotlin.gradle.template.plugin") + + assert(project.tasks.getByName("templateExample") is TemplateExampleTask) + } + + @Test + fun `extension templateExampleConfig is created correctly`() { + val project = ProjectBuilder.builder().build() + project.pluginManager.apply("com.ncorti.kotlin.gradle.template.plugin") + + assertNotNull(project.extensions.getByName("templateExampleConfig")) + } + + @Test + fun `parameters are passed correctly from extension to task`() { + val project = ProjectBuilder.builder().build() + project.pluginManager.apply("com.ncorti.kotlin.gradle.template.plugin") + val aFile = File(project.projectDir, ".tmp") + (project.extensions.getByName("templateExampleConfig") as TemplateExtension).apply { + tag.set("a-sample-tag") + message.set("just-a-message") + outputFile.set(aFile) + } + + val task = project.tasks.getByName("templateExample") as TemplateExampleTask + + assertEquals("a-sample-tag", task.tag.get()) + assertEquals("just-a-message", task.message.get()) + assertEquals(aFile, task.outputFile.get().asFile) + } +} diff --git a/plugin-build/settings.gradle.kts b/plugin-build/settings.gradle.kts new file mode 100644 index 00000000..2103a968 --- /dev/null +++ b/plugin-build/settings.gradle.kts @@ -0,0 +1,30 @@ +pluginManagement { + repositories { + gradlePluginPortal() + mavenCentral() + } +} + +dependencyResolutionManagement { + repositories { + google() + mavenCentral() + } +} + +plugins { + `gradle-enterprise` +} + +gradleEnterprise { + buildScan { + termsOfServiceUrl = "https://gradle.com/terms-of-service" + termsOfServiceAgree = "yes" + publishAlwaysIf(System.getenv("GITHUB_ACTIONS") == "true") + publishOnFailure() + } +} + +rootProject.name = ("com.ncorti.kotlin.gradle.template") + +include(":plugin") diff --git a/sentry-samples/kmp-app-cocoapods/iosApp/iosApp.xcworkspace/xcshareddata/swiftpm/Package.resolved b/sentry-samples/kmp-app-cocoapods/iosApp/iosApp.xcworkspace/xcshareddata/swiftpm/Package.resolved new file mode 100644 index 00000000..b1ad2be5 --- /dev/null +++ b/sentry-samples/kmp-app-cocoapods/iosApp/iosApp.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -0,0 +1,14 @@ +{ + "pins" : [ + { + "identity" : "alamofire", + "kind" : "remoteSourceControl", + "location" : "https://github.com/Alamofire/Alamofire.git", + "state" : { + "revision" : "723fa5a6c65812aec4a0d7cc432ee198883b6e00", + "version" : "5.9.0" + } + } + ], + "version" : 2 +} diff --git a/sentry-samples/kmp-app-spm/shared/build.gradle.kts b/sentry-samples/kmp-app-spm/shared/build.gradle.kts index 183a4fee..199f7ec1 100644 --- a/sentry-samples/kmp-app-spm/shared/build.gradle.kts +++ b/sentry-samples/kmp-app-spm/shared/build.gradle.kts @@ -3,6 +3,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { kotlin("multiplatform") id("com.android.library") + id("com.ncorti.kotlin.gradle.template.plugin") } java { diff --git a/sentry-samples/kmp-app-spm/shared/src/commonTest/kotlin/CompilationTest.kt b/sentry-samples/kmp-app-spm/shared/src/commonTest/kotlin/CompilationTest.kt new file mode 100644 index 00000000..594de367 --- /dev/null +++ b/sentry-samples/kmp-app-spm/shared/src/commonTest/kotlin/CompilationTest.kt @@ -0,0 +1,8 @@ +import kotlin.test.Test + +class CompilationTest { + @Test + fun test() { + print("see if this runs"); + } +} \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index 3e294e97..6c747e4a 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -20,6 +20,7 @@ dependencyResolutionManagement { rootProject.name = "sentry-kotlin-multiplatform-sdk" include(":sentry-kotlin-multiplatform") +includeBuild("plugin-build") /* Simple KMP App with targets: From 4b48be5ea8ea6d0a59459d761f48a642ce1e1888 Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Thu, 25 Apr 2024 02:40:50 +0200 Subject: [PATCH 02/78] Update --- .../gradle/template/plugin/TemplatePlugin.kt | 124 +++++++++++------- 1 file changed, 74 insertions(+), 50 deletions(-) diff --git a/plugin-build/plugin/src/main/java/com/ncorti/kotlin/gradle/template/plugin/TemplatePlugin.kt b/plugin-build/plugin/src/main/java/com/ncorti/kotlin/gradle/template/plugin/TemplatePlugin.kt index d6965f48..8610822a 100644 --- a/plugin-build/plugin/src/main/java/com/ncorti/kotlin/gradle/template/plugin/TemplatePlugin.kt +++ b/plugin-build/plugin/src/main/java/com/ncorti/kotlin/gradle/template/plugin/TemplatePlugin.kt @@ -5,11 +5,13 @@ import okhttp3.Request import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.api.tasks.Copy +import org.gradle.configurationcache.extensions.capitalized import org.jetbrains.kotlin.de.undercouch.gradle.tasks.download.Download import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension import org.jetbrains.kotlin.gradle.dsl.kotlinExtension import org.jetbrains.kotlin.gradle.kpm.external.project import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType +import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget import java.io.File import java.io.FileOutputStream import java.io.IOException @@ -22,66 +24,88 @@ class TemplatePlugin : Plugin { override fun apply(project: Project): Unit = with(project) { afterEvaluate { val extension = project.extensions.findByName("kotlin") - if (extension is KotlinMultiplatformExtension) { - extension.targets.withType(org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget::class.java).forEach { - it.compilations.all { - if (it.compilationName == "test" && it.target.platformType == KotlinPlatformType.native) { - it.compilerOptions.configure { - freeCompilerArgs.add("-linker-options") - val path = "${project.buildDir}/sentry-temp/Carthage/Build/Sentry.xcframework/ios-arm64_x86_64-simulator/" - print(path) - freeCompilerArgs.add("-F$path") - } - } - } - } - it.tasks.register("downloadSentry", Download::class.java) { download -> - // TODO: only if it doesn't exist or give the option to overwrite - val sentryVersion = project.findProperty("sentryVersion") as String? ?: "8.21.0" - val downloadPath = "${project.layout.buildDirectory.asFile.get().path}/sentry-temp" - val zipFile = "$downloadPath/Sentry.xcframework.zip" - - println(downloadPath) - download.src("https://github.com/getsentry/sentry-cocoa/releases/download/$sentryVersion/Sentry.xcframework.zip") - download.dest(File(zipFile)) - download.overwrite(true) - - println("finished downloading Sentry") - } + if (extension !is KotlinMultiplatformExtension) { + return@afterEvaluate + } - it.tasks.register("setupSentry", Copy::class.java) { copy -> - copy.dependsOn("downloadSentry") - val zipFile = "${project.buildDir}/sentry-temp/Sentry.xcframework.zip" - copy.from(zipTree(zipFile)) - copy.into("${project.buildDir}/sentry-temp") + val nativeTargets = extension.targets.withType(KotlinNativeTarget::class.java) + val targetNames = nativeTargets.map { target -> target.name } + val buildDir = it.layout.buildDirectory.asFile.get().path - copy.from(project.fileTree("${project.buildDir}/sentry-temp/Carthage/Build/Sentry.xcframework/ios-arm64_x86_64-simulator/Sentry.framework")) - copy.into("${project.buildDir}/bin/iosSimulatorArm64/debugTest/frameworks/Sentry.framework") - } + extension.addLinkerOpts(buildDir) + registerSentryDownloadTask() + registerDownloadAndUnzipSentryTask() + registerCopyFrameworkToTestDirsTask(targetNames) - project.tasks.named("linkDebugTestIosSimulatorArm64").configure { task -> - task.dependsOn("setupSentry") - } + project.tasks.named { name -> name.contains("linkDebugTest") }.configureEach { task -> + task.dependsOn("copyFrameworkToTestDirs") } } } } -private fun KotlinMultiplatformExtension.downloadAndSetupSentry() { - targets.withType(org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget::class.java).forEach { +private fun Project.registerSentryDownloadTask() { + tasks.register("downloadSentryFramework", Download::class.java) { download -> + val sentryVersion = project.findProperty("sentryVersion") as String? ?: "8.21.0" + val downloadPath = "${project.layout.buildDirectory.asFile.get().path}/sentry-temp" + val zipFile = "$downloadPath/Sentry.xcframework.zip" + + download.src("https://github.com/getsentry/sentry-cocoa/releases/download/$sentryVersion/Sentry.xcframework.zip") + download.dest(File(zipFile)) + download.overwrite(false) + } +} + +private fun Project.registerDownloadAndUnzipSentryTask() { + tasks.register("downloadAndUnzipSentryFramework", Copy::class.java) { copy -> + copy.dependsOn("downloadSentryFramework") + val zipFile = "$buildDir/sentry-temp/Sentry.xcframework.zip" + copy.from(zipTree(zipFile)) + copy.into("$buildDir/sentry-temp") } } -private fun configureDownloadTask(project: Project) { - val sentryVersion = project.findProperty("sentryVersion") as String? ?: "8.21.0" - val downloadPath = "${project.layout.buildDirectory.asFile.get().path}/sentry-temp" - val zipFile = "$downloadPath/Sentry.xcframework.zip" +private fun Project.registerCopyFrameworkToTestDirsTask(targetNames: List) { + tasks.register("copyFrameworkToTestDirs", Copy::class.java) { copy -> + copy.dependsOn("downloadAndUnzipSentryFramework") + targetNames.forEach { target -> + val platform = when (target) { + "iosSimulator64" -> "ios-arm64_x86_64-simulator" + // Add other mappings as needed for different targets + else -> null + } + if (platform != null) { + val frameworkPath = + "$buildDir/sentry-temp/Carthage/Build/Sentry.xcframework/$platform/Sentry.framework" + copy.from(project.fileTree(frameworkPath)) + copy.into("$buildDir/bin/${target}/debugTest/frameworks/Sentry.framework") + } + } + } +} -// project.tasks.register("downloadSentry") { -// group = "build setup" -// description = "Download Sentry framework." -// src("https://github.com/getsentry/sentry-cocoa/releases/download/$sentryVersion/Sentry.xcframework.zip") -// dest(File(zipFile)) -// overwrite(true) -// } +private fun getFrameworkPath(buildDir: String, target: KotlinNativeTarget): String? { + val platform = when (target.name) { + "iosSimulator64" -> "ios-arm64_x86_64-simulator" + else -> null + } + return platform?.let { "$buildDir/sentry-temp/Carthage/Build/Sentry.xcframework/$it/Sentry.framework" } } + +private fun KotlinMultiplatformExtension.addLinkerOpts(buildDir: String) { + targets.withType(KotlinNativeTarget::class.java).forEach { target -> + target.compilations.all { + if (it.compilationName == "test" && it.target.platformType == KotlinPlatformType.native) { + it.compilerOptions.configure { + freeCompilerArgs.add("-linker-options") + val platform: String? = when (target.name) { + "iosSimulatorArm64" -> "ios-arm64_x86_64-simulator" + else -> null + } + val path = "$buildDir/sentry-temp/Carthage/Build/Sentry.xcframework/$platform/" + freeCompilerArgs.add("-F$path") + } + } + } + } +} \ No newline at end of file From 51130b08ed326ec64d1a85e231c223b835fa3cac Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Fri, 26 Apr 2024 01:34:55 +0200 Subject: [PATCH 03/78] Update --- plugin-build/gradle.properties | 6 +- plugin-build/plugin/build.gradle.kts | 1 - .../template/plugin/TemplateExtension.kt | 28 ----- .../gradle/template/plugin/TemplatePlugin.kt | 111 ----------------- .../gradle/plugin/SentryExtension.kt | 23 ++++ .../gradle/plugin/SentryPlugin.kt | 115 ++++++++++++++++++ .../gradle}/plugin/TemplateExampleTask.kt | 2 +- .../template/plugin/TemplatePluginTest.kt | 43 ------- plugin-build/settings.gradle.kts | 3 +- .../shared/src/commonTest/kotlin/Test.kt | 8 ++ .../kmp-app-spm/shared/build.gradle.kts | 6 +- 11 files changed, 157 insertions(+), 189 deletions(-) delete mode 100644 plugin-build/plugin/src/main/java/com/ncorti/kotlin/gradle/template/plugin/TemplateExtension.kt delete mode 100644 plugin-build/plugin/src/main/java/com/ncorti/kotlin/gradle/template/plugin/TemplatePlugin.kt create mode 100644 plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryExtension.kt create mode 100644 plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt rename plugin-build/plugin/src/main/java/{com/ncorti/kotlin/gradle/template => io/sentry/kotlin/multiplatform/gradle}/plugin/TemplateExampleTask.kt (96%) delete mode 100644 plugin-build/plugin/src/test/java/com/ncorti/kotlin/gradle/template/plugin/TemplatePluginTest.kt create mode 100644 sentry-samples/kmp-app-cocoapods/shared/src/commonTest/kotlin/Test.kt diff --git a/plugin-build/gradle.properties b/plugin-build/gradle.properties index 3e4ac7f7..393aaf7c 100644 --- a/plugin-build/gradle.properties +++ b/plugin-build/gradle.properties @@ -1,8 +1,8 @@ -ID=com.ncorti.kotlin.gradle.template.plugin +ID=io.sentry.kotlin.multiplatform.gradle.plugin VERSION=1.0.0 -GROUP=com.ncorti.kotlin.gradle.template +GROUP=io.sentry DISPLAY_NAME=An empty Gradle Plugin from a template DESCRIPTION=An empty Gradle plugin created from a template WEBSITE=https://github.com/cortinico/kotlin-gradle-plugin-template VCS_URL=https://github.com/cortinico/kotlin-gradle-plugin-template -IMPLEMENTATION_CLASS=com.ncorti.kotlin.gradle.template.plugin.TemplatePlugin +IMPLEMENTATION_CLASS=io.sentry.kotlin.multiplatform.gradle.plugin.SentryPlugin diff --git a/plugin-build/plugin/build.gradle.kts b/plugin-build/plugin/build.gradle.kts index 3687159b..1a8015a7 100644 --- a/plugin-build/plugin/build.gradle.kts +++ b/plugin-build/plugin/build.gradle.kts @@ -11,7 +11,6 @@ dependencies { implementation(kotlin("stdlib")) implementation(gradleApi()) implementation(kotlin("gradle-plugin")) - implementation("com.squareup.okhttp3:okhttp:4.9.0") testImplementation(libs.junit) } diff --git a/plugin-build/plugin/src/main/java/com/ncorti/kotlin/gradle/template/plugin/TemplateExtension.kt b/plugin-build/plugin/src/main/java/com/ncorti/kotlin/gradle/template/plugin/TemplateExtension.kt deleted file mode 100644 index 7a8bec3b..00000000 --- a/plugin-build/plugin/src/main/java/com/ncorti/kotlin/gradle/template/plugin/TemplateExtension.kt +++ /dev/null @@ -1,28 +0,0 @@ -package com.ncorti.kotlin.gradle.template.plugin - -import org.gradle.api.Project -import org.gradle.api.file.RegularFileProperty -import org.gradle.api.provider.Property -import javax.inject.Inject - -const val DEFAULT_OUTPUT_FILE = "template-example.txt" - -@Suppress("UnnecessaryAbstractClass") -abstract class TemplateExtension - @Inject - constructor(project: Project) { - private val objects = project.objects - - // Example of a property that is mandatory. The task will - // fail if this property is not set as is annotated with @Optional. - val message: Property = objects.property(String::class.java) - - // Example of a property that is optional. - val tag: Property = objects.property(String::class.java) - - // Example of a property with a default set with .convention - val outputFile: RegularFileProperty = - objects.fileProperty().convention( - project.layout.buildDirectory.file(DEFAULT_OUTPUT_FILE), - ) - } diff --git a/plugin-build/plugin/src/main/java/com/ncorti/kotlin/gradle/template/plugin/TemplatePlugin.kt b/plugin-build/plugin/src/main/java/com/ncorti/kotlin/gradle/template/plugin/TemplatePlugin.kt deleted file mode 100644 index 8610822a..00000000 --- a/plugin-build/plugin/src/main/java/com/ncorti/kotlin/gradle/template/plugin/TemplatePlugin.kt +++ /dev/null @@ -1,111 +0,0 @@ -package com.ncorti.kotlin.gradle.template.plugin - -import okhttp3.OkHttpClient -import okhttp3.Request -import org.gradle.api.Plugin -import org.gradle.api.Project -import org.gradle.api.tasks.Copy -import org.gradle.configurationcache.extensions.capitalized -import org.jetbrains.kotlin.de.undercouch.gradle.tasks.download.Download -import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension -import org.jetbrains.kotlin.gradle.dsl.kotlinExtension -import org.jetbrains.kotlin.gradle.kpm.external.project -import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType -import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget -import java.io.File -import java.io.FileOutputStream -import java.io.IOException - -const val EXTENSION_NAME = "templateExampleConfig" -const val TASK_NAME = "templateExample" - -@Suppress("unused") -class TemplatePlugin : Plugin { - override fun apply(project: Project): Unit = with(project) { - afterEvaluate { - val extension = project.extensions.findByName("kotlin") - if (extension !is KotlinMultiplatformExtension) { - return@afterEvaluate - } - - val nativeTargets = extension.targets.withType(KotlinNativeTarget::class.java) - val targetNames = nativeTargets.map { target -> target.name } - val buildDir = it.layout.buildDirectory.asFile.get().path - - extension.addLinkerOpts(buildDir) - registerSentryDownloadTask() - registerDownloadAndUnzipSentryTask() - registerCopyFrameworkToTestDirsTask(targetNames) - - project.tasks.named { name -> name.contains("linkDebugTest") }.configureEach { task -> - task.dependsOn("copyFrameworkToTestDirs") - } - } - } -} - -private fun Project.registerSentryDownloadTask() { - tasks.register("downloadSentryFramework", Download::class.java) { download -> - val sentryVersion = project.findProperty("sentryVersion") as String? ?: "8.21.0" - val downloadPath = "${project.layout.buildDirectory.asFile.get().path}/sentry-temp" - val zipFile = "$downloadPath/Sentry.xcframework.zip" - - download.src("https://github.com/getsentry/sentry-cocoa/releases/download/$sentryVersion/Sentry.xcframework.zip") - download.dest(File(zipFile)) - download.overwrite(false) - } -} - -private fun Project.registerDownloadAndUnzipSentryTask() { - tasks.register("downloadAndUnzipSentryFramework", Copy::class.java) { copy -> - copy.dependsOn("downloadSentryFramework") - val zipFile = "$buildDir/sentry-temp/Sentry.xcframework.zip" - copy.from(zipTree(zipFile)) - copy.into("$buildDir/sentry-temp") - } -} - -private fun Project.registerCopyFrameworkToTestDirsTask(targetNames: List) { - tasks.register("copyFrameworkToTestDirs", Copy::class.java) { copy -> - copy.dependsOn("downloadAndUnzipSentryFramework") - targetNames.forEach { target -> - val platform = when (target) { - "iosSimulator64" -> "ios-arm64_x86_64-simulator" - // Add other mappings as needed for different targets - else -> null - } - if (platform != null) { - val frameworkPath = - "$buildDir/sentry-temp/Carthage/Build/Sentry.xcframework/$platform/Sentry.framework" - copy.from(project.fileTree(frameworkPath)) - copy.into("$buildDir/bin/${target}/debugTest/frameworks/Sentry.framework") - } - } - } -} - -private fun getFrameworkPath(buildDir: String, target: KotlinNativeTarget): String? { - val platform = when (target.name) { - "iosSimulator64" -> "ios-arm64_x86_64-simulator" - else -> null - } - return platform?.let { "$buildDir/sentry-temp/Carthage/Build/Sentry.xcframework/$it/Sentry.framework" } -} - -private fun KotlinMultiplatformExtension.addLinkerOpts(buildDir: String) { - targets.withType(KotlinNativeTarget::class.java).forEach { target -> - target.compilations.all { - if (it.compilationName == "test" && it.target.platformType == KotlinPlatformType.native) { - it.compilerOptions.configure { - freeCompilerArgs.add("-linker-options") - val platform: String? = when (target.name) { - "iosSimulatorArm64" -> "ios-arm64_x86_64-simulator" - else -> null - } - val path = "$buildDir/sentry-temp/Carthage/Build/Sentry.xcframework/$platform/" - freeCompilerArgs.add("-F$path") - } - } - } - } -} \ No newline at end of file diff --git a/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryExtension.kt b/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryExtension.kt new file mode 100644 index 00000000..9841a718 --- /dev/null +++ b/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryExtension.kt @@ -0,0 +1,23 @@ +package io.sentry.kotlin.multiplatform.gradle.plugin + +import org.gradle.api.Project +import org.gradle.api.provider.Property +import javax.inject.Inject + +@Suppress("UnnecessaryAbstractClass") +abstract class SentryExtension +@Inject +constructor(project: Project) { + private val objects = project.objects + + val sentryCocoaVersion: Property = objects.property(String::class.java) + + /** + * When enabled the plugin will download the Sentry.xcframework and link the framework with linkeropts. + * This fixes the issue with the Sentry framework not being found when running tests on Apple targets. + * + * Defaults to `true`. + */ + val enableSentryTestLinking: Property = + objects.property(Boolean::class.java).convention(true) +} diff --git a/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt b/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt new file mode 100644 index 00000000..cc411097 --- /dev/null +++ b/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt @@ -0,0 +1,115 @@ +package io.sentry.kotlin.multiplatform.gradle.plugin + +import org.gradle.api.NamedDomainObjectCollection +import org.gradle.api.Plugin +import org.gradle.api.Project +import org.gradle.api.file.DuplicatesStrategy +import org.gradle.api.tasks.Copy +import org.jetbrains.kotlin.de.undercouch.gradle.tasks.download.Download +import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension +import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType +import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget +import java.io.File + +const val EXTENSION_NAME = "sentry" +const val TASK_NAME = "templateExample" + +@Suppress("unused") +class SentryPlugin : Plugin { + override fun apply(project: Project): Unit = with(project) { + val extension = project.extensions.create(EXTENSION_NAME, SentryExtension::class.java, project) + + afterEvaluate { + if (extension.enableSentryTestLinking.get()) { + setupSentryFrameworkForTests() + } + } + } + + companion object { + private const val KOTLIN_EXTENSION_NAME = "kotlin" + } + + private fun Project.setupSentryFrameworkForTests() { + val extension = this.extensions.findByName(KOTLIN_EXTENSION_NAME) + + if (extension !is KotlinMultiplatformExtension) { + return + } + + val nativeTargets = extension.targets.withType(KotlinNativeTarget::class.java) + val buildDir = layout.buildDirectory.asFile.get().path + + extension.addLinkerOpts(buildDir) + registerSentryDownloadTask() + registerDownloadAndUnzipSentryTask() + registerCopyFrameworkToTestDirsTask(nativeTargets) + + tasks.named { name -> name.contains("linkDebugTest") }.configureEach { task -> + task.dependsOn("copyFrameworkToTestDirs") + } + } + + private fun Project.registerSentryDownloadTask() { + val buildDir = layout.buildDirectory.asFile.get().path + tasks.register("downloadSentryFramework", Download::class.java) { download -> + val sentryVersion = project.findProperty("sentryVersion") as String? ?: "8.21.0" + val downloadPath = "$buildDir/sentry-temp" + val zipFile = "$downloadPath/Sentry.xcframework.zip" + + download.src("https://github.com/getsentry/sentry-cocoa/releases/download/$sentryVersion/Sentry.xcframework.zip") + download.dest(File(zipFile)) + download.overwrite(false) + } + } + + private fun Project.registerDownloadAndUnzipSentryTask() { + val buildDir = layout.buildDirectory.asFile.get().path + tasks.register("downloadAndUnzipSentryFramework", Copy::class.java) { copy -> + copy.dependsOn("downloadSentryFramework") + val zipFile = "$buildDir/sentry-temp/Sentry.xcframework.zip" + copy.from(zipTree(zipFile)) + copy.into("$buildDir/sentry-temp") + } + } + + private fun Project.registerCopyFrameworkToTestDirsTask(targets: NamedDomainObjectCollection) { + val buildDir = layout.buildDirectory.asFile.get().path + tasks.register("copyFrameworkToTestDirs", Copy::class.java) { copy -> + copy.dependsOn("downloadAndUnzipSentryFramework") + + copy.duplicatesStrategy = DuplicatesStrategy.INCLUDE + + targets.forEach { target -> + val frameworkPath = + "$buildDir/sentry-temp/Carthage/Build/Sentry.xcframework/${target.xcFrameworkDir()}/Sentry.framework" + copy.from(fileTree(frameworkPath)) + copy.into("$buildDir/bin/${target.name}/debugTest/frameworks/Sentry.framework") + } + } + } + + private fun KotlinNativeTarget.xcFrameworkDir(): String? { + return when (name) { + "iosSimulatorArm64" -> "ios-arm64_x86_64-simulator" + "iosX64" -> "ios-arm64_x86_64-simulator" // TODO: check if this is correct + "iosArm64" -> "ios-arm64" + else -> null + } + } + + private fun KotlinMultiplatformExtension.addLinkerOpts(buildDir: String) { + targets.withType(KotlinNativeTarget::class.java).forEach { target -> + target.compilations.all { + if (it.compilationName == "test" && it.target.platformType == KotlinPlatformType.native) { + it.compilerOptions.configure { + freeCompilerArgs.add("-linker-options") + val path = + "$buildDir/sentry-temp/Carthage/Build/Sentry.xcframework/${target.xcFrameworkDir()}/" + freeCompilerArgs.add("-F$path") + } + } + } + } + } +} \ No newline at end of file diff --git a/plugin-build/plugin/src/main/java/com/ncorti/kotlin/gradle/template/plugin/TemplateExampleTask.kt b/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/TemplateExampleTask.kt similarity index 96% rename from plugin-build/plugin/src/main/java/com/ncorti/kotlin/gradle/template/plugin/TemplateExampleTask.kt rename to plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/TemplateExampleTask.kt index 0ddd20fc..7f108a99 100644 --- a/plugin-build/plugin/src/main/java/com/ncorti/kotlin/gradle/template/plugin/TemplateExampleTask.kt +++ b/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/TemplateExampleTask.kt @@ -1,4 +1,4 @@ -package com.ncorti.kotlin.gradle.template.plugin +package io.sentry.kotlin.multiplatform.gradle.plugin import org.gradle.api.DefaultTask import org.gradle.api.file.RegularFileProperty diff --git a/plugin-build/plugin/src/test/java/com/ncorti/kotlin/gradle/template/plugin/TemplatePluginTest.kt b/plugin-build/plugin/src/test/java/com/ncorti/kotlin/gradle/template/plugin/TemplatePluginTest.kt deleted file mode 100644 index 9b45d64d..00000000 --- a/plugin-build/plugin/src/test/java/com/ncorti/kotlin/gradle/template/plugin/TemplatePluginTest.kt +++ /dev/null @@ -1,43 +0,0 @@ -package com.ncorti.kotlin.gradle.template.plugin - -import org.gradle.testfixtures.ProjectBuilder -import org.junit.Assert.assertEquals -import org.junit.Assert.assertNotNull -import org.junit.Test -import java.io.File - -class TemplatePluginTest { - @Test - fun `plugin is applied correctly to the project`() { - val project = ProjectBuilder.builder().build() - project.pluginManager.apply("com.ncorti.kotlin.gradle.template.plugin") - - assert(project.tasks.getByName("templateExample") is TemplateExampleTask) - } - - @Test - fun `extension templateExampleConfig is created correctly`() { - val project = ProjectBuilder.builder().build() - project.pluginManager.apply("com.ncorti.kotlin.gradle.template.plugin") - - assertNotNull(project.extensions.getByName("templateExampleConfig")) - } - - @Test - fun `parameters are passed correctly from extension to task`() { - val project = ProjectBuilder.builder().build() - project.pluginManager.apply("com.ncorti.kotlin.gradle.template.plugin") - val aFile = File(project.projectDir, ".tmp") - (project.extensions.getByName("templateExampleConfig") as TemplateExtension).apply { - tag.set("a-sample-tag") - message.set("just-a-message") - outputFile.set(aFile) - } - - val task = project.tasks.getByName("templateExample") as TemplateExampleTask - - assertEquals("a-sample-tag", task.tag.get()) - assertEquals("just-a-message", task.message.get()) - assertEquals(aFile, task.outputFile.get().asFile) - } -} diff --git a/plugin-build/settings.gradle.kts b/plugin-build/settings.gradle.kts index 2103a968..d2d74964 100644 --- a/plugin-build/settings.gradle.kts +++ b/plugin-build/settings.gradle.kts @@ -25,6 +25,7 @@ gradleEnterprise { } } -rootProject.name = ("com.ncorti.kotlin.gradle.template") +rootProject.name = ("io.sentry.kotlin.multiplatform.gradle.plugin") include(":plugin") +include(":${rootProject.name}:buildSrc") diff --git a/sentry-samples/kmp-app-cocoapods/shared/src/commonTest/kotlin/Test.kt b/sentry-samples/kmp-app-cocoapods/shared/src/commonTest/kotlin/Test.kt new file mode 100644 index 00000000..f03d75f5 --- /dev/null +++ b/sentry-samples/kmp-app-cocoapods/shared/src/commonTest/kotlin/Test.kt @@ -0,0 +1,8 @@ +import kotlin.test.Test + +class Test { + @Test + fun test() { + print("see if this runs") + } +} \ No newline at end of file diff --git a/sentry-samples/kmp-app-spm/shared/build.gradle.kts b/sentry-samples/kmp-app-spm/shared/build.gradle.kts index 199f7ec1..88ab52d1 100644 --- a/sentry-samples/kmp-app-spm/shared/build.gradle.kts +++ b/sentry-samples/kmp-app-spm/shared/build.gradle.kts @@ -3,7 +3,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { kotlin("multiplatform") id("com.android.library") - id("com.ncorti.kotlin.gradle.template.plugin") + id("io.sentry.kotlin.multiplatform.gradle.plugin") } java { @@ -50,3 +50,7 @@ android { minSdk = Config.Android.minSdkVersion } } + +sentry { + enableSentryTestLinking = false +} \ No newline at end of file From 34105106fffbdaf94b8a6d7ac8977176da897b4c Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Fri, 26 Apr 2024 01:50:39 +0200 Subject: [PATCH 04/78] Update --- plugin-build/settings.gradle.kts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugin-build/settings.gradle.kts b/plugin-build/settings.gradle.kts index d2d74964..bc6a5480 100644 --- a/plugin-build/settings.gradle.kts +++ b/plugin-build/settings.gradle.kts @@ -27,5 +27,4 @@ gradleEnterprise { rootProject.name = ("io.sentry.kotlin.multiplatform.gradle.plugin") -include(":plugin") -include(":${rootProject.name}:buildSrc") +include(":plugin") \ No newline at end of file From 2499417d372347a17c7739980d70846a1f16c2a7 Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Fri, 3 May 2024 02:44:13 +0200 Subject: [PATCH 05/78] Update --- .run/iosApp-spm.run.xml | 2 +- buildSrc/src/main/java/Config.kt | 2 +- .../gradle/plugin/SentryPlugin.kt | 20 ++++++++++++++++++- sentry-kotlin-multiplatform/build.gradle.kts | 5 ++++- .../sentry_kotlin_multiplatform.podspec | 2 +- .../kmp-app-cocoapods/iosApp/Podfile.lock | 17 ++++++---------- .../kmp-app-cocoapods/shared/build.gradle.kts | 6 +++++- .../kmp-app-cocoapods/shared/shared.podspec | 2 +- .../kmp-app-spm/desktopApp/build.gradle.kts | 2 +- .../iosApp.xcodeproj/project.pbxproj | 5 ++++- .../xcshareddata/swiftpm/Package.resolved | 7 ++++--- .../kmp-app-spm/shared/build.gradle.kts | 8 ++++---- settings.gradle.kts | 6 +++--- 13 files changed, 54 insertions(+), 30 deletions(-) diff --git a/.run/iosApp-spm.run.xml b/.run/iosApp-spm.run.xml index 6295acd9..97e33f02 100644 --- a/.run/iosApp-spm.run.xml +++ b/.run/iosApp-spm.run.xml @@ -1,5 +1,5 @@ - + diff --git a/buildSrc/src/main/java/Config.kt b/buildSrc/src/main/java/Config.kt index cbce6d75..d92353d8 100644 --- a/buildSrc/src/main/java/Config.kt +++ b/buildSrc/src/main/java/Config.kt @@ -36,7 +36,7 @@ object Config { val sentryAndroid = "io.sentry:sentry-android:$sentryJavaVersion" val sentryJava = "io.sentry:sentry:$sentryJavaVersion" - val sentryCocoaVersion = "8.20.0" + val sentryCocoaVersion = "8.25.0" val sentryCocoa = "Sentry" object Samples { diff --git a/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt b/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt index cc411097..18bdc1ec 100644 --- a/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt +++ b/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt @@ -4,10 +4,12 @@ import org.gradle.api.NamedDomainObjectCollection import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.api.file.DuplicatesStrategy +import org.gradle.api.plugins.ExtensionAware import org.gradle.api.tasks.Copy import org.jetbrains.kotlin.de.undercouch.gradle.tasks.download.Download import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType +import org.jetbrains.kotlin.gradle.plugin.cocoapods.CocoapodsExtension import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget import java.io.File @@ -18,11 +20,27 @@ const val TASK_NAME = "templateExample" class SentryPlugin : Plugin { override fun apply(project: Project): Unit = with(project) { val extension = project.extensions.create(EXTENSION_NAME, SentryExtension::class.java, project) - afterEvaluate { if (extension.enableSentryTestLinking.get()) { setupSentryFrameworkForTests() } + + println("hello") + val extension = this.extensions.findByName(KOTLIN_EXTENSION_NAME) + if (extension !is KotlinMultiplatformExtension) { + return@afterEvaluate + } + + (extension as ExtensionAware).extensions.configure(CocoapodsExtension::class.java) { cocoapods -> + println(cocoapods.pods.size) + cocoapods.pods.forEach { pod -> + println(pod.name) + } + } + +// println(project.plugins.findPlugin("org.jetbrains.kotlin.native.cocoapods")) + +// println(project.extensions.getByType(CocoapodsExtension::class.java)) } } diff --git a/sentry-kotlin-multiplatform/build.gradle.kts b/sentry-kotlin-multiplatform/build.gradle.kts index de4b815e..45dda945 100644 --- a/sentry-kotlin-multiplatform/build.gradle.kts +++ b/sentry-kotlin-multiplatform/build.gradle.kts @@ -145,7 +145,10 @@ kotlin { homepage = "https://github.com/getsentry/sentry-kotlin-multiplatform" version = "0.0.1" - pod(Config.Libs.sentryCocoa, Config.Libs.sentryCocoaVersion) + pod(Config.Libs.sentryCocoa) { + version = Config.Libs.sentryCocoaVersion + extraOpts += listOf("-compiler-option", "-fmodules") + } ios.deploymentTarget = Config.Cocoa.iosDeploymentTarget osx.deploymentTarget = Config.Cocoa.osxDeploymentTarget diff --git a/sentry-kotlin-multiplatform/sentry_kotlin_multiplatform.podspec b/sentry-kotlin-multiplatform/sentry_kotlin_multiplatform.podspec index fd365097..d99a70af 100644 --- a/sentry-kotlin-multiplatform/sentry_kotlin_multiplatform.podspec +++ b/sentry-kotlin-multiplatform/sentry_kotlin_multiplatform.podspec @@ -12,7 +12,7 @@ Pod::Spec.new do |spec| spec.osx.deployment_target = '10.13' spec.tvos.deployment_target = '11.0' spec.watchos.deployment_target = '4.0' - spec.dependency 'Sentry', '8.20.0' + spec.dependency 'Sentry', '8.25.0' if !Dir.exist?('build/cocoapods/framework/sentry_kotlin_multiplatform.framework') || Dir.empty?('build/cocoapods/framework/sentry_kotlin_multiplatform.framework') raise " diff --git a/sentry-samples/kmp-app-cocoapods/iosApp/Podfile.lock b/sentry-samples/kmp-app-cocoapods/iosApp/Podfile.lock index ea11a31b..20ce8b8e 100644 --- a/sentry-samples/kmp-app-cocoapods/iosApp/Podfile.lock +++ b/sentry-samples/kmp-app-cocoapods/iosApp/Podfile.lock @@ -1,12 +1,9 @@ PODS: - - Sentry (8.20.0): - - Sentry/Core (= 8.20.0) - - SentryPrivate (= 8.20.0) - - Sentry/Core (8.20.0): - - SentryPrivate (= 8.20.0) - - SentryPrivate (8.20.0) + - Sentry (8.25.0): + - Sentry/Core (= 8.25.0) + - Sentry/Core (8.25.0) - shared (1.0): - - Sentry (= 8.20.0) + - Sentry (= 8.25.0) DEPENDENCIES: - shared (from `../shared`) @@ -14,16 +11,14 @@ DEPENDENCIES: SPEC REPOS: trunk: - Sentry - - SentryPrivate EXTERNAL SOURCES: shared: :path: "../shared" SPEC CHECKSUMS: - Sentry: a8d7b373b9f9868442b02a0c425192f693103cbf - SentryPrivate: 006b24af16828441f70e2ab6adf241bd0a8ad130 - shared: 1f6c0649407365a649be810e8ee7f09e1fc32868 + Sentry: cd86fc55628f5b7c572cabe66cc8f95a9d2f165a + shared: 9b60306d775c7bb09035fb0d355ab1a6f253e819 PODFILE CHECKSUM: f282da88f39e69507b0a255187c8a6b644477756 diff --git a/sentry-samples/kmp-app-cocoapods/shared/build.gradle.kts b/sentry-samples/kmp-app-cocoapods/shared/build.gradle.kts index b6537b4b..56f54271 100644 --- a/sentry-samples/kmp-app-cocoapods/shared/build.gradle.kts +++ b/sentry-samples/kmp-app-cocoapods/shared/build.gradle.kts @@ -4,6 +4,7 @@ plugins { kotlin("multiplatform") kotlin("native.cocoapods") id("com.android.library") + id("io.sentry.kotlin.multiplatform.gradle.plugin") } java { @@ -31,7 +32,10 @@ kotlin { ios.deploymentTarget = "14.1" podfile = project.file("../iosApp/Podfile") - pod("Sentry", Config.Libs.sentryCocoaVersion) + pod("Sentry") { + version = Config.Libs.sentryCocoaVersion + extraOpts += listOf("-compiler-option", "-fmodules") + } framework { baseName = "shared" diff --git a/sentry-samples/kmp-app-cocoapods/shared/shared.podspec b/sentry-samples/kmp-app-cocoapods/shared/shared.podspec index 46ad91f3..59f24592 100644 --- a/sentry-samples/kmp-app-cocoapods/shared/shared.podspec +++ b/sentry-samples/kmp-app-cocoapods/shared/shared.podspec @@ -9,7 +9,7 @@ Pod::Spec.new do |spec| spec.vendored_frameworks = 'build/cocoapods/framework/shared.framework' spec.libraries = 'c++' spec.ios.deployment_target = '14.1' - spec.dependency 'Sentry', '8.20.0' + spec.dependency 'Sentry', '8.25.0' if !Dir.exist?('build/cocoapods/framework/shared.framework') || Dir.empty?('build/cocoapods/framework/shared.framework') raise " diff --git a/sentry-samples/kmp-app-spm/desktopApp/build.gradle.kts b/sentry-samples/kmp-app-spm/desktopApp/build.gradle.kts index dfb98898..637dd0f1 100644 --- a/sentry-samples/kmp-app-spm/desktopApp/build.gradle.kts +++ b/sentry-samples/kmp-app-spm/desktopApp/build.gradle.kts @@ -31,7 +31,7 @@ kotlin { sourceSets { val jvmMain by getting { dependencies { - implementation(rootProject.project(":sentry-samples:kmp-app-cocoapods:shared")) +// implementation(rootProject.project(":sentry-samples:kmp-app-cocoapods:shared")) implementation(compose.desktop.currentOs) } } diff --git a/sentry-samples/kmp-app-spm/iosApp.xcodeproj/project.pbxproj b/sentry-samples/kmp-app-spm/iosApp.xcodeproj/project.pbxproj index 4fc741d7..1f72511d 100644 --- a/sentry-samples/kmp-app-spm/iosApp.xcodeproj/project.pbxproj +++ b/sentry-samples/kmp-app-spm/iosApp.xcodeproj/project.pbxproj @@ -355,6 +355,8 @@ "$(inherited)", "@executable_path/Frameworks", ); + OTHER_CFLAGS = ""; + "OTHER_CFLAGS[arch=*]" = "\"-compiler-option -fmodules\""; OTHER_LDFLAGS = ( "$(inherited)", "-framework", @@ -380,6 +382,7 @@ "$(inherited)", "@executable_path/Frameworks", ); + OTHER_CFLAGS = ""; OTHER_LDFLAGS = ( "$(inherited)", "-framework", @@ -421,7 +424,7 @@ repositoryURL = "https://github.com/getsentry/sentry-cocoa.git"; requirement = { kind = exactVersion; - version = 8.20.0; + version = 8.25.0; }; }; /* End XCRemoteSwiftPackageReference section */ diff --git a/sentry-samples/kmp-app-spm/iosApp.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/sentry-samples/kmp-app-spm/iosApp.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 50e76216..a2546f12 100644 --- a/sentry-samples/kmp-app-spm/iosApp.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/sentry-samples/kmp-app-spm/iosApp.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -1,14 +1,15 @@ { + "originHash" : "7b5e54f81ac1ebaa640945691cb38c371b637198701f04fba811702fc8e7067e", "pins" : [ { "identity" : "sentry-cocoa", "kind" : "remoteSourceControl", "location" : "https://github.com/getsentry/sentry-cocoa.git", "state" : { - "revision" : "b847a202a517a90763e8fd0656d8028aeee7b78d", - "version" : "8.20.0" + "revision" : "82af013792dca3784a2dc5e7f975159fb9d263b3", + "version" : "8.25.0" } } ], - "version" : 2 + "version" : 3 } diff --git a/sentry-samples/kmp-app-spm/shared/build.gradle.kts b/sentry-samples/kmp-app-spm/shared/build.gradle.kts index 88ab52d1..ffec72d1 100644 --- a/sentry-samples/kmp-app-spm/shared/build.gradle.kts +++ b/sentry-samples/kmp-app-spm/shared/build.gradle.kts @@ -3,7 +3,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { kotlin("multiplatform") id("com.android.library") - id("io.sentry.kotlin.multiplatform.gradle.plugin") +// id("io.sentry.kotlin.multiplatform.gradle.plugin") } java { @@ -51,6 +51,6 @@ android { } } -sentry { - enableSentryTestLinking = false -} \ No newline at end of file +//sentry { +// enableSentryTestLinking = false +//} \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index 6c747e4a..de561143 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -38,9 +38,9 @@ Simple KMP App with targets: - iOS with SwiftUI and Cocoapods - JVM Desktop with Jetpack Compose */ -include("sentry-samples:kmp-app-cocoapods:shared") -include("sentry-samples:kmp-app-cocoapods:androidApp") -include("sentry-samples:kmp-app-cocoapods:desktopApp") +//include("sentry-samples:kmp-app-cocoapods:shared") +//include("sentry-samples:kmp-app-cocoapods:androidApp") +//include("sentry-samples:kmp-app-cocoapods:desktopApp") /* KMP App with MVVM and Dependency Injection with Koin: From e1ba06b4781946fed1fc25e6884a091a7e56dc58 Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Sat, 4 May 2024 03:07:36 +0200 Subject: [PATCH 06/78] Update plugin --- .../gradle/plugin/SentryExtension.kt | 5 +- .../gradle/plugin/SentryPlugin.kt | 72 ++++++++++--------- 2 files changed, 42 insertions(+), 35 deletions(-) diff --git a/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryExtension.kt b/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryExtension.kt index 9841a718..5a146d09 100644 --- a/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryExtension.kt +++ b/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryExtension.kt @@ -13,10 +13,11 @@ constructor(project: Project) { val sentryCocoaVersion: Property = objects.property(String::class.java) /** - * When enabled the plugin will download the Sentry.xcframework and link the framework with linkeropts. + * When enabled the plugin will download the Sentry.xcframework and link the framework with linker-opts. * This fixes the issue with the Sentry framework not being found when running tests on Apple targets. + * For example when trying to run tests using SPM. * - * Defaults to `true`. + * Defaults to `true` but is automatically **disabled** if the Cocoapods Gradle plugin is available. */ val enableSentryTestLinking: Property = objects.property(Boolean::class.java).convention(true) diff --git a/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt b/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt index 18bdc1ec..ce89f0c6 100644 --- a/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt +++ b/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt @@ -1,9 +1,7 @@ package io.sentry.kotlin.multiplatform.gradle.plugin -import org.gradle.api.NamedDomainObjectCollection import org.gradle.api.Plugin import org.gradle.api.Project -import org.gradle.api.file.DuplicatesStrategy import org.gradle.api.plugins.ExtensionAware import org.gradle.api.tasks.Copy import org.jetbrains.kotlin.de.undercouch.gradle.tasks.download.Download @@ -14,38 +12,45 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget import java.io.File const val EXTENSION_NAME = "sentry" -const val TASK_NAME = "templateExample" +const val COCOAPODS_PLUGIN_NAME = "org.jetbrains.kotlin.plugin.cocoapods" +const val KOTLIN_EXTENSION_NAME = "kotlin" @Suppress("unused") class SentryPlugin : Plugin { override fun apply(project: Project): Unit = with(project) { - val extension = project.extensions.create(EXTENSION_NAME, SentryExtension::class.java, project) + val extension = + project.extensions.create(EXTENSION_NAME, SentryExtension::class.java, project) afterEvaluate { - if (extension.enableSentryTestLinking.get()) { - setupSentryFrameworkForTests() - } - - println("hello") - val extension = this.extensions.findByName(KOTLIN_EXTENSION_NAME) - if (extension !is KotlinMultiplatformExtension) { - return@afterEvaluate - } - - (extension as ExtensionAware).extensions.configure(CocoapodsExtension::class.java) { cocoapods -> - println(cocoapods.pods.size) - cocoapods.pods.forEach { pod -> - println(pod.name) + val hasCocoapodsPlugin = project.pluginManager.hasPlugin(COCOAPODS_PLUGIN_NAME) + if (hasCocoapodsPlugin) { + setupCocoapods() + } else { + if (extension.enableSentryTestLinking.get()) { + // Test linking is only necessary when NOT using the Kotlin Cocoapods plugin + setupSentryFrameworkForTests() } } - -// println(project.plugins.findPlugin("org.jetbrains.kotlin.native.cocoapods")) - -// println(project.extensions.getByType(CocoapodsExtension::class.java)) } } - companion object { - private const val KOTLIN_EXTENSION_NAME = "kotlin" + /** + * Installs the Sentry pod if not yet installed and configures the compiler options + */ + private fun Project.setupCocoapods() { + val kmpExtension = this.extensions.findByName(KOTLIN_EXTENSION_NAME) + (kmpExtension as ExtensionAware).extensions.configure(CocoapodsExtension::class.java) { cocoapods -> + val sentryPod = cocoapods.pods.findByName("Sentry") + if (sentryPod == null) { + cocoapods.pod("Sentry") { + version = "8.25.0" + extraOpts += listOf("-compiler-option", "-fmodules") + } + } else { + if (!sentryPod.extraOpts.contains("-fmodules")) { + sentryPod.extraOpts += listOf("-compiler-option", "-fmodules") + } + } + } } private fun Project.setupSentryFrameworkForTests() { @@ -55,13 +60,14 @@ class SentryPlugin : Plugin { return } - val nativeTargets = extension.targets.withType(KotlinNativeTarget::class.java) + val appleTargets = extension.targets.withType(KotlinNativeTarget::class.java) + .filter { it.konanTarget.family.isAppleFamily } val buildDir = layout.buildDirectory.asFile.get().path extension.addLinkerOpts(buildDir) registerSentryDownloadTask() registerDownloadAndUnzipSentryTask() - registerCopyFrameworkToTestDirsTask(nativeTargets) + registerCopyFrameworkToTestDirsTask(appleTargets) tasks.named { name -> name.contains("linkDebugTest") }.configureEach { task -> task.dependsOn("copyFrameworkToTestDirs") @@ -71,7 +77,7 @@ class SentryPlugin : Plugin { private fun Project.registerSentryDownloadTask() { val buildDir = layout.buildDirectory.asFile.get().path tasks.register("downloadSentryFramework", Download::class.java) { download -> - val sentryVersion = project.findProperty("sentryVersion") as String? ?: "8.21.0" + val sentryVersion = project.findProperty("sentryVersion") as String? ?: "8.25.0" val downloadPath = "$buildDir/sentry-temp" val zipFile = "$downloadPath/Sentry.xcframework.zip" @@ -91,18 +97,18 @@ class SentryPlugin : Plugin { } } - private fun Project.registerCopyFrameworkToTestDirsTask(targets: NamedDomainObjectCollection) { + private fun Project.registerCopyFrameworkToTestDirsTask(targets: List) { val buildDir = layout.buildDirectory.asFile.get().path tasks.register("copyFrameworkToTestDirs", Copy::class.java) { copy -> copy.dependsOn("downloadAndUnzipSentryFramework") - copy.duplicatesStrategy = DuplicatesStrategy.INCLUDE - targets.forEach { target -> val frameworkPath = "$buildDir/sentry-temp/Carthage/Build/Sentry.xcframework/${target.xcFrameworkDir()}/Sentry.framework" - copy.from(fileTree(frameworkPath)) - copy.into("$buildDir/bin/${target.name}/debugTest/frameworks/Sentry.framework") + copy { + it.from(fileTree(frameworkPath)) + it.into("$buildDir/bin/${target.name}/debugTest/frameworks/Sentry.framework") + } } } } @@ -110,7 +116,7 @@ class SentryPlugin : Plugin { private fun KotlinNativeTarget.xcFrameworkDir(): String? { return when (name) { "iosSimulatorArm64" -> "ios-arm64_x86_64-simulator" - "iosX64" -> "ios-arm64_x86_64-simulator" // TODO: check if this is correct + "iosX64" -> "ios-arm64_x86_64-simulator" "iosArm64" -> "ios-arm64" else -> null } From 3937b0162d1765b3768d38bebeebab9076a784be Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Sat, 4 May 2024 03:08:31 +0200 Subject: [PATCH 07/78] Update --- .../multiplatform/gradle/plugin/SentryPlugin.kt | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt b/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt index ce89f0c6..68967e87 100644 --- a/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt +++ b/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt @@ -38,6 +38,10 @@ class SentryPlugin : Plugin { */ private fun Project.setupCocoapods() { val kmpExtension = this.extensions.findByName(KOTLIN_EXTENSION_NAME) + if (kmpExtension !is KotlinMultiplatformExtension) { + return + } + (kmpExtension as ExtensionAware).extensions.configure(CocoapodsExtension::class.java) { cocoapods -> val sentryPod = cocoapods.pods.findByName("Sentry") if (sentryPod == null) { @@ -54,17 +58,16 @@ class SentryPlugin : Plugin { } private fun Project.setupSentryFrameworkForTests() { - val extension = this.extensions.findByName(KOTLIN_EXTENSION_NAME) - - if (extension !is KotlinMultiplatformExtension) { + val kmpExtension = this.extensions.findByName(KOTLIN_EXTENSION_NAME) + if (kmpExtension !is KotlinMultiplatformExtension) { return } - val appleTargets = extension.targets.withType(KotlinNativeTarget::class.java) + val appleTargets = kmpExtension.targets.withType(KotlinNativeTarget::class.java) .filter { it.konanTarget.family.isAppleFamily } val buildDir = layout.buildDirectory.asFile.get().path - extension.addLinkerOpts(buildDir) + kmpExtension.addLinkerOpts(buildDir) registerSentryDownloadTask() registerDownloadAndUnzipSentryTask() registerCopyFrameworkToTestDirsTask(appleTargets) From 54380662fcbad9f75886a29713cc870b8f5b18e2 Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Wed, 15 May 2024 12:22:37 +0200 Subject: [PATCH 08/78] Update --- plugin-build/build.gradle.kts | 4 ---- plugin-build/gradle/libs.versions.toml | 1 + plugin-build/gradle/wrapper | 1 + plugin-build/gradlew | 1 + plugin-build/gradlew.bat | 1 + plugin-build/plugin/build.gradle.kts | 31 +++++++++++++++++--------- 6 files changed, 24 insertions(+), 15 deletions(-) create mode 120000 plugin-build/gradle/wrapper create mode 120000 plugin-build/gradlew create mode 120000 plugin-build/gradlew.bat diff --git a/plugin-build/build.gradle.kts b/plugin-build/build.gradle.kts index 908ab692..cfd2f0a5 100644 --- a/plugin-build/build.gradle.kts +++ b/plugin-build/build.gradle.kts @@ -45,7 +45,3 @@ tasks.withType().configureEach { tasks.register("clean", Delete::class.java) { delete(rootProject.layout.buildDirectory) } - -tasks.wrapper { - distributionType = Wrapper.DistributionType.ALL -} diff --git a/plugin-build/gradle/libs.versions.toml b/plugin-build/gradle/libs.versions.toml index dc4894dd..92ea4d16 100644 --- a/plugin-build/gradle/libs.versions.toml +++ b/plugin-build/gradle/libs.versions.toml @@ -11,6 +11,7 @@ kotlin = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin"} ktlint = { id = "org.jlleitschuh.gradle.ktlint", version.ref = "ktlintGradle"} pluginPublish = { id = "com.gradle.plugin-publish", version.ref = "pluginPublish"} versionCheck = { id = "com.github.ben-manes.versions", version.ref = "versionCheck"} +vanniktech-publish = { id = "com.vanniktech.maven.publish", version = "0.18.0"} [libraries] junit = "junit:junit:4.13.2" diff --git a/plugin-build/gradle/wrapper b/plugin-build/gradle/wrapper new file mode 120000 index 00000000..3232fe4e --- /dev/null +++ b/plugin-build/gradle/wrapper @@ -0,0 +1 @@ +../../gradle/wrapper \ No newline at end of file diff --git a/plugin-build/gradlew b/plugin-build/gradlew new file mode 120000 index 00000000..502f5a2d --- /dev/null +++ b/plugin-build/gradlew @@ -0,0 +1 @@ +../gradlew \ No newline at end of file diff --git a/plugin-build/gradlew.bat b/plugin-build/gradlew.bat new file mode 120000 index 00000000..28401328 --- /dev/null +++ b/plugin-build/gradlew.bat @@ -0,0 +1 @@ +../gradlew.bat \ No newline at end of file diff --git a/plugin-build/plugin/build.gradle.kts b/plugin-build/plugin/build.gradle.kts index 1a8015a7..603ebad3 100644 --- a/plugin-build/plugin/build.gradle.kts +++ b/plugin-build/plugin/build.gradle.kts @@ -1,10 +1,13 @@ +import com.vanniktech.maven.publish.MavenPublishPluginExtension import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { kotlin("jvm") `java-gradle-plugin` - alias(libs.plugins.pluginPublish) +// alias(libs.plugins.pluginPublish) id("de.undercouch.download") version "5.6.0" + alias(libs.plugins.vanniktech.publish) + id("distribution") } dependencies { @@ -44,16 +47,22 @@ gradlePlugin { vcsUrl.set(property("VCS_URL").toString()) } -tasks.create("setupPluginUploadFromEnvironment") { - doLast { - val key = System.getenv("GRADLE_PUBLISH_KEY") - val secret = System.getenv("GRADLE_PUBLISH_SECRET") +val publish = extensions.getByType(MavenPublishPluginExtension::class.java) +// signing is done when uploading files to MC +// via gpg:sign-and-deploy-file (release.kts) +publish.releaseSigningEnabled = false - if (key == null || secret == null) { - throw GradleException("gradlePublishKey and/or gradlePublishSecret are not defined environment variables") - } +tasks.named("distZip").configure { + dependsOn("publishToMavenLocal") +} + +val sep = File.separator - System.setProperty("gradle.publish.key", key) - System.setProperty("gradle.publish.secret", secret) +distributions { + main { + contents { + from("build${sep}libs") + from("build${sep}publications${sep}maven") + } } -} +} \ No newline at end of file From f6b4e7cde7348892962db9ae0ebd308821de6a42 Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Wed, 5 Jun 2024 20:57:01 +0200 Subject: [PATCH 09/78] Update --- .../gradle/plugin/LinkerExtension.kt | 15 ++ .../gradle/plugin/SentryExtension.kt | 4 + .../gradle/plugin/SentryPlugin.kt | 219 ++++++++++-------- .../iosApp.xcodeproj/project.pbxproj | 20 +- .../xcshareddata/swiftpm/Package.resolved | 4 +- .../kmp-app-spm/shared/build.gradle.kts | 12 +- .../kmp-app-spm/shared/shared.podspec | 50 ++++ 7 files changed, 211 insertions(+), 113 deletions(-) create mode 100644 plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/LinkerExtension.kt create mode 100644 sentry-samples/kmp-app-spm/shared/shared.podspec diff --git a/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/LinkerExtension.kt b/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/LinkerExtension.kt new file mode 100644 index 00000000..4f5425bb --- /dev/null +++ b/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/LinkerExtension.kt @@ -0,0 +1,15 @@ +package io.sentry.kotlin.multiplatform.gradle.plugin + +import org.gradle.api.Project +import org.gradle.api.provider.Property +import javax.inject.Inject + + +@Suppress("UnnecessaryAbstractClass") +abstract class LinkerExtension +@Inject +constructor(project: Project) { + private val objects = project.objects + + val xcodeprojPath: Property = objects.property(String::class.java) +} diff --git a/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryExtension.kt b/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryExtension.kt index 5a146d09..4ff6577b 100644 --- a/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryExtension.kt +++ b/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryExtension.kt @@ -12,6 +12,8 @@ constructor(project: Project) { val sentryCocoaVersion: Property = objects.property(String::class.java) + val autoInstallCocoapodsDependency: Property = objects.property(Boolean::class.java).convention(true) + /** * When enabled the plugin will download the Sentry.xcframework and link the framework with linker-opts. * This fixes the issue with the Sentry framework not being found when running tests on Apple targets. @@ -21,4 +23,6 @@ constructor(project: Project) { */ val enableSentryTestLinking: Property = objects.property(Boolean::class.java).convention(true) + + val linker: LinkerExtension = objects.newInstance(LinkerExtension::class.java, project) } diff --git a/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt b/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt index 68967e87..0ad2b91a 100644 --- a/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt +++ b/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt @@ -1,17 +1,19 @@ package io.sentry.kotlin.multiplatform.gradle.plugin +import org.gradle.api.GradleException import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.api.plugins.ExtensionAware -import org.gradle.api.tasks.Copy -import org.jetbrains.kotlin.de.undercouch.gradle.tasks.download.Download import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension -import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType import org.jetbrains.kotlin.gradle.plugin.cocoapods.CocoapodsExtension +import org.jetbrains.kotlin.gradle.plugin.mpp.Framework import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget +import org.jetbrains.kotlin.gradle.plugin.mpp.TestExecutable +import java.io.ByteArrayOutputStream import java.io.File -const val EXTENSION_NAME = "sentry" +const val SENTRY_EXTENSION_NAME = "sentry" +const val LINKER_EXTENSION_NAME = "linker" const val COCOAPODS_PLUGIN_NAME = "org.jetbrains.kotlin.plugin.cocoapods" const val KOTLIN_EXTENSION_NAME = "kotlin" @@ -19,124 +21,149 @@ const val KOTLIN_EXTENSION_NAME = "kotlin" class SentryPlugin : Plugin { override fun apply(project: Project): Unit = with(project) { val extension = - project.extensions.create(EXTENSION_NAME, SentryExtension::class.java, project) + project.extensions.create(SENTRY_EXTENSION_NAME, SentryExtension::class.java, project) + project.extensions.add(LINKER_EXTENSION_NAME, extension.linker) + afterEvaluate { val hasCocoapodsPlugin = project.pluginManager.hasPlugin(COCOAPODS_PLUGIN_NAME) if (hasCocoapodsPlugin) { setupCocoapods() } else { - if (extension.enableSentryTestLinking.get()) { - // Test linking is only necessary when NOT using the Kotlin Cocoapods plugin - setupSentryFrameworkForTests() - } + configureLinkingOptions(extension.linker) } } } +} - /** - * Installs the Sentry pod if not yet installed and configures the compiler options - */ - private fun Project.setupCocoapods() { - val kmpExtension = this.extensions.findByName(KOTLIN_EXTENSION_NAME) - if (kmpExtension !is KotlinMultiplatformExtension) { - return - } - - (kmpExtension as ExtensionAware).extensions.configure(CocoapodsExtension::class.java) { cocoapods -> - val sentryPod = cocoapods.pods.findByName("Sentry") - if (sentryPod == null) { - cocoapods.pod("Sentry") { - version = "8.25.0" - extraOpts += listOf("-compiler-option", "-fmodules") - } - } else { - if (!sentryPod.extraOpts.contains("-fmodules")) { - sentryPod.extraOpts += listOf("-compiler-option", "-fmodules") - } - } - } +private fun Project.configureLinkingOptions(linkerExtension: LinkerExtension) { + val kmpExtension = this.extensions.findByName(KOTLIN_EXTENSION_NAME) + if (kmpExtension !is KotlinMultiplatformExtension) { + // todo: log, not multiplatform found + return } - private fun Project.setupSentryFrameworkForTests() { - val kmpExtension = this.extensions.findByName(KOTLIN_EXTENSION_NAME) - if (kmpExtension !is KotlinMultiplatformExtension) { - return - } + val customXcodeprojPath = linkerExtension.xcodeprojPath.orNull + println("customXcodeprojPath: $customXcodeprojPath") - val appleTargets = kmpExtension.targets.withType(KotlinNativeTarget::class.java) - .filter { it.konanTarget.family.isAppleFamily } - val buildDir = layout.buildDirectory.asFile.get().path + val derivedDataPath = findDerivedDataPath(customXcodeprojPath) - kmpExtension.addLinkerOpts(buildDir) - registerSentryDownloadTask() - registerDownloadAndUnzipSentryTask() - registerCopyFrameworkToTestDirsTask(appleTargets) + kmpExtension.appleTargets().all { target -> + val frameworkArchitecture = target.frameworkArchitecture() + val dynamicFrameworkPath = + "$derivedDataPath/SourcePackages/artifacts/sentry-cocoa/Sentry-Dynamic/Sentry-Dynamic.xcframework/$frameworkArchitecture" + val staticFrameworkPath = + "$derivedDataPath/SourcePackages/artifacts/sentry-cocoa/Sentry/Sentry.xcframework/$frameworkArchitecture" - tasks.named { name -> name.contains("linkDebugTest") }.configureEach { task -> - task.dependsOn("copyFrameworkToTestDirs") - } - } + target.binaries.all { binary -> + if (frameworkArchitecture == null) { + // todo: log, unsupported architecture + return@all + } - private fun Project.registerSentryDownloadTask() { - val buildDir = layout.buildDirectory.asFile.get().path - tasks.register("downloadSentryFramework", Download::class.java) { download -> - val sentryVersion = project.findProperty("sentryVersion") as String? ?: "8.25.0" - val downloadPath = "$buildDir/sentry-temp" - val zipFile = "$downloadPath/Sentry.xcframework.zip" + var path = dynamicFrameworkPath + if (!File(dynamicFrameworkPath).exists()) { + // if it doesn't exist still search for the static one since we need either one + // for test linking + // todo: log, dynamic framework not found, using static framework + path = staticFrameworkPath - download.src("https://github.com/getsentry/sentry-cocoa/releases/download/$sentryVersion/Sentry.xcframework.zip") - download.dest(File(zipFile)) - download.overwrite(false) - } - } + if (!File(staticFrameworkPath).exists()) { + // todo: log, static framework also not found, error + return@all + } + } - private fun Project.registerDownloadAndUnzipSentryTask() { - val buildDir = layout.buildDirectory.asFile.get().path - tasks.register("downloadAndUnzipSentryFramework", Copy::class.java) { copy -> - copy.dependsOn("downloadSentryFramework") - val zipFile = "$buildDir/sentry-temp/Sentry.xcframework.zip" - copy.from(zipTree(zipFile)) - copy.into("$buildDir/sentry-temp") + val testExecutable = binary is TestExecutable + val dynamicFramework = binary is Framework && !binary.isStatic + if (testExecutable) { + binary.linkerOpts("-rpath", "$path/Sentry.framework") + binary.linkerOpts("-F$path") + } else if (dynamicFramework) { + binary.linkerOpts("-F$path") + } } } +} + +private fun Project.findDerivedDataPath(customXcodeprojPath: String? = null): String { + val xcodeprojPath = customXcodeprojPath ?: findXcodeprojFile(rootDir)?.absolutePath + val buildDirOutput = ByteArrayOutputStream() + exec { + it.commandLine = listOf( + "xcodebuild", "-project", xcodeprojPath, "-showBuildSettings" + ) + it.standardOutput = buildDirOutput + } + val buildSettings = buildDirOutput.toString("UTF-8") + val buildDirRegex = Regex("BUILD_DIR = (.+)") + val buildDirMatch = buildDirRegex.find(buildSettings) + val buildDir = buildDirMatch?.groupValues?.get(1) + ?: throw GradleException("BUILD_DIR not found in xcodebuild output") + val derivedDataPath = buildDir.replace("/Build/Products", "") + return derivedDataPath +} + +private fun findXcodeprojFile(dir: File): File? { + val ignoredDirectories = listOf("build", "DerivedData") + + fun searchDirectory(directory: File): File? { + val files = directory.listFiles() ?: return null + + for (file in files) { + if (file.name in ignoredDirectories) { + continue + } - private fun Project.registerCopyFrameworkToTestDirsTask(targets: List) { - val buildDir = layout.buildDirectory.asFile.get().path - tasks.register("copyFrameworkToTestDirs", Copy::class.java) { copy -> - copy.dependsOn("downloadAndUnzipSentryFramework") - - targets.forEach { target -> - val frameworkPath = - "$buildDir/sentry-temp/Carthage/Build/Sentry.xcframework/${target.xcFrameworkDir()}/Sentry.framework" - copy { - it.from(fileTree(frameworkPath)) - it.into("$buildDir/bin/${target.name}/debugTest/frameworks/Sentry.framework") - } + // Recursively search the subdirectory + val result = searchDirectory(file) + if (result != null) { + return result + } + + if (file.extension == "xcodeproj") { + return file } } + return null } - private fun KotlinNativeTarget.xcFrameworkDir(): String? { - return when (name) { - "iosSimulatorArm64" -> "ios-arm64_x86_64-simulator" - "iosX64" -> "ios-arm64_x86_64-simulator" - "iosArm64" -> "ios-arm64" - else -> null - } + return searchDirectory(dir) +} + +private fun KotlinMultiplatformExtension.appleTargets() = + targets.withType(KotlinNativeTarget::class.java) + .matching { it.konanTarget.family.isAppleFamily } + +/** + * Installs the Sentry pod if not yet installed and configures the compiler options + */ +private fun Project.setupCocoapods() { + val kmpExtension = this.extensions.findByName(KOTLIN_EXTENSION_NAME) + if (kmpExtension !is KotlinMultiplatformExtension) { + return } - private fun KotlinMultiplatformExtension.addLinkerOpts(buildDir: String) { - targets.withType(KotlinNativeTarget::class.java).forEach { target -> - target.compilations.all { - if (it.compilationName == "test" && it.target.platformType == KotlinPlatformType.native) { - it.compilerOptions.configure { - freeCompilerArgs.add("-linker-options") - val path = - "$buildDir/sentry-temp/Carthage/Build/Sentry.xcframework/${target.xcFrameworkDir()}/" - freeCompilerArgs.add("-F$path") - } - } + (kmpExtension as ExtensionAware).extensions.configure(CocoapodsExtension::class.java) { cocoapods -> + val sentryPod = cocoapods.pods.findByName("Sentry") + if (sentryPod == null) { + cocoapods.pod("Sentry") { + version = "8.25.0" + linkOnly = true + extraOpts += listOf("-compiler-option", "-fmodules") } } } -} \ No newline at end of file +} + +/** + * Transforms a Kotlin Multiplatform target name to the architecture name that is found inside + * Sentry's framework directory. + */ +private fun KotlinNativeTarget.frameworkArchitecture(): String? { + return when (name) { + "iosSimulatorArm64" -> "ios-arm64_x86_64-simulator" + "iosX64" -> "ios-arm64_x86_64-simulator" + "iosArm64" -> "ios-arm64" + else -> null + } +} diff --git a/sentry-samples/kmp-app-spm/iosApp.xcodeproj/project.pbxproj b/sentry-samples/kmp-app-spm/iosApp.xcodeproj/project.pbxproj index 1f72511d..1275688a 100644 --- a/sentry-samples/kmp-app-spm/iosApp.xcodeproj/project.pbxproj +++ b/sentry-samples/kmp-app-spm/iosApp.xcodeproj/project.pbxproj @@ -9,9 +9,9 @@ /* Begin PBXBuildFile section */ 058557BB273AAA24004C7B11 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 058557BA273AAA24004C7B11 /* Assets.xcassets */; }; 058557D9273AAEEB004C7B11 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 058557D8273AAEEB004C7B11 /* Preview Assets.xcassets */; }; - 1DBB948028897D4700E79663 /* Sentry in Frameworks */ = {isa = PBXBuildFile; productRef = 1DBB947F28897D4700E79663 /* Sentry */; }; 2152FB042600AC8F00CF470E /* iOSApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2152FB032600AC8F00CF470E /* iOSApp.swift */; }; 243652EF29F34FF500FD902A /* sentry.png in Resources */ = {isa = PBXBuildFile; fileRef = 243652EE29F34FF500FD902A /* sentry.png */; }; + 24E1CB3C2C10780200F78D70 /* Sentry-Dynamic in Frameworks */ = {isa = PBXBuildFile; productRef = 24E1CB3B2C10780200F78D70 /* Sentry-Dynamic */; }; 7555FF83242A565900829871 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7555FF82242A565900829871 /* ContentView.swift */; }; /* End PBXBuildFile section */ @@ -44,7 +44,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 1DBB948028897D4700E79663 /* Sentry in Frameworks */, + 24E1CB3C2C10780200F78D70 /* Sentry-Dynamic in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -117,7 +117,7 @@ ); name = iosApp; packageProductDependencies = ( - 1DBB947F28897D4700E79663 /* Sentry */, + 24E1CB3B2C10780200F78D70 /* Sentry-Dynamic */, ); productName = NSExceptionKtSample; productReference = 7555FF7B242A565900829871 /* iosApp.app */; @@ -148,7 +148,7 @@ ); mainGroup = 7555FF72242A565900829871; packageReferences = ( - 1DBB947E28897D4700E79663 /* XCRemoteSwiftPackageReference "sentry-cocoa" */, + 24E1CB3A2C10780200F78D70 /* XCRemoteSwiftPackageReference "sentry-cocoa" */, ); productRefGroup = 7555FF7C242A565900829871 /* Products */; projectDirPath = ""; @@ -419,21 +419,21 @@ /* End XCConfigurationList section */ /* Begin XCRemoteSwiftPackageReference section */ - 1DBB947E28897D4700E79663 /* XCRemoteSwiftPackageReference "sentry-cocoa" */ = { + 24E1CB3A2C10780200F78D70 /* XCRemoteSwiftPackageReference "sentry-cocoa" */ = { isa = XCRemoteSwiftPackageReference; repositoryURL = "https://github.com/getsentry/sentry-cocoa.git"; requirement = { - kind = exactVersion; - version = 8.25.0; + kind = upToNextMajorVersion; + minimumVersion = 8.27.0; }; }; /* End XCRemoteSwiftPackageReference section */ /* Begin XCSwiftPackageProductDependency section */ - 1DBB947F28897D4700E79663 /* Sentry */ = { + 24E1CB3B2C10780200F78D70 /* Sentry-Dynamic */ = { isa = XCSwiftPackageProductDependency; - package = 1DBB947E28897D4700E79663 /* XCRemoteSwiftPackageReference "sentry-cocoa" */; - productName = Sentry; + package = 24E1CB3A2C10780200F78D70 /* XCRemoteSwiftPackageReference "sentry-cocoa" */; + productName = "Sentry-Dynamic"; }; /* End XCSwiftPackageProductDependency section */ }; diff --git a/sentry-samples/kmp-app-spm/iosApp.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/sentry-samples/kmp-app-spm/iosApp.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index a2546f12..79a363aa 100644 --- a/sentry-samples/kmp-app-spm/iosApp.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/sentry-samples/kmp-app-spm/iosApp.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -6,8 +6,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/getsentry/sentry-cocoa.git", "state" : { - "revision" : "82af013792dca3784a2dc5e7f975159fb9d263b3", - "version" : "8.25.0" + "revision" : "e6f9da251a4696eec602dd8da8fc689af0a4d8f7", + "version" : "8.27.0" } } ], diff --git a/sentry-samples/kmp-app-spm/shared/build.gradle.kts b/sentry-samples/kmp-app-spm/shared/build.gradle.kts index ffec72d1..9311a033 100644 --- a/sentry-samples/kmp-app-spm/shared/build.gradle.kts +++ b/sentry-samples/kmp-app-spm/shared/build.gradle.kts @@ -3,7 +3,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { kotlin("multiplatform") id("com.android.library") -// id("io.sentry.kotlin.multiplatform.gradle.plugin") + id("io.sentry.kotlin.multiplatform.gradle.plugin") } java { @@ -27,7 +27,7 @@ kotlin { ).forEach { it.binaries.framework { baseName = "shared" - isStatic = true + isStatic = false export(project(":sentry-kotlin-multiplatform")) } } @@ -51,6 +51,8 @@ android { } } -//sentry { -// enableSentryTestLinking = false -//} \ No newline at end of file +sentry { + linker { + // xcodeprojPath.set("/Users/giancarlobuenaflor/Desktop/SentryProjects/sentry-kotlin-multiplatform/sentry-samples/kmp-app-spm/iosApp.xcodeproj") + } +} \ No newline at end of file diff --git a/sentry-samples/kmp-app-spm/shared/shared.podspec b/sentry-samples/kmp-app-spm/shared/shared.podspec new file mode 100644 index 00000000..fe0acedb --- /dev/null +++ b/sentry-samples/kmp-app-spm/shared/shared.podspec @@ -0,0 +1,50 @@ +Pod::Spec.new do |spec| + spec.name = 'shared' + spec.version = '0.7.1' + spec.homepage = '' + spec.source = { :http=> ''} + spec.authors = '' + spec.license = '' + spec.summary = '' + spec.vendored_frameworks = 'build/cocoapods/framework/shared.framework' + spec.libraries = 'c++' + + + + if !Dir.exist?('build/cocoapods/framework/shared.framework') || Dir.empty?('build/cocoapods/framework/shared.framework') + raise " + + Kotlin framework 'shared' doesn't exist yet, so a proper Xcode project can't be generated. + 'pod install' should be executed after running ':generateDummyFramework' Gradle task: + + ./gradlew :sentry-samples:kmp-app-spm:shared:generateDummyFramework + + Alternatively, proper pod installation is performed during Gradle sync in the IDE (if Podfile location is set)" + end + + spec.pod_target_xcconfig = { + 'KOTLIN_PROJECT_PATH' => ':sentry-samples:kmp-app-spm:shared', + 'PRODUCT_MODULE_NAME' => 'shared', + } + + spec.script_phases = [ + { + :name => 'Build shared', + :execution_position => :before_compile, + :shell_path => '/bin/sh', + :script => <<-SCRIPT + if [ "YES" = "$OVERRIDE_KOTLIN_BUILD_IDE_SUPPORTED" ]; then + echo "Skipping Gradle build task invocation due to OVERRIDE_KOTLIN_BUILD_IDE_SUPPORTED environment variable set to \"YES\"" + exit 0 + fi + set -ev + REPO_ROOT="$PODS_TARGET_SRCROOT" + "$REPO_ROOT/../../../gradlew" -p "$REPO_ROOT" $KOTLIN_PROJECT_PATH:syncFramework \ + -Pkotlin.native.cocoapods.platform=$PLATFORM_NAME \ + -Pkotlin.native.cocoapods.archs="$ARCHS" \ + -Pkotlin.native.cocoapods.configuration="$CONFIGURATION" + SCRIPT + } + ] + +end \ No newline at end of file From 429e3b13a9122d35d818368d7de00933446184f0 Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Wed, 5 Jun 2024 20:58:15 +0200 Subject: [PATCH 10/78] Update --- .../gradle/plugin/SentryPlugin.kt | 9 ++-- .../gradle/plugin/TemplateExampleTask.kt | 46 ------------------- 2 files changed, 5 insertions(+), 50 deletions(-) delete mode 100644 plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/TemplateExampleTask.kt diff --git a/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt b/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt index 0ad2b91a..078df4b4 100644 --- a/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt +++ b/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt @@ -12,10 +12,10 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.TestExecutable import java.io.ByteArrayOutputStream import java.io.File -const val SENTRY_EXTENSION_NAME = "sentry" -const val LINKER_EXTENSION_NAME = "linker" -const val COCOAPODS_PLUGIN_NAME = "org.jetbrains.kotlin.plugin.cocoapods" -const val KOTLIN_EXTENSION_NAME = "kotlin" +internal const val SENTRY_EXTENSION_NAME = "sentry" +internal const val LINKER_EXTENSION_NAME = "linker" +internal const val COCOAPODS_PLUGIN_NAME = "org.jetbrains.kotlin.plugin.cocoapods" +internal const val KOTLIN_EXTENSION_NAME = "kotlin" @Suppress("unused") class SentryPlugin : Plugin { @@ -164,6 +164,7 @@ private fun KotlinNativeTarget.frameworkArchitecture(): String? { "iosSimulatorArm64" -> "ios-arm64_x86_64-simulator" "iosX64" -> "ios-arm64_x86_64-simulator" "iosArm64" -> "ios-arm64" + // todo: add more targets else -> null } } diff --git a/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/TemplateExampleTask.kt b/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/TemplateExampleTask.kt deleted file mode 100644 index 7f108a99..00000000 --- a/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/TemplateExampleTask.kt +++ /dev/null @@ -1,46 +0,0 @@ -package io.sentry.kotlin.multiplatform.gradle.plugin - -import org.gradle.api.DefaultTask -import org.gradle.api.file.RegularFileProperty -import org.gradle.api.provider.Property -import org.gradle.api.tasks.Input -import org.gradle.api.tasks.Optional -import org.gradle.api.tasks.OutputFile -import org.gradle.api.tasks.TaskAction -import org.gradle.api.tasks.options.Option - -abstract class TemplateExampleTask : DefaultTask() { - init { - description = "Just a sample template task" - - // Don't forget to set the group here. - // group = BasePlugin.BUILD_GROUP - } - - @get:Input - @get:Option(option = "message2", description = "A message to be printed in the output file") - abstract val message2: Property - - @get:Input - @get:Option(option = "message", description = "A message to be printed in the output file") - abstract val message: Property - - @get:Input - @get:Option(option = "tag", description = "A Tag to be used for debug and in the output file") - @get:Optional - abstract val tag: Property - - @get:OutputFile - abstract val outputFile: RegularFileProperty - - @TaskAction - fun sampleAction() { - val prettyTag = tag.orNull?.let { "[$it]" } ?: "" - - logger.lifecycle("$prettyTag message is: ${message.orNull}") - logger.lifecycle("$prettyTag tag is: ${tag.orNull}") - logger.lifecycle("$prettyTag outputFile is: ${outputFile.orNull}") - - outputFile.get().asFile.writeText("$prettyTag ${message.get()}") - } -} From ed5dce8308d4fd2c52b7347c9abfbf61d28668bc Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Wed, 5 Jun 2024 21:01:18 +0200 Subject: [PATCH 11/78] Update --- .../multiplatform/gradle/plugin/SentryExtension.kt | 13 ++----------- .../multiplatform/gradle/plugin/SentryPlugin.kt | 8 ++++---- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryExtension.kt b/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryExtension.kt index 4ff6577b..da45bce9 100644 --- a/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryExtension.kt +++ b/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryExtension.kt @@ -10,19 +10,10 @@ abstract class SentryExtension constructor(project: Project) { private val objects = project.objects - val sentryCocoaVersion: Property = objects.property(String::class.java) - - val autoInstallCocoapodsDependency: Property = objects.property(Boolean::class.java).convention(true) - /** - * When enabled the plugin will download the Sentry.xcframework and link the framework with linker-opts. - * This fixes the issue with the Sentry framework not being found when running tests on Apple targets. - * For example when trying to run tests using SPM. - * - * Defaults to `true` but is automatically **disabled** if the Cocoapods Gradle plugin is available. + * Auto-installs the Sentry-Cocoa SDK pod if the cocoapods plugin is enabled. */ - val enableSentryTestLinking: Property = - objects.property(Boolean::class.java).convention(true) + val autoInstallWithCocoapods: Property = objects.property(Boolean::class.java).convention(true) val linker: LinkerExtension = objects.newInstance(LinkerExtension::class.java, project) } diff --git a/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt b/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt index 078df4b4..de71b156 100644 --- a/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt +++ b/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt @@ -26,8 +26,8 @@ class SentryPlugin : Plugin { afterEvaluate { val hasCocoapodsPlugin = project.pluginManager.hasPlugin(COCOAPODS_PLUGIN_NAME) - if (hasCocoapodsPlugin) { - setupCocoapods() + if (hasCocoapodsPlugin && extension.autoInstallWithCocoapods.get()) { + installPod() } else { configureLinkingOptions(extension.linker) } @@ -137,7 +137,7 @@ private fun KotlinMultiplatformExtension.appleTargets() = /** * Installs the Sentry pod if not yet installed and configures the compiler options */ -private fun Project.setupCocoapods() { +private fun Project.installPod() { val kmpExtension = this.extensions.findByName(KOTLIN_EXTENSION_NAME) if (kmpExtension !is KotlinMultiplatformExtension) { return @@ -147,7 +147,7 @@ private fun Project.setupCocoapods() { val sentryPod = cocoapods.pods.findByName("Sentry") if (sentryPod == null) { cocoapods.pod("Sentry") { - version = "8.25.0" + version = "~> 8.25" // todo: check if this constraint is good enough linkOnly = true extraOpts += listOf("-compiler-option", "-fmodules") } From 99104d4a262e594e089eb7c267a5fdd04303eb7f Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Wed, 5 Jun 2024 21:02:33 +0200 Subject: [PATCH 12/78] Updatee --- .../kotlin/multiplatform/gradle/plugin/SentryExtension.kt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryExtension.kt b/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryExtension.kt index da45bce9..30dcc48b 100644 --- a/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryExtension.kt +++ b/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryExtension.kt @@ -13,7 +13,13 @@ constructor(project: Project) { /** * Auto-installs the Sentry-Cocoa SDK pod if the cocoapods plugin is enabled. */ - val autoInstallWithCocoapods: Property = objects.property(Boolean::class.java).convention(true) + val autoInstallWithCocoapods: Property = + objects.property(Boolean::class.java).convention(true) + /** + * Linker configuration. + * + * If you use SPM this configuration is necessary for setting up linking the framework and test executable. + */ val linker: LinkerExtension = objects.newInstance(LinkerExtension::class.java, project) } From 0dbb7f625ed68a1ae844f3f7944ed1be84f0dace Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Wed, 5 Jun 2024 21:09:58 +0200 Subject: [PATCH 13/78] Update doc --- .../kotlin/multiplatform/gradle/plugin/SentryPlugin.kt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt b/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt index de71b156..c97fa4a2 100644 --- a/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt +++ b/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt @@ -103,6 +103,11 @@ private fun Project.findDerivedDataPath(customXcodeprojPath: String? = null): St return derivedDataPath } +/** + * Searches for a xcodeproj starting from the root directory. + * This function will only work for monorepos and if it is not, + * the user needs to provide the custom path through the linker configuration. + */ private fun findXcodeprojFile(dir: File): File? { val ignoredDirectories = listOf("build", "DerivedData") From 454f85f4133d12f9f9cdcb9f88c60417bb21e26a Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Wed, 5 Jun 2024 21:10:39 +0200 Subject: [PATCH 14/78] Update docs --- .../sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt b/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt index c97fa4a2..68fe6e68 100644 --- a/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt +++ b/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt @@ -106,7 +106,7 @@ private fun Project.findDerivedDataPath(customXcodeprojPath: String? = null): St /** * Searches for a xcodeproj starting from the root directory. * This function will only work for monorepos and if it is not, - * the user needs to provide the custom path through the linker configuration. + * the user needs to provide the custom path through the [LinkerExtension] configuration. */ private fun findXcodeprojFile(dir: File): File? { val ignoredDirectories = listOf("build", "DerivedData") From 5bc7070bf866d4478656c0d629bf3a36ab7dc708 Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Wed, 5 Jun 2024 21:13:33 +0200 Subject: [PATCH 15/78] Remove print --- .../sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt | 2 -- 1 file changed, 2 deletions(-) diff --git a/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt b/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt index 68fe6e68..8f1c4b84 100644 --- a/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt +++ b/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt @@ -43,8 +43,6 @@ private fun Project.configureLinkingOptions(linkerExtension: LinkerExtension) { } val customXcodeprojPath = linkerExtension.xcodeprojPath.orNull - println("customXcodeprojPath: $customXcodeprojPath") - val derivedDataPath = findDerivedDataPath(customXcodeprojPath) kmpExtension.appleTargets().all { target -> From 36aab7ba65facb93452957344731ad388bbee9ea Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Wed, 5 Jun 2024 21:14:01 +0200 Subject: [PATCH 16/78] Update --- .../sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt b/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt index 8f1c4b84..5aceddc2 100644 --- a/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt +++ b/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt @@ -36,7 +36,7 @@ class SentryPlugin : Plugin { } private fun Project.configureLinkingOptions(linkerExtension: LinkerExtension) { - val kmpExtension = this.extensions.findByName(KOTLIN_EXTENSION_NAME) + val kmpExtension = extensions.findByName(KOTLIN_EXTENSION_NAME) if (kmpExtension !is KotlinMultiplatformExtension) { // todo: log, not multiplatform found return @@ -141,7 +141,7 @@ private fun KotlinMultiplatformExtension.appleTargets() = * Installs the Sentry pod if not yet installed and configures the compiler options */ private fun Project.installPod() { - val kmpExtension = this.extensions.findByName(KOTLIN_EXTENSION_NAME) + val kmpExtension = extensions.findByName(KOTLIN_EXTENSION_NAME) if (kmpExtension !is KotlinMultiplatformExtension) { return } From 6ef48aab03e6a26e8681cff16d2b70d76092df9b Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Thu, 6 Jun 2024 13:18:15 +0200 Subject: [PATCH 17/78] Update --- plugin-build/plugin/build.gradle.kts | 2 - .../gradle/plugin/SentryPlugin.kt | 54 +++++------ .../gradle/plugin/SentryPluginTest.kt | 95 +++++++++++++++++++ plugin-build/settings.gradle.kts | 13 --- 4 files changed, 120 insertions(+), 44 deletions(-) create mode 100644 plugin-build/plugin/src/test/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPluginTest.kt diff --git a/plugin-build/plugin/build.gradle.kts b/plugin-build/plugin/build.gradle.kts index 603ebad3..58b68966 100644 --- a/plugin-build/plugin/build.gradle.kts +++ b/plugin-build/plugin/build.gradle.kts @@ -4,8 +4,6 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { kotlin("jvm") `java-gradle-plugin` -// alias(libs.plugins.pluginPublish) - id("de.undercouch.download") version "5.6.0" alias(libs.plugins.vanniktech.publish) id("distribution") } diff --git a/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt b/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt index 5aceddc2..c3f078d0 100644 --- a/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt +++ b/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt @@ -6,6 +6,7 @@ import org.gradle.api.Project import org.gradle.api.plugins.ExtensionAware import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension import org.jetbrains.kotlin.gradle.plugin.cocoapods.CocoapodsExtension +import org.jetbrains.kotlin.gradle.plugin.cocoapods.KotlinCocoapodsPlugin import org.jetbrains.kotlin.gradle.plugin.mpp.Framework import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget import org.jetbrains.kotlin.gradle.plugin.mpp.TestExecutable @@ -14,7 +15,6 @@ import java.io.File internal const val SENTRY_EXTENSION_NAME = "sentry" internal const val LINKER_EXTENSION_NAME = "linker" -internal const val COCOAPODS_PLUGIN_NAME = "org.jetbrains.kotlin.plugin.cocoapods" internal const val KOTLIN_EXTENSION_NAME = "kotlin" @Suppress("unused") @@ -25,9 +25,10 @@ class SentryPlugin : Plugin { project.extensions.add(LINKER_EXTENSION_NAME, extension.linker) afterEvaluate { - val hasCocoapodsPlugin = project.pluginManager.hasPlugin(COCOAPODS_PLUGIN_NAME) + val hasCocoapodsPlugin = + project.plugins.findPlugin(KotlinCocoapodsPlugin::class.java) != null if (hasCocoapodsPlugin && extension.autoInstallWithCocoapods.get()) { - installPod() + installSentryPod() } else { configureLinkingOptions(extension.linker) } @@ -35,7 +36,7 @@ class SentryPlugin : Plugin { } } -private fun Project.configureLinkingOptions(linkerExtension: LinkerExtension) { +internal fun Project.configureLinkingOptions(linkerExtension: LinkerExtension) { val kmpExtension = extensions.findByName(KOTLIN_EXTENSION_NAME) if (kmpExtension !is KotlinMultiplatformExtension) { // todo: log, not multiplatform found @@ -46,37 +47,34 @@ private fun Project.configureLinkingOptions(linkerExtension: LinkerExtension) { val derivedDataPath = findDerivedDataPath(customXcodeprojPath) kmpExtension.appleTargets().all { target -> - val frameworkArchitecture = target.frameworkArchitecture() + val frameworkArchitecture = target.toSentryFrameworkArchitecture() val dynamicFrameworkPath = "$derivedDataPath/SourcePackages/artifacts/sentry-cocoa/Sentry-Dynamic/Sentry-Dynamic.xcframework/$frameworkArchitecture" val staticFrameworkPath = "$derivedDataPath/SourcePackages/artifacts/sentry-cocoa/Sentry/Sentry.xcframework/$frameworkArchitecture" - target.binaries.all { binary -> + target.binaries.all binaries@{ binary -> if (frameworkArchitecture == null) { // todo: log, unsupported architecture - return@all + return@binaries } - var path = dynamicFrameworkPath - if (!File(dynamicFrameworkPath).exists()) { - // if it doesn't exist still search for the static one since we need either one - // for test linking - // todo: log, dynamic framework not found, using static framework - path = staticFrameworkPath + val path = when { + File(dynamicFrameworkPath).exists() -> dynamicFrameworkPath + File(staticFrameworkPath).exists() -> { + // todo: log, dynamic framework not found, try using static framework + staticFrameworkPath + } - if (!File(staticFrameworkPath).exists()) { + else -> { // todo: log, static framework also not found, error - return@all + return@binaries } } - val testExecutable = binary is TestExecutable - val dynamicFramework = binary is Framework && !binary.isStatic - if (testExecutable) { - binary.linkerOpts("-rpath", "$path/Sentry.framework") - binary.linkerOpts("-F$path") - } else if (dynamicFramework) { + if (binary is TestExecutable) { + binary.linkerOpts("-rpath", "$path/Sentry.framework", "-F$path") + } else if (binary is Framework) { binary.linkerOpts("-F$path") } } @@ -106,7 +104,7 @@ private fun Project.findDerivedDataPath(customXcodeprojPath: String? = null): St * This function will only work for monorepos and if it is not, * the user needs to provide the custom path through the [LinkerExtension] configuration. */ -private fun findXcodeprojFile(dir: File): File? { +internal fun findXcodeprojFile(dir: File): File? { val ignoredDirectories = listOf("build", "DerivedData") fun searchDirectory(directory: File): File? { @@ -137,19 +135,17 @@ private fun KotlinMultiplatformExtension.appleTargets() = targets.withType(KotlinNativeTarget::class.java) .matching { it.konanTarget.family.isAppleFamily } -/** - * Installs the Sentry pod if not yet installed and configures the compiler options - */ -private fun Project.installPod() { +internal fun Project.installSentryPod() { val kmpExtension = extensions.findByName(KOTLIN_EXTENSION_NAME) if (kmpExtension !is KotlinMultiplatformExtension) { return } (kmpExtension as ExtensionAware).extensions.configure(CocoapodsExtension::class.java) { cocoapods -> - val sentryPod = cocoapods.pods.findByName("Sentry") + val podName = "Sentry" + val sentryPod = cocoapods.pods.findByName(podName) if (sentryPod == null) { - cocoapods.pod("Sentry") { + cocoapods.pod(podName) { version = "~> 8.25" // todo: check if this constraint is good enough linkOnly = true extraOpts += listOf("-compiler-option", "-fmodules") @@ -162,7 +158,7 @@ private fun Project.installPod() { * Transforms a Kotlin Multiplatform target name to the architecture name that is found inside * Sentry's framework directory. */ -private fun KotlinNativeTarget.frameworkArchitecture(): String? { +internal fun KotlinNativeTarget.toSentryFrameworkArchitecture(): String? { return when (name) { "iosSimulatorArm64" -> "ios-arm64_x86_64-simulator" "iosX64" -> "ios-arm64_x86_64-simulator" diff --git a/plugin-build/plugin/src/test/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPluginTest.kt b/plugin-build/plugin/src/test/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPluginTest.kt new file mode 100644 index 00000000..ae92a47a --- /dev/null +++ b/plugin-build/plugin/src/test/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPluginTest.kt @@ -0,0 +1,95 @@ +package io.sentry.kotlin.multiplatform.gradle.plugin + +import junit.framework.TestCase.assertEquals +import junit.framework.TestCase.assertNotNull +import junit.framework.TestCase.assertNull +import org.gradle.api.plugins.ExtensionAware +import org.gradle.testfixtures.ProjectBuilder +import org.jetbrains.kotlin.gradle.plugin.cocoapods.CocoapodsExtension +import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget +import org.junit.Test +import org.mockito.Mockito.mock +import org.mockito.Mockito.`when` + +class SentryPluginTest { + @Test + fun `plugin is applied correctly to the project`() { + val project = ProjectBuilder.builder().build() + project.pluginManager.apply("io.sentry.kotlin.multiplatform.gradle.plugin") + + assert(project.plugins.hasPlugin(SentryPlugin::class.java)) + } + + @Test + fun `extension sentry is created correctly`() { + val project = ProjectBuilder.builder().build() + project.pluginManager.apply("io.sentry.kotlin.multiplatform.gradle.plugin") + + assertNotNull(project.extensions.getByName("sentry")) + } + + @Test + fun `extension linker is created correctly`() { + val project = ProjectBuilder.builder().build() + project.pluginManager.apply("io.sentry.kotlin.multiplatform.gradle.plugin") + + assertNotNull(project.extensions.getByName("linker")) + } + + @Test + fun `frameworkArchitecture returns transformed target with supported targets`() { + val target = mock(KotlinNativeTarget::class.java) + + `when`(target.name).thenReturn("iosSimulatorArm64") + assertEquals("ios-arm64_x86_64-simulator", target.toSentryFrameworkArchitecture()) + + `when`(target.name).thenReturn("iosX64") + assertEquals("ios-arm64_x86_64-simulator", target.toSentryFrameworkArchitecture()) + + `when`(target.name).thenReturn("iosArm64") + assertEquals("ios-arm64", target.toSentryFrameworkArchitecture()) + } + + @Test + fun `frameworkArchitecture returns null with unsupported targets`() { + val target = mock(KotlinNativeTarget::class.java) + + `when`(target.name).thenReturn("unsupported") + assertNull(target.toSentryFrameworkArchitecture()) + } + + @Test + fun `install Sentry pod when cocoapods plugin is applied and no custom Sentry configuration exists`() { + val project = ProjectBuilder.builder().build() + project.pluginManager.apply("io.sentry.kotlin.multiplatform.gradle.plugin") + project.pluginManager.apply("org.jetbrains.kotlin.multiplatform") + project.pluginManager.apply("org.jetbrains.kotlin.native.cocoapods") + + project.afterEvaluate { + val cocoapodsExtension = project.extensions.findByType(CocoapodsExtension::class.java) + assertNotNull(cocoapodsExtension?.pods?.findByName("Sentry")) + } + } + + @Test + fun `do not install Sentry pod when cocoapods plugin is applied and custom Sentry configuration exists`() { + val project = ProjectBuilder.builder().build() + project.pluginManager.apply("io.sentry.kotlin.multiplatform.gradle.plugin") + project.pluginManager.apply("org.jetbrains.kotlin.multiplatform") + project.pluginManager.apply("org.jetbrains.kotlin.native.cocoapods") + + val kmpExtension = project.extensions.findByName("kotlin") + (kmpExtension as ExtensionAware).extensions.configure(CocoapodsExtension::class.java) { cocoapods -> + cocoapods.pod("Sentry") { + version = "custom version" + } + } + + // plugin does not configure sentry pod if there is already an existing configuration + project.afterEvaluate { + val cocoapodsExtension = project.extensions.findByType(CocoapodsExtension::class.java) + val pod = cocoapodsExtension?.pods?.findByName("Sentry") + assertEquals(pod?.version, "custom version") + } + } +} \ No newline at end of file diff --git a/plugin-build/settings.gradle.kts b/plugin-build/settings.gradle.kts index bc6a5480..3083218c 100644 --- a/plugin-build/settings.gradle.kts +++ b/plugin-build/settings.gradle.kts @@ -12,19 +12,6 @@ dependencyResolutionManagement { } } -plugins { - `gradle-enterprise` -} - -gradleEnterprise { - buildScan { - termsOfServiceUrl = "https://gradle.com/terms-of-service" - termsOfServiceAgree = "yes" - publishAlwaysIf(System.getenv("GITHUB_ACTIONS") == "true") - publishOnFailure() - } -} - rootProject.name = ("io.sentry.kotlin.multiplatform.gradle.plugin") include(":plugin") \ No newline at end of file From 0bd2eb9dc83bbbe6cdfdc008ca60b4b9db42db40 Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Thu, 6 Jun 2024 13:18:53 +0200 Subject: [PATCH 18/78] Update comment --- .../kotlin/multiplatform/gradle/plugin/SentryExtension.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryExtension.kt b/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryExtension.kt index 30dcc48b..2b4c1eaf 100644 --- a/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryExtension.kt +++ b/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryExtension.kt @@ -11,7 +11,8 @@ constructor(project: Project) { private val objects = project.objects /** - * Auto-installs the Sentry-Cocoa SDK pod if the cocoapods plugin is enabled. + * Auto-installs the Sentry-Cocoa SDK pod if the cocoapods plugin is enabled and no existing + * Sentry pod configuration exists. */ val autoInstallWithCocoapods: Property = objects.property(Boolean::class.java).convention(true) From 18f79062f19e49a471a94dddec0fe23e5e2bd642 Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Thu, 6 Jun 2024 13:25:24 +0200 Subject: [PATCH 19/78] Update --- .../kotlin/multiplatform/gradle/plugin/SentryPlugin.kt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt b/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt index c3f078d0..dc29ce75 100644 --- a/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt +++ b/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt @@ -48,17 +48,17 @@ internal fun Project.configureLinkingOptions(linkerExtension: LinkerExtension) { kmpExtension.appleTargets().all { target -> val frameworkArchitecture = target.toSentryFrameworkArchitecture() + if (frameworkArchitecture == null) { + // todo: log, unsupported architecture + return@all + } + val dynamicFrameworkPath = "$derivedDataPath/SourcePackages/artifacts/sentry-cocoa/Sentry-Dynamic/Sentry-Dynamic.xcframework/$frameworkArchitecture" val staticFrameworkPath = "$derivedDataPath/SourcePackages/artifacts/sentry-cocoa/Sentry/Sentry.xcframework/$frameworkArchitecture" target.binaries.all binaries@{ binary -> - if (frameworkArchitecture == null) { - // todo: log, unsupported architecture - return@binaries - } - val path = when { File(dynamicFrameworkPath).exists() -> dynamicFrameworkPath File(staticFrameworkPath).exists() -> { From 5b7ccc02ddbe502540846d9976d56e0e8b5eb083 Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Fri, 7 Jun 2024 13:28:32 +0200 Subject: [PATCH 20/78] Update --- .../gradle/plugin/AutoInstallExtension.kt | 26 +++++++++ .../plugin/CocoapodsAutoInstallExtension.kt | 30 ++++++++++ .../gradle/plugin/SentryExtension.kt | 9 +-- .../gradle/plugin/SentryPlugin.kt | 58 +++++++++++++++++-- .../plugin/SourceSetAutoInstallExtension.kt | 28 +++++++++ 5 files changed, 139 insertions(+), 12 deletions(-) create mode 100644 plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/AutoInstallExtension.kt create mode 100644 plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/CocoapodsAutoInstallExtension.kt create mode 100644 plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SourceSetAutoInstallExtension.kt diff --git a/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/AutoInstallExtension.kt b/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/AutoInstallExtension.kt new file mode 100644 index 00000000..024b11e5 --- /dev/null +++ b/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/AutoInstallExtension.kt @@ -0,0 +1,26 @@ +package io.sentry.kotlin.multiplatform.gradle.plugin + +import org.gradle.api.Project +import org.gradle.api.provider.Property +import javax.inject.Inject + +@Suppress("UnnecessaryAbstractClass") +abstract class AutoInstallExtension +@Inject +constructor(project: Project) { + private val objects = project.objects + + /** + * Enable auto-installation of the Sentry dependencies through [CocoapodsAutoInstallExtension] + * + * Disabling this will prevent the plugin from auto installing anything. + * + * Defaults to true. + */ + val enabled: Property = objects.property(Boolean::class.java) + .convention(true) + + val cocoapods: CocoapodsAutoInstallExtension = objects.newInstance(CocoapodsAutoInstallExtension::class.java, project) + + val commonMain: SourceSetAutoInstallExtension = objects.newInstance(SourceSetAutoInstallExtension::class.java, project) +} diff --git a/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/CocoapodsAutoInstallExtension.kt b/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/CocoapodsAutoInstallExtension.kt new file mode 100644 index 00000000..1b3bdfa7 --- /dev/null +++ b/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/CocoapodsAutoInstallExtension.kt @@ -0,0 +1,30 @@ +package io.sentry.kotlin.multiplatform.gradle.plugin + +import org.gradle.api.Project +import org.gradle.api.provider.Property +import javax.inject.Inject + +@Suppress("UnnecessaryAbstractClass") +abstract class CocoapodsAutoInstallExtension +@Inject +constructor(project: Project) { + private val objects = project.objects + + /** + * Enable auto-installation of the Sentry Cocoa SDK pod. + * + * If the cocoapods plugin is applied and no existing Sentry pod configuration exists, the Sentry-Cocoa SDK pod will be installed + * + * Defaults to true. + */ + val enabled: Property = objects.property(Boolean::class.java) + .convention(true) + + /** + * Overrides default Sentry Cocoa version. + * + * Defaults to the `~> 8.25`. + */ + val sentryCocoaVersion: Property = objects.property(String::class.java) + .convention("~> 8.25") // todo: grab the latest version properly +} diff --git a/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryExtension.kt b/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryExtension.kt index 2b4c1eaf..c0080aac 100644 --- a/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryExtension.kt +++ b/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryExtension.kt @@ -10,17 +10,12 @@ abstract class SentryExtension constructor(project: Project) { private val objects = project.objects - /** - * Auto-installs the Sentry-Cocoa SDK pod if the cocoapods plugin is enabled and no existing - * Sentry pod configuration exists. - */ - val autoInstallWithCocoapods: Property = - objects.property(Boolean::class.java).convention(true) - /** * Linker configuration. * * If you use SPM this configuration is necessary for setting up linking the framework and test executable. */ val linker: LinkerExtension = objects.newInstance(LinkerExtension::class.java, project) + + val autoInstall: AutoInstallExtension = objects.newInstance(AutoInstallExtension::class.java, project) } diff --git a/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt b/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt index dc29ce75..63fccd84 100644 --- a/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt +++ b/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt @@ -15,6 +15,9 @@ import java.io.File internal const val SENTRY_EXTENSION_NAME = "sentry" internal const val LINKER_EXTENSION_NAME = "linker" +internal const val AUTO_INSTALL_EXTENSION_NAME = "autoInstall" +internal const val COCOAPODS_AUTO_INSTALL_EXTENSION_NAME = "cocoapods" +internal const val COMMON_MAIN_AUTO_INSTALL_EXTENSION_NAME = "commonMain" internal const val KOTLIN_EXTENSION_NAME = "kotlin" @Suppress("unused") @@ -23,19 +26,63 @@ class SentryPlugin : Plugin { val extension = project.extensions.create(SENTRY_EXTENSION_NAME, SentryExtension::class.java, project) project.extensions.add(LINKER_EXTENSION_NAME, extension.linker) + project.extensions.add(AUTO_INSTALL_EXTENSION_NAME, extension.autoInstall) + project.extensions.add( + COCOAPODS_AUTO_INSTALL_EXTENSION_NAME, + extension.autoInstall.cocoapods + ) + project.extensions.add( + COMMON_MAIN_AUTO_INSTALL_EXTENSION_NAME, + extension.autoInstall.commonMain + ) afterEvaluate { val hasCocoapodsPlugin = project.plugins.findPlugin(KotlinCocoapodsPlugin::class.java) != null - if (hasCocoapodsPlugin && extension.autoInstallWithCocoapods.get()) { - installSentryPod() - } else { + + if (extension.autoInstall.enabled.get()) { + installSentryDependency(extension.autoInstall.commonMain) + + if (hasCocoapodsPlugin) { + installSentryDependency(extension.autoInstall.cocoapods) + } + } + + if (!hasCocoapodsPlugin) { configureLinkingOptions(extension.linker) } } } } +internal fun Project.installSentryDependency(sourceSetAutoInstallExtension: SourceSetAutoInstallExtension) { + val kmpExtension = extensions.findByName(KOTLIN_EXTENSION_NAME) + if (kmpExtension !is KotlinMultiplatformExtension) { + // todo: log, not multiplatform found + return + } + + if (!sourceSetAutoInstallExtension.enabled.get()) { + return + } + + val unsupportedTargets = listOf("wasm", "js", "mingw", "linux") + kmpExtension.targets.forEach { target -> + if (unsupportedTargets.any { unsupported -> target.name.contains(unsupported) }) { + throw GradleException("Unsupported target: ${target.name}. Cannot auto install in commonMain. Please create an intermediate sourceSet with targets that the SDK supports and add the dependency manually.") + } + } + + val commonMain = kmpExtension.sourceSets.find { + it.name.contains("common") + } + + val sentryVersion = sourceSetAutoInstallExtension.sentryKmpVersion.get() + commonMain?.dependencies { + api("io.sentry:sentry-kotlin-multiplatform:$sentryVersion") + } +} + internal fun Project.configureLinkingOptions(linkerExtension: LinkerExtension) { val kmpExtension = extensions.findByName(KOTLIN_EXTENSION_NAME) if (kmpExtension !is KotlinMultiplatformExtension) { @@ -135,7 +182,7 @@ private fun KotlinMultiplatformExtension.appleTargets() = targets.withType(KotlinNativeTarget::class.java) .matching { it.konanTarget.family.isAppleFamily } -internal fun Project.installSentryPod() { +internal fun Project.installSentryDependency(cocoapodsAutoInstallExtension: CocoapodsAutoInstallExtension) { val kmpExtension = extensions.findByName(KOTLIN_EXTENSION_NAME) if (kmpExtension !is KotlinMultiplatformExtension) { return @@ -146,7 +193,8 @@ internal fun Project.installSentryPod() { val sentryPod = cocoapods.pods.findByName(podName) if (sentryPod == null) { cocoapods.pod(podName) { - version = "~> 8.25" // todo: check if this constraint is good enough + version = + cocoapodsAutoInstallExtension.sentryCocoaVersion.get() linkOnly = true extraOpts += listOf("-compiler-option", "-fmodules") } diff --git a/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SourceSetAutoInstallExtension.kt b/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SourceSetAutoInstallExtension.kt new file mode 100644 index 00000000..dea9eeae --- /dev/null +++ b/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SourceSetAutoInstallExtension.kt @@ -0,0 +1,28 @@ +package io.sentry.kotlin.multiplatform.gradle.plugin + +import org.gradle.api.Project +import org.gradle.api.provider.Property +import javax.inject.Inject + +@Suppress("UnnecessaryAbstractClass") +abstract class SourceSetAutoInstallExtension +@Inject +constructor(project: Project) { + private val objects = project.objects + + /** + * Enable auto-installation of the Sentry Kotlin Multiplatform SDK dependency in the commonMain source set. + * + * Defaults to true. + */ + val enabled: Property = objects.property(Boolean::class.java) + .convention(true) + + /** + * Overrides the default Sentry Kotlin Multiplatform SDK dependency version. + * + * Defaults to the latest version of the Sentry Kotlin Multiplatform SDK. + */ + val sentryKmpVersion: Property = objects.property(String::class.java) + .convention("latest.release") // Replace with the actual default version +} \ No newline at end of file From 8f8c587c9e80e66250d383433e8495d34e0c03c5 Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Fri, 7 Jun 2024 13:30:25 +0200 Subject: [PATCH 21/78] Update --- .../gradle/plugin/SentryPlugin.kt | 46 +++++++++---------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt b/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt index 63fccd84..5b1acec5 100644 --- a/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt +++ b/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt @@ -41,10 +41,10 @@ class SentryPlugin : Plugin { project.plugins.findPlugin(KotlinCocoapodsPlugin::class.java) != null if (extension.autoInstall.enabled.get()) { - installSentryDependency(extension.autoInstall.commonMain) + installSentryForKmp(extension.autoInstall.commonMain) if (hasCocoapodsPlugin) { - installSentryDependency(extension.autoInstall.cocoapods) + installSentryForCocoapods(extension.autoInstall.cocoapods) } } @@ -55,7 +55,7 @@ class SentryPlugin : Plugin { } } -internal fun Project.installSentryDependency(sourceSetAutoInstallExtension: SourceSetAutoInstallExtension) { +internal fun Project.installSentryForKmp(sourceSetAutoInstallExtension: SourceSetAutoInstallExtension) { val kmpExtension = extensions.findByName(KOTLIN_EXTENSION_NAME) if (kmpExtension !is KotlinMultiplatformExtension) { // todo: log, not multiplatform found @@ -83,6 +83,26 @@ internal fun Project.installSentryDependency(sourceSetAutoInstallExtension: Sour } } +internal fun Project.installSentryForCocoapods(cocoapodsAutoInstallExtension: CocoapodsAutoInstallExtension) { + val kmpExtension = extensions.findByName(KOTLIN_EXTENSION_NAME) + if (kmpExtension !is KotlinMultiplatformExtension) { + return + } + + (kmpExtension as ExtensionAware).extensions.configure(CocoapodsExtension::class.java) { cocoapods -> + val podName = "Sentry" + val sentryPod = cocoapods.pods.findByName(podName) + if (sentryPod == null) { + cocoapods.pod(podName) { + version = + cocoapodsAutoInstallExtension.sentryCocoaVersion.get() + linkOnly = true + extraOpts += listOf("-compiler-option", "-fmodules") + } + } + } +} + internal fun Project.configureLinkingOptions(linkerExtension: LinkerExtension) { val kmpExtension = extensions.findByName(KOTLIN_EXTENSION_NAME) if (kmpExtension !is KotlinMultiplatformExtension) { @@ -182,26 +202,6 @@ private fun KotlinMultiplatformExtension.appleTargets() = targets.withType(KotlinNativeTarget::class.java) .matching { it.konanTarget.family.isAppleFamily } -internal fun Project.installSentryDependency(cocoapodsAutoInstallExtension: CocoapodsAutoInstallExtension) { - val kmpExtension = extensions.findByName(KOTLIN_EXTENSION_NAME) - if (kmpExtension !is KotlinMultiplatformExtension) { - return - } - - (kmpExtension as ExtensionAware).extensions.configure(CocoapodsExtension::class.java) { cocoapods -> - val podName = "Sentry" - val sentryPod = cocoapods.pods.findByName(podName) - if (sentryPod == null) { - cocoapods.pod(podName) { - version = - cocoapodsAutoInstallExtension.sentryCocoaVersion.get() - linkOnly = true - extraOpts += listOf("-compiler-option", "-fmodules") - } - } - } -} - /** * Transforms a Kotlin Multiplatform target name to the architecture name that is found inside * Sentry's framework directory. From 764eda2af079d66028976583017b36edab27c624 Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Fri, 7 Jun 2024 18:53:28 +0200 Subject: [PATCH 22/78] Format --- .../gradle/plugin/AutoInstallExtension.kt | 31 ++--- .../plugin/CocoapodsAutoInstallExtension.kt | 42 +++--- .../gradle/plugin/LinkerExtension.kt | 11 +- .../gradle/plugin/SentryExtension.kt | 23 ++-- .../gradle/plugin/SentryPlugin.kt | 126 ++++++++++-------- .../plugin/SourceSetAutoInstallExtension.kt | 38 +++--- .../gradle/plugin/SentryPluginTest.kt | 2 +- 7 files changed, 145 insertions(+), 128 deletions(-) diff --git a/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/AutoInstallExtension.kt b/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/AutoInstallExtension.kt index 024b11e5..807f3702 100644 --- a/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/AutoInstallExtension.kt +++ b/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/AutoInstallExtension.kt @@ -6,21 +6,22 @@ import javax.inject.Inject @Suppress("UnnecessaryAbstractClass") abstract class AutoInstallExtension -@Inject -constructor(project: Project) { - private val objects = project.objects + @Inject + constructor(project: Project) { + private val objects = project.objects - /** - * Enable auto-installation of the Sentry dependencies through [CocoapodsAutoInstallExtension] - * - * Disabling this will prevent the plugin from auto installing anything. - * - * Defaults to true. - */ - val enabled: Property = objects.property(Boolean::class.java) - .convention(true) + /** + * Enable auto-installation of the Sentry dependencies through [CocoapodsAutoInstallExtension] + * + * Disabling this will prevent the plugin from auto installing anything. + * + * Defaults to true. + */ + val enabled: Property = + objects.property(Boolean::class.java) + .convention(true) - val cocoapods: CocoapodsAutoInstallExtension = objects.newInstance(CocoapodsAutoInstallExtension::class.java, project) + val cocoapods: CocoapodsAutoInstallExtension = objects.newInstance(CocoapodsAutoInstallExtension::class.java, project) - val commonMain: SourceSetAutoInstallExtension = objects.newInstance(SourceSetAutoInstallExtension::class.java, project) -} + val commonMain: SourceSetAutoInstallExtension = objects.newInstance(SourceSetAutoInstallExtension::class.java, project) + } diff --git a/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/CocoapodsAutoInstallExtension.kt b/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/CocoapodsAutoInstallExtension.kt index 1b3bdfa7..c6e75147 100644 --- a/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/CocoapodsAutoInstallExtension.kt +++ b/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/CocoapodsAutoInstallExtension.kt @@ -6,25 +6,27 @@ import javax.inject.Inject @Suppress("UnnecessaryAbstractClass") abstract class CocoapodsAutoInstallExtension -@Inject -constructor(project: Project) { - private val objects = project.objects + @Inject + constructor(project: Project) { + private val objects = project.objects - /** - * Enable auto-installation of the Sentry Cocoa SDK pod. - * - * If the cocoapods plugin is applied and no existing Sentry pod configuration exists, the Sentry-Cocoa SDK pod will be installed - * - * Defaults to true. - */ - val enabled: Property = objects.property(Boolean::class.java) - .convention(true) + /** + * Enable auto-installation of the Sentry Cocoa SDK pod. + * + * If the cocoapods plugin is applied and no existing Sentry pod configuration exists, the Sentry-Cocoa SDK pod will be installed + * + * Defaults to true. + */ + val enabled: Property = + objects.property(Boolean::class.java) + .convention(true) - /** - * Overrides default Sentry Cocoa version. - * - * Defaults to the `~> 8.25`. - */ - val sentryCocoaVersion: Property = objects.property(String::class.java) - .convention("~> 8.25") // todo: grab the latest version properly -} + /** + * Overrides default Sentry Cocoa version. + * + * Defaults to the `~> 8.25`. + */ + val sentryCocoaVersion: Property = + objects.property(String::class.java) + .convention("~> 8.25") // todo: grab the latest version properly + } diff --git a/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/LinkerExtension.kt b/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/LinkerExtension.kt index 4f5425bb..117b678f 100644 --- a/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/LinkerExtension.kt +++ b/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/LinkerExtension.kt @@ -4,12 +4,11 @@ import org.gradle.api.Project import org.gradle.api.provider.Property import javax.inject.Inject - @Suppress("UnnecessaryAbstractClass") abstract class LinkerExtension -@Inject -constructor(project: Project) { - private val objects = project.objects + @Inject + constructor(project: Project) { + private val objects = project.objects - val xcodeprojPath: Property = objects.property(String::class.java) -} + val xcodeprojPath: Property = objects.property(String::class.java) + } diff --git a/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryExtension.kt b/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryExtension.kt index c0080aac..60937583 100644 --- a/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryExtension.kt +++ b/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryExtension.kt @@ -1,21 +1,20 @@ package io.sentry.kotlin.multiplatform.gradle.plugin import org.gradle.api.Project -import org.gradle.api.provider.Property import javax.inject.Inject @Suppress("UnnecessaryAbstractClass") abstract class SentryExtension -@Inject -constructor(project: Project) { - private val objects = project.objects + @Inject + constructor(project: Project) { + private val objects = project.objects - /** - * Linker configuration. - * - * If you use SPM this configuration is necessary for setting up linking the framework and test executable. - */ - val linker: LinkerExtension = objects.newInstance(LinkerExtension::class.java, project) + /** + * Linker configuration. + * + * If you use SPM this configuration is necessary for setting up linking the framework and test executable. + */ + val linker: LinkerExtension = objects.newInstance(LinkerExtension::class.java, project) - val autoInstall: AutoInstallExtension = objects.newInstance(AutoInstallExtension::class.java, project) -} + val autoInstall: AutoInstallExtension = objects.newInstance(AutoInstallExtension::class.java, project) + } diff --git a/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt b/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt index 5b1acec5..2bce3277 100644 --- a/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt +++ b/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt @@ -22,62 +22,74 @@ internal const val KOTLIN_EXTENSION_NAME = "kotlin" @Suppress("unused") class SentryPlugin : Plugin { - override fun apply(project: Project): Unit = with(project) { - val extension = - project.extensions.create(SENTRY_EXTENSION_NAME, SentryExtension::class.java, project) - project.extensions.add(LINKER_EXTENSION_NAME, extension.linker) - project.extensions.add(AUTO_INSTALL_EXTENSION_NAME, extension.autoInstall) - project.extensions.add( - COCOAPODS_AUTO_INSTALL_EXTENSION_NAME, - extension.autoInstall.cocoapods - ) - project.extensions.add( - COMMON_MAIN_AUTO_INSTALL_EXTENSION_NAME, - extension.autoInstall.commonMain - ) - - afterEvaluate { - val hasCocoapodsPlugin = - project.plugins.findPlugin(KotlinCocoapodsPlugin::class.java) != null - - if (extension.autoInstall.enabled.get()) { - installSentryForKmp(extension.autoInstall.commonMain) - - if (hasCocoapodsPlugin) { - installSentryForCocoapods(extension.autoInstall.cocoapods) + override fun apply(project: Project): Unit = + with(project) { + val sentryExtension = + project.extensions.create( + SENTRY_EXTENSION_NAME, + SentryExtension::class.java, + project, + ) + project.extensions.add(LINKER_EXTENSION_NAME, sentryExtension.linker) + project.extensions.add(AUTO_INSTALL_EXTENSION_NAME, sentryExtension.autoInstall) + project.extensions.add( + COCOAPODS_AUTO_INSTALL_EXTENSION_NAME, + sentryExtension.autoInstall.cocoapods, + ) + project.extensions.add( + COMMON_MAIN_AUTO_INSTALL_EXTENSION_NAME, + sentryExtension.autoInstall.commonMain, + ) + + afterEvaluate { + val hasCocoapodsPlugin = + project.plugins.findPlugin(KotlinCocoapodsPlugin::class.java) != null + + if (sentryExtension.autoInstall.enabled.get()) { + if (sentryExtension.autoInstall.commonMain.enabled.get()) { + installSentryForKmp(sentryExtension.autoInstall.commonMain) + } + if (hasCocoapodsPlugin && sentryExtension.autoInstall.cocoapods.enabled.get()) { + installSentryForCocoapods(sentryExtension.autoInstall.cocoapods) + } } - } - if (!hasCocoapodsPlugin) { - configureLinkingOptions(extension.linker) + // If the user is not using the cocoapods plugin, linking to the framework is not automatic + // so we have to take care of that + if (!hasCocoapodsPlugin) { + configureLinkingOptions(sentryExtension.linker) + } } } - } } -internal fun Project.installSentryForKmp(sourceSetAutoInstallExtension: SourceSetAutoInstallExtension) { +internal fun Project.installSentryForKmp(commonMainAutoInstallExtension: SourceSetAutoInstallExtension) { val kmpExtension = extensions.findByName(KOTLIN_EXTENSION_NAME) if (kmpExtension !is KotlinMultiplatformExtension) { // todo: log, not multiplatform found return } - if (!sourceSetAutoInstallExtension.enabled.get()) { - return - } - val unsupportedTargets = listOf("wasm", "js", "mingw", "linux") kmpExtension.targets.forEach { target -> - if (unsupportedTargets.any { unsupported -> target.name.contains(unsupported) }) { - throw GradleException("Unsupported target: ${target.name}. Cannot auto install in commonMain. Please create an intermediate sourceSet with targets that the SDK supports and add the dependency manually.") + if (unsupportedTargets.any { unsupported -> + target.name.contains(unsupported) + } + ) { + throw GradleException( + "Unsupported target: ${target.name}. " + + "Cannot auto install in commonMain. " + + "Please create an intermediate sourceSet with targets that the SDK supports and add the dependency manually.", + ) } } - val commonMain = kmpExtension.sourceSets.find { - it.name.contains("common") - } + val commonMain = + kmpExtension.sourceSets.find { + it.name.contains("common") + } - val sentryVersion = sourceSetAutoInstallExtension.sentryKmpVersion.get() + val sentryVersion = commonMainAutoInstallExtension.sentryKmpVersion.get() commonMain?.dependencies { api("io.sentry:sentry-kotlin-multiplatform:$sentryVersion") } @@ -94,8 +106,7 @@ internal fun Project.installSentryForCocoapods(cocoapodsAutoInstallExtension: Co val sentryPod = cocoapods.pods.findByName(podName) if (sentryPod == null) { cocoapods.pod(podName) { - version = - cocoapodsAutoInstallExtension.sentryCocoaVersion.get() + version = cocoapodsAutoInstallExtension.sentryCocoaVersion.get() linkOnly = true extraOpts += listOf("-compiler-option", "-fmodules") } @@ -126,19 +137,20 @@ internal fun Project.configureLinkingOptions(linkerExtension: LinkerExtension) { "$derivedDataPath/SourcePackages/artifacts/sentry-cocoa/Sentry/Sentry.xcframework/$frameworkArchitecture" target.binaries.all binaries@{ binary -> - val path = when { - File(dynamicFrameworkPath).exists() -> dynamicFrameworkPath - File(staticFrameworkPath).exists() -> { - // todo: log, dynamic framework not found, try using static framework - staticFrameworkPath + val path = + when { + File(dynamicFrameworkPath).exists() -> dynamicFrameworkPath + File(staticFrameworkPath).exists() -> { + // todo: log, dynamic framework not found, try using static framework + staticFrameworkPath + } + + else -> { + // todo: log, static framework also not found, error + return@binaries + } } - else -> { - // todo: log, static framework also not found, error - return@binaries - } - } - if (binary is TestExecutable) { binary.linkerOpts("-rpath", "$path/Sentry.framework", "-F$path") } else if (binary is Framework) { @@ -152,16 +164,18 @@ private fun Project.findDerivedDataPath(customXcodeprojPath: String? = null): St val xcodeprojPath = customXcodeprojPath ?: findXcodeprojFile(rootDir)?.absolutePath val buildDirOutput = ByteArrayOutputStream() exec { - it.commandLine = listOf( - "xcodebuild", "-project", xcodeprojPath, "-showBuildSettings" - ) + it.commandLine = + listOf( + "xcodebuild", "-project", xcodeprojPath, "-showBuildSettings", + ) it.standardOutput = buildDirOutput } val buildSettings = buildDirOutput.toString("UTF-8") val buildDirRegex = Regex("BUILD_DIR = (.+)") val buildDirMatch = buildDirRegex.find(buildSettings) - val buildDir = buildDirMatch?.groupValues?.get(1) - ?: throw GradleException("BUILD_DIR not found in xcodebuild output") + val buildDir = + buildDirMatch?.groupValues?.get(1) + ?: throw GradleException("BUILD_DIR not found in xcodebuild output") val derivedDataPath = buildDir.replace("/Build/Products", "") return derivedDataPath } diff --git a/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SourceSetAutoInstallExtension.kt b/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SourceSetAutoInstallExtension.kt index dea9eeae..f2831011 100644 --- a/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SourceSetAutoInstallExtension.kt +++ b/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SourceSetAutoInstallExtension.kt @@ -6,23 +6,25 @@ import javax.inject.Inject @Suppress("UnnecessaryAbstractClass") abstract class SourceSetAutoInstallExtension -@Inject -constructor(project: Project) { - private val objects = project.objects + @Inject + constructor(project: Project) { + private val objects = project.objects - /** - * Enable auto-installation of the Sentry Kotlin Multiplatform SDK dependency in the commonMain source set. - * - * Defaults to true. - */ - val enabled: Property = objects.property(Boolean::class.java) - .convention(true) + /** + * Enable auto-installation of the Sentry Kotlin Multiplatform SDK dependency in the commonMain source set. + * + * Defaults to true. + */ + val enabled: Property = + objects.property(Boolean::class.java) + .convention(true) - /** - * Overrides the default Sentry Kotlin Multiplatform SDK dependency version. - * - * Defaults to the latest version of the Sentry Kotlin Multiplatform SDK. - */ - val sentryKmpVersion: Property = objects.property(String::class.java) - .convention("latest.release") // Replace with the actual default version -} \ No newline at end of file + /** + * Overrides the default Sentry Kotlin Multiplatform SDK dependency version. + * + * Defaults to the latest version of the Sentry Kotlin Multiplatform SDK. + */ + val sentryKmpVersion: Property = + objects.property(String::class.java) + .convention("latest.release") // Replace with the actual default version + } diff --git a/plugin-build/plugin/src/test/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPluginTest.kt b/plugin-build/plugin/src/test/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPluginTest.kt index ae92a47a..326f1216 100644 --- a/plugin-build/plugin/src/test/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPluginTest.kt +++ b/plugin-build/plugin/src/test/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPluginTest.kt @@ -92,4 +92,4 @@ class SentryPluginTest { assertEquals(pod?.version, "custom version") } } -} \ No newline at end of file +} From de523acf567f20ed330beef50badce3aba951830 Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Fri, 7 Jun 2024 18:54:03 +0200 Subject: [PATCH 23/78] Format --- plugin-build/plugin/build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin-build/plugin/build.gradle.kts b/plugin-build/plugin/build.gradle.kts index 58b68966..047568aa 100644 --- a/plugin-build/plugin/build.gradle.kts +++ b/plugin-build/plugin/build.gradle.kts @@ -63,4 +63,4 @@ distributions { from("build${sep}publications${sep}maven") } } -} \ No newline at end of file +} From 8fa4104de4f364b25a6ee46721ba008453d6a6d8 Mon Sep 17 00:00:00 2001 From: Giancarlo Buenaflor Date: Mon, 10 Jun 2024 19:55:40 +0200 Subject: [PATCH 24/78] Update plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt Co-authored-by: Roman Zavarnitsyn --- .../sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt b/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt index 2bce3277..930c2544 100644 --- a/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt +++ b/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt @@ -79,7 +79,7 @@ internal fun Project.installSentryForKmp(commonMainAutoInstallExtension: SourceS throw GradleException( "Unsupported target: ${target.name}. " + "Cannot auto install in commonMain. " + - "Please create an intermediate sourceSet with targets that the SDK supports and add the dependency manually.", + "Please create an intermediate sourceSet with targets that the Sentry SDK supports (apple, jvm, android) and add the dependency manually.", ) } } From 0cdeace9ed6ae49b430e3f705d223f563da9ddc1 Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Mon, 10 Jun 2024 19:57:06 +0200 Subject: [PATCH 25/78] check if isStatic in linking --- .../gradle/plugin/SentryPlugin.kt | 33 ++++++++++--------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt b/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt index 930c2544..dc119517 100644 --- a/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt +++ b/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt @@ -7,6 +7,8 @@ import org.gradle.api.plugins.ExtensionAware import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension import org.jetbrains.kotlin.gradle.plugin.cocoapods.CocoapodsExtension import org.jetbrains.kotlin.gradle.plugin.cocoapods.KotlinCocoapodsPlugin +import org.jetbrains.kotlin.gradle.plugin.mpp.AbstractExecutable +import org.jetbrains.kotlin.gradle.plugin.mpp.AbstractNativeLibrary import org.jetbrains.kotlin.gradle.plugin.mpp.Framework import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget import org.jetbrains.kotlin.gradle.plugin.mpp.TestExecutable @@ -136,25 +138,24 @@ internal fun Project.configureLinkingOptions(linkerExtension: LinkerExtension) { val staticFrameworkPath = "$derivedDataPath/SourcePackages/artifacts/sentry-cocoa/Sentry/Sentry.xcframework/$frameworkArchitecture" - target.binaries.all binaries@{ binary -> - val path = - when { - File(dynamicFrameworkPath).exists() -> dynamicFrameworkPath - File(staticFrameworkPath).exists() -> { - // todo: log, dynamic framework not found, try using static framework - staticFrameworkPath - } + val dynamicFrameworkExists = File(dynamicFrameworkPath).exists() + val staticFrameworkExists = File(staticFrameworkPath).exists() - else -> { - // todo: log, static framework also not found, error - return@binaries - } - } + if (!dynamicFrameworkExists && !staticFrameworkExists) { + throw GradleException("Sentry Cocoa Framework not found at $dynamicFrameworkPath or $staticFrameworkPath") + } + target.binaries.all binaries@{ binary -> if (binary is TestExecutable) { - binary.linkerOpts("-rpath", "$path/Sentry.framework", "-F$path") - } else if (binary is Framework) { - binary.linkerOpts("-F$path") + val frameworkPath = + if (dynamicFrameworkExists) dynamicFrameworkPath else staticFrameworkPath + binary.linkerOpts("-rpath", "$path/Sentry.framework", "-F$frameworkPath") + } + + if (binary is Framework) { + val frameworkPath = + if (binary.isStatic) staticFrameworkPath else dynamicFrameworkPath + binary.linkerOpts("-F$frameworkPath") } } } From 6fd58379b081eec5d62a57d3346adc04d0e58917 Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Mon, 10 Jun 2024 18:21:06 +0200 Subject: [PATCH 26/78] Update plugin build dir name and ID --- .../build.gradle.kts | 0 .../gradle.properties | 4 ++-- .../gradle/libs.versions.toml | 0 .../gradle/wrapper | 0 .../gradlew | 0 .../gradlew.bat | 0 .../plugin/build.gradle.kts | 0 .../multiplatform/gradle/plugin/AutoInstallExtension.kt | 0 .../gradle/plugin/CocoapodsAutoInstallExtension.kt | 0 .../kotlin/multiplatform/gradle/plugin/LinkerExtension.kt | 0 .../kotlin/multiplatform/gradle/plugin/SentryExtension.kt | 0 .../sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt | 0 .../gradle/plugin/SourceSetAutoInstallExtension.kt | 0 .../kotlin/multiplatform/gradle/plugin/SentryPluginTest.kt | 0 .../settings.gradle.kts | 2 +- 15 files changed, 3 insertions(+), 3 deletions(-) rename {plugin-build => sentry-kotlin-multiplatform-gradle-plugin}/build.gradle.kts (100%) rename {plugin-build => sentry-kotlin-multiplatform-gradle-plugin}/gradle.properties (84%) rename {plugin-build => sentry-kotlin-multiplatform-gradle-plugin}/gradle/libs.versions.toml (100%) rename {plugin-build => sentry-kotlin-multiplatform-gradle-plugin}/gradle/wrapper (100%) rename {plugin-build => sentry-kotlin-multiplatform-gradle-plugin}/gradlew (100%) rename {plugin-build => sentry-kotlin-multiplatform-gradle-plugin}/gradlew.bat (100%) rename {plugin-build => sentry-kotlin-multiplatform-gradle-plugin}/plugin/build.gradle.kts (100%) rename {plugin-build => sentry-kotlin-multiplatform-gradle-plugin}/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/AutoInstallExtension.kt (100%) rename {plugin-build => sentry-kotlin-multiplatform-gradle-plugin}/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/CocoapodsAutoInstallExtension.kt (100%) rename {plugin-build => sentry-kotlin-multiplatform-gradle-plugin}/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/LinkerExtension.kt (100%) rename {plugin-build => sentry-kotlin-multiplatform-gradle-plugin}/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryExtension.kt (100%) rename {plugin-build => sentry-kotlin-multiplatform-gradle-plugin}/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt (100%) rename {plugin-build => sentry-kotlin-multiplatform-gradle-plugin}/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SourceSetAutoInstallExtension.kt (100%) rename {plugin-build => sentry-kotlin-multiplatform-gradle-plugin}/plugin/src/test/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPluginTest.kt (100%) rename {plugin-build => sentry-kotlin-multiplatform-gradle-plugin}/settings.gradle.kts (93%) diff --git a/plugin-build/build.gradle.kts b/sentry-kotlin-multiplatform-gradle-plugin/build.gradle.kts similarity index 100% rename from plugin-build/build.gradle.kts rename to sentry-kotlin-multiplatform-gradle-plugin/build.gradle.kts diff --git a/plugin-build/gradle.properties b/sentry-kotlin-multiplatform-gradle-plugin/gradle.properties similarity index 84% rename from plugin-build/gradle.properties rename to sentry-kotlin-multiplatform-gradle-plugin/gradle.properties index 393aaf7c..533ee963 100644 --- a/plugin-build/gradle.properties +++ b/sentry-kotlin-multiplatform-gradle-plugin/gradle.properties @@ -1,5 +1,5 @@ -ID=io.sentry.kotlin.multiplatform.gradle.plugin -VERSION=1.0.0 +ID=io.sentry.kotlin.multiplatform.gradle +VERSION=0.7.2 GROUP=io.sentry DISPLAY_NAME=An empty Gradle Plugin from a template DESCRIPTION=An empty Gradle plugin created from a template diff --git a/plugin-build/gradle/libs.versions.toml b/sentry-kotlin-multiplatform-gradle-plugin/gradle/libs.versions.toml similarity index 100% rename from plugin-build/gradle/libs.versions.toml rename to sentry-kotlin-multiplatform-gradle-plugin/gradle/libs.versions.toml diff --git a/plugin-build/gradle/wrapper b/sentry-kotlin-multiplatform-gradle-plugin/gradle/wrapper similarity index 100% rename from plugin-build/gradle/wrapper rename to sentry-kotlin-multiplatform-gradle-plugin/gradle/wrapper diff --git a/plugin-build/gradlew b/sentry-kotlin-multiplatform-gradle-plugin/gradlew similarity index 100% rename from plugin-build/gradlew rename to sentry-kotlin-multiplatform-gradle-plugin/gradlew diff --git a/plugin-build/gradlew.bat b/sentry-kotlin-multiplatform-gradle-plugin/gradlew.bat similarity index 100% rename from plugin-build/gradlew.bat rename to sentry-kotlin-multiplatform-gradle-plugin/gradlew.bat diff --git a/plugin-build/plugin/build.gradle.kts b/sentry-kotlin-multiplatform-gradle-plugin/plugin/build.gradle.kts similarity index 100% rename from plugin-build/plugin/build.gradle.kts rename to sentry-kotlin-multiplatform-gradle-plugin/plugin/build.gradle.kts diff --git a/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/AutoInstallExtension.kt b/sentry-kotlin-multiplatform-gradle-plugin/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/AutoInstallExtension.kt similarity index 100% rename from plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/AutoInstallExtension.kt rename to sentry-kotlin-multiplatform-gradle-plugin/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/AutoInstallExtension.kt diff --git a/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/CocoapodsAutoInstallExtension.kt b/sentry-kotlin-multiplatform-gradle-plugin/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/CocoapodsAutoInstallExtension.kt similarity index 100% rename from plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/CocoapodsAutoInstallExtension.kt rename to sentry-kotlin-multiplatform-gradle-plugin/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/CocoapodsAutoInstallExtension.kt diff --git a/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/LinkerExtension.kt b/sentry-kotlin-multiplatform-gradle-plugin/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/LinkerExtension.kt similarity index 100% rename from plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/LinkerExtension.kt rename to sentry-kotlin-multiplatform-gradle-plugin/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/LinkerExtension.kt diff --git a/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryExtension.kt b/sentry-kotlin-multiplatform-gradle-plugin/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryExtension.kt similarity index 100% rename from plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryExtension.kt rename to sentry-kotlin-multiplatform-gradle-plugin/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryExtension.kt diff --git a/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt b/sentry-kotlin-multiplatform-gradle-plugin/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt similarity index 100% rename from plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt rename to sentry-kotlin-multiplatform-gradle-plugin/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt diff --git a/plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SourceSetAutoInstallExtension.kt b/sentry-kotlin-multiplatform-gradle-plugin/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SourceSetAutoInstallExtension.kt similarity index 100% rename from plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SourceSetAutoInstallExtension.kt rename to sentry-kotlin-multiplatform-gradle-plugin/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SourceSetAutoInstallExtension.kt diff --git a/plugin-build/plugin/src/test/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPluginTest.kt b/sentry-kotlin-multiplatform-gradle-plugin/plugin/src/test/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPluginTest.kt similarity index 100% rename from plugin-build/plugin/src/test/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPluginTest.kt rename to sentry-kotlin-multiplatform-gradle-plugin/plugin/src/test/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPluginTest.kt diff --git a/plugin-build/settings.gradle.kts b/sentry-kotlin-multiplatform-gradle-plugin/settings.gradle.kts similarity index 93% rename from plugin-build/settings.gradle.kts rename to sentry-kotlin-multiplatform-gradle-plugin/settings.gradle.kts index 3083218c..17c55c6e 100644 --- a/plugin-build/settings.gradle.kts +++ b/sentry-kotlin-multiplatform-gradle-plugin/settings.gradle.kts @@ -14,4 +14,4 @@ dependencyResolutionManagement { rootProject.name = ("io.sentry.kotlin.multiplatform.gradle.plugin") -include(":plugin") \ No newline at end of file +include(":plugin") From f1e31a360d51d86eb760a90efb4ada61d1e83229 Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Mon, 10 Jun 2024 18:22:51 +0200 Subject: [PATCH 27/78] Add deps only with compileOnly --- .../plugin/build.gradle.kts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sentry-kotlin-multiplatform-gradle-plugin/plugin/build.gradle.kts b/sentry-kotlin-multiplatform-gradle-plugin/plugin/build.gradle.kts index 047568aa..b75afc5c 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/plugin/build.gradle.kts +++ b/sentry-kotlin-multiplatform-gradle-plugin/plugin/build.gradle.kts @@ -9,9 +9,9 @@ plugins { } dependencies { - implementation(kotlin("stdlib")) - implementation(gradleApi()) - implementation(kotlin("gradle-plugin")) + compileOnly(kotlin("stdlib")) + compileOnly(gradleApi()) + compileOnly(kotlin("gradle-plugin")) testImplementation(libs.junit) } From 392d33681bfeba09612899ef22cb3988cb66af3c Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Mon, 10 Jun 2024 19:11:02 +0200 Subject: [PATCH 28/78] Update --- .../gradle.properties | 6 +----- .../plugin/build.gradle.kts | 9 --------- .../settings.gradle.kts | 2 +- 3 files changed, 2 insertions(+), 15 deletions(-) diff --git a/sentry-kotlin-multiplatform-gradle-plugin/gradle.properties b/sentry-kotlin-multiplatform-gradle-plugin/gradle.properties index 533ee963..6c97cd6d 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/gradle.properties +++ b/sentry-kotlin-multiplatform-gradle-plugin/gradle.properties @@ -1,8 +1,4 @@ ID=io.sentry.kotlin.multiplatform.gradle +IMPLEMENTATION_CLASS=io.sentry.kotlin.multiplatform.gradle.plugin.SentryPlugin VERSION=0.7.2 GROUP=io.sentry -DISPLAY_NAME=An empty Gradle Plugin from a template -DESCRIPTION=An empty Gradle plugin created from a template -WEBSITE=https://github.com/cortinico/kotlin-gradle-plugin-template -VCS_URL=https://github.com/cortinico/kotlin-gradle-plugin-template -IMPLEMENTATION_CLASS=io.sentry.kotlin.multiplatform.gradle.plugin.SentryPlugin diff --git a/sentry-kotlin-multiplatform-gradle-plugin/plugin/build.gradle.kts b/sentry-kotlin-multiplatform-gradle-plugin/plugin/build.gradle.kts index b75afc5c..49afb3dd 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/plugin/build.gradle.kts +++ b/sentry-kotlin-multiplatform-gradle-plugin/plugin/build.gradle.kts @@ -32,19 +32,10 @@ gradlePlugin { create(property("ID").toString()) { id = property("ID").toString() implementationClass = property("IMPLEMENTATION_CLASS").toString() - version = property("VERSION").toString() - description = property("DESCRIPTION").toString() - displayName = property("DISPLAY_NAME").toString() - tags.set(listOf("plugin", "gradle", "sample", "template")) } } } -gradlePlugin { - website.set(property("WEBSITE").toString()) - vcsUrl.set(property("VCS_URL").toString()) -} - val publish = extensions.getByType(MavenPublishPluginExtension::class.java) // signing is done when uploading files to MC // via gpg:sign-and-deploy-file (release.kts) diff --git a/sentry-kotlin-multiplatform-gradle-plugin/settings.gradle.kts b/sentry-kotlin-multiplatform-gradle-plugin/settings.gradle.kts index 17c55c6e..3271e08c 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/settings.gradle.kts +++ b/sentry-kotlin-multiplatform-gradle-plugin/settings.gradle.kts @@ -12,6 +12,6 @@ dependencyResolutionManagement { } } -rootProject.name = ("io.sentry.kotlin.multiplatform.gradle.plugin") +rootProject.name = "io.sentry.kotlin.multiplatform.gradle.plugin" include(":plugin") From 370a39638bd86fdfb2cf4e9d372ac3b8238c2852 Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Mon, 10 Jun 2024 19:20:13 +0200 Subject: [PATCH 29/78] Updaet --- .../build.gradle.kts | 4 ++-- .../gradle.properties | 8 ++++---- .../plugin/build.gradle.kts | 6 +++--- settings.gradle.kts | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/sentry-kotlin-multiplatform-gradle-plugin/build.gradle.kts b/sentry-kotlin-multiplatform-gradle-plugin/build.gradle.kts index cfd2f0a5..77bcea9f 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/build.gradle.kts +++ b/sentry-kotlin-multiplatform-gradle-plugin/build.gradle.kts @@ -9,8 +9,8 @@ plugins { } allprojects { - group = property("GROUP").toString() - version = property("VERSION").toString() + group = property("group").toString() + version = property("version").toString() apply { plugin(rootProject.libs.plugins.detekt.get().pluginId) diff --git a/sentry-kotlin-multiplatform-gradle-plugin/gradle.properties b/sentry-kotlin-multiplatform-gradle-plugin/gradle.properties index 6c97cd6d..c7d12a2b 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/gradle.properties +++ b/sentry-kotlin-multiplatform-gradle-plugin/gradle.properties @@ -1,4 +1,4 @@ -ID=io.sentry.kotlin.multiplatform.gradle -IMPLEMENTATION_CLASS=io.sentry.kotlin.multiplatform.gradle.plugin.SentryPlugin -VERSION=0.7.2 -GROUP=io.sentry +id=io.sentry.kotlin.multiplatform.gradle +implementation_class=io.sentry.kotlin.multiplatform.gradle.plugin.SentryPlugin +versionName=0.7.1 +group=io.sentry diff --git a/sentry-kotlin-multiplatform-gradle-plugin/plugin/build.gradle.kts b/sentry-kotlin-multiplatform-gradle-plugin/plugin/build.gradle.kts index 49afb3dd..b80113b8 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/plugin/build.gradle.kts +++ b/sentry-kotlin-multiplatform-gradle-plugin/plugin/build.gradle.kts @@ -29,9 +29,9 @@ tasks.withType { gradlePlugin { plugins { - create(property("ID").toString()) { - id = property("ID").toString() - implementationClass = property("IMPLEMENTATION_CLASS").toString() + create(property("id").toString()) { + id = property("id").toString() + implementationClass = property("implementation_class").toString() } } } diff --git a/settings.gradle.kts b/settings.gradle.kts index de561143..5643daf7 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -20,7 +20,7 @@ dependencyResolutionManagement { rootProject.name = "sentry-kotlin-multiplatform-sdk" include(":sentry-kotlin-multiplatform") -includeBuild("plugin-build") +includeBuild("sentry-kotlin-multiplatform-gradle-plugin") /* Simple KMP App with targets: From 409ec2f2a2d179b41f88a5185d8898f8a189af21 Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Mon, 10 Jun 2024 19:20:38 +0200 Subject: [PATCH 30/78] Include gradle plugin version bump --- scripts/bump-version.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/bump-version.sh b/scripts/bump-version.sh index 0f68b3c4..4d11d697 100755 --- a/scripts/bump-version.sh +++ b/scripts/bump-version.sh @@ -12,7 +12,9 @@ OLD_VERSION="$1" NEW_VERSION="$2" GRADLE_FILEPATH="gradle.properties" +PLUGIN_GRADLE_FILEPATH="sentry-kotlin-multiplatform-gradle-plugin/gradle.properties" # Replace `versionName` with the given version VERSION_NAME_PATTERN="versionName" perl -pi -e "s/$VERSION_NAME_PATTERN=.*$/$VERSION_NAME_PATTERN=$NEW_VERSION/g" $GRADLE_FILEPATH +perl -pi -e "s/$VERSION_NAME_PATTERN=.*$/$VERSION_NAME_PATTERN=$NEW_VERSION/g" $PLUGIN_GRADLE_FILEPATH From abcce27b2347eda9988cabd435e2133bc7a23836 Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Mon, 10 Jun 2024 19:44:46 +0200 Subject: [PATCH 31/78] Update project name --- sentry-kotlin-multiplatform-gradle-plugin/settings.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sentry-kotlin-multiplatform-gradle-plugin/settings.gradle.kts b/sentry-kotlin-multiplatform-gradle-plugin/settings.gradle.kts index 3271e08c..6bd3d3e1 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/settings.gradle.kts +++ b/sentry-kotlin-multiplatform-gradle-plugin/settings.gradle.kts @@ -12,6 +12,6 @@ dependencyResolutionManagement { } } -rootProject.name = "io.sentry.kotlin.multiplatform.gradle.plugin" +rootProject.name = "sentry-kotlin-multiplatform-gradle-plugin" include(":plugin") From 6108cdad477fa10545c8afecbea27d8e4900473e Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Mon, 10 Jun 2024 19:54:38 +0200 Subject: [PATCH 32/78] Use buildconfig --- .../gradle.properties | 3 ++- .../gradle/libs.versions.toml | 1 + .../plugin/build.gradle.kts | 11 ++++++++++- .../gradle/plugin/CocoapodsAutoInstallExtension.kt | 5 +++-- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/sentry-kotlin-multiplatform-gradle-plugin/gradle.properties b/sentry-kotlin-multiplatform-gradle-plugin/gradle.properties index c7d12a2b..669f009d 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/gradle.properties +++ b/sentry-kotlin-multiplatform-gradle-plugin/gradle.properties @@ -1,4 +1,5 @@ id=io.sentry.kotlin.multiplatform.gradle -implementation_class=io.sentry.kotlin.multiplatform.gradle.plugin.SentryPlugin +implementationClass=io.sentry.kotlin.multiplatform.gradle.plugin.SentryPlugin versionName=0.7.1 group=io.sentry +sentryCocoaVersion = 8.26.0 \ No newline at end of file diff --git a/sentry-kotlin-multiplatform-gradle-plugin/gradle/libs.versions.toml b/sentry-kotlin-multiplatform-gradle-plugin/gradle/libs.versions.toml index 92ea4d16..82893cb5 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/gradle/libs.versions.toml +++ b/sentry-kotlin-multiplatform-gradle-plugin/gradle/libs.versions.toml @@ -12,6 +12,7 @@ ktlint = { id = "org.jlleitschuh.gradle.ktlint", version.ref = "ktlintGradle"} pluginPublish = { id = "com.gradle.plugin-publish", version.ref = "pluginPublish"} versionCheck = { id = "com.github.ben-manes.versions", version.ref = "versionCheck"} vanniktech-publish = { id = "com.vanniktech.maven.publish", version = "0.18.0"} +buildConfig = { id = "com.github.gmazzo.buildconfig", version = "5.3.5"} [libraries] junit = "junit:junit:4.13.2" diff --git a/sentry-kotlin-multiplatform-gradle-plugin/plugin/build.gradle.kts b/sentry-kotlin-multiplatform-gradle-plugin/plugin/build.gradle.kts index b80113b8..34b1b9ce 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/plugin/build.gradle.kts +++ b/sentry-kotlin-multiplatform-gradle-plugin/plugin/build.gradle.kts @@ -6,6 +6,7 @@ plugins { `java-gradle-plugin` alias(libs.plugins.vanniktech.publish) id("distribution") + alias(libs.plugins.buildConfig) } dependencies { @@ -31,7 +32,7 @@ gradlePlugin { plugins { create(property("id").toString()) { id = property("id").toString() - implementationClass = property("implementation_class").toString() + implementationClass = property("implementationClass").toString() } } } @@ -55,3 +56,11 @@ distributions { } } } + +buildConfig { + useKotlinOutput() + packageName("io.sentry") + className("BuildConfig") + + buildConfigField("String", "SentryCocoaVersion", provider { "\"${project.property("sentryCocoaVersion")}\"" }) +} \ No newline at end of file diff --git a/sentry-kotlin-multiplatform-gradle-plugin/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/CocoapodsAutoInstallExtension.kt b/sentry-kotlin-multiplatform-gradle-plugin/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/CocoapodsAutoInstallExtension.kt index c6e75147..2fd56e57 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/CocoapodsAutoInstallExtension.kt +++ b/sentry-kotlin-multiplatform-gradle-plugin/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/CocoapodsAutoInstallExtension.kt @@ -1,5 +1,6 @@ package io.sentry.kotlin.multiplatform.gradle.plugin +import io.sentry.BuildConfig import org.gradle.api.Project import org.gradle.api.provider.Property import javax.inject.Inject @@ -24,9 +25,9 @@ abstract class CocoapodsAutoInstallExtension /** * Overrides default Sentry Cocoa version. * - * Defaults to the `~> 8.25`. + * Defaults to the version used in the latest KMP SDK. */ val sentryCocoaVersion: Property = objects.property(String::class.java) - .convention("~> 8.25") // todo: grab the latest version properly + .convention(BuildConfig.SentryCocoaVersion) // todo: grab the latest version properly } From 5dc9130a1650d1e6695e877eaccb24e49de22607 Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Mon, 10 Jun 2024 19:55:16 +0200 Subject: [PATCH 33/78] Remove todo --- .../gradle/plugin/CocoapodsAutoInstallExtension.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sentry-kotlin-multiplatform-gradle-plugin/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/CocoapodsAutoInstallExtension.kt b/sentry-kotlin-multiplatform-gradle-plugin/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/CocoapodsAutoInstallExtension.kt index 2fd56e57..b45e9814 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/CocoapodsAutoInstallExtension.kt +++ b/sentry-kotlin-multiplatform-gradle-plugin/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/CocoapodsAutoInstallExtension.kt @@ -29,5 +29,5 @@ abstract class CocoapodsAutoInstallExtension */ val sentryCocoaVersion: Property = objects.property(String::class.java) - .convention(BuildConfig.SentryCocoaVersion) // todo: grab the latest version properly + .convention(BuildConfig.SentryCocoaVersion) } From 38db5e882ef25983f0d4b8ed5ab4c2e30628c178 Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Mon, 10 Jun 2024 19:59:40 +0200 Subject: [PATCH 34/78] Change sentry extension name to sentryKmp --- .../sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sentry-kotlin-multiplatform-gradle-plugin/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt b/sentry-kotlin-multiplatform-gradle-plugin/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt index dc119517..e10b75ab 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt +++ b/sentry-kotlin-multiplatform-gradle-plugin/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt @@ -15,7 +15,7 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.TestExecutable import java.io.ByteArrayOutputStream import java.io.File -internal const val SENTRY_EXTENSION_NAME = "sentry" +internal const val SENTRY_EXTENSION_NAME = "sentryKmp" internal const val LINKER_EXTENSION_NAME = "linker" internal const val AUTO_INSTALL_EXTENSION_NAME = "autoInstall" internal const val COCOAPODS_AUTO_INSTALL_EXTENSION_NAME = "cocoapods" From fb1ca4b38e8b929a84667b43172496b29da32b03 Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Mon, 10 Jun 2024 20:00:25 +0200 Subject: [PATCH 35/78] Set androidNative to unsupported targets --- .../sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sentry-kotlin-multiplatform-gradle-plugin/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt b/sentry-kotlin-multiplatform-gradle-plugin/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt index e10b75ab..92934d38 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt +++ b/sentry-kotlin-multiplatform-gradle-plugin/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt @@ -72,7 +72,7 @@ internal fun Project.installSentryForKmp(commonMainAutoInstallExtension: SourceS return } - val unsupportedTargets = listOf("wasm", "js", "mingw", "linux") + val unsupportedTargets = listOf("wasm", "js", "mingw", "linux", "androidNative") kmpExtension.targets.forEach { target -> if (unsupportedTargets.any { unsupported -> target.name.contains(unsupported) From d3e2891cb92067906fadb1b743aeb6815eb50316 Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Mon, 10 Jun 2024 21:39:04 +0200 Subject: [PATCH 36/78] add symlinks --- .../kotlin-multiplatform-gradle-plugin.yml | 0 .../build.gradle.kts | 109 ++++++-- .../gradle/wrapper | 2 +- .../plugin/build.gradle.kts | 66 ----- .../build.gradle.kts | 76 ++++++ .../gradle}/AutoInstallExtension.kt | 0 .../gradle}/CocoapodsAutoInstallExtension.kt | 0 .../multiplatform/gradle}/LinkerExtension.kt | 0 .../multiplatform/gradle}/SentryExtension.kt | 0 .../multiplatform/gradle}/SentryPlugin.kt | 0 .../gradle}/SourceSetAutoInstallExtension.kt | 0 .../gradle/plugin/SentryPluginTest.kt | 0 .../gradle/AutoInstallExtension.kt | 27 ++ .../gradle/CocoapodsAutoInstallExtension.kt | 33 +++ .../multiplatform/gradle/LinkerExtension.kt | 14 ++ .../multiplatform/gradle/SentryExtension.kt | 20 ++ .../multiplatform/gradle/SentryPlugin.kt | 232 ++++++++++++++++++ .../gradle/SourceSetAutoInstallExtension.kt | 30 +++ .../gradle/plugin/SentryPluginTest.kt | 95 +++++++ 19 files changed, 613 insertions(+), 91 deletions(-) create mode 100644 .github/workflows/kotlin-multiplatform-gradle-plugin.yml delete mode 100644 sentry-kotlin-multiplatform-gradle-plugin/plugin/build.gradle.kts create mode 100644 sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/build.gradle.kts rename sentry-kotlin-multiplatform-gradle-plugin/{plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin => sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle}/AutoInstallExtension.kt (100%) rename sentry-kotlin-multiplatform-gradle-plugin/{plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin => sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle}/CocoapodsAutoInstallExtension.kt (100%) rename sentry-kotlin-multiplatform-gradle-plugin/{plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin => sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle}/LinkerExtension.kt (100%) rename sentry-kotlin-multiplatform-gradle-plugin/{plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin => sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle}/SentryExtension.kt (100%) rename sentry-kotlin-multiplatform-gradle-plugin/{plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin => sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle}/SentryPlugin.kt (100%) rename sentry-kotlin-multiplatform-gradle-plugin/{plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin => sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle}/SourceSetAutoInstallExtension.kt (100%) rename sentry-kotlin-multiplatform-gradle-plugin/{plugin => sentry-kotlin-multiplatform-gradle-plugin}/src/test/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPluginTest.kt (100%) create mode 100644 sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/AutoInstallExtension.kt create mode 100644 sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/CocoapodsAutoInstallExtension.kt create mode 100644 sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/LinkerExtension.kt create mode 100644 sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryExtension.kt create mode 100644 sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryPlugin.kt create mode 100644 sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SourceSetAutoInstallExtension.kt create mode 100644 sentry-kotlin-multiplatform-gradle-plugin/src/test/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPluginTest.kt diff --git a/.github/workflows/kotlin-multiplatform-gradle-plugin.yml b/.github/workflows/kotlin-multiplatform-gradle-plugin.yml new file mode 100644 index 00000000..e69de29b diff --git a/sentry-kotlin-multiplatform-gradle-plugin/build.gradle.kts b/sentry-kotlin-multiplatform-gradle-plugin/build.gradle.kts index 77bcea9f..c40e064e 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/build.gradle.kts +++ b/sentry-kotlin-multiplatform-gradle-plugin/build.gradle.kts @@ -1,47 +1,108 @@ import io.gitlab.arturbosch.detekt.Detekt +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { - alias(libs.plugins.kotlin) apply false - alias(libs.plugins.pluginPublish) apply false + alias(libs.plugins.kotlin) + alias(libs.plugins.pluginPublish) alias(libs.plugins.detekt) alias(libs.plugins.ktlint) alias(libs.plugins.versionCheck) + `java-gradle-plugin` + alias(libs.plugins.vanniktech.publish) + id("distribution") + alias(libs.plugins.buildConfig) } -allprojects { - group = property("group").toString() - version = property("version").toString() +dependencies { + compileOnly(kotlin("stdlib")) + compileOnly(gradleApi()) + compileOnly(kotlin("gradle-plugin")) - apply { - plugin(rootProject.libs.plugins.detekt.get().pluginId) - plugin(rootProject.libs.plugins.ktlint.get().pluginId) + testImplementation(libs.junit) +} + +java { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 +} + +tasks.withType { + kotlinOptions { + jvmTarget = JavaVersion.VERSION_1_8.toString() + } +} + +gradlePlugin { + plugins { + create(property("id").toString()) { + id = property("id").toString() + implementationClass = property("implementationClass").toString() + } + } +} + +//val publish = extensions.getByType(MavenPublishPluginExtension::class.java) +//// signing is done when uploading files to MC +//// via gpg:sign-and-deploy-file (release.kts) +//publish.releaseSigningEnabled = false + +tasks.named("distZip").configure { + dependsOn("publishToMavenLocal") + this.doLast { + val distributionFilePath = + "${project.layout.buildDirectory.asFile.get().path}${sep}distributions${sep}${project.name}-${project.version}.zip" + val file = File(distributionFilePath) + if (!file.exists()) throw IllegalStateException("Distribution file: $distributionFilePath does not exist") + if (file.length() == 0L) throw IllegalStateException("Distribution file: $distributionFilePath is empty") } +} + +val sep = File.separator - ktlint { - debug.set(false) - verbose.set(true) - android.set(false) - outputToConsole.set(true) - ignoreFailures.set(false) - enableExperimentalRules.set(true) - filter { - exclude("**/generated/**") - include("**/kotlin/**") +distributions { + main { + contents { + from("build${sep}libs") + from("build${sep}publications${sep}maven") } } +} + +buildConfig { + useKotlinOutput() + packageName("io.sentry") + className("BuildConfig") - detekt { - config.setFrom(rootProject.files("../config/detekt/detekt.yml")) + buildConfigField( + "String", + "SentryCocoaVersion", + provider { "\"${project.property("sentryCocoaVersion")}\"" }) +} + +ktlint { + debug.set(false) + verbose.set(true) + android.set(false) + outputToConsole.set(true) + ignoreFailures.set(false) + enableExperimentalRules.set(true) + filter { + exclude("**/generated/**") + include("**/kotlin/**") } } +detekt { + config.setFrom(rootProject.files("../config/detekt/detekt.yml")) +} + tasks.withType().configureEach { reports { html.required.set(true) html.outputLocation.set(file("build/reports/detekt.html")) } } - -tasks.register("clean", Delete::class.java) { - delete(rootProject.layout.buildDirectory) -} +// +//tasks.register("clean", Delete::class.java) { +// delete(rootProject.layout.buildDirectory) +//} diff --git a/sentry-kotlin-multiplatform-gradle-plugin/gradle/wrapper b/sentry-kotlin-multiplatform-gradle-plugin/gradle/wrapper index 3232fe4e..cbfd2e1d 120000 --- a/sentry-kotlin-multiplatform-gradle-plugin/gradle/wrapper +++ b/sentry-kotlin-multiplatform-gradle-plugin/gradle/wrapper @@ -1 +1 @@ -../../gradle/wrapper \ No newline at end of file +../../gradle/wrapper/ \ No newline at end of file diff --git a/sentry-kotlin-multiplatform-gradle-plugin/plugin/build.gradle.kts b/sentry-kotlin-multiplatform-gradle-plugin/plugin/build.gradle.kts deleted file mode 100644 index 34b1b9ce..00000000 --- a/sentry-kotlin-multiplatform-gradle-plugin/plugin/build.gradle.kts +++ /dev/null @@ -1,66 +0,0 @@ -import com.vanniktech.maven.publish.MavenPublishPluginExtension -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile - -plugins { - kotlin("jvm") - `java-gradle-plugin` - alias(libs.plugins.vanniktech.publish) - id("distribution") - alias(libs.plugins.buildConfig) -} - -dependencies { - compileOnly(kotlin("stdlib")) - compileOnly(gradleApi()) - compileOnly(kotlin("gradle-plugin")) - - testImplementation(libs.junit) -} - -java { - sourceCompatibility = JavaVersion.VERSION_1_8 - targetCompatibility = JavaVersion.VERSION_1_8 -} - -tasks.withType { - kotlinOptions { - jvmTarget = JavaVersion.VERSION_1_8.toString() - } -} - -gradlePlugin { - plugins { - create(property("id").toString()) { - id = property("id").toString() - implementationClass = property("implementationClass").toString() - } - } -} - -val publish = extensions.getByType(MavenPublishPluginExtension::class.java) -// signing is done when uploading files to MC -// via gpg:sign-and-deploy-file (release.kts) -publish.releaseSigningEnabled = false - -tasks.named("distZip").configure { - dependsOn("publishToMavenLocal") -} - -val sep = File.separator - -distributions { - main { - contents { - from("build${sep}libs") - from("build${sep}publications${sep}maven") - } - } -} - -buildConfig { - useKotlinOutput() - packageName("io.sentry") - className("BuildConfig") - - buildConfigField("String", "SentryCocoaVersion", provider { "\"${project.property("sentryCocoaVersion")}\"" }) -} \ No newline at end of file diff --git a/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/build.gradle.kts b/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/build.gradle.kts new file mode 100644 index 00000000..b7be7015 --- /dev/null +++ b/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/build.gradle.kts @@ -0,0 +1,76 @@ +//import com.vanniktech.maven.publish.MavenPublishPluginExtension +//import org.jetbrains.kotlin.gradle.tasks.KotlinCompile +// +//plugins { +// kotlin("jvm") +// `java-gradle-plugin` +// alias(libs.plugins.vanniktech.publish) +// id("distribution") +// alias(libs.plugins.buildConfig) +//} +// +//dependencies { +// compileOnly(kotlin("stdlib")) +// compileOnly(gradleApi()) +// compileOnly(kotlin("gradle-plugin")) +// +// testImplementation(libs.junit) +//} +// +//java { +// sourceCompatibility = JavaVersion.VERSION_1_8 +// targetCompatibility = JavaVersion.VERSION_1_8 +//} +// +//tasks.withType { +// kotlinOptions { +// jvmTarget = JavaVersion.VERSION_1_8.toString() +// } +//} +// +//gradlePlugin { +// plugins { +// create(property("id").toString()) { +// id = property("id").toString() +// implementationClass = property("implementationClass").toString() +// } +// } +//} +// +//val publish = extensions.getByType(MavenPublishPluginExtension::class.java) +//// signing is done when uploading files to MC +//// via gpg:sign-and-deploy-file (release.kts) +//publish.releaseSigningEnabled = false +// +//tasks.named("distZip").configure { +// dependsOn("publishToMavenLocal") +// this.doLast { +// val distributionFilePath = +// "${project.layout.buildDirectory.asFile.get().path}${sep}distributions${sep}${project.name}-${project.version}.zip" +// val file = File(distributionFilePath) +// if (!file.exists()) throw IllegalStateException("Distribution file: $distributionFilePath does not exist") +// if (file.length() == 0L) throw IllegalStateException("Distribution file: $distributionFilePath is empty") +// } +//} +// +//val sep = File.separator +// +//distributions { +// main { +// contents { +// from("build${sep}libs") +// from("build${sep}publications${sep}maven") +// } +// } +//} +// +//buildConfig { +// useKotlinOutput() +// packageName("io.sentry") +// className("BuildConfig") +// +// buildConfigField( +// "String", +// "SentryCocoaVersion", +// provider { "\"${project.property("sentryCocoaVersion")}\"" }) +//} \ No newline at end of file diff --git a/sentry-kotlin-multiplatform-gradle-plugin/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/AutoInstallExtension.kt b/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/AutoInstallExtension.kt similarity index 100% rename from sentry-kotlin-multiplatform-gradle-plugin/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/AutoInstallExtension.kt rename to sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/AutoInstallExtension.kt diff --git a/sentry-kotlin-multiplatform-gradle-plugin/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/CocoapodsAutoInstallExtension.kt b/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/CocoapodsAutoInstallExtension.kt similarity index 100% rename from sentry-kotlin-multiplatform-gradle-plugin/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/CocoapodsAutoInstallExtension.kt rename to sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/CocoapodsAutoInstallExtension.kt diff --git a/sentry-kotlin-multiplatform-gradle-plugin/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/LinkerExtension.kt b/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/LinkerExtension.kt similarity index 100% rename from sentry-kotlin-multiplatform-gradle-plugin/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/LinkerExtension.kt rename to sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/LinkerExtension.kt diff --git a/sentry-kotlin-multiplatform-gradle-plugin/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryExtension.kt b/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryExtension.kt similarity index 100% rename from sentry-kotlin-multiplatform-gradle-plugin/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryExtension.kt rename to sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryExtension.kt diff --git a/sentry-kotlin-multiplatform-gradle-plugin/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt b/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryPlugin.kt similarity index 100% rename from sentry-kotlin-multiplatform-gradle-plugin/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt rename to sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryPlugin.kt diff --git a/sentry-kotlin-multiplatform-gradle-plugin/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SourceSetAutoInstallExtension.kt b/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SourceSetAutoInstallExtension.kt similarity index 100% rename from sentry-kotlin-multiplatform-gradle-plugin/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SourceSetAutoInstallExtension.kt rename to sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SourceSetAutoInstallExtension.kt diff --git a/sentry-kotlin-multiplatform-gradle-plugin/plugin/src/test/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPluginTest.kt b/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/test/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPluginTest.kt similarity index 100% rename from sentry-kotlin-multiplatform-gradle-plugin/plugin/src/test/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPluginTest.kt rename to sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/test/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPluginTest.kt diff --git a/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/AutoInstallExtension.kt b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/AutoInstallExtension.kt new file mode 100644 index 00000000..807f3702 --- /dev/null +++ b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/AutoInstallExtension.kt @@ -0,0 +1,27 @@ +package io.sentry.kotlin.multiplatform.gradle.plugin + +import org.gradle.api.Project +import org.gradle.api.provider.Property +import javax.inject.Inject + +@Suppress("UnnecessaryAbstractClass") +abstract class AutoInstallExtension + @Inject + constructor(project: Project) { + private val objects = project.objects + + /** + * Enable auto-installation of the Sentry dependencies through [CocoapodsAutoInstallExtension] + * + * Disabling this will prevent the plugin from auto installing anything. + * + * Defaults to true. + */ + val enabled: Property = + objects.property(Boolean::class.java) + .convention(true) + + val cocoapods: CocoapodsAutoInstallExtension = objects.newInstance(CocoapodsAutoInstallExtension::class.java, project) + + val commonMain: SourceSetAutoInstallExtension = objects.newInstance(SourceSetAutoInstallExtension::class.java, project) + } diff --git a/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/CocoapodsAutoInstallExtension.kt b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/CocoapodsAutoInstallExtension.kt new file mode 100644 index 00000000..b45e9814 --- /dev/null +++ b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/CocoapodsAutoInstallExtension.kt @@ -0,0 +1,33 @@ +package io.sentry.kotlin.multiplatform.gradle.plugin + +import io.sentry.BuildConfig +import org.gradle.api.Project +import org.gradle.api.provider.Property +import javax.inject.Inject + +@Suppress("UnnecessaryAbstractClass") +abstract class CocoapodsAutoInstallExtension + @Inject + constructor(project: Project) { + private val objects = project.objects + + /** + * Enable auto-installation of the Sentry Cocoa SDK pod. + * + * If the cocoapods plugin is applied and no existing Sentry pod configuration exists, the Sentry-Cocoa SDK pod will be installed + * + * Defaults to true. + */ + val enabled: Property = + objects.property(Boolean::class.java) + .convention(true) + + /** + * Overrides default Sentry Cocoa version. + * + * Defaults to the version used in the latest KMP SDK. + */ + val sentryCocoaVersion: Property = + objects.property(String::class.java) + .convention(BuildConfig.SentryCocoaVersion) + } diff --git a/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/LinkerExtension.kt b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/LinkerExtension.kt new file mode 100644 index 00000000..117b678f --- /dev/null +++ b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/LinkerExtension.kt @@ -0,0 +1,14 @@ +package io.sentry.kotlin.multiplatform.gradle.plugin + +import org.gradle.api.Project +import org.gradle.api.provider.Property +import javax.inject.Inject + +@Suppress("UnnecessaryAbstractClass") +abstract class LinkerExtension + @Inject + constructor(project: Project) { + private val objects = project.objects + + val xcodeprojPath: Property = objects.property(String::class.java) + } diff --git a/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryExtension.kt b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryExtension.kt new file mode 100644 index 00000000..60937583 --- /dev/null +++ b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryExtension.kt @@ -0,0 +1,20 @@ +package io.sentry.kotlin.multiplatform.gradle.plugin + +import org.gradle.api.Project +import javax.inject.Inject + +@Suppress("UnnecessaryAbstractClass") +abstract class SentryExtension + @Inject + constructor(project: Project) { + private val objects = project.objects + + /** + * Linker configuration. + * + * If you use SPM this configuration is necessary for setting up linking the framework and test executable. + */ + val linker: LinkerExtension = objects.newInstance(LinkerExtension::class.java, project) + + val autoInstall: AutoInstallExtension = objects.newInstance(AutoInstallExtension::class.java, project) + } diff --git a/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryPlugin.kt b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryPlugin.kt new file mode 100644 index 00000000..92934d38 --- /dev/null +++ b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryPlugin.kt @@ -0,0 +1,232 @@ +package io.sentry.kotlin.multiplatform.gradle.plugin + +import org.gradle.api.GradleException +import org.gradle.api.Plugin +import org.gradle.api.Project +import org.gradle.api.plugins.ExtensionAware +import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension +import org.jetbrains.kotlin.gradle.plugin.cocoapods.CocoapodsExtension +import org.jetbrains.kotlin.gradle.plugin.cocoapods.KotlinCocoapodsPlugin +import org.jetbrains.kotlin.gradle.plugin.mpp.AbstractExecutable +import org.jetbrains.kotlin.gradle.plugin.mpp.AbstractNativeLibrary +import org.jetbrains.kotlin.gradle.plugin.mpp.Framework +import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget +import org.jetbrains.kotlin.gradle.plugin.mpp.TestExecutable +import java.io.ByteArrayOutputStream +import java.io.File + +internal const val SENTRY_EXTENSION_NAME = "sentryKmp" +internal const val LINKER_EXTENSION_NAME = "linker" +internal const val AUTO_INSTALL_EXTENSION_NAME = "autoInstall" +internal const val COCOAPODS_AUTO_INSTALL_EXTENSION_NAME = "cocoapods" +internal const val COMMON_MAIN_AUTO_INSTALL_EXTENSION_NAME = "commonMain" +internal const val KOTLIN_EXTENSION_NAME = "kotlin" + +@Suppress("unused") +class SentryPlugin : Plugin { + override fun apply(project: Project): Unit = + with(project) { + val sentryExtension = + project.extensions.create( + SENTRY_EXTENSION_NAME, + SentryExtension::class.java, + project, + ) + project.extensions.add(LINKER_EXTENSION_NAME, sentryExtension.linker) + project.extensions.add(AUTO_INSTALL_EXTENSION_NAME, sentryExtension.autoInstall) + project.extensions.add( + COCOAPODS_AUTO_INSTALL_EXTENSION_NAME, + sentryExtension.autoInstall.cocoapods, + ) + project.extensions.add( + COMMON_MAIN_AUTO_INSTALL_EXTENSION_NAME, + sentryExtension.autoInstall.commonMain, + ) + + afterEvaluate { + val hasCocoapodsPlugin = + project.plugins.findPlugin(KotlinCocoapodsPlugin::class.java) != null + + if (sentryExtension.autoInstall.enabled.get()) { + if (sentryExtension.autoInstall.commonMain.enabled.get()) { + installSentryForKmp(sentryExtension.autoInstall.commonMain) + } + if (hasCocoapodsPlugin && sentryExtension.autoInstall.cocoapods.enabled.get()) { + installSentryForCocoapods(sentryExtension.autoInstall.cocoapods) + } + } + + // If the user is not using the cocoapods plugin, linking to the framework is not automatic + // so we have to take care of that + if (!hasCocoapodsPlugin) { + configureLinkingOptions(sentryExtension.linker) + } + } + } +} + +internal fun Project.installSentryForKmp(commonMainAutoInstallExtension: SourceSetAutoInstallExtension) { + val kmpExtension = extensions.findByName(KOTLIN_EXTENSION_NAME) + if (kmpExtension !is KotlinMultiplatformExtension) { + // todo: log, not multiplatform found + return + } + + val unsupportedTargets = listOf("wasm", "js", "mingw", "linux", "androidNative") + kmpExtension.targets.forEach { target -> + if (unsupportedTargets.any { unsupported -> + target.name.contains(unsupported) + } + ) { + throw GradleException( + "Unsupported target: ${target.name}. " + + "Cannot auto install in commonMain. " + + "Please create an intermediate sourceSet with targets that the Sentry SDK supports (apple, jvm, android) and add the dependency manually.", + ) + } + } + + val commonMain = + kmpExtension.sourceSets.find { + it.name.contains("common") + } + + val sentryVersion = commonMainAutoInstallExtension.sentryKmpVersion.get() + commonMain?.dependencies { + api("io.sentry:sentry-kotlin-multiplatform:$sentryVersion") + } +} + +internal fun Project.installSentryForCocoapods(cocoapodsAutoInstallExtension: CocoapodsAutoInstallExtension) { + val kmpExtension = extensions.findByName(KOTLIN_EXTENSION_NAME) + if (kmpExtension !is KotlinMultiplatformExtension) { + return + } + + (kmpExtension as ExtensionAware).extensions.configure(CocoapodsExtension::class.java) { cocoapods -> + val podName = "Sentry" + val sentryPod = cocoapods.pods.findByName(podName) + if (sentryPod == null) { + cocoapods.pod(podName) { + version = cocoapodsAutoInstallExtension.sentryCocoaVersion.get() + linkOnly = true + extraOpts += listOf("-compiler-option", "-fmodules") + } + } + } +} + +internal fun Project.configureLinkingOptions(linkerExtension: LinkerExtension) { + val kmpExtension = extensions.findByName(KOTLIN_EXTENSION_NAME) + if (kmpExtension !is KotlinMultiplatformExtension) { + // todo: log, not multiplatform found + return + } + + val customXcodeprojPath = linkerExtension.xcodeprojPath.orNull + val derivedDataPath = findDerivedDataPath(customXcodeprojPath) + + kmpExtension.appleTargets().all { target -> + val frameworkArchitecture = target.toSentryFrameworkArchitecture() + if (frameworkArchitecture == null) { + // todo: log, unsupported architecture + return@all + } + + val dynamicFrameworkPath = + "$derivedDataPath/SourcePackages/artifacts/sentry-cocoa/Sentry-Dynamic/Sentry-Dynamic.xcframework/$frameworkArchitecture" + val staticFrameworkPath = + "$derivedDataPath/SourcePackages/artifacts/sentry-cocoa/Sentry/Sentry.xcframework/$frameworkArchitecture" + + val dynamicFrameworkExists = File(dynamicFrameworkPath).exists() + val staticFrameworkExists = File(staticFrameworkPath).exists() + + if (!dynamicFrameworkExists && !staticFrameworkExists) { + throw GradleException("Sentry Cocoa Framework not found at $dynamicFrameworkPath or $staticFrameworkPath") + } + + target.binaries.all binaries@{ binary -> + if (binary is TestExecutable) { + val frameworkPath = + if (dynamicFrameworkExists) dynamicFrameworkPath else staticFrameworkPath + binary.linkerOpts("-rpath", "$path/Sentry.framework", "-F$frameworkPath") + } + + if (binary is Framework) { + val frameworkPath = + if (binary.isStatic) staticFrameworkPath else dynamicFrameworkPath + binary.linkerOpts("-F$frameworkPath") + } + } + } +} + +private fun Project.findDerivedDataPath(customXcodeprojPath: String? = null): String { + val xcodeprojPath = customXcodeprojPath ?: findXcodeprojFile(rootDir)?.absolutePath + val buildDirOutput = ByteArrayOutputStream() + exec { + it.commandLine = + listOf( + "xcodebuild", "-project", xcodeprojPath, "-showBuildSettings", + ) + it.standardOutput = buildDirOutput + } + val buildSettings = buildDirOutput.toString("UTF-8") + val buildDirRegex = Regex("BUILD_DIR = (.+)") + val buildDirMatch = buildDirRegex.find(buildSettings) + val buildDir = + buildDirMatch?.groupValues?.get(1) + ?: throw GradleException("BUILD_DIR not found in xcodebuild output") + val derivedDataPath = buildDir.replace("/Build/Products", "") + return derivedDataPath +} + +/** + * Searches for a xcodeproj starting from the root directory. + * This function will only work for monorepos and if it is not, + * the user needs to provide the custom path through the [LinkerExtension] configuration. + */ +internal fun findXcodeprojFile(dir: File): File? { + val ignoredDirectories = listOf("build", "DerivedData") + + fun searchDirectory(directory: File): File? { + val files = directory.listFiles() ?: return null + + for (file in files) { + if (file.name in ignoredDirectories) { + continue + } + + // Recursively search the subdirectory + val result = searchDirectory(file) + if (result != null) { + return result + } + + if (file.extension == "xcodeproj") { + return file + } + } + return null + } + + return searchDirectory(dir) +} + +private fun KotlinMultiplatformExtension.appleTargets() = + targets.withType(KotlinNativeTarget::class.java) + .matching { it.konanTarget.family.isAppleFamily } + +/** + * Transforms a Kotlin Multiplatform target name to the architecture name that is found inside + * Sentry's framework directory. + */ +internal fun KotlinNativeTarget.toSentryFrameworkArchitecture(): String? { + return when (name) { + "iosSimulatorArm64" -> "ios-arm64_x86_64-simulator" + "iosX64" -> "ios-arm64_x86_64-simulator" + "iosArm64" -> "ios-arm64" + // todo: add more targets + else -> null + } +} diff --git a/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SourceSetAutoInstallExtension.kt b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SourceSetAutoInstallExtension.kt new file mode 100644 index 00000000..f2831011 --- /dev/null +++ b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SourceSetAutoInstallExtension.kt @@ -0,0 +1,30 @@ +package io.sentry.kotlin.multiplatform.gradle.plugin + +import org.gradle.api.Project +import org.gradle.api.provider.Property +import javax.inject.Inject + +@Suppress("UnnecessaryAbstractClass") +abstract class SourceSetAutoInstallExtension + @Inject + constructor(project: Project) { + private val objects = project.objects + + /** + * Enable auto-installation of the Sentry Kotlin Multiplatform SDK dependency in the commonMain source set. + * + * Defaults to true. + */ + val enabled: Property = + objects.property(Boolean::class.java) + .convention(true) + + /** + * Overrides the default Sentry Kotlin Multiplatform SDK dependency version. + * + * Defaults to the latest version of the Sentry Kotlin Multiplatform SDK. + */ + val sentryKmpVersion: Property = + objects.property(String::class.java) + .convention("latest.release") // Replace with the actual default version + } diff --git a/sentry-kotlin-multiplatform-gradle-plugin/src/test/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPluginTest.kt b/sentry-kotlin-multiplatform-gradle-plugin/src/test/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPluginTest.kt new file mode 100644 index 00000000..326f1216 --- /dev/null +++ b/sentry-kotlin-multiplatform-gradle-plugin/src/test/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPluginTest.kt @@ -0,0 +1,95 @@ +package io.sentry.kotlin.multiplatform.gradle.plugin + +import junit.framework.TestCase.assertEquals +import junit.framework.TestCase.assertNotNull +import junit.framework.TestCase.assertNull +import org.gradle.api.plugins.ExtensionAware +import org.gradle.testfixtures.ProjectBuilder +import org.jetbrains.kotlin.gradle.plugin.cocoapods.CocoapodsExtension +import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget +import org.junit.Test +import org.mockito.Mockito.mock +import org.mockito.Mockito.`when` + +class SentryPluginTest { + @Test + fun `plugin is applied correctly to the project`() { + val project = ProjectBuilder.builder().build() + project.pluginManager.apply("io.sentry.kotlin.multiplatform.gradle.plugin") + + assert(project.plugins.hasPlugin(SentryPlugin::class.java)) + } + + @Test + fun `extension sentry is created correctly`() { + val project = ProjectBuilder.builder().build() + project.pluginManager.apply("io.sentry.kotlin.multiplatform.gradle.plugin") + + assertNotNull(project.extensions.getByName("sentry")) + } + + @Test + fun `extension linker is created correctly`() { + val project = ProjectBuilder.builder().build() + project.pluginManager.apply("io.sentry.kotlin.multiplatform.gradle.plugin") + + assertNotNull(project.extensions.getByName("linker")) + } + + @Test + fun `frameworkArchitecture returns transformed target with supported targets`() { + val target = mock(KotlinNativeTarget::class.java) + + `when`(target.name).thenReturn("iosSimulatorArm64") + assertEquals("ios-arm64_x86_64-simulator", target.toSentryFrameworkArchitecture()) + + `when`(target.name).thenReturn("iosX64") + assertEquals("ios-arm64_x86_64-simulator", target.toSentryFrameworkArchitecture()) + + `when`(target.name).thenReturn("iosArm64") + assertEquals("ios-arm64", target.toSentryFrameworkArchitecture()) + } + + @Test + fun `frameworkArchitecture returns null with unsupported targets`() { + val target = mock(KotlinNativeTarget::class.java) + + `when`(target.name).thenReturn("unsupported") + assertNull(target.toSentryFrameworkArchitecture()) + } + + @Test + fun `install Sentry pod when cocoapods plugin is applied and no custom Sentry configuration exists`() { + val project = ProjectBuilder.builder().build() + project.pluginManager.apply("io.sentry.kotlin.multiplatform.gradle.plugin") + project.pluginManager.apply("org.jetbrains.kotlin.multiplatform") + project.pluginManager.apply("org.jetbrains.kotlin.native.cocoapods") + + project.afterEvaluate { + val cocoapodsExtension = project.extensions.findByType(CocoapodsExtension::class.java) + assertNotNull(cocoapodsExtension?.pods?.findByName("Sentry")) + } + } + + @Test + fun `do not install Sentry pod when cocoapods plugin is applied and custom Sentry configuration exists`() { + val project = ProjectBuilder.builder().build() + project.pluginManager.apply("io.sentry.kotlin.multiplatform.gradle.plugin") + project.pluginManager.apply("org.jetbrains.kotlin.multiplatform") + project.pluginManager.apply("org.jetbrains.kotlin.native.cocoapods") + + val kmpExtension = project.extensions.findByName("kotlin") + (kmpExtension as ExtensionAware).extensions.configure(CocoapodsExtension::class.java) { cocoapods -> + cocoapods.pod("Sentry") { + version = "custom version" + } + } + + // plugin does not configure sentry pod if there is already an existing configuration + project.afterEvaluate { + val cocoapodsExtension = project.extensions.findByType(CocoapodsExtension::class.java) + val pod = cocoapodsExtension?.pods?.findByName("Sentry") + assertEquals(pod?.version, "custom version") + } + } +} From a2ce28836bb51aaaaa06cd83da456a9c74c6bdba Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Mon, 10 Jun 2024 21:43:45 +0200 Subject: [PATCH 37/78] Update --- sentry-kotlin-multiplatform-gradle-plugin/gradle.properties | 2 +- .../multiplatform/gradle/{plugin => }/SentryPluginTest.kt | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) rename sentry-kotlin-multiplatform-gradle-plugin/src/test/java/io/sentry/kotlin/multiplatform/gradle/{plugin => }/SentryPluginTest.kt (98%) diff --git a/sentry-kotlin-multiplatform-gradle-plugin/gradle.properties b/sentry-kotlin-multiplatform-gradle-plugin/gradle.properties index 669f009d..7dc95db4 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/gradle.properties +++ b/sentry-kotlin-multiplatform-gradle-plugin/gradle.properties @@ -2,4 +2,4 @@ id=io.sentry.kotlin.multiplatform.gradle implementationClass=io.sentry.kotlin.multiplatform.gradle.plugin.SentryPlugin versionName=0.7.1 group=io.sentry -sentryCocoaVersion = 8.26.0 \ No newline at end of file +sentryCocoaVersion=8.26.0 # TODO: Update update-cocoa.sh so this is auto updated as well \ No newline at end of file diff --git a/sentry-kotlin-multiplatform-gradle-plugin/src/test/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPluginTest.kt b/sentry-kotlin-multiplatform-gradle-plugin/src/test/java/io/sentry/kotlin/multiplatform/gradle/SentryPluginTest.kt similarity index 98% rename from sentry-kotlin-multiplatform-gradle-plugin/src/test/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPluginTest.kt rename to sentry-kotlin-multiplatform-gradle-plugin/src/test/java/io/sentry/kotlin/multiplatform/gradle/SentryPluginTest.kt index 326f1216..b6b7f5c8 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/src/test/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPluginTest.kt +++ b/sentry-kotlin-multiplatform-gradle-plugin/src/test/java/io/sentry/kotlin/multiplatform/gradle/SentryPluginTest.kt @@ -1,5 +1,4 @@ -package io.sentry.kotlin.multiplatform.gradle.plugin - +import io.sentry.kotlin.multiplatform.gradle.plugin.SentryPlugin import junit.framework.TestCase.assertEquals import junit.framework.TestCase.assertNotNull import junit.framework.TestCase.assertNull From f6afac1bd6d3a219dd478942d8d54c26b74aeb70 Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Mon, 10 Jun 2024 21:44:59 +0200 Subject: [PATCH 38/78] Update --- sentry-kotlin-multiplatform-gradle-plugin/gradle.properties | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sentry-kotlin-multiplatform-gradle-plugin/gradle.properties b/sentry-kotlin-multiplatform-gradle-plugin/gradle.properties index 7dc95db4..bf48f331 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/gradle.properties +++ b/sentry-kotlin-multiplatform-gradle-plugin/gradle.properties @@ -2,4 +2,5 @@ id=io.sentry.kotlin.multiplatform.gradle implementationClass=io.sentry.kotlin.multiplatform.gradle.plugin.SentryPlugin versionName=0.7.1 group=io.sentry -sentryCocoaVersion=8.26.0 # TODO: Update update-cocoa.sh so this is auto updated as well \ No newline at end of file +# TODO: Update update-cocoa.sh so the cocoa version is auto updated as well +sentryCocoaVersion=8.26.0 From 50a9e26843fc521d710eb2be157db4d4cdb77d62 Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Mon, 10 Jun 2024 21:56:45 +0200 Subject: [PATCH 39/78] Update' --- .../sentry/kotlin/multiplatform/gradle/AutoInstallExtension.kt | 2 +- .../multiplatform/gradle/CocoapodsAutoInstallExtension.kt | 2 +- .../io/sentry/kotlin/multiplatform/gradle/LinkerExtension.kt | 2 +- .../io/sentry/kotlin/multiplatform/gradle/SentryExtension.kt | 2 +- .../java/io/sentry/kotlin/multiplatform/gradle/SentryPlugin.kt | 2 +- .../multiplatform/gradle/SourceSetAutoInstallExtension.kt | 2 +- .../kotlin/multiplatform/gradle/plugin/SentryPluginTest.kt | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/AutoInstallExtension.kt b/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/AutoInstallExtension.kt index 807f3702..892bb7d3 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/AutoInstallExtension.kt +++ b/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/AutoInstallExtension.kt @@ -1,4 +1,4 @@ -package io.sentry.kotlin.multiplatform.gradle.plugin +package io.sentry.kotlin.multiplatform.gradle import org.gradle.api.Project import org.gradle.api.provider.Property diff --git a/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/CocoapodsAutoInstallExtension.kt b/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/CocoapodsAutoInstallExtension.kt index b45e9814..c75a2961 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/CocoapodsAutoInstallExtension.kt +++ b/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/CocoapodsAutoInstallExtension.kt @@ -1,4 +1,4 @@ -package io.sentry.kotlin.multiplatform.gradle.plugin +package io.sentry.kotlin.multiplatform.gradle import io.sentry.BuildConfig import org.gradle.api.Project diff --git a/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/LinkerExtension.kt b/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/LinkerExtension.kt index 117b678f..bce451d2 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/LinkerExtension.kt +++ b/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/LinkerExtension.kt @@ -1,4 +1,4 @@ -package io.sentry.kotlin.multiplatform.gradle.plugin +package io.sentry.kotlin.multiplatform.gradle import org.gradle.api.Project import org.gradle.api.provider.Property diff --git a/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryExtension.kt b/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryExtension.kt index 60937583..45b5ae62 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryExtension.kt +++ b/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryExtension.kt @@ -1,4 +1,4 @@ -package io.sentry.kotlin.multiplatform.gradle.plugin +package io.sentry.kotlin.multiplatform.gradle import org.gradle.api.Project import javax.inject.Inject diff --git a/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryPlugin.kt b/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryPlugin.kt index 92934d38..3c0e0388 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryPlugin.kt +++ b/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryPlugin.kt @@ -1,4 +1,4 @@ -package io.sentry.kotlin.multiplatform.gradle.plugin +package io.sentry.kotlin.multiplatform.gradle import org.gradle.api.GradleException import org.gradle.api.Plugin diff --git a/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SourceSetAutoInstallExtension.kt b/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SourceSetAutoInstallExtension.kt index f2831011..6ce9bb48 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SourceSetAutoInstallExtension.kt +++ b/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SourceSetAutoInstallExtension.kt @@ -1,4 +1,4 @@ -package io.sentry.kotlin.multiplatform.gradle.plugin +package io.sentry.kotlin.multiplatform.gradle import org.gradle.api.Project import org.gradle.api.provider.Property diff --git a/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/test/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPluginTest.kt b/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/test/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPluginTest.kt index 326f1216..62905d54 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/test/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPluginTest.kt +++ b/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/test/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPluginTest.kt @@ -1,4 +1,4 @@ -package io.sentry.kotlin.multiplatform.gradle.plugin +package io.sentry.kotlin.multiplatform.gradle import junit.framework.TestCase.assertEquals import junit.framework.TestCase.assertNotNull From 8b718e3c7c2900ba7bbfec3eb90166961180e402 Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Mon, 10 Jun 2024 21:57:09 +0200 Subject: [PATCH 40/78] Update --- .../build.gradle.kts | 17 +++++------ .../settings.gradle.kts | 2 -- .../gradle/AutoInstallExtension.kt | 2 +- .../gradle/CocoapodsAutoInstallExtension.kt | 2 +- .../multiplatform/gradle/LinkerExtension.kt | 2 +- .../multiplatform/gradle/SentryExtension.kt | 2 +- .../multiplatform/gradle/SentryPlugin.kt | 4 +-- .../gradle/SourceSetAutoInstallExtension.kt | 2 +- .../multiplatform/gradle/SentryPluginTest.kt | 29 ++----------------- 9 files changed, 16 insertions(+), 46 deletions(-) diff --git a/sentry-kotlin-multiplatform-gradle-plugin/build.gradle.kts b/sentry-kotlin-multiplatform-gradle-plugin/build.gradle.kts index c40e064e..fa36db8e 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/build.gradle.kts +++ b/sentry-kotlin-multiplatform-gradle-plugin/build.gradle.kts @@ -1,9 +1,9 @@ +import com.vanniktech.maven.publish.MavenPublishPluginExtension import io.gitlab.arturbosch.detekt.Detekt import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { alias(libs.plugins.kotlin) - alias(libs.plugins.pluginPublish) alias(libs.plugins.detekt) alias(libs.plugins.ktlint) alias(libs.plugins.versionCheck) @@ -13,6 +13,9 @@ plugins { alias(libs.plugins.buildConfig) } +version = property("versionName").toString() +group = property("group").toString() + dependencies { compileOnly(kotlin("stdlib")) compileOnly(gradleApi()) @@ -41,10 +44,10 @@ gradlePlugin { } } -//val publish = extensions.getByType(MavenPublishPluginExtension::class.java) -//// signing is done when uploading files to MC -//// via gpg:sign-and-deploy-file (release.kts) -//publish.releaseSigningEnabled = false +val publish = extensions.getByType(MavenPublishPluginExtension::class.java) +// signing is done when uploading files to MC +// via gpg:sign-and-deploy-file (release.kts) +publish.releaseSigningEnabled = false tasks.named("distZip").configure { dependsOn("publishToMavenLocal") @@ -102,7 +105,3 @@ tasks.withType().configureEach { html.outputLocation.set(file("build/reports/detekt.html")) } } -// -//tasks.register("clean", Delete::class.java) { -// delete(rootProject.layout.buildDirectory) -//} diff --git a/sentry-kotlin-multiplatform-gradle-plugin/settings.gradle.kts b/sentry-kotlin-multiplatform-gradle-plugin/settings.gradle.kts index 6bd3d3e1..4ef43ffb 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/settings.gradle.kts +++ b/sentry-kotlin-multiplatform-gradle-plugin/settings.gradle.kts @@ -13,5 +13,3 @@ dependencyResolutionManagement { } rootProject.name = "sentry-kotlin-multiplatform-gradle-plugin" - -include(":plugin") diff --git a/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/AutoInstallExtension.kt b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/AutoInstallExtension.kt index 807f3702..892bb7d3 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/AutoInstallExtension.kt +++ b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/AutoInstallExtension.kt @@ -1,4 +1,4 @@ -package io.sentry.kotlin.multiplatform.gradle.plugin +package io.sentry.kotlin.multiplatform.gradle import org.gradle.api.Project import org.gradle.api.provider.Property diff --git a/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/CocoapodsAutoInstallExtension.kt b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/CocoapodsAutoInstallExtension.kt index b45e9814..c75a2961 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/CocoapodsAutoInstallExtension.kt +++ b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/CocoapodsAutoInstallExtension.kt @@ -1,4 +1,4 @@ -package io.sentry.kotlin.multiplatform.gradle.plugin +package io.sentry.kotlin.multiplatform.gradle import io.sentry.BuildConfig import org.gradle.api.Project diff --git a/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/LinkerExtension.kt b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/LinkerExtension.kt index 117b678f..bce451d2 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/LinkerExtension.kt +++ b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/LinkerExtension.kt @@ -1,4 +1,4 @@ -package io.sentry.kotlin.multiplatform.gradle.plugin +package io.sentry.kotlin.multiplatform.gradle import org.gradle.api.Project import org.gradle.api.provider.Property diff --git a/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryExtension.kt b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryExtension.kt index 60937583..45b5ae62 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryExtension.kt +++ b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryExtension.kt @@ -1,4 +1,4 @@ -package io.sentry.kotlin.multiplatform.gradle.plugin +package io.sentry.kotlin.multiplatform.gradle import org.gradle.api.Project import javax.inject.Inject diff --git a/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryPlugin.kt b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryPlugin.kt index 92934d38..f6573d0b 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryPlugin.kt +++ b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryPlugin.kt @@ -1,4 +1,4 @@ -package io.sentry.kotlin.multiplatform.gradle.plugin +package io.sentry.kotlin.multiplatform.gradle import org.gradle.api.GradleException import org.gradle.api.Plugin @@ -7,8 +7,6 @@ import org.gradle.api.plugins.ExtensionAware import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension import org.jetbrains.kotlin.gradle.plugin.cocoapods.CocoapodsExtension import org.jetbrains.kotlin.gradle.plugin.cocoapods.KotlinCocoapodsPlugin -import org.jetbrains.kotlin.gradle.plugin.mpp.AbstractExecutable -import org.jetbrains.kotlin.gradle.plugin.mpp.AbstractNativeLibrary import org.jetbrains.kotlin.gradle.plugin.mpp.Framework import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget import org.jetbrains.kotlin.gradle.plugin.mpp.TestExecutable diff --git a/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SourceSetAutoInstallExtension.kt b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SourceSetAutoInstallExtension.kt index f2831011..6ce9bb48 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SourceSetAutoInstallExtension.kt +++ b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SourceSetAutoInstallExtension.kt @@ -1,4 +1,4 @@ -package io.sentry.kotlin.multiplatform.gradle.plugin +package io.sentry.kotlin.multiplatform.gradle import org.gradle.api.Project import org.gradle.api.provider.Property diff --git a/sentry-kotlin-multiplatform-gradle-plugin/src/test/java/io/sentry/kotlin/multiplatform/gradle/SentryPluginTest.kt b/sentry-kotlin-multiplatform-gradle-plugin/src/test/java/io/sentry/kotlin/multiplatform/gradle/SentryPluginTest.kt index b6b7f5c8..d70a4a84 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/src/test/java/io/sentry/kotlin/multiplatform/gradle/SentryPluginTest.kt +++ b/sentry-kotlin-multiplatform-gradle-plugin/src/test/java/io/sentry/kotlin/multiplatform/gradle/SentryPluginTest.kt @@ -1,14 +1,11 @@ -import io.sentry.kotlin.multiplatform.gradle.plugin.SentryPlugin +package io.sentry.kotlin.multiplatform.gradle + import junit.framework.TestCase.assertEquals import junit.framework.TestCase.assertNotNull -import junit.framework.TestCase.assertNull import org.gradle.api.plugins.ExtensionAware import org.gradle.testfixtures.ProjectBuilder import org.jetbrains.kotlin.gradle.plugin.cocoapods.CocoapodsExtension -import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget import org.junit.Test -import org.mockito.Mockito.mock -import org.mockito.Mockito.`when` class SentryPluginTest { @Test @@ -35,28 +32,6 @@ class SentryPluginTest { assertNotNull(project.extensions.getByName("linker")) } - @Test - fun `frameworkArchitecture returns transformed target with supported targets`() { - val target = mock(KotlinNativeTarget::class.java) - - `when`(target.name).thenReturn("iosSimulatorArm64") - assertEquals("ios-arm64_x86_64-simulator", target.toSentryFrameworkArchitecture()) - - `when`(target.name).thenReturn("iosX64") - assertEquals("ios-arm64_x86_64-simulator", target.toSentryFrameworkArchitecture()) - - `when`(target.name).thenReturn("iosArm64") - assertEquals("ios-arm64", target.toSentryFrameworkArchitecture()) - } - - @Test - fun `frameworkArchitecture returns null with unsupported targets`() { - val target = mock(KotlinNativeTarget::class.java) - - `when`(target.name).thenReturn("unsupported") - assertNull(target.toSentryFrameworkArchitecture()) - } - @Test fun `install Sentry pod when cocoapods plugin is applied and no custom Sentry configuration exists`() { val project = ProjectBuilder.builder().build() From 51d51361b66f1b16d3c4736a8f633024e9cd3ce2 Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Tue, 11 Jun 2024 02:15:52 +0200 Subject: [PATCH 41/78] Add CI --- .../kotlin-multiplatform-gradle-plugin.yml | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/.github/workflows/kotlin-multiplatform-gradle-plugin.yml b/.github/workflows/kotlin-multiplatform-gradle-plugin.yml index e69de29b..12fb0bb7 100644 --- a/.github/workflows/kotlin-multiplatform-gradle-plugin.yml +++ b/.github/workflows/kotlin-multiplatform-gradle-plugin.yml @@ -0,0 +1,39 @@ +name: "Plugin: sentry-kotlin-multiplatform" +on: + push: + branches: + - main + - release/** + pull_request: + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + archive-distribution: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: JDK setup + uses: actions/setup-java@v3 + with: + java-version: 17 + distribution: temurin + + - name: Cached Gradle + uses: gradle/gradle-build-action@842c587ad8aa4c68eeba24c396e15af4c2e9f30a + + - name: DistZip + run: | + cd sentry-kotlin-multiplatform-gradle-plugin && ./gradlew distZip + + - name: Archive packages + uses: actions/upload-artifact@v3 + with: + name: ${{ github.sha }} + if-no-files-found: error + path: | + ./*/build/distributions/*.zip From 87f7a7f1aa78abaa63139ce0d3546b218afa4261 Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Tue, 11 Jun 2024 02:24:13 +0200 Subject: [PATCH 42/78] Add to craft --- .craft.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.craft.yml b/.craft.yml index 56039d39..f2ce1e96 100644 --- a/.craft.yml +++ b/.craft.yml @@ -2,6 +2,7 @@ minVersion: 1.2.1 changelogPolicy: auto targets: - name: maven + id: kmp gradleCliPath: ./gradlew mavenCliPath: scripts/mvnw mavenSettingsPath: scripts/settings.xml @@ -14,8 +15,19 @@ targets: kmp: rootDistDirRegex: /^(?!.*(?:jvm|android|ios|watchos|tvos|macos)).*$/ appleDistDirRegex: /(ios|watchos|tvos|macos)/ + excludeNames: /sentry-kotlin-multiplatform-gradle-plugin.*$/ + - name: maven + id: plugin + gradleCliPath: ./gradlew + mavenCliPath: scripts/mvnw + mavenSettingsPath: scripts/settings.xml + mavenRepoId: ossrh + mavenRepoUrl: https://oss.sonatype.org/service/local/staging/deploy/maven2/ + android: false + includeNames: /sentry-kotlin-multiplatform-gradle-plugin.*$/ - name: github - name: registry sdks: maven:io.sentry:sentry-kotlin-multiplatform: + maven:io.sentry:sentry-kotlin-multiplatform-gradle-plugin: From 6b0eaa5cce37b603636c3de579e364493793600f Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Tue, 11 Jun 2024 02:34:32 +0200 Subject: [PATCH 43/78] Remove package.resolved --- .../xcshareddata/swiftpm/Package.resolved | 14 -------------- 1 file changed, 14 deletions(-) delete mode 100644 sentry-samples/kmp-app-cocoapods/iosApp/iosApp.xcworkspace/xcshareddata/swiftpm/Package.resolved diff --git a/sentry-samples/kmp-app-cocoapods/iosApp/iosApp.xcworkspace/xcshareddata/swiftpm/Package.resolved b/sentry-samples/kmp-app-cocoapods/iosApp/iosApp.xcworkspace/xcshareddata/swiftpm/Package.resolved deleted file mode 100644 index b1ad2be5..00000000 --- a/sentry-samples/kmp-app-cocoapods/iosApp/iosApp.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ /dev/null @@ -1,14 +0,0 @@ -{ - "pins" : [ - { - "identity" : "alamofire", - "kind" : "remoteSourceControl", - "location" : "https://github.com/Alamofire/Alamofire.git", - "state" : { - "revision" : "723fa5a6c65812aec4a0d7cc432ee198883b6e00", - "version" : "5.9.0" - } - } - ], - "version" : 2 -} From 2f269254638c35755d788c27b7ffaf03b1ce609b Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Tue, 11 Jun 2024 02:37:03 +0200 Subject: [PATCH 44/78] Format --- .../build.gradle.kts | 3 +- .../gradle.properties | 2 +- .../build.gradle.kts | 46 +++++++++---------- .../gradle/AutoInstallExtension.kt | 32 ++++++------- .../gradle/CocoapodsAutoInstallExtension.kt | 44 +++++++++--------- .../multiplatform/gradle/LinkerExtension.kt | 10 ++-- .../multiplatform/gradle/SentryExtension.kt | 22 ++++----- .../multiplatform/gradle/SentryPlugin.kt | 19 ++++---- .../gradle/SourceSetAutoInstallExtension.kt | 40 ++++++++-------- .../gradle/AutoInstallExtension.kt | 32 ++++++------- .../gradle/CocoapodsAutoInstallExtension.kt | 44 +++++++++--------- .../multiplatform/gradle/LinkerExtension.kt | 10 ++-- .../multiplatform/gradle/SentryExtension.kt | 22 ++++----- .../multiplatform/gradle/SentryPlugin.kt | 17 ++++--- .../gradle/SourceSetAutoInstallExtension.kt | 40 ++++++++-------- .../kmp-app-cocoapods/shared/build.gradle.kts | 2 +- .../shared/src/commonTest/kotlin/Test.kt | 8 ---- .../kmp-app-spm/shared/build.gradle.kts | 8 +--- .../src/commonTest/kotlin/CompilationTest.kt | 4 +- 19 files changed, 198 insertions(+), 207 deletions(-) delete mode 100644 sentry-samples/kmp-app-cocoapods/shared/src/commonTest/kotlin/Test.kt diff --git a/sentry-kotlin-multiplatform-gradle-plugin/build.gradle.kts b/sentry-kotlin-multiplatform-gradle-plugin/build.gradle.kts index fa36db8e..e0a111bf 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/build.gradle.kts +++ b/sentry-kotlin-multiplatform-gradle-plugin/build.gradle.kts @@ -79,7 +79,8 @@ buildConfig { buildConfigField( "String", "SentryCocoaVersion", - provider { "\"${project.property("sentryCocoaVersion")}\"" }) + provider { "\"${project.property("sentryCocoaVersion")}\"" } + ) } ktlint { diff --git a/sentry-kotlin-multiplatform-gradle-plugin/gradle.properties b/sentry-kotlin-multiplatform-gradle-plugin/gradle.properties index bf48f331..73eb14b5 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/gradle.properties +++ b/sentry-kotlin-multiplatform-gradle-plugin/gradle.properties @@ -1,5 +1,5 @@ id=io.sentry.kotlin.multiplatform.gradle -implementationClass=io.sentry.kotlin.multiplatform.gradle.plugin.SentryPlugin +implementationClass=io.sentry.kotlin.multiplatform.gradle.SentryPlugin versionName=0.7.1 group=io.sentry # TODO: Update update-cocoa.sh so the cocoa version is auto updated as well diff --git a/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/build.gradle.kts b/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/build.gradle.kts index b7be7015..450641ee 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/build.gradle.kts +++ b/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/build.gradle.kts @@ -1,48 +1,48 @@ -//import com.vanniktech.maven.publish.MavenPublishPluginExtension -//import org.jetbrains.kotlin.gradle.tasks.KotlinCompile +// import com.vanniktech.maven.publish.MavenPublishPluginExtension +// import org.jetbrains.kotlin.gradle.tasks.KotlinCompile // -//plugins { +// plugins { // kotlin("jvm") // `java-gradle-plugin` // alias(libs.plugins.vanniktech.publish) // id("distribution") // alias(libs.plugins.buildConfig) -//} +// } // -//dependencies { +// dependencies { // compileOnly(kotlin("stdlib")) // compileOnly(gradleApi()) // compileOnly(kotlin("gradle-plugin")) // // testImplementation(libs.junit) -//} +// } // -//java { +// java { // sourceCompatibility = JavaVersion.VERSION_1_8 // targetCompatibility = JavaVersion.VERSION_1_8 -//} +// } // -//tasks.withType { +// tasks.withType { // kotlinOptions { // jvmTarget = JavaVersion.VERSION_1_8.toString() // } -//} +// } // -//gradlePlugin { +// gradlePlugin { // plugins { // create(property("id").toString()) { // id = property("id").toString() // implementationClass = property("implementationClass").toString() // } // } -//} +// } // -//val publish = extensions.getByType(MavenPublishPluginExtension::class.java) -//// signing is done when uploading files to MC -//// via gpg:sign-and-deploy-file (release.kts) -//publish.releaseSigningEnabled = false +// val publish = extensions.getByType(MavenPublishPluginExtension::class.java) +// // signing is done when uploading files to MC +// // via gpg:sign-and-deploy-file (release.kts) +// publish.releaseSigningEnabled = false // -//tasks.named("distZip").configure { +// tasks.named("distZip").configure { // dependsOn("publishToMavenLocal") // this.doLast { // val distributionFilePath = @@ -51,20 +51,20 @@ // if (!file.exists()) throw IllegalStateException("Distribution file: $distributionFilePath does not exist") // if (file.length() == 0L) throw IllegalStateException("Distribution file: $distributionFilePath is empty") // } -//} +// } // -//val sep = File.separator +// val sep = File.separator // -//distributions { +// distributions { // main { // contents { // from("build${sep}libs") // from("build${sep}publications${sep}maven") // } // } -//} +// } // -//buildConfig { +// buildConfig { // useKotlinOutput() // packageName("io.sentry") // className("BuildConfig") @@ -73,4 +73,4 @@ // "String", // "SentryCocoaVersion", // provider { "\"${project.property("sentryCocoaVersion")}\"" }) -//} \ No newline at end of file +// } diff --git a/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/AutoInstallExtension.kt b/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/AutoInstallExtension.kt index 892bb7d3..34349201 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/AutoInstallExtension.kt +++ b/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/AutoInstallExtension.kt @@ -6,22 +6,22 @@ import javax.inject.Inject @Suppress("UnnecessaryAbstractClass") abstract class AutoInstallExtension - @Inject - constructor(project: Project) { - private val objects = project.objects +@Inject +constructor(project: Project) { + private val objects = project.objects - /** - * Enable auto-installation of the Sentry dependencies through [CocoapodsAutoInstallExtension] - * - * Disabling this will prevent the plugin from auto installing anything. - * - * Defaults to true. - */ - val enabled: Property = - objects.property(Boolean::class.java) - .convention(true) + /** + * Enable auto-installation of the Sentry dependencies through [CocoapodsAutoInstallExtension] + * + * Disabling this will prevent the plugin from auto installing anything. + * + * Defaults to true. + */ + val enabled: Property = + objects.property(Boolean::class.java) + .convention(true) - val cocoapods: CocoapodsAutoInstallExtension = objects.newInstance(CocoapodsAutoInstallExtension::class.java, project) + val cocoapods: CocoapodsAutoInstallExtension = objects.newInstance(CocoapodsAutoInstallExtension::class.java, project) - val commonMain: SourceSetAutoInstallExtension = objects.newInstance(SourceSetAutoInstallExtension::class.java, project) - } + val commonMain: SourceSetAutoInstallExtension = objects.newInstance(SourceSetAutoInstallExtension::class.java, project) +} diff --git a/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/CocoapodsAutoInstallExtension.kt b/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/CocoapodsAutoInstallExtension.kt index c75a2961..173893ee 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/CocoapodsAutoInstallExtension.kt +++ b/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/CocoapodsAutoInstallExtension.kt @@ -7,27 +7,27 @@ import javax.inject.Inject @Suppress("UnnecessaryAbstractClass") abstract class CocoapodsAutoInstallExtension - @Inject - constructor(project: Project) { - private val objects = project.objects +@Inject +constructor(project: Project) { + private val objects = project.objects - /** - * Enable auto-installation of the Sentry Cocoa SDK pod. - * - * If the cocoapods plugin is applied and no existing Sentry pod configuration exists, the Sentry-Cocoa SDK pod will be installed - * - * Defaults to true. - */ - val enabled: Property = - objects.property(Boolean::class.java) - .convention(true) + /** + * Enable auto-installation of the Sentry Cocoa SDK pod. + * + * If the cocoapods plugin is applied and no existing Sentry pod configuration exists, the Sentry-Cocoa SDK pod will be installed + * + * Defaults to true. + */ + val enabled: Property = + objects.property(Boolean::class.java) + .convention(true) - /** - * Overrides default Sentry Cocoa version. - * - * Defaults to the version used in the latest KMP SDK. - */ - val sentryCocoaVersion: Property = - objects.property(String::class.java) - .convention(BuildConfig.SentryCocoaVersion) - } + /** + * Overrides default Sentry Cocoa version. + * + * Defaults to the version used in the latest KMP SDK. + */ + val sentryCocoaVersion: Property = + objects.property(String::class.java) + .convention(BuildConfig.SentryCocoaVersion) +} diff --git a/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/LinkerExtension.kt b/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/LinkerExtension.kt index bce451d2..ef9a77ed 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/LinkerExtension.kt +++ b/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/LinkerExtension.kt @@ -6,9 +6,9 @@ import javax.inject.Inject @Suppress("UnnecessaryAbstractClass") abstract class LinkerExtension - @Inject - constructor(project: Project) { - private val objects = project.objects +@Inject +constructor(project: Project) { + private val objects = project.objects - val xcodeprojPath: Property = objects.property(String::class.java) - } + val xcodeprojPath: Property = objects.property(String::class.java) +} diff --git a/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryExtension.kt b/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryExtension.kt index 45b5ae62..9f9439e0 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryExtension.kt +++ b/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryExtension.kt @@ -5,16 +5,16 @@ import javax.inject.Inject @Suppress("UnnecessaryAbstractClass") abstract class SentryExtension - @Inject - constructor(project: Project) { - private val objects = project.objects +@Inject +constructor(project: Project) { + private val objects = project.objects - /** - * Linker configuration. - * - * If you use SPM this configuration is necessary for setting up linking the framework and test executable. - */ - val linker: LinkerExtension = objects.newInstance(LinkerExtension::class.java, project) + /** + * Linker configuration. + * + * If you use SPM this configuration is necessary for setting up linking the framework and test executable. + */ + val linker: LinkerExtension = objects.newInstance(LinkerExtension::class.java, project) - val autoInstall: AutoInstallExtension = objects.newInstance(AutoInstallExtension::class.java, project) - } + val autoInstall: AutoInstallExtension = objects.newInstance(AutoInstallExtension::class.java, project) +} diff --git a/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryPlugin.kt b/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryPlugin.kt index 3c0e0388..2f1480be 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryPlugin.kt +++ b/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryPlugin.kt @@ -7,8 +7,6 @@ import org.gradle.api.plugins.ExtensionAware import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension import org.jetbrains.kotlin.gradle.plugin.cocoapods.CocoapodsExtension import org.jetbrains.kotlin.gradle.plugin.cocoapods.KotlinCocoapodsPlugin -import org.jetbrains.kotlin.gradle.plugin.mpp.AbstractExecutable -import org.jetbrains.kotlin.gradle.plugin.mpp.AbstractNativeLibrary import org.jetbrains.kotlin.gradle.plugin.mpp.Framework import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget import org.jetbrains.kotlin.gradle.plugin.mpp.TestExecutable @@ -30,17 +28,17 @@ class SentryPlugin : Plugin { project.extensions.create( SENTRY_EXTENSION_NAME, SentryExtension::class.java, - project, + project ) project.extensions.add(LINKER_EXTENSION_NAME, sentryExtension.linker) project.extensions.add(AUTO_INSTALL_EXTENSION_NAME, sentryExtension.autoInstall) project.extensions.add( COCOAPODS_AUTO_INSTALL_EXTENSION_NAME, - sentryExtension.autoInstall.cocoapods, + sentryExtension.autoInstall.cocoapods ) project.extensions.add( COMMON_MAIN_AUTO_INSTALL_EXTENSION_NAME, - sentryExtension.autoInstall.commonMain, + sentryExtension.autoInstall.commonMain ) afterEvaluate { @@ -75,13 +73,13 @@ internal fun Project.installSentryForKmp(commonMainAutoInstallExtension: SourceS val unsupportedTargets = listOf("wasm", "js", "mingw", "linux", "androidNative") kmpExtension.targets.forEach { target -> if (unsupportedTargets.any { unsupported -> - target.name.contains(unsupported) - } + target.name.contains(unsupported) + } ) { throw GradleException( "Unsupported target: ${target.name}. " + "Cannot auto install in commonMain. " + - "Please create an intermediate sourceSet with targets that the Sentry SDK supports (apple, jvm, android) and add the dependency manually.", + "Please create an intermediate sourceSet with targets that the Sentry SDK supports (apple, jvm, android) and add the dependency manually." ) } } @@ -167,7 +165,10 @@ private fun Project.findDerivedDataPath(customXcodeprojPath: String? = null): St exec { it.commandLine = listOf( - "xcodebuild", "-project", xcodeprojPath, "-showBuildSettings", + "xcodebuild", + "-project", + xcodeprojPath, + "-showBuildSettings" ) it.standardOutput = buildDirOutput } diff --git a/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SourceSetAutoInstallExtension.kt b/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SourceSetAutoInstallExtension.kt index 6ce9bb48..2dd4501e 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SourceSetAutoInstallExtension.kt +++ b/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SourceSetAutoInstallExtension.kt @@ -6,25 +6,25 @@ import javax.inject.Inject @Suppress("UnnecessaryAbstractClass") abstract class SourceSetAutoInstallExtension - @Inject - constructor(project: Project) { - private val objects = project.objects +@Inject +constructor(project: Project) { + private val objects = project.objects - /** - * Enable auto-installation of the Sentry Kotlin Multiplatform SDK dependency in the commonMain source set. - * - * Defaults to true. - */ - val enabled: Property = - objects.property(Boolean::class.java) - .convention(true) + /** + * Enable auto-installation of the Sentry Kotlin Multiplatform SDK dependency in the commonMain source set. + * + * Defaults to true. + */ + val enabled: Property = + objects.property(Boolean::class.java) + .convention(true) - /** - * Overrides the default Sentry Kotlin Multiplatform SDK dependency version. - * - * Defaults to the latest version of the Sentry Kotlin Multiplatform SDK. - */ - val sentryKmpVersion: Property = - objects.property(String::class.java) - .convention("latest.release") // Replace with the actual default version - } + /** + * Overrides the default Sentry Kotlin Multiplatform SDK dependency version. + * + * Defaults to the latest version of the Sentry Kotlin Multiplatform SDK. + */ + val sentryKmpVersion: Property = + objects.property(String::class.java) + .convention("latest.release") // Replace with the actual default version +} diff --git a/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/AutoInstallExtension.kt b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/AutoInstallExtension.kt index 892bb7d3..34349201 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/AutoInstallExtension.kt +++ b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/AutoInstallExtension.kt @@ -6,22 +6,22 @@ import javax.inject.Inject @Suppress("UnnecessaryAbstractClass") abstract class AutoInstallExtension - @Inject - constructor(project: Project) { - private val objects = project.objects +@Inject +constructor(project: Project) { + private val objects = project.objects - /** - * Enable auto-installation of the Sentry dependencies through [CocoapodsAutoInstallExtension] - * - * Disabling this will prevent the plugin from auto installing anything. - * - * Defaults to true. - */ - val enabled: Property = - objects.property(Boolean::class.java) - .convention(true) + /** + * Enable auto-installation of the Sentry dependencies through [CocoapodsAutoInstallExtension] + * + * Disabling this will prevent the plugin from auto installing anything. + * + * Defaults to true. + */ + val enabled: Property = + objects.property(Boolean::class.java) + .convention(true) - val cocoapods: CocoapodsAutoInstallExtension = objects.newInstance(CocoapodsAutoInstallExtension::class.java, project) + val cocoapods: CocoapodsAutoInstallExtension = objects.newInstance(CocoapodsAutoInstallExtension::class.java, project) - val commonMain: SourceSetAutoInstallExtension = objects.newInstance(SourceSetAutoInstallExtension::class.java, project) - } + val commonMain: SourceSetAutoInstallExtension = objects.newInstance(SourceSetAutoInstallExtension::class.java, project) +} diff --git a/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/CocoapodsAutoInstallExtension.kt b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/CocoapodsAutoInstallExtension.kt index c75a2961..173893ee 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/CocoapodsAutoInstallExtension.kt +++ b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/CocoapodsAutoInstallExtension.kt @@ -7,27 +7,27 @@ import javax.inject.Inject @Suppress("UnnecessaryAbstractClass") abstract class CocoapodsAutoInstallExtension - @Inject - constructor(project: Project) { - private val objects = project.objects +@Inject +constructor(project: Project) { + private val objects = project.objects - /** - * Enable auto-installation of the Sentry Cocoa SDK pod. - * - * If the cocoapods plugin is applied and no existing Sentry pod configuration exists, the Sentry-Cocoa SDK pod will be installed - * - * Defaults to true. - */ - val enabled: Property = - objects.property(Boolean::class.java) - .convention(true) + /** + * Enable auto-installation of the Sentry Cocoa SDK pod. + * + * If the cocoapods plugin is applied and no existing Sentry pod configuration exists, the Sentry-Cocoa SDK pod will be installed + * + * Defaults to true. + */ + val enabled: Property = + objects.property(Boolean::class.java) + .convention(true) - /** - * Overrides default Sentry Cocoa version. - * - * Defaults to the version used in the latest KMP SDK. - */ - val sentryCocoaVersion: Property = - objects.property(String::class.java) - .convention(BuildConfig.SentryCocoaVersion) - } + /** + * Overrides default Sentry Cocoa version. + * + * Defaults to the version used in the latest KMP SDK. + */ + val sentryCocoaVersion: Property = + objects.property(String::class.java) + .convention(BuildConfig.SentryCocoaVersion) +} diff --git a/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/LinkerExtension.kt b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/LinkerExtension.kt index bce451d2..ef9a77ed 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/LinkerExtension.kt +++ b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/LinkerExtension.kt @@ -6,9 +6,9 @@ import javax.inject.Inject @Suppress("UnnecessaryAbstractClass") abstract class LinkerExtension - @Inject - constructor(project: Project) { - private val objects = project.objects +@Inject +constructor(project: Project) { + private val objects = project.objects - val xcodeprojPath: Property = objects.property(String::class.java) - } + val xcodeprojPath: Property = objects.property(String::class.java) +} diff --git a/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryExtension.kt b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryExtension.kt index 45b5ae62..9f9439e0 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryExtension.kt +++ b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryExtension.kt @@ -5,16 +5,16 @@ import javax.inject.Inject @Suppress("UnnecessaryAbstractClass") abstract class SentryExtension - @Inject - constructor(project: Project) { - private val objects = project.objects +@Inject +constructor(project: Project) { + private val objects = project.objects - /** - * Linker configuration. - * - * If you use SPM this configuration is necessary for setting up linking the framework and test executable. - */ - val linker: LinkerExtension = objects.newInstance(LinkerExtension::class.java, project) + /** + * Linker configuration. + * + * If you use SPM this configuration is necessary for setting up linking the framework and test executable. + */ + val linker: LinkerExtension = objects.newInstance(LinkerExtension::class.java, project) - val autoInstall: AutoInstallExtension = objects.newInstance(AutoInstallExtension::class.java, project) - } + val autoInstall: AutoInstallExtension = objects.newInstance(AutoInstallExtension::class.java, project) +} diff --git a/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryPlugin.kt b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryPlugin.kt index f6573d0b..2f1480be 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryPlugin.kt +++ b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryPlugin.kt @@ -28,17 +28,17 @@ class SentryPlugin : Plugin { project.extensions.create( SENTRY_EXTENSION_NAME, SentryExtension::class.java, - project, + project ) project.extensions.add(LINKER_EXTENSION_NAME, sentryExtension.linker) project.extensions.add(AUTO_INSTALL_EXTENSION_NAME, sentryExtension.autoInstall) project.extensions.add( COCOAPODS_AUTO_INSTALL_EXTENSION_NAME, - sentryExtension.autoInstall.cocoapods, + sentryExtension.autoInstall.cocoapods ) project.extensions.add( COMMON_MAIN_AUTO_INSTALL_EXTENSION_NAME, - sentryExtension.autoInstall.commonMain, + sentryExtension.autoInstall.commonMain ) afterEvaluate { @@ -73,13 +73,13 @@ internal fun Project.installSentryForKmp(commonMainAutoInstallExtension: SourceS val unsupportedTargets = listOf("wasm", "js", "mingw", "linux", "androidNative") kmpExtension.targets.forEach { target -> if (unsupportedTargets.any { unsupported -> - target.name.contains(unsupported) - } + target.name.contains(unsupported) + } ) { throw GradleException( "Unsupported target: ${target.name}. " + "Cannot auto install in commonMain. " + - "Please create an intermediate sourceSet with targets that the Sentry SDK supports (apple, jvm, android) and add the dependency manually.", + "Please create an intermediate sourceSet with targets that the Sentry SDK supports (apple, jvm, android) and add the dependency manually." ) } } @@ -165,7 +165,10 @@ private fun Project.findDerivedDataPath(customXcodeprojPath: String? = null): St exec { it.commandLine = listOf( - "xcodebuild", "-project", xcodeprojPath, "-showBuildSettings", + "xcodebuild", + "-project", + xcodeprojPath, + "-showBuildSettings" ) it.standardOutput = buildDirOutput } diff --git a/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SourceSetAutoInstallExtension.kt b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SourceSetAutoInstallExtension.kt index 6ce9bb48..2dd4501e 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SourceSetAutoInstallExtension.kt +++ b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SourceSetAutoInstallExtension.kt @@ -6,25 +6,25 @@ import javax.inject.Inject @Suppress("UnnecessaryAbstractClass") abstract class SourceSetAutoInstallExtension - @Inject - constructor(project: Project) { - private val objects = project.objects +@Inject +constructor(project: Project) { + private val objects = project.objects - /** - * Enable auto-installation of the Sentry Kotlin Multiplatform SDK dependency in the commonMain source set. - * - * Defaults to true. - */ - val enabled: Property = - objects.property(Boolean::class.java) - .convention(true) + /** + * Enable auto-installation of the Sentry Kotlin Multiplatform SDK dependency in the commonMain source set. + * + * Defaults to true. + */ + val enabled: Property = + objects.property(Boolean::class.java) + .convention(true) - /** - * Overrides the default Sentry Kotlin Multiplatform SDK dependency version. - * - * Defaults to the latest version of the Sentry Kotlin Multiplatform SDK. - */ - val sentryKmpVersion: Property = - objects.property(String::class.java) - .convention("latest.release") // Replace with the actual default version - } + /** + * Overrides the default Sentry Kotlin Multiplatform SDK dependency version. + * + * Defaults to the latest version of the Sentry Kotlin Multiplatform SDK. + */ + val sentryKmpVersion: Property = + objects.property(String::class.java) + .convention("latest.release") // Replace with the actual default version +} diff --git a/sentry-samples/kmp-app-cocoapods/shared/build.gradle.kts b/sentry-samples/kmp-app-cocoapods/shared/build.gradle.kts index 607b8c0a..6eeca01c 100644 --- a/sentry-samples/kmp-app-cocoapods/shared/build.gradle.kts +++ b/sentry-samples/kmp-app-cocoapods/shared/build.gradle.kts @@ -4,7 +4,7 @@ plugins { kotlin("multiplatform") kotlin("native.cocoapods") id("com.android.library") - id("io.sentry.kotlin.multiplatform.gradle.plugin") + id("io.sentry.kotlin.multiplatform.gradle") } java { diff --git a/sentry-samples/kmp-app-cocoapods/shared/src/commonTest/kotlin/Test.kt b/sentry-samples/kmp-app-cocoapods/shared/src/commonTest/kotlin/Test.kt deleted file mode 100644 index f03d75f5..00000000 --- a/sentry-samples/kmp-app-cocoapods/shared/src/commonTest/kotlin/Test.kt +++ /dev/null @@ -1,8 +0,0 @@ -import kotlin.test.Test - -class Test { - @Test - fun test() { - print("see if this runs") - } -} \ No newline at end of file diff --git a/sentry-samples/kmp-app-spm/shared/build.gradle.kts b/sentry-samples/kmp-app-spm/shared/build.gradle.kts index 9311a033..5b235ad9 100644 --- a/sentry-samples/kmp-app-spm/shared/build.gradle.kts +++ b/sentry-samples/kmp-app-spm/shared/build.gradle.kts @@ -3,7 +3,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { kotlin("multiplatform") id("com.android.library") - id("io.sentry.kotlin.multiplatform.gradle.plugin") + id("io.sentry.kotlin.multiplatform.gradle") } java { @@ -50,9 +50,3 @@ android { minSdk = Config.Android.minSdkVersion } } - -sentry { - linker { - // xcodeprojPath.set("/Users/giancarlobuenaflor/Desktop/SentryProjects/sentry-kotlin-multiplatform/sentry-samples/kmp-app-spm/iosApp.xcodeproj") - } -} \ No newline at end of file diff --git a/sentry-samples/kmp-app-spm/shared/src/commonTest/kotlin/CompilationTest.kt b/sentry-samples/kmp-app-spm/shared/src/commonTest/kotlin/CompilationTest.kt index 594de367..c821abec 100644 --- a/sentry-samples/kmp-app-spm/shared/src/commonTest/kotlin/CompilationTest.kt +++ b/sentry-samples/kmp-app-spm/shared/src/commonTest/kotlin/CompilationTest.kt @@ -3,6 +3,6 @@ import kotlin.test.Test class CompilationTest { @Test fun test() { - print("see if this runs"); + print("see if this runs") } -} \ No newline at end of file +} From bd2c5373b812d57548f06b280292dc406e9de854 Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Tue, 11 Jun 2024 02:37:46 +0200 Subject: [PATCH 45/78] Update --- sentry-samples/kmp-app-cocoapods/iosApp/Podfile.lock | 1 - 1 file changed, 1 deletion(-) diff --git a/sentry-samples/kmp-app-cocoapods/iosApp/Podfile.lock b/sentry-samples/kmp-app-cocoapods/iosApp/Podfile.lock index 413640d4..3e582d9f 100644 --- a/sentry-samples/kmp-app-cocoapods/iosApp/Podfile.lock +++ b/sentry-samples/kmp-app-cocoapods/iosApp/Podfile.lock @@ -1,5 +1,4 @@ PODS: - - Sentry (8.26.0): - Sentry/Core (= 8.26.0) - Sentry/Core (8.26.0) From 38db1a9b92294a328e176ce139e378c82bd43850 Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Tue, 11 Jun 2024 02:40:22 +0200 Subject: [PATCH 46/78] Update changelog --- CHANGELOG.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 109306ce..ca889bb9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # Changelog +## Unreleased + +### Features + +- Add plugin ([#230](https://github.com/getsentry/sentry-kotlin-multiplatform/pull/230)) + - Install via `plugins { id("io.sentry.kotlin.multiplatform.gradle") version "{version}" }` + - Enables auto installing of the KMP SDK to commonMain (if all targets are supported) + - Configures linking for SPM (both dynamic and static frameworks) + ## 0.7.1 ### Fixes From 1317545bb308ab45263e383abe0867a0b1b1f5c2 Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Tue, 11 Jun 2024 02:40:40 +0200 Subject: [PATCH 47/78] Enable cocoapods sample --- settings.gradle.kts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/settings.gradle.kts b/settings.gradle.kts index 5643daf7..ae3265f4 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -38,9 +38,9 @@ Simple KMP App with targets: - iOS with SwiftUI and Cocoapods - JVM Desktop with Jetpack Compose */ -//include("sentry-samples:kmp-app-cocoapods:shared") -//include("sentry-samples:kmp-app-cocoapods:androidApp") -//include("sentry-samples:kmp-app-cocoapods:desktopApp") +include("sentry-samples:kmp-app-cocoapods:shared") +include("sentry-samples:kmp-app-cocoapods:androidApp") +include("sentry-samples:kmp-app-cocoapods:desktopApp") /* KMP App with MVVM and Dependency Injection with Koin: From e96287a5280c79e6874145896b09606e20326712 Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Tue, 11 Jun 2024 02:42:34 +0200 Subject: [PATCH 48/78] Update --- sentry-samples/kmp-app-spm/desktopApp/build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sentry-samples/kmp-app-spm/desktopApp/build.gradle.kts b/sentry-samples/kmp-app-spm/desktopApp/build.gradle.kts index 637dd0f1..dfb98898 100644 --- a/sentry-samples/kmp-app-spm/desktopApp/build.gradle.kts +++ b/sentry-samples/kmp-app-spm/desktopApp/build.gradle.kts @@ -31,7 +31,7 @@ kotlin { sourceSets { val jvmMain by getting { dependencies { -// implementation(rootProject.project(":sentry-samples:kmp-app-cocoapods:shared")) + implementation(rootProject.project(":sentry-samples:kmp-app-cocoapods:shared")) implementation(compose.desktop.currentOs) } } From b0b10501cfe343392508b13adb9b71e5ead6f801 Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Tue, 11 Jun 2024 02:43:07 +0200 Subject: [PATCH 49/78] Remove podspec from spm sample --- .../kmp-app-spm/shared/shared.podspec | 50 ------------------- 1 file changed, 50 deletions(-) delete mode 100644 sentry-samples/kmp-app-spm/shared/shared.podspec diff --git a/sentry-samples/kmp-app-spm/shared/shared.podspec b/sentry-samples/kmp-app-spm/shared/shared.podspec deleted file mode 100644 index fe0acedb..00000000 --- a/sentry-samples/kmp-app-spm/shared/shared.podspec +++ /dev/null @@ -1,50 +0,0 @@ -Pod::Spec.new do |spec| - spec.name = 'shared' - spec.version = '0.7.1' - spec.homepage = '' - spec.source = { :http=> ''} - spec.authors = '' - spec.license = '' - spec.summary = '' - spec.vendored_frameworks = 'build/cocoapods/framework/shared.framework' - spec.libraries = 'c++' - - - - if !Dir.exist?('build/cocoapods/framework/shared.framework') || Dir.empty?('build/cocoapods/framework/shared.framework') - raise " - - Kotlin framework 'shared' doesn't exist yet, so a proper Xcode project can't be generated. - 'pod install' should be executed after running ':generateDummyFramework' Gradle task: - - ./gradlew :sentry-samples:kmp-app-spm:shared:generateDummyFramework - - Alternatively, proper pod installation is performed during Gradle sync in the IDE (if Podfile location is set)" - end - - spec.pod_target_xcconfig = { - 'KOTLIN_PROJECT_PATH' => ':sentry-samples:kmp-app-spm:shared', - 'PRODUCT_MODULE_NAME' => 'shared', - } - - spec.script_phases = [ - { - :name => 'Build shared', - :execution_position => :before_compile, - :shell_path => '/bin/sh', - :script => <<-SCRIPT - if [ "YES" = "$OVERRIDE_KOTLIN_BUILD_IDE_SUPPORTED" ]; then - echo "Skipping Gradle build task invocation due to OVERRIDE_KOTLIN_BUILD_IDE_SUPPORTED environment variable set to \"YES\"" - exit 0 - fi - set -ev - REPO_ROOT="$PODS_TARGET_SRCROOT" - "$REPO_ROOT/../../../gradlew" -p "$REPO_ROOT" $KOTLIN_PROJECT_PATH:syncFramework \ - -Pkotlin.native.cocoapods.platform=$PLATFORM_NAME \ - -Pkotlin.native.cocoapods.archs="$ARCHS" \ - -Pkotlin.native.cocoapods.configuration="$CONFIGURATION" - SCRIPT - } - ] - -end \ No newline at end of file From 2a5cb181c7dff9d1205f4a54bcfe39f5c920323e Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Tue, 11 Jun 2024 02:43:42 +0200 Subject: [PATCH 50/78] Remove --- .../build.gradle.kts | 76 ------ .../gradle/AutoInstallExtension.kt | 27 -- .../gradle/CocoapodsAutoInstallExtension.kt | 33 --- .../multiplatform/gradle/LinkerExtension.kt | 14 -- .../multiplatform/gradle/SentryExtension.kt | 20 -- .../multiplatform/gradle/SentryPlugin.kt | 233 ------------------ .../gradle/SourceSetAutoInstallExtension.kt | 30 --- .../gradle/plugin/SentryPluginTest.kt | 95 ------- 8 files changed, 528 deletions(-) delete mode 100644 sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/build.gradle.kts delete mode 100644 sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/AutoInstallExtension.kt delete mode 100644 sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/CocoapodsAutoInstallExtension.kt delete mode 100644 sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/LinkerExtension.kt delete mode 100644 sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryExtension.kt delete mode 100644 sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryPlugin.kt delete mode 100644 sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SourceSetAutoInstallExtension.kt delete mode 100644 sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/test/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPluginTest.kt diff --git a/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/build.gradle.kts b/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/build.gradle.kts deleted file mode 100644 index 450641ee..00000000 --- a/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/build.gradle.kts +++ /dev/null @@ -1,76 +0,0 @@ -// import com.vanniktech.maven.publish.MavenPublishPluginExtension -// import org.jetbrains.kotlin.gradle.tasks.KotlinCompile -// -// plugins { -// kotlin("jvm") -// `java-gradle-plugin` -// alias(libs.plugins.vanniktech.publish) -// id("distribution") -// alias(libs.plugins.buildConfig) -// } -// -// dependencies { -// compileOnly(kotlin("stdlib")) -// compileOnly(gradleApi()) -// compileOnly(kotlin("gradle-plugin")) -// -// testImplementation(libs.junit) -// } -// -// java { -// sourceCompatibility = JavaVersion.VERSION_1_8 -// targetCompatibility = JavaVersion.VERSION_1_8 -// } -// -// tasks.withType { -// kotlinOptions { -// jvmTarget = JavaVersion.VERSION_1_8.toString() -// } -// } -// -// gradlePlugin { -// plugins { -// create(property("id").toString()) { -// id = property("id").toString() -// implementationClass = property("implementationClass").toString() -// } -// } -// } -// -// val publish = extensions.getByType(MavenPublishPluginExtension::class.java) -// // signing is done when uploading files to MC -// // via gpg:sign-and-deploy-file (release.kts) -// publish.releaseSigningEnabled = false -// -// tasks.named("distZip").configure { -// dependsOn("publishToMavenLocal") -// this.doLast { -// val distributionFilePath = -// "${project.layout.buildDirectory.asFile.get().path}${sep}distributions${sep}${project.name}-${project.version}.zip" -// val file = File(distributionFilePath) -// if (!file.exists()) throw IllegalStateException("Distribution file: $distributionFilePath does not exist") -// if (file.length() == 0L) throw IllegalStateException("Distribution file: $distributionFilePath is empty") -// } -// } -// -// val sep = File.separator -// -// distributions { -// main { -// contents { -// from("build${sep}libs") -// from("build${sep}publications${sep}maven") -// } -// } -// } -// -// buildConfig { -// useKotlinOutput() -// packageName("io.sentry") -// className("BuildConfig") -// -// buildConfigField( -// "String", -// "SentryCocoaVersion", -// provider { "\"${project.property("sentryCocoaVersion")}\"" }) -// } diff --git a/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/AutoInstallExtension.kt b/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/AutoInstallExtension.kt deleted file mode 100644 index 34349201..00000000 --- a/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/AutoInstallExtension.kt +++ /dev/null @@ -1,27 +0,0 @@ -package io.sentry.kotlin.multiplatform.gradle - -import org.gradle.api.Project -import org.gradle.api.provider.Property -import javax.inject.Inject - -@Suppress("UnnecessaryAbstractClass") -abstract class AutoInstallExtension -@Inject -constructor(project: Project) { - private val objects = project.objects - - /** - * Enable auto-installation of the Sentry dependencies through [CocoapodsAutoInstallExtension] - * - * Disabling this will prevent the plugin from auto installing anything. - * - * Defaults to true. - */ - val enabled: Property = - objects.property(Boolean::class.java) - .convention(true) - - val cocoapods: CocoapodsAutoInstallExtension = objects.newInstance(CocoapodsAutoInstallExtension::class.java, project) - - val commonMain: SourceSetAutoInstallExtension = objects.newInstance(SourceSetAutoInstallExtension::class.java, project) -} diff --git a/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/CocoapodsAutoInstallExtension.kt b/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/CocoapodsAutoInstallExtension.kt deleted file mode 100644 index 173893ee..00000000 --- a/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/CocoapodsAutoInstallExtension.kt +++ /dev/null @@ -1,33 +0,0 @@ -package io.sentry.kotlin.multiplatform.gradle - -import io.sentry.BuildConfig -import org.gradle.api.Project -import org.gradle.api.provider.Property -import javax.inject.Inject - -@Suppress("UnnecessaryAbstractClass") -abstract class CocoapodsAutoInstallExtension -@Inject -constructor(project: Project) { - private val objects = project.objects - - /** - * Enable auto-installation of the Sentry Cocoa SDK pod. - * - * If the cocoapods plugin is applied and no existing Sentry pod configuration exists, the Sentry-Cocoa SDK pod will be installed - * - * Defaults to true. - */ - val enabled: Property = - objects.property(Boolean::class.java) - .convention(true) - - /** - * Overrides default Sentry Cocoa version. - * - * Defaults to the version used in the latest KMP SDK. - */ - val sentryCocoaVersion: Property = - objects.property(String::class.java) - .convention(BuildConfig.SentryCocoaVersion) -} diff --git a/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/LinkerExtension.kt b/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/LinkerExtension.kt deleted file mode 100644 index ef9a77ed..00000000 --- a/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/LinkerExtension.kt +++ /dev/null @@ -1,14 +0,0 @@ -package io.sentry.kotlin.multiplatform.gradle - -import org.gradle.api.Project -import org.gradle.api.provider.Property -import javax.inject.Inject - -@Suppress("UnnecessaryAbstractClass") -abstract class LinkerExtension -@Inject -constructor(project: Project) { - private val objects = project.objects - - val xcodeprojPath: Property = objects.property(String::class.java) -} diff --git a/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryExtension.kt b/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryExtension.kt deleted file mode 100644 index 9f9439e0..00000000 --- a/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryExtension.kt +++ /dev/null @@ -1,20 +0,0 @@ -package io.sentry.kotlin.multiplatform.gradle - -import org.gradle.api.Project -import javax.inject.Inject - -@Suppress("UnnecessaryAbstractClass") -abstract class SentryExtension -@Inject -constructor(project: Project) { - private val objects = project.objects - - /** - * Linker configuration. - * - * If you use SPM this configuration is necessary for setting up linking the framework and test executable. - */ - val linker: LinkerExtension = objects.newInstance(LinkerExtension::class.java, project) - - val autoInstall: AutoInstallExtension = objects.newInstance(AutoInstallExtension::class.java, project) -} diff --git a/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryPlugin.kt b/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryPlugin.kt deleted file mode 100644 index 2f1480be..00000000 --- a/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryPlugin.kt +++ /dev/null @@ -1,233 +0,0 @@ -package io.sentry.kotlin.multiplatform.gradle - -import org.gradle.api.GradleException -import org.gradle.api.Plugin -import org.gradle.api.Project -import org.gradle.api.plugins.ExtensionAware -import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension -import org.jetbrains.kotlin.gradle.plugin.cocoapods.CocoapodsExtension -import org.jetbrains.kotlin.gradle.plugin.cocoapods.KotlinCocoapodsPlugin -import org.jetbrains.kotlin.gradle.plugin.mpp.Framework -import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget -import org.jetbrains.kotlin.gradle.plugin.mpp.TestExecutable -import java.io.ByteArrayOutputStream -import java.io.File - -internal const val SENTRY_EXTENSION_NAME = "sentryKmp" -internal const val LINKER_EXTENSION_NAME = "linker" -internal const val AUTO_INSTALL_EXTENSION_NAME = "autoInstall" -internal const val COCOAPODS_AUTO_INSTALL_EXTENSION_NAME = "cocoapods" -internal const val COMMON_MAIN_AUTO_INSTALL_EXTENSION_NAME = "commonMain" -internal const val KOTLIN_EXTENSION_NAME = "kotlin" - -@Suppress("unused") -class SentryPlugin : Plugin { - override fun apply(project: Project): Unit = - with(project) { - val sentryExtension = - project.extensions.create( - SENTRY_EXTENSION_NAME, - SentryExtension::class.java, - project - ) - project.extensions.add(LINKER_EXTENSION_NAME, sentryExtension.linker) - project.extensions.add(AUTO_INSTALL_EXTENSION_NAME, sentryExtension.autoInstall) - project.extensions.add( - COCOAPODS_AUTO_INSTALL_EXTENSION_NAME, - sentryExtension.autoInstall.cocoapods - ) - project.extensions.add( - COMMON_MAIN_AUTO_INSTALL_EXTENSION_NAME, - sentryExtension.autoInstall.commonMain - ) - - afterEvaluate { - val hasCocoapodsPlugin = - project.plugins.findPlugin(KotlinCocoapodsPlugin::class.java) != null - - if (sentryExtension.autoInstall.enabled.get()) { - if (sentryExtension.autoInstall.commonMain.enabled.get()) { - installSentryForKmp(sentryExtension.autoInstall.commonMain) - } - if (hasCocoapodsPlugin && sentryExtension.autoInstall.cocoapods.enabled.get()) { - installSentryForCocoapods(sentryExtension.autoInstall.cocoapods) - } - } - - // If the user is not using the cocoapods plugin, linking to the framework is not automatic - // so we have to take care of that - if (!hasCocoapodsPlugin) { - configureLinkingOptions(sentryExtension.linker) - } - } - } -} - -internal fun Project.installSentryForKmp(commonMainAutoInstallExtension: SourceSetAutoInstallExtension) { - val kmpExtension = extensions.findByName(KOTLIN_EXTENSION_NAME) - if (kmpExtension !is KotlinMultiplatformExtension) { - // todo: log, not multiplatform found - return - } - - val unsupportedTargets = listOf("wasm", "js", "mingw", "linux", "androidNative") - kmpExtension.targets.forEach { target -> - if (unsupportedTargets.any { unsupported -> - target.name.contains(unsupported) - } - ) { - throw GradleException( - "Unsupported target: ${target.name}. " + - "Cannot auto install in commonMain. " + - "Please create an intermediate sourceSet with targets that the Sentry SDK supports (apple, jvm, android) and add the dependency manually." - ) - } - } - - val commonMain = - kmpExtension.sourceSets.find { - it.name.contains("common") - } - - val sentryVersion = commonMainAutoInstallExtension.sentryKmpVersion.get() - commonMain?.dependencies { - api("io.sentry:sentry-kotlin-multiplatform:$sentryVersion") - } -} - -internal fun Project.installSentryForCocoapods(cocoapodsAutoInstallExtension: CocoapodsAutoInstallExtension) { - val kmpExtension = extensions.findByName(KOTLIN_EXTENSION_NAME) - if (kmpExtension !is KotlinMultiplatformExtension) { - return - } - - (kmpExtension as ExtensionAware).extensions.configure(CocoapodsExtension::class.java) { cocoapods -> - val podName = "Sentry" - val sentryPod = cocoapods.pods.findByName(podName) - if (sentryPod == null) { - cocoapods.pod(podName) { - version = cocoapodsAutoInstallExtension.sentryCocoaVersion.get() - linkOnly = true - extraOpts += listOf("-compiler-option", "-fmodules") - } - } - } -} - -internal fun Project.configureLinkingOptions(linkerExtension: LinkerExtension) { - val kmpExtension = extensions.findByName(KOTLIN_EXTENSION_NAME) - if (kmpExtension !is KotlinMultiplatformExtension) { - // todo: log, not multiplatform found - return - } - - val customXcodeprojPath = linkerExtension.xcodeprojPath.orNull - val derivedDataPath = findDerivedDataPath(customXcodeprojPath) - - kmpExtension.appleTargets().all { target -> - val frameworkArchitecture = target.toSentryFrameworkArchitecture() - if (frameworkArchitecture == null) { - // todo: log, unsupported architecture - return@all - } - - val dynamicFrameworkPath = - "$derivedDataPath/SourcePackages/artifacts/sentry-cocoa/Sentry-Dynamic/Sentry-Dynamic.xcframework/$frameworkArchitecture" - val staticFrameworkPath = - "$derivedDataPath/SourcePackages/artifacts/sentry-cocoa/Sentry/Sentry.xcframework/$frameworkArchitecture" - - val dynamicFrameworkExists = File(dynamicFrameworkPath).exists() - val staticFrameworkExists = File(staticFrameworkPath).exists() - - if (!dynamicFrameworkExists && !staticFrameworkExists) { - throw GradleException("Sentry Cocoa Framework not found at $dynamicFrameworkPath or $staticFrameworkPath") - } - - target.binaries.all binaries@{ binary -> - if (binary is TestExecutable) { - val frameworkPath = - if (dynamicFrameworkExists) dynamicFrameworkPath else staticFrameworkPath - binary.linkerOpts("-rpath", "$path/Sentry.framework", "-F$frameworkPath") - } - - if (binary is Framework) { - val frameworkPath = - if (binary.isStatic) staticFrameworkPath else dynamicFrameworkPath - binary.linkerOpts("-F$frameworkPath") - } - } - } -} - -private fun Project.findDerivedDataPath(customXcodeprojPath: String? = null): String { - val xcodeprojPath = customXcodeprojPath ?: findXcodeprojFile(rootDir)?.absolutePath - val buildDirOutput = ByteArrayOutputStream() - exec { - it.commandLine = - listOf( - "xcodebuild", - "-project", - xcodeprojPath, - "-showBuildSettings" - ) - it.standardOutput = buildDirOutput - } - val buildSettings = buildDirOutput.toString("UTF-8") - val buildDirRegex = Regex("BUILD_DIR = (.+)") - val buildDirMatch = buildDirRegex.find(buildSettings) - val buildDir = - buildDirMatch?.groupValues?.get(1) - ?: throw GradleException("BUILD_DIR not found in xcodebuild output") - val derivedDataPath = buildDir.replace("/Build/Products", "") - return derivedDataPath -} - -/** - * Searches for a xcodeproj starting from the root directory. - * This function will only work for monorepos and if it is not, - * the user needs to provide the custom path through the [LinkerExtension] configuration. - */ -internal fun findXcodeprojFile(dir: File): File? { - val ignoredDirectories = listOf("build", "DerivedData") - - fun searchDirectory(directory: File): File? { - val files = directory.listFiles() ?: return null - - for (file in files) { - if (file.name in ignoredDirectories) { - continue - } - - // Recursively search the subdirectory - val result = searchDirectory(file) - if (result != null) { - return result - } - - if (file.extension == "xcodeproj") { - return file - } - } - return null - } - - return searchDirectory(dir) -} - -private fun KotlinMultiplatformExtension.appleTargets() = - targets.withType(KotlinNativeTarget::class.java) - .matching { it.konanTarget.family.isAppleFamily } - -/** - * Transforms a Kotlin Multiplatform target name to the architecture name that is found inside - * Sentry's framework directory. - */ -internal fun KotlinNativeTarget.toSentryFrameworkArchitecture(): String? { - return when (name) { - "iosSimulatorArm64" -> "ios-arm64_x86_64-simulator" - "iosX64" -> "ios-arm64_x86_64-simulator" - "iosArm64" -> "ios-arm64" - // todo: add more targets - else -> null - } -} diff --git a/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SourceSetAutoInstallExtension.kt b/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SourceSetAutoInstallExtension.kt deleted file mode 100644 index 2dd4501e..00000000 --- a/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SourceSetAutoInstallExtension.kt +++ /dev/null @@ -1,30 +0,0 @@ -package io.sentry.kotlin.multiplatform.gradle - -import org.gradle.api.Project -import org.gradle.api.provider.Property -import javax.inject.Inject - -@Suppress("UnnecessaryAbstractClass") -abstract class SourceSetAutoInstallExtension -@Inject -constructor(project: Project) { - private val objects = project.objects - - /** - * Enable auto-installation of the Sentry Kotlin Multiplatform SDK dependency in the commonMain source set. - * - * Defaults to true. - */ - val enabled: Property = - objects.property(Boolean::class.java) - .convention(true) - - /** - * Overrides the default Sentry Kotlin Multiplatform SDK dependency version. - * - * Defaults to the latest version of the Sentry Kotlin Multiplatform SDK. - */ - val sentryKmpVersion: Property = - objects.property(String::class.java) - .convention("latest.release") // Replace with the actual default version -} diff --git a/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/test/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPluginTest.kt b/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/test/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPluginTest.kt deleted file mode 100644 index 62905d54..00000000 --- a/sentry-kotlin-multiplatform-gradle-plugin/sentry-kotlin-multiplatform-gradle-plugin/src/test/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPluginTest.kt +++ /dev/null @@ -1,95 +0,0 @@ -package io.sentry.kotlin.multiplatform.gradle - -import junit.framework.TestCase.assertEquals -import junit.framework.TestCase.assertNotNull -import junit.framework.TestCase.assertNull -import org.gradle.api.plugins.ExtensionAware -import org.gradle.testfixtures.ProjectBuilder -import org.jetbrains.kotlin.gradle.plugin.cocoapods.CocoapodsExtension -import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget -import org.junit.Test -import org.mockito.Mockito.mock -import org.mockito.Mockito.`when` - -class SentryPluginTest { - @Test - fun `plugin is applied correctly to the project`() { - val project = ProjectBuilder.builder().build() - project.pluginManager.apply("io.sentry.kotlin.multiplatform.gradle.plugin") - - assert(project.plugins.hasPlugin(SentryPlugin::class.java)) - } - - @Test - fun `extension sentry is created correctly`() { - val project = ProjectBuilder.builder().build() - project.pluginManager.apply("io.sentry.kotlin.multiplatform.gradle.plugin") - - assertNotNull(project.extensions.getByName("sentry")) - } - - @Test - fun `extension linker is created correctly`() { - val project = ProjectBuilder.builder().build() - project.pluginManager.apply("io.sentry.kotlin.multiplatform.gradle.plugin") - - assertNotNull(project.extensions.getByName("linker")) - } - - @Test - fun `frameworkArchitecture returns transformed target with supported targets`() { - val target = mock(KotlinNativeTarget::class.java) - - `when`(target.name).thenReturn("iosSimulatorArm64") - assertEquals("ios-arm64_x86_64-simulator", target.toSentryFrameworkArchitecture()) - - `when`(target.name).thenReturn("iosX64") - assertEquals("ios-arm64_x86_64-simulator", target.toSentryFrameworkArchitecture()) - - `when`(target.name).thenReturn("iosArm64") - assertEquals("ios-arm64", target.toSentryFrameworkArchitecture()) - } - - @Test - fun `frameworkArchitecture returns null with unsupported targets`() { - val target = mock(KotlinNativeTarget::class.java) - - `when`(target.name).thenReturn("unsupported") - assertNull(target.toSentryFrameworkArchitecture()) - } - - @Test - fun `install Sentry pod when cocoapods plugin is applied and no custom Sentry configuration exists`() { - val project = ProjectBuilder.builder().build() - project.pluginManager.apply("io.sentry.kotlin.multiplatform.gradle.plugin") - project.pluginManager.apply("org.jetbrains.kotlin.multiplatform") - project.pluginManager.apply("org.jetbrains.kotlin.native.cocoapods") - - project.afterEvaluate { - val cocoapodsExtension = project.extensions.findByType(CocoapodsExtension::class.java) - assertNotNull(cocoapodsExtension?.pods?.findByName("Sentry")) - } - } - - @Test - fun `do not install Sentry pod when cocoapods plugin is applied and custom Sentry configuration exists`() { - val project = ProjectBuilder.builder().build() - project.pluginManager.apply("io.sentry.kotlin.multiplatform.gradle.plugin") - project.pluginManager.apply("org.jetbrains.kotlin.multiplatform") - project.pluginManager.apply("org.jetbrains.kotlin.native.cocoapods") - - val kmpExtension = project.extensions.findByName("kotlin") - (kmpExtension as ExtensionAware).extensions.configure(CocoapodsExtension::class.java) { cocoapods -> - cocoapods.pod("Sentry") { - version = "custom version" - } - } - - // plugin does not configure sentry pod if there is already an existing configuration - project.afterEvaluate { - val cocoapodsExtension = project.extensions.findByType(CocoapodsExtension::class.java) - val pod = cocoapodsExtension?.pods?.findByName("Sentry") - assertEquals(pod?.version, "custom version") - } - } -} From 0e5253de62bcb73920688ba86241b835adf995f6 Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Tue, 11 Jun 2024 03:13:44 +0200 Subject: [PATCH 51/78] Format --- .../build.gradle.kts | 125 ++++--- .../gradle/libs.versions.toml | 13 +- .../settings.gradle.kts | 16 +- .../gradle/AutoInstallExtension.kt | 32 +- .../gradle/CocoapodsAutoInstallExtension.kt | 42 ++- .../multiplatform/gradle/LinkerExtension.kt | 10 +- .../multiplatform/gradle/SentryExtension.kt | 24 +- .../multiplatform/gradle/SentryPlugin.kt | 321 +++++++++--------- .../gradle/SourceSetAutoInstallExtension.kt | 40 ++- .../multiplatform/gradle/SentryPluginTest.kt | 91 +++-- 10 files changed, 342 insertions(+), 372 deletions(-) diff --git a/sentry-kotlin-multiplatform-gradle-plugin/build.gradle.kts b/sentry-kotlin-multiplatform-gradle-plugin/build.gradle.kts index e0a111bf..e5e4b9e5 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/build.gradle.kts +++ b/sentry-kotlin-multiplatform-gradle-plugin/build.gradle.kts @@ -1,47 +1,45 @@ +import com.diffplug.gradle.spotless.SpotlessExtension +import com.diffplug.spotless.LineEnding import com.vanniktech.maven.publish.MavenPublishPluginExtension import io.gitlab.arturbosch.detekt.Detekt import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { - alias(libs.plugins.kotlin) - alias(libs.plugins.detekt) - alias(libs.plugins.ktlint) - alias(libs.plugins.versionCheck) - `java-gradle-plugin` - alias(libs.plugins.vanniktech.publish) - id("distribution") - alias(libs.plugins.buildConfig) + alias(libs.plugins.kotlin) + alias(libs.plugins.detekt) + `java-gradle-plugin` + alias(libs.plugins.vanniktech.publish) + id("distribution") + alias(libs.plugins.buildConfig) + alias(libs.plugins.spotless) } version = property("versionName").toString() + group = property("group").toString() dependencies { - compileOnly(kotlin("stdlib")) - compileOnly(gradleApi()) - compileOnly(kotlin("gradle-plugin")) + compileOnly(kotlin("stdlib")) + compileOnly(gradleApi()) + compileOnly(kotlin("gradle-plugin")) - testImplementation(libs.junit) + testImplementation(libs.junit) } java { - sourceCompatibility = JavaVersion.VERSION_1_8 - targetCompatibility = JavaVersion.VERSION_1_8 + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 } -tasks.withType { - kotlinOptions { - jvmTarget = JavaVersion.VERSION_1_8.toString() - } -} +tasks.withType { kotlinOptions { jvmTarget = JavaVersion.VERSION_1_8.toString() } } gradlePlugin { - plugins { - create(property("id").toString()) { - id = property("id").toString() - implementationClass = property("implementationClass").toString() - } + plugins { + create(property("id").toString()) { + id = property("id").toString() + implementationClass = property("implementationClass").toString() } + } } val publish = extensions.getByType(MavenPublishPluginExtension::class.java) @@ -50,59 +48,56 @@ val publish = extensions.getByType(MavenPublishPluginExtension::class.java) publish.releaseSigningEnabled = false tasks.named("distZip").configure { - dependsOn("publishToMavenLocal") - this.doLast { - val distributionFilePath = - "${project.layout.buildDirectory.asFile.get().path}${sep}distributions${sep}${project.name}-${project.version}.zip" - val file = File(distributionFilePath) - if (!file.exists()) throw IllegalStateException("Distribution file: $distributionFilePath does not exist") - if (file.length() == 0L) throw IllegalStateException("Distribution file: $distributionFilePath is empty") - } + dependsOn("publishToMavenLocal") + this.doLast { + val distributionFilePath = + "${project.layout.buildDirectory.asFile.get().path}${sep}distributions${sep}${project.name}-${project.version}.zip" + val file = File(distributionFilePath) + if (!file.exists()) + throw IllegalStateException("Distribution file: $distributionFilePath does not exist") + if (file.length() == 0L) + throw IllegalStateException("Distribution file: $distributionFilePath is empty") + } } val sep = File.separator distributions { - main { - contents { - from("build${sep}libs") - from("build${sep}publications${sep}maven") - } + main { + contents { + from("build${sep}libs") + from("build${sep}publications${sep}maven") } + } } buildConfig { - useKotlinOutput() - packageName("io.sentry") - className("BuildConfig") - - buildConfigField( - "String", - "SentryCocoaVersion", - provider { "\"${project.property("sentryCocoaVersion")}\"" } - ) -} + useKotlinOutput() + packageName("io.sentry") + className("BuildConfig") -ktlint { - debug.set(false) - verbose.set(true) - android.set(false) - outputToConsole.set(true) - ignoreFailures.set(false) - enableExperimentalRules.set(true) - filter { - exclude("**/generated/**") - include("**/kotlin/**") - } + buildConfigField( + "String", "SentryCocoaVersion", provider { "\"${project.property("sentryCocoaVersion")}\"" }) } -detekt { - config.setFrom(rootProject.files("../config/detekt/detekt.yml")) -} +detekt { config.setFrom(rootProject.files("../config/detekt/detekt.yml")) } tasks.withType().configureEach { - reports { - html.required.set(true) - html.outputLocation.set(file("build/reports/detekt.html")) - } + reports { + html.required.set(true) + html.outputLocation.set(file("build/reports/detekt.html")) + } +} + +configure { + kotlin { + target("**/*.kt") + ktfmt("0.30") + } + kotlinGradle { + target("**/*.kts") + ktfmt("0.30") + } + + lineEndings = LineEnding.UNIX } diff --git a/sentry-kotlin-multiplatform-gradle-plugin/gradle/libs.versions.toml b/sentry-kotlin-multiplatform-gradle-plugin/gradle/libs.versions.toml index 82893cb5..c4dac671 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/gradle/libs.versions.toml +++ b/sentry-kotlin-multiplatform-gradle-plugin/gradle/libs.versions.toml @@ -1,18 +1,19 @@ [versions] detekt = "1.23.6" kotlin = "1.9.23" -ktlintGradle = "12.1.0" pluginPublish = "1.2.1" -versionCheck = "0.51.0" +buildConfig = "5.3.5" +vanniktechPublish = "0.18.0" +spotless = "6.25.0" +ktfmt = "0.18.0" [plugins] detekt = { id = "io.gitlab.arturbosch.detekt", version.ref = "detekt"} kotlin = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin"} -ktlint = { id = "org.jlleitschuh.gradle.ktlint", version.ref = "ktlintGradle"} pluginPublish = { id = "com.gradle.plugin-publish", version.ref = "pluginPublish"} -versionCheck = { id = "com.github.ben-manes.versions", version.ref = "versionCheck"} -vanniktech-publish = { id = "com.vanniktech.maven.publish", version = "0.18.0"} -buildConfig = { id = "com.github.gmazzo.buildconfig", version = "5.3.5"} +vanniktech-publish = { id = "com.vanniktech.maven.publish", version.ref = "vanniktechPublish"} +buildConfig = { id = "com.github.gmazzo.buildconfig", version.ref = "buildConfig"} +spotless = { id = "com.diffplug.spotless", version.ref = "spotless"} [libraries] junit = "junit:junit:4.13.2" diff --git a/sentry-kotlin-multiplatform-gradle-plugin/settings.gradle.kts b/sentry-kotlin-multiplatform-gradle-plugin/settings.gradle.kts index 4ef43ffb..22ef8566 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/settings.gradle.kts +++ b/sentry-kotlin-multiplatform-gradle-plugin/settings.gradle.kts @@ -1,15 +1,15 @@ pluginManagement { - repositories { - gradlePluginPortal() - mavenCentral() - } + repositories { + gradlePluginPortal() + mavenCentral() + } } dependencyResolutionManagement { - repositories { - google() - mavenCentral() - } + repositories { + google() + mavenCentral() + } } rootProject.name = "sentry-kotlin-multiplatform-gradle-plugin" diff --git a/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/AutoInstallExtension.kt b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/AutoInstallExtension.kt index 34349201..7e21130e 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/AutoInstallExtension.kt +++ b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/AutoInstallExtension.kt @@ -1,27 +1,25 @@ package io.sentry.kotlin.multiplatform.gradle +import javax.inject.Inject import org.gradle.api.Project import org.gradle.api.provider.Property -import javax.inject.Inject @Suppress("UnnecessaryAbstractClass") -abstract class AutoInstallExtension -@Inject -constructor(project: Project) { - private val objects = project.objects +abstract class AutoInstallExtension @Inject constructor(project: Project) { + private val objects = project.objects - /** - * Enable auto-installation of the Sentry dependencies through [CocoapodsAutoInstallExtension] - * - * Disabling this will prevent the plugin from auto installing anything. - * - * Defaults to true. - */ - val enabled: Property = - objects.property(Boolean::class.java) - .convention(true) + /** + * Enable auto-installation of the Sentry dependencies through [CocoapodsAutoInstallExtension] + * + * Disabling this will prevent the plugin from auto installing anything. + * + * Defaults to true. + */ + val enabled: Property = objects.property(Boolean::class.java).convention(true) - val cocoapods: CocoapodsAutoInstallExtension = objects.newInstance(CocoapodsAutoInstallExtension::class.java, project) + val cocoapods: CocoapodsAutoInstallExtension = + objects.newInstance(CocoapodsAutoInstallExtension::class.java, project) - val commonMain: SourceSetAutoInstallExtension = objects.newInstance(SourceSetAutoInstallExtension::class.java, project) + val commonMain: SourceSetAutoInstallExtension = + objects.newInstance(SourceSetAutoInstallExtension::class.java, project) } diff --git a/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/CocoapodsAutoInstallExtension.kt b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/CocoapodsAutoInstallExtension.kt index 173893ee..307da1f3 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/CocoapodsAutoInstallExtension.kt +++ b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/CocoapodsAutoInstallExtension.kt @@ -1,33 +1,29 @@ package io.sentry.kotlin.multiplatform.gradle import io.sentry.BuildConfig +import javax.inject.Inject import org.gradle.api.Project import org.gradle.api.provider.Property -import javax.inject.Inject @Suppress("UnnecessaryAbstractClass") -abstract class CocoapodsAutoInstallExtension -@Inject -constructor(project: Project) { - private val objects = project.objects +abstract class CocoapodsAutoInstallExtension @Inject constructor(project: Project) { + private val objects = project.objects - /** - * Enable auto-installation of the Sentry Cocoa SDK pod. - * - * If the cocoapods plugin is applied and no existing Sentry pod configuration exists, the Sentry-Cocoa SDK pod will be installed - * - * Defaults to true. - */ - val enabled: Property = - objects.property(Boolean::class.java) - .convention(true) + /** + * Enable auto-installation of the Sentry Cocoa SDK pod. + * + * If the cocoapods plugin is applied and no existing Sentry pod configuration exists, the + * Sentry-Cocoa SDK pod will be installed. + * + * Defaults to true. + */ + val enabled: Property = objects.property(Boolean::class.java).convention(true) - /** - * Overrides default Sentry Cocoa version. - * - * Defaults to the version used in the latest KMP SDK. - */ - val sentryCocoaVersion: Property = - objects.property(String::class.java) - .convention(BuildConfig.SentryCocoaVersion) + /** + * Overrides default Sentry Cocoa version. + * + * Defaults to the version used in the latest KMP SDK. + */ + val sentryCocoaVersion: Property = + objects.property(String::class.java).convention(BuildConfig.SentryCocoaVersion) } diff --git a/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/LinkerExtension.kt b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/LinkerExtension.kt index ef9a77ed..a8469635 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/LinkerExtension.kt +++ b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/LinkerExtension.kt @@ -1,14 +1,12 @@ package io.sentry.kotlin.multiplatform.gradle +import javax.inject.Inject import org.gradle.api.Project import org.gradle.api.provider.Property -import javax.inject.Inject @Suppress("UnnecessaryAbstractClass") -abstract class LinkerExtension -@Inject -constructor(project: Project) { - private val objects = project.objects +abstract class LinkerExtension @Inject constructor(project: Project) { + private val objects = project.objects - val xcodeprojPath: Property = objects.property(String::class.java) + val xcodeprojPath: Property = objects.property(String::class.java) } diff --git a/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryExtension.kt b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryExtension.kt index 9f9439e0..9244e362 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryExtension.kt +++ b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryExtension.kt @@ -1,20 +1,20 @@ package io.sentry.kotlin.multiplatform.gradle -import org.gradle.api.Project import javax.inject.Inject +import org.gradle.api.Project @Suppress("UnnecessaryAbstractClass") -abstract class SentryExtension -@Inject -constructor(project: Project) { - private val objects = project.objects +abstract class SentryExtension @Inject constructor(project: Project) { + private val objects = project.objects - /** - * Linker configuration. - * - * If you use SPM this configuration is necessary for setting up linking the framework and test executable. - */ - val linker: LinkerExtension = objects.newInstance(LinkerExtension::class.java, project) + /** + * Linker configuration. + * + * If you use SPM this configuration is necessary for setting up linking the framework and test + * executable. + */ + val linker: LinkerExtension = objects.newInstance(LinkerExtension::class.java, project) - val autoInstall: AutoInstallExtension = objects.newInstance(AutoInstallExtension::class.java, project) + val autoInstall: AutoInstallExtension = + objects.newInstance(AutoInstallExtension::class.java, project) } diff --git a/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryPlugin.kt b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryPlugin.kt index 2f1480be..274d07c3 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryPlugin.kt +++ b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryPlugin.kt @@ -1,5 +1,7 @@ package io.sentry.kotlin.multiplatform.gradle +import java.io.ByteArrayOutputStream +import java.io.File import org.gradle.api.GradleException import org.gradle.api.Plugin import org.gradle.api.Project @@ -10,8 +12,6 @@ import org.jetbrains.kotlin.gradle.plugin.cocoapods.KotlinCocoapodsPlugin import org.jetbrains.kotlin.gradle.plugin.mpp.Framework import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget import org.jetbrains.kotlin.gradle.plugin.mpp.TestExecutable -import java.io.ByteArrayOutputStream -import java.io.File internal const val SENTRY_EXTENSION_NAME = "sentryKmp" internal const val LINKER_EXTENSION_NAME = "linker" @@ -22,212 +22,197 @@ internal const val KOTLIN_EXTENSION_NAME = "kotlin" @Suppress("unused") class SentryPlugin : Plugin { - override fun apply(project: Project): Unit = - with(project) { - val sentryExtension = - project.extensions.create( - SENTRY_EXTENSION_NAME, - SentryExtension::class.java, - project - ) - project.extensions.add(LINKER_EXTENSION_NAME, sentryExtension.linker) - project.extensions.add(AUTO_INSTALL_EXTENSION_NAME, sentryExtension.autoInstall) - project.extensions.add( - COCOAPODS_AUTO_INSTALL_EXTENSION_NAME, - sentryExtension.autoInstall.cocoapods - ) - project.extensions.add( - COMMON_MAIN_AUTO_INSTALL_EXTENSION_NAME, - sentryExtension.autoInstall.commonMain - ) - - afterEvaluate { - val hasCocoapodsPlugin = - project.plugins.findPlugin(KotlinCocoapodsPlugin::class.java) != null - - if (sentryExtension.autoInstall.enabled.get()) { - if (sentryExtension.autoInstall.commonMain.enabled.get()) { - installSentryForKmp(sentryExtension.autoInstall.commonMain) - } - if (hasCocoapodsPlugin && sentryExtension.autoInstall.cocoapods.enabled.get()) { - installSentryForCocoapods(sentryExtension.autoInstall.cocoapods) - } - } - - // If the user is not using the cocoapods plugin, linking to the framework is not automatic - // so we have to take care of that - if (!hasCocoapodsPlugin) { - configureLinkingOptions(sentryExtension.linker) - } + override fun apply(project: Project): Unit = + with(project) { + val sentryExtension = + project.extensions.create(SENTRY_EXTENSION_NAME, SentryExtension::class.java, project) + project.extensions.add(LINKER_EXTENSION_NAME, sentryExtension.linker) + project.extensions.add(AUTO_INSTALL_EXTENSION_NAME, sentryExtension.autoInstall) + project.extensions.add( + COCOAPODS_AUTO_INSTALL_EXTENSION_NAME, sentryExtension.autoInstall.cocoapods) + project.extensions.add( + COMMON_MAIN_AUTO_INSTALL_EXTENSION_NAME, sentryExtension.autoInstall.commonMain) + + afterEvaluate { + val hasCocoapodsPlugin = + project.plugins.findPlugin(KotlinCocoapodsPlugin::class.java) != null + + if (sentryExtension.autoInstall.enabled.get()) { + if (sentryExtension.autoInstall.commonMain.enabled.get()) { + installSentryForKmp(sentryExtension.autoInstall.commonMain) } + if (hasCocoapodsPlugin && sentryExtension.autoInstall.cocoapods.enabled.get()) { + installSentryForCocoapods(sentryExtension.autoInstall.cocoapods) + } + } + + // If the user is not using the cocoapods plugin, linking to the framework is not + // automatic + // so we have to take care of that + if (!hasCocoapodsPlugin) { + configureLinkingOptions(sentryExtension.linker) + } } + } } -internal fun Project.installSentryForKmp(commonMainAutoInstallExtension: SourceSetAutoInstallExtension) { - val kmpExtension = extensions.findByName(KOTLIN_EXTENSION_NAME) - if (kmpExtension !is KotlinMultiplatformExtension) { - // todo: log, not multiplatform found - return - } - - val unsupportedTargets = listOf("wasm", "js", "mingw", "linux", "androidNative") - kmpExtension.targets.forEach { target -> - if (unsupportedTargets.any { unsupported -> - target.name.contains(unsupported) - } - ) { - throw GradleException( - "Unsupported target: ${target.name}. " + - "Cannot auto install in commonMain. " + - "Please create an intermediate sourceSet with targets that the Sentry SDK supports (apple, jvm, android) and add the dependency manually." - ) - } +internal fun Project.installSentryForKmp( + commonMainAutoInstallExtension: SourceSetAutoInstallExtension +) { + val kmpExtension = extensions.findByName(KOTLIN_EXTENSION_NAME) + if (kmpExtension !is KotlinMultiplatformExtension) { + // todo: log, not multiplatform found + return + } + + val unsupportedTargets = listOf("wasm", "js", "mingw", "linux", "androidNative") + kmpExtension.targets.forEach { target -> + if (unsupportedTargets.any { unsupported -> target.name.contains(unsupported) }) { + throw GradleException( + "Unsupported target: ${target.name}. " + + "Cannot auto install in commonMain. " + + "Please create an intermediate sourceSet with targets that the Sentry SDK " + + "supports (apple, jvm, android) and add the dependency manually.") } + } - val commonMain = - kmpExtension.sourceSets.find { - it.name.contains("common") - } + val commonMain = kmpExtension.sourceSets.find { it.name.contains("common") } - val sentryVersion = commonMainAutoInstallExtension.sentryKmpVersion.get() - commonMain?.dependencies { - api("io.sentry:sentry-kotlin-multiplatform:$sentryVersion") - } + val sentryVersion = commonMainAutoInstallExtension.sentryKmpVersion.get() + commonMain?.dependencies { api("io.sentry:sentry-kotlin-multiplatform:$sentryVersion") } } -internal fun Project.installSentryForCocoapods(cocoapodsAutoInstallExtension: CocoapodsAutoInstallExtension) { - val kmpExtension = extensions.findByName(KOTLIN_EXTENSION_NAME) - if (kmpExtension !is KotlinMultiplatformExtension) { - return - } - - (kmpExtension as ExtensionAware).extensions.configure(CocoapodsExtension::class.java) { cocoapods -> - val podName = "Sentry" - val sentryPod = cocoapods.pods.findByName(podName) - if (sentryPod == null) { - cocoapods.pod(podName) { - version = cocoapodsAutoInstallExtension.sentryCocoaVersion.get() - linkOnly = true - extraOpts += listOf("-compiler-option", "-fmodules") - } - } +internal fun Project.installSentryForCocoapods( + cocoapodsAutoInstallExtension: CocoapodsAutoInstallExtension +) { + val kmpExtension = extensions.findByName(KOTLIN_EXTENSION_NAME) + if (kmpExtension !is KotlinMultiplatformExtension) { + return + } + + (kmpExtension as ExtensionAware).extensions.configure(CocoapodsExtension::class.java) { cocoapods + -> + val podName = "Sentry" + val sentryPod = cocoapods.pods.findByName(podName) + if (sentryPod == null) { + cocoapods.pod(podName) { + version = cocoapodsAutoInstallExtension.sentryCocoaVersion.get() + linkOnly = true + extraOpts += listOf("-compiler-option", "-fmodules") + } } + } } internal fun Project.configureLinkingOptions(linkerExtension: LinkerExtension) { - val kmpExtension = extensions.findByName(KOTLIN_EXTENSION_NAME) - if (kmpExtension !is KotlinMultiplatformExtension) { - // todo: log, not multiplatform found - return + val kmpExtension = extensions.findByName(KOTLIN_EXTENSION_NAME) + if (kmpExtension !is KotlinMultiplatformExtension) { + // todo: log, not multiplatform found + return + } + + val customXcodeprojPath = linkerExtension.xcodeprojPath.orNull + val derivedDataPath = findDerivedDataPath(customXcodeprojPath) + + kmpExtension.appleTargets().all { target -> + val frameworkArchitecture = target.toSentryFrameworkArchitecture() + if (frameworkArchitecture == null) { + // todo: log, unsupported architecture + return@all } - val customXcodeprojPath = linkerExtension.xcodeprojPath.orNull - val derivedDataPath = findDerivedDataPath(customXcodeprojPath) + val dynamicFrameworkPath = + "$derivedDataPath/SourcePackages/artifacts/sentry-cocoa/Sentry-Dynamic/Sentry-Dynamic.xcframework/$frameworkArchitecture" + val staticFrameworkPath = + "$derivedDataPath/SourcePackages/artifacts/sentry-cocoa/Sentry/Sentry.xcframework/$frameworkArchitecture" - kmpExtension.appleTargets().all { target -> - val frameworkArchitecture = target.toSentryFrameworkArchitecture() - if (frameworkArchitecture == null) { - // todo: log, unsupported architecture - return@all - } + val dynamicFrameworkExists = File(dynamicFrameworkPath).exists() + val staticFrameworkExists = File(staticFrameworkPath).exists() - val dynamicFrameworkPath = - "$derivedDataPath/SourcePackages/artifacts/sentry-cocoa/Sentry-Dynamic/Sentry-Dynamic.xcframework/$frameworkArchitecture" - val staticFrameworkPath = - "$derivedDataPath/SourcePackages/artifacts/sentry-cocoa/Sentry/Sentry.xcframework/$frameworkArchitecture" - - val dynamicFrameworkExists = File(dynamicFrameworkPath).exists() - val staticFrameworkExists = File(staticFrameworkPath).exists() - - if (!dynamicFrameworkExists && !staticFrameworkExists) { - throw GradleException("Sentry Cocoa Framework not found at $dynamicFrameworkPath or $staticFrameworkPath") - } - - target.binaries.all binaries@{ binary -> - if (binary is TestExecutable) { - val frameworkPath = - if (dynamicFrameworkExists) dynamicFrameworkPath else staticFrameworkPath - binary.linkerOpts("-rpath", "$path/Sentry.framework", "-F$frameworkPath") - } + if (!dynamicFrameworkExists && !staticFrameworkExists) { + throw GradleException( + "Sentry Cocoa Framework not found at $dynamicFrameworkPath or $staticFrameworkPath") + } - if (binary is Framework) { - val frameworkPath = - if (binary.isStatic) staticFrameworkPath else dynamicFrameworkPath - binary.linkerOpts("-F$frameworkPath") - } - } + target.binaries.all binaries@{ binary -> + if (binary is TestExecutable) { + val frameworkPath = + if (dynamicFrameworkExists) dynamicFrameworkPath else staticFrameworkPath + binary.linkerOpts("-rpath", "$path/Sentry.framework", "-F$frameworkPath") + } + + if (binary is Framework) { + val frameworkPath = if (binary.isStatic) staticFrameworkPath else dynamicFrameworkPath + binary.linkerOpts("-F$frameworkPath") + } } + } } private fun Project.findDerivedDataPath(customXcodeprojPath: String? = null): String { - val xcodeprojPath = customXcodeprojPath ?: findXcodeprojFile(rootDir)?.absolutePath - val buildDirOutput = ByteArrayOutputStream() - exec { - it.commandLine = - listOf( - "xcodebuild", - "-project", - xcodeprojPath, - "-showBuildSettings" - ) - it.standardOutput = buildDirOutput - } - val buildSettings = buildDirOutput.toString("UTF-8") - val buildDirRegex = Regex("BUILD_DIR = (.+)") - val buildDirMatch = buildDirRegex.find(buildSettings) - val buildDir = - buildDirMatch?.groupValues?.get(1) - ?: throw GradleException("BUILD_DIR not found in xcodebuild output") - val derivedDataPath = buildDir.replace("/Build/Products", "") - return derivedDataPath + val xcodeprojPath = customXcodeprojPath ?: findXcodeprojFile(rootDir)?.absolutePath + val buildDirOutput = ByteArrayOutputStream() + exec { + it.commandLine = listOf("xcodebuild", "-project", xcodeprojPath, "-showBuildSettings") + it.standardOutput = buildDirOutput + } + val buildSettings = buildDirOutput.toString("UTF-8") + val buildDirRegex = Regex("BUILD_DIR = (.+)") + val buildDirMatch = buildDirRegex.find(buildSettings) + val buildDir = + buildDirMatch?.groupValues?.get(1) + ?: throw GradleException("BUILD_DIR not found in xcodebuild output") + val derivedDataPath = buildDir.replace("/Build/Products", "") + return derivedDataPath } /** - * Searches for a xcodeproj starting from the root directory. - * This function will only work for monorepos and if it is not, - * the user needs to provide the custom path through the [LinkerExtension] configuration. + * Searches for a xcodeproj starting from the root directory. This function will only work for + * monorepos and if it is not, the user needs to provide the custom path through the + * [LinkerExtension] configuration. */ internal fun findXcodeprojFile(dir: File): File? { - val ignoredDirectories = listOf("build", "DerivedData") + val ignoredDirectories = listOf("build", "DerivedData") - fun searchDirectory(directory: File): File? { - val files = directory.listFiles() ?: return null + fun searchDirectory(directory: File): File? { + val files = directory.listFiles() ?: return null - for (file in files) { - if (file.name in ignoredDirectories) { - continue - } + for (file in files) { + if (file.name in ignoredDirectories) { + continue + } - // Recursively search the subdirectory - val result = searchDirectory(file) - if (result != null) { - return result - } + // Recursively search the subdirectory + val result = searchDirectory(file) + if (result != null) { + return result + } - if (file.extension == "xcodeproj") { - return file - } - } - return null + if (file.extension == "xcodeproj") { + return file + } } + return null + } - return searchDirectory(dir) + return searchDirectory(dir) } private fun KotlinMultiplatformExtension.appleTargets() = - targets.withType(KotlinNativeTarget::class.java) - .matching { it.konanTarget.family.isAppleFamily } + targets.withType(KotlinNativeTarget::class.java).matching { + it.konanTarget.family.isAppleFamily + } /** * Transforms a Kotlin Multiplatform target name to the architecture name that is found inside * Sentry's framework directory. */ internal fun KotlinNativeTarget.toSentryFrameworkArchitecture(): String? { - return when (name) { - "iosSimulatorArm64" -> "ios-arm64_x86_64-simulator" - "iosX64" -> "ios-arm64_x86_64-simulator" - "iosArm64" -> "ios-arm64" - // todo: add more targets - else -> null - } + return when (name) { + "iosSimulatorArm64" -> "ios-arm64_x86_64-simulator" + "iosX64" -> "ios-arm64_x86_64-simulator" + "iosArm64" -> "ios-arm64" + // todo: add more targets + else -> null + } } diff --git a/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SourceSetAutoInstallExtension.kt b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SourceSetAutoInstallExtension.kt index 2dd4501e..938b95de 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SourceSetAutoInstallExtension.kt +++ b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SourceSetAutoInstallExtension.kt @@ -1,30 +1,28 @@ package io.sentry.kotlin.multiplatform.gradle +import javax.inject.Inject import org.gradle.api.Project import org.gradle.api.provider.Property -import javax.inject.Inject @Suppress("UnnecessaryAbstractClass") -abstract class SourceSetAutoInstallExtension -@Inject -constructor(project: Project) { - private val objects = project.objects +abstract class SourceSetAutoInstallExtension @Inject constructor(project: Project) { + private val objects = project.objects - /** - * Enable auto-installation of the Sentry Kotlin Multiplatform SDK dependency in the commonMain source set. - * - * Defaults to true. - */ - val enabled: Property = - objects.property(Boolean::class.java) - .convention(true) + /** + * Enable auto-installation of the Sentry Kotlin Multiplatform SDK dependency in the commonMain + * source set. + * + * Defaults to true. + */ + val enabled: Property = objects.property(Boolean::class.java).convention(true) - /** - * Overrides the default Sentry Kotlin Multiplatform SDK dependency version. - * - * Defaults to the latest version of the Sentry Kotlin Multiplatform SDK. - */ - val sentryKmpVersion: Property = - objects.property(String::class.java) - .convention("latest.release") // Replace with the actual default version + /** + * Overrides the default Sentry Kotlin Multiplatform SDK dependency version. + * + * Defaults to the latest version of the Sentry Kotlin Multiplatform SDK. + */ + val sentryKmpVersion: Property = + objects + .property(String::class.java) + .convention("latest.release") // Replace with the actual default version } diff --git a/sentry-kotlin-multiplatform-gradle-plugin/src/test/java/io/sentry/kotlin/multiplatform/gradle/SentryPluginTest.kt b/sentry-kotlin-multiplatform-gradle-plugin/src/test/java/io/sentry/kotlin/multiplatform/gradle/SentryPluginTest.kt index d70a4a84..b15e7ba8 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/src/test/java/io/sentry/kotlin/multiplatform/gradle/SentryPluginTest.kt +++ b/sentry-kotlin-multiplatform-gradle-plugin/src/test/java/io/sentry/kotlin/multiplatform/gradle/SentryPluginTest.kt @@ -8,62 +8,61 @@ import org.jetbrains.kotlin.gradle.plugin.cocoapods.CocoapodsExtension import org.junit.Test class SentryPluginTest { - @Test - fun `plugin is applied correctly to the project`() { - val project = ProjectBuilder.builder().build() - project.pluginManager.apply("io.sentry.kotlin.multiplatform.gradle.plugin") + @Test + fun `plugin is applied correctly to the project`() { + val project = ProjectBuilder.builder().build() + project.pluginManager.apply("io.sentry.kotlin.multiplatform.gradle.plugin") - assert(project.plugins.hasPlugin(SentryPlugin::class.java)) - } + assert(project.plugins.hasPlugin(SentryPlugin::class.java)) + } - @Test - fun `extension sentry is created correctly`() { - val project = ProjectBuilder.builder().build() - project.pluginManager.apply("io.sentry.kotlin.multiplatform.gradle.plugin") + @Test + fun `extension sentry is created correctly`() { + val project = ProjectBuilder.builder().build() + project.pluginManager.apply("io.sentry.kotlin.multiplatform.gradle.plugin") - assertNotNull(project.extensions.getByName("sentry")) - } + assertNotNull(project.extensions.getByName("sentry")) + } - @Test - fun `extension linker is created correctly`() { - val project = ProjectBuilder.builder().build() - project.pluginManager.apply("io.sentry.kotlin.multiplatform.gradle.plugin") + @Test + fun `extension linker is created correctly`() { + val project = ProjectBuilder.builder().build() + project.pluginManager.apply("io.sentry.kotlin.multiplatform.gradle.plugin") - assertNotNull(project.extensions.getByName("linker")) - } + assertNotNull(project.extensions.getByName("linker")) + } - @Test - fun `install Sentry pod when cocoapods plugin is applied and no custom Sentry configuration exists`() { - val project = ProjectBuilder.builder().build() - project.pluginManager.apply("io.sentry.kotlin.multiplatform.gradle.plugin") - project.pluginManager.apply("org.jetbrains.kotlin.multiplatform") - project.pluginManager.apply("org.jetbrains.kotlin.native.cocoapods") + @Test + fun `install Sentry pod when cocoapods plugin is applied and no custom Sentry configuration exists`() { + val project = ProjectBuilder.builder().build() + project.pluginManager.apply("io.sentry.kotlin.multiplatform.gradle.plugin") + project.pluginManager.apply("org.jetbrains.kotlin.multiplatform") + project.pluginManager.apply("org.jetbrains.kotlin.native.cocoapods") - project.afterEvaluate { - val cocoapodsExtension = project.extensions.findByType(CocoapodsExtension::class.java) - assertNotNull(cocoapodsExtension?.pods?.findByName("Sentry")) - } + project.afterEvaluate { + val cocoapodsExtension = project.extensions.findByType(CocoapodsExtension::class.java) + assertNotNull(cocoapodsExtension?.pods?.findByName("Sentry")) } + } - @Test - fun `do not install Sentry pod when cocoapods plugin is applied and custom Sentry configuration exists`() { - val project = ProjectBuilder.builder().build() - project.pluginManager.apply("io.sentry.kotlin.multiplatform.gradle.plugin") - project.pluginManager.apply("org.jetbrains.kotlin.multiplatform") - project.pluginManager.apply("org.jetbrains.kotlin.native.cocoapods") + @Test + fun `do not install Sentry pod when cocoapods plugin is applied and custom Sentry configuration exists`() { + val project = ProjectBuilder.builder().build() + project.pluginManager.apply("io.sentry.kotlin.multiplatform.gradle.plugin") + project.pluginManager.apply("org.jetbrains.kotlin.multiplatform") + project.pluginManager.apply("org.jetbrains.kotlin.native.cocoapods") - val kmpExtension = project.extensions.findByName("kotlin") - (kmpExtension as ExtensionAware).extensions.configure(CocoapodsExtension::class.java) { cocoapods -> - cocoapods.pod("Sentry") { - version = "custom version" - } - } + val kmpExtension = project.extensions.findByName("kotlin") + (kmpExtension as ExtensionAware).extensions.configure(CocoapodsExtension::class.java) { + cocoapods -> + cocoapods.pod("Sentry") { version = "custom version" } + } - // plugin does not configure sentry pod if there is already an existing configuration - project.afterEvaluate { - val cocoapodsExtension = project.extensions.findByType(CocoapodsExtension::class.java) - val pod = cocoapodsExtension?.pods?.findByName("Sentry") - assertEquals(pod?.version, "custom version") - } + // plugin does not configure sentry pod if there is already an existing configuration + project.afterEvaluate { + val cocoapodsExtension = project.extensions.findByType(CocoapodsExtension::class.java) + val pod = cocoapodsExtension?.pods?.findByName("Sentry") + assertEquals(pod?.version, "custom version") } + } } From 20f69c2dc8122c6e654c40b15ce6150e962873f2 Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Tue, 11 Jun 2024 03:24:16 +0200 Subject: [PATCH 52/78] Update --- .github/workflows/analyze.yml | 3 +- build.gradle.kts | 7 + .../build.gradle.kts | 105 +++---- .../gradle/libs.versions.toml | 3 - .../settings.gradle.kts | 16 +- .../gradle/AutoInstallExtension.kt | 28 +- .../gradle/CocoapodsAutoInstallExtension.kt | 36 +-- .../multiplatform/gradle/LinkerExtension.kt | 6 +- .../multiplatform/gradle/SentryExtension.kt | 22 +- .../multiplatform/gradle/SentryPlugin.kt | 290 +++++++++--------- .../gradle/SourceSetAutoInstallExtension.kt | 36 +-- .../multiplatform/gradle/SentryPluginTest.kt | 90 +++--- 12 files changed, 321 insertions(+), 321 deletions(-) diff --git a/.github/workflows/analyze.yml b/.github/workflows/analyze.yml index ee498dd0..47d438b6 100644 --- a/.github/workflows/analyze.yml +++ b/.github/workflows/analyze.yml @@ -26,4 +26,5 @@ jobs: distribution: temurin - name: Analyze - run: ./gradlew apiCheck detekt \ No newline at end of file + run: + ./gradlew apiCheck detekt spotlessCheck \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index 93d3f0d5..7a15ad86 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -72,10 +72,12 @@ spotless { kotlin { target("**/*.kt") + targetExclude("**/generated/**/*.kt") ktlint() } kotlinGradle { target("**/*.kts") + targetExclude("**/generated/**/*.kts") ktlint() } } @@ -115,3 +117,8 @@ val detektProjectBaseline by tasks.registering(io.gitlab.arturbosch.detekt.Detek include("**/*.kt") detektExcludes() } + +// Configure tasks so it is also run for the plugin +tasks.getByName("detekt") { + gradle.includedBuild("sentry-kotlin-multiplatform-gradle-plugin").task(":detekt") +} diff --git a/sentry-kotlin-multiplatform-gradle-plugin/build.gradle.kts b/sentry-kotlin-multiplatform-gradle-plugin/build.gradle.kts index e5e4b9e5..4a2dd34d 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/build.gradle.kts +++ b/sentry-kotlin-multiplatform-gradle-plugin/build.gradle.kts @@ -1,17 +1,14 @@ -import com.diffplug.gradle.spotless.SpotlessExtension -import com.diffplug.spotless.LineEnding import com.vanniktech.maven.publish.MavenPublishPluginExtension import io.gitlab.arturbosch.detekt.Detekt import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { - alias(libs.plugins.kotlin) - alias(libs.plugins.detekt) - `java-gradle-plugin` - alias(libs.plugins.vanniktech.publish) - id("distribution") - alias(libs.plugins.buildConfig) - alias(libs.plugins.spotless) + alias(libs.plugins.kotlin) + alias(libs.plugins.detekt) + `java-gradle-plugin` + alias(libs.plugins.vanniktech.publish) + id("distribution") + alias(libs.plugins.buildConfig) } version = property("versionName").toString() @@ -19,27 +16,27 @@ version = property("versionName").toString() group = property("group").toString() dependencies { - compileOnly(kotlin("stdlib")) - compileOnly(gradleApi()) - compileOnly(kotlin("gradle-plugin")) + compileOnly(kotlin("stdlib")) + compileOnly(gradleApi()) + compileOnly(kotlin("gradle-plugin")) - testImplementation(libs.junit) + testImplementation(libs.junit) } java { - sourceCompatibility = JavaVersion.VERSION_1_8 - targetCompatibility = JavaVersion.VERSION_1_8 + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 } tasks.withType { kotlinOptions { jvmTarget = JavaVersion.VERSION_1_8.toString() } } gradlePlugin { - plugins { - create(property("id").toString()) { - id = property("id").toString() - implementationClass = property("implementationClass").toString() + plugins { + create(property("id").toString()) { + id = property("id").toString() + implementationClass = property("implementationClass").toString() + } } - } } val publish = extensions.getByType(MavenPublishPluginExtension::class.java) @@ -48,56 +45,48 @@ val publish = extensions.getByType(MavenPublishPluginExtension::class.java) publish.releaseSigningEnabled = false tasks.named("distZip").configure { - dependsOn("publishToMavenLocal") - this.doLast { - val distributionFilePath = - "${project.layout.buildDirectory.asFile.get().path}${sep}distributions${sep}${project.name}-${project.version}.zip" - val file = File(distributionFilePath) - if (!file.exists()) - throw IllegalStateException("Distribution file: $distributionFilePath does not exist") - if (file.length() == 0L) - throw IllegalStateException("Distribution file: $distributionFilePath is empty") - } + dependsOn("publishToMavenLocal") + this.doLast { + val distributionFilePath = + "${project.layout.buildDirectory.asFile.get().path}${sep}distributions${sep}${project.name}-${project.version}.zip" + val file = File(distributionFilePath) + if (!file.exists()) { + throw IllegalStateException("Distribution file: $distributionFilePath does not exist") + } + if (file.length() == 0L) { + throw IllegalStateException("Distribution file: $distributionFilePath is empty") + } + } } val sep = File.separator distributions { - main { - contents { - from("build${sep}libs") - from("build${sep}publications${sep}maven") + main { + contents { + from("build${sep}libs") + from("build${sep}publications${sep}maven") + } } - } } buildConfig { - useKotlinOutput() - packageName("io.sentry") - className("BuildConfig") - - buildConfigField( - "String", "SentryCocoaVersion", provider { "\"${project.property("sentryCocoaVersion")}\"" }) + useKotlinOutput() + packageName("io.sentry") + className("BuildConfig") + + buildConfigField( + "String", + "SentryCocoaVersion", + provider { "\"${project.property("sentryCocoaVersion")}\"" } + ) } detekt { config.setFrom(rootProject.files("../config/detekt/detekt.yml")) } tasks.withType().configureEach { - reports { - html.required.set(true) - html.outputLocation.set(file("build/reports/detekt.html")) - } -} - -configure { - kotlin { - target("**/*.kt") - ktfmt("0.30") - } - kotlinGradle { - target("**/*.kts") - ktfmt("0.30") - } - - lineEndings = LineEnding.UNIX + reports { + html.required.set(true) + html.outputLocation.set(file("build/reports/detekt.html")) + } } diff --git a/sentry-kotlin-multiplatform-gradle-plugin/gradle/libs.versions.toml b/sentry-kotlin-multiplatform-gradle-plugin/gradle/libs.versions.toml index c4dac671..45d8f474 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/gradle/libs.versions.toml +++ b/sentry-kotlin-multiplatform-gradle-plugin/gradle/libs.versions.toml @@ -4,8 +4,6 @@ kotlin = "1.9.23" pluginPublish = "1.2.1" buildConfig = "5.3.5" vanniktechPublish = "0.18.0" -spotless = "6.25.0" -ktfmt = "0.18.0" [plugins] detekt = { id = "io.gitlab.arturbosch.detekt", version.ref = "detekt"} @@ -13,7 +11,6 @@ kotlin = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin"} pluginPublish = { id = "com.gradle.plugin-publish", version.ref = "pluginPublish"} vanniktech-publish = { id = "com.vanniktech.maven.publish", version.ref = "vanniktechPublish"} buildConfig = { id = "com.github.gmazzo.buildconfig", version.ref = "buildConfig"} -spotless = { id = "com.diffplug.spotless", version.ref = "spotless"} [libraries] junit = "junit:junit:4.13.2" diff --git a/sentry-kotlin-multiplatform-gradle-plugin/settings.gradle.kts b/sentry-kotlin-multiplatform-gradle-plugin/settings.gradle.kts index 22ef8566..4ef43ffb 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/settings.gradle.kts +++ b/sentry-kotlin-multiplatform-gradle-plugin/settings.gradle.kts @@ -1,15 +1,15 @@ pluginManagement { - repositories { - gradlePluginPortal() - mavenCentral() - } + repositories { + gradlePluginPortal() + mavenCentral() + } } dependencyResolutionManagement { - repositories { - google() - mavenCentral() - } + repositories { + google() + mavenCentral() + } } rootProject.name = "sentry-kotlin-multiplatform-gradle-plugin" diff --git a/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/AutoInstallExtension.kt b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/AutoInstallExtension.kt index 7e21130e..a639afc5 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/AutoInstallExtension.kt +++ b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/AutoInstallExtension.kt @@ -1,25 +1,25 @@ package io.sentry.kotlin.multiplatform.gradle -import javax.inject.Inject import org.gradle.api.Project import org.gradle.api.provider.Property +import javax.inject.Inject @Suppress("UnnecessaryAbstractClass") abstract class AutoInstallExtension @Inject constructor(project: Project) { - private val objects = project.objects + private val objects = project.objects - /** - * Enable auto-installation of the Sentry dependencies through [CocoapodsAutoInstallExtension] - * - * Disabling this will prevent the plugin from auto installing anything. - * - * Defaults to true. - */ - val enabled: Property = objects.property(Boolean::class.java).convention(true) + /** + * Enable auto-installation of the Sentry dependencies through [CocoapodsAutoInstallExtension] + * + * Disabling this will prevent the plugin from auto installing anything. + * + * Defaults to true. + */ + val enabled: Property = objects.property(Boolean::class.java).convention(true) - val cocoapods: CocoapodsAutoInstallExtension = - objects.newInstance(CocoapodsAutoInstallExtension::class.java, project) + val cocoapods: CocoapodsAutoInstallExtension = + objects.newInstance(CocoapodsAutoInstallExtension::class.java, project) - val commonMain: SourceSetAutoInstallExtension = - objects.newInstance(SourceSetAutoInstallExtension::class.java, project) + val commonMain: SourceSetAutoInstallExtension = + objects.newInstance(SourceSetAutoInstallExtension::class.java, project) } diff --git a/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/CocoapodsAutoInstallExtension.kt b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/CocoapodsAutoInstallExtension.kt index 307da1f3..9bb1f7a1 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/CocoapodsAutoInstallExtension.kt +++ b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/CocoapodsAutoInstallExtension.kt @@ -1,29 +1,29 @@ package io.sentry.kotlin.multiplatform.gradle import io.sentry.BuildConfig -import javax.inject.Inject import org.gradle.api.Project import org.gradle.api.provider.Property +import javax.inject.Inject @Suppress("UnnecessaryAbstractClass") abstract class CocoapodsAutoInstallExtension @Inject constructor(project: Project) { - private val objects = project.objects + private val objects = project.objects - /** - * Enable auto-installation of the Sentry Cocoa SDK pod. - * - * If the cocoapods plugin is applied and no existing Sentry pod configuration exists, the - * Sentry-Cocoa SDK pod will be installed. - * - * Defaults to true. - */ - val enabled: Property = objects.property(Boolean::class.java).convention(true) + /** + * Enable auto-installation of the Sentry Cocoa SDK pod. + * + * If the cocoapods plugin is applied and no existing Sentry pod configuration exists, the + * Sentry-Cocoa SDK pod will be installed. + * + * Defaults to true. + */ + val enabled: Property = objects.property(Boolean::class.java).convention(true) - /** - * Overrides default Sentry Cocoa version. - * - * Defaults to the version used in the latest KMP SDK. - */ - val sentryCocoaVersion: Property = - objects.property(String::class.java).convention(BuildConfig.SentryCocoaVersion) + /** + * Overrides default Sentry Cocoa version. + * + * Defaults to the version used in the latest KMP SDK. + */ + val sentryCocoaVersion: Property = + objects.property(String::class.java).convention(BuildConfig.SentryCocoaVersion) } diff --git a/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/LinkerExtension.kt b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/LinkerExtension.kt index a8469635..e8d21e9b 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/LinkerExtension.kt +++ b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/LinkerExtension.kt @@ -1,12 +1,12 @@ package io.sentry.kotlin.multiplatform.gradle -import javax.inject.Inject import org.gradle.api.Project import org.gradle.api.provider.Property +import javax.inject.Inject @Suppress("UnnecessaryAbstractClass") abstract class LinkerExtension @Inject constructor(project: Project) { - private val objects = project.objects + private val objects = project.objects - val xcodeprojPath: Property = objects.property(String::class.java) + val xcodeprojPath: Property = objects.property(String::class.java) } diff --git a/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryExtension.kt b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryExtension.kt index 9244e362..38baf874 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryExtension.kt +++ b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryExtension.kt @@ -1,20 +1,20 @@ package io.sentry.kotlin.multiplatform.gradle -import javax.inject.Inject import org.gradle.api.Project +import javax.inject.Inject @Suppress("UnnecessaryAbstractClass") abstract class SentryExtension @Inject constructor(project: Project) { - private val objects = project.objects + private val objects = project.objects - /** - * Linker configuration. - * - * If you use SPM this configuration is necessary for setting up linking the framework and test - * executable. - */ - val linker: LinkerExtension = objects.newInstance(LinkerExtension::class.java, project) + /** + * Linker configuration. + * + * If you use SPM this configuration is necessary for setting up linking the framework and test + * executable. + */ + val linker: LinkerExtension = objects.newInstance(LinkerExtension::class.java, project) - val autoInstall: AutoInstallExtension = - objects.newInstance(AutoInstallExtension::class.java, project) + val autoInstall: AutoInstallExtension = + objects.newInstance(AutoInstallExtension::class.java, project) } diff --git a/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryPlugin.kt b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryPlugin.kt index 274d07c3..1106740f 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryPlugin.kt +++ b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryPlugin.kt @@ -1,7 +1,5 @@ package io.sentry.kotlin.multiplatform.gradle -import java.io.ByteArrayOutputStream -import java.io.File import org.gradle.api.GradleException import org.gradle.api.Plugin import org.gradle.api.Project @@ -12,6 +10,8 @@ import org.jetbrains.kotlin.gradle.plugin.cocoapods.KotlinCocoapodsPlugin import org.jetbrains.kotlin.gradle.plugin.mpp.Framework import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget import org.jetbrains.kotlin.gradle.plugin.mpp.TestExecutable +import java.io.ByteArrayOutputStream +import java.io.File internal const val SENTRY_EXTENSION_NAME = "sentryKmp" internal const val LINKER_EXTENSION_NAME = "linker" @@ -22,148 +22,154 @@ internal const val KOTLIN_EXTENSION_NAME = "kotlin" @Suppress("unused") class SentryPlugin : Plugin { - override fun apply(project: Project): Unit = - with(project) { - val sentryExtension = - project.extensions.create(SENTRY_EXTENSION_NAME, SentryExtension::class.java, project) - project.extensions.add(LINKER_EXTENSION_NAME, sentryExtension.linker) - project.extensions.add(AUTO_INSTALL_EXTENSION_NAME, sentryExtension.autoInstall) - project.extensions.add( - COCOAPODS_AUTO_INSTALL_EXTENSION_NAME, sentryExtension.autoInstall.cocoapods) - project.extensions.add( - COMMON_MAIN_AUTO_INSTALL_EXTENSION_NAME, sentryExtension.autoInstall.commonMain) - - afterEvaluate { - val hasCocoapodsPlugin = - project.plugins.findPlugin(KotlinCocoapodsPlugin::class.java) != null - - if (sentryExtension.autoInstall.enabled.get()) { - if (sentryExtension.autoInstall.commonMain.enabled.get()) { - installSentryForKmp(sentryExtension.autoInstall.commonMain) + override fun apply(project: Project): Unit = + with(project) { + val sentryExtension = + project.extensions.create(SENTRY_EXTENSION_NAME, SentryExtension::class.java, project) + project.extensions.add(LINKER_EXTENSION_NAME, sentryExtension.linker) + project.extensions.add(AUTO_INSTALL_EXTENSION_NAME, sentryExtension.autoInstall) + project.extensions.add( + COCOAPODS_AUTO_INSTALL_EXTENSION_NAME, + sentryExtension.autoInstall.cocoapods + ) + project.extensions.add( + COMMON_MAIN_AUTO_INSTALL_EXTENSION_NAME, + sentryExtension.autoInstall.commonMain + ) + + afterEvaluate { + val hasCocoapodsPlugin = + project.plugins.findPlugin(KotlinCocoapodsPlugin::class.java) != null + + if (sentryExtension.autoInstall.enabled.get()) { + if (sentryExtension.autoInstall.commonMain.enabled.get()) { + installSentryForKmp(sentryExtension.autoInstall.commonMain) + } + if (hasCocoapodsPlugin && sentryExtension.autoInstall.cocoapods.enabled.get()) { + installSentryForCocoapods(sentryExtension.autoInstall.cocoapods) + } + } + + // If the user is not using the cocoapods plugin, linking to the framework is not + // automatic + // so we have to take care of that + if (!hasCocoapodsPlugin) { + configureLinkingOptions(sentryExtension.linker) + } } - if (hasCocoapodsPlugin && sentryExtension.autoInstall.cocoapods.enabled.get()) { - installSentryForCocoapods(sentryExtension.autoInstall.cocoapods) - } - } - - // If the user is not using the cocoapods plugin, linking to the framework is not - // automatic - // so we have to take care of that - if (!hasCocoapodsPlugin) { - configureLinkingOptions(sentryExtension.linker) - } } - } } internal fun Project.installSentryForKmp( commonMainAutoInstallExtension: SourceSetAutoInstallExtension ) { - val kmpExtension = extensions.findByName(KOTLIN_EXTENSION_NAME) - if (kmpExtension !is KotlinMultiplatformExtension) { - // todo: log, not multiplatform found - return - } - - val unsupportedTargets = listOf("wasm", "js", "mingw", "linux", "androidNative") - kmpExtension.targets.forEach { target -> - if (unsupportedTargets.any { unsupported -> target.name.contains(unsupported) }) { - throw GradleException( - "Unsupported target: ${target.name}. " + - "Cannot auto install in commonMain. " + - "Please create an intermediate sourceSet with targets that the Sentry SDK " + - "supports (apple, jvm, android) and add the dependency manually.") + val kmpExtension = extensions.findByName(KOTLIN_EXTENSION_NAME) + if (kmpExtension !is KotlinMultiplatformExtension) { + // todo: log, not multiplatform found + return + } + + val unsupportedTargets = listOf("wasm", "js", "mingw", "linux", "androidNative") + kmpExtension.targets.forEach { target -> + if (unsupportedTargets.any { unsupported -> target.name.contains(unsupported) }) { + throw GradleException( + "Unsupported target: ${target.name}. " + + "Cannot auto install in commonMain. " + + "Please create an intermediate sourceSet with targets that the Sentry SDK " + + "supports (apple, jvm, android) and add the dependency manually." + ) + } } - } - val commonMain = kmpExtension.sourceSets.find { it.name.contains("common") } + val commonMain = kmpExtension.sourceSets.find { it.name.contains("common") } - val sentryVersion = commonMainAutoInstallExtension.sentryKmpVersion.get() - commonMain?.dependencies { api("io.sentry:sentry-kotlin-multiplatform:$sentryVersion") } + val sentryVersion = commonMainAutoInstallExtension.sentryKmpVersion.get() + commonMain?.dependencies { api("io.sentry:sentry-kotlin-multiplatform:$sentryVersion") } } internal fun Project.installSentryForCocoapods( cocoapodsAutoInstallExtension: CocoapodsAutoInstallExtension ) { - val kmpExtension = extensions.findByName(KOTLIN_EXTENSION_NAME) - if (kmpExtension !is KotlinMultiplatformExtension) { - return - } - - (kmpExtension as ExtensionAware).extensions.configure(CocoapodsExtension::class.java) { cocoapods - -> - val podName = "Sentry" - val sentryPod = cocoapods.pods.findByName(podName) - if (sentryPod == null) { - cocoapods.pod(podName) { - version = cocoapodsAutoInstallExtension.sentryCocoaVersion.get() - linkOnly = true - extraOpts += listOf("-compiler-option", "-fmodules") - } + val kmpExtension = extensions.findByName(KOTLIN_EXTENSION_NAME) + if (kmpExtension !is KotlinMultiplatformExtension) { + return + } + + (kmpExtension as ExtensionAware).extensions.configure(CocoapodsExtension::class.java) { cocoapods + -> + val podName = "Sentry" + val sentryPod = cocoapods.pods.findByName(podName) + if (sentryPod == null) { + cocoapods.pod(podName) { + version = cocoapodsAutoInstallExtension.sentryCocoaVersion.get() + linkOnly = true + extraOpts += listOf("-compiler-option", "-fmodules") + } + } } - } } internal fun Project.configureLinkingOptions(linkerExtension: LinkerExtension) { - val kmpExtension = extensions.findByName(KOTLIN_EXTENSION_NAME) - if (kmpExtension !is KotlinMultiplatformExtension) { - // todo: log, not multiplatform found - return - } - - val customXcodeprojPath = linkerExtension.xcodeprojPath.orNull - val derivedDataPath = findDerivedDataPath(customXcodeprojPath) - - kmpExtension.appleTargets().all { target -> - val frameworkArchitecture = target.toSentryFrameworkArchitecture() - if (frameworkArchitecture == null) { - // todo: log, unsupported architecture - return@all + val kmpExtension = extensions.findByName(KOTLIN_EXTENSION_NAME) + if (kmpExtension !is KotlinMultiplatformExtension) { + // todo: log, not multiplatform found + return } - val dynamicFrameworkPath = - "$derivedDataPath/SourcePackages/artifacts/sentry-cocoa/Sentry-Dynamic/Sentry-Dynamic.xcframework/$frameworkArchitecture" - val staticFrameworkPath = - "$derivedDataPath/SourcePackages/artifacts/sentry-cocoa/Sentry/Sentry.xcframework/$frameworkArchitecture" + val customXcodeprojPath = linkerExtension.xcodeprojPath.orNull + val derivedDataPath = findDerivedDataPath(customXcodeprojPath) - val dynamicFrameworkExists = File(dynamicFrameworkPath).exists() - val staticFrameworkExists = File(staticFrameworkPath).exists() + kmpExtension.appleTargets().all { target -> + val frameworkArchitecture = target.toSentryFrameworkArchitecture() + if (frameworkArchitecture == null) { + // todo: log, unsupported architecture + return@all + } - if (!dynamicFrameworkExists && !staticFrameworkExists) { - throw GradleException( - "Sentry Cocoa Framework not found at $dynamicFrameworkPath or $staticFrameworkPath") - } + val dynamicFrameworkPath = + "$derivedDataPath/SourcePackages/artifacts/sentry-cocoa/Sentry-Dynamic/Sentry-Dynamic.xcframework/$frameworkArchitecture" + val staticFrameworkPath = + "$derivedDataPath/SourcePackages/artifacts/sentry-cocoa/Sentry/Sentry.xcframework/$frameworkArchitecture" - target.binaries.all binaries@{ binary -> - if (binary is TestExecutable) { - val frameworkPath = - if (dynamicFrameworkExists) dynamicFrameworkPath else staticFrameworkPath - binary.linkerOpts("-rpath", "$path/Sentry.framework", "-F$frameworkPath") - } - - if (binary is Framework) { - val frameworkPath = if (binary.isStatic) staticFrameworkPath else dynamicFrameworkPath - binary.linkerOpts("-F$frameworkPath") - } + val dynamicFrameworkExists = File(dynamicFrameworkPath).exists() + val staticFrameworkExists = File(staticFrameworkPath).exists() + + if (!dynamicFrameworkExists && !staticFrameworkExists) { + throw GradleException( + "Sentry Cocoa Framework not found at $dynamicFrameworkPath or $staticFrameworkPath" + ) + } + + target.binaries.all binaries@{ binary -> + if (binary is TestExecutable) { + val frameworkPath = + if (dynamicFrameworkExists) dynamicFrameworkPath else staticFrameworkPath + binary.linkerOpts("-rpath", "$path/Sentry.framework", "-F$frameworkPath") + } + + if (binary is Framework) { + val frameworkPath = if (binary.isStatic) staticFrameworkPath else dynamicFrameworkPath + binary.linkerOpts("-F$frameworkPath") + } + } } - } } private fun Project.findDerivedDataPath(customXcodeprojPath: String? = null): String { - val xcodeprojPath = customXcodeprojPath ?: findXcodeprojFile(rootDir)?.absolutePath - val buildDirOutput = ByteArrayOutputStream() - exec { - it.commandLine = listOf("xcodebuild", "-project", xcodeprojPath, "-showBuildSettings") - it.standardOutput = buildDirOutput - } - val buildSettings = buildDirOutput.toString("UTF-8") - val buildDirRegex = Regex("BUILD_DIR = (.+)") - val buildDirMatch = buildDirRegex.find(buildSettings) - val buildDir = - buildDirMatch?.groupValues?.get(1) - ?: throw GradleException("BUILD_DIR not found in xcodebuild output") - val derivedDataPath = buildDir.replace("/Build/Products", "") - return derivedDataPath + val xcodeprojPath = customXcodeprojPath ?: findXcodeprojFile(rootDir)?.absolutePath + val buildDirOutput = ByteArrayOutputStream() + exec { + it.commandLine = listOf("xcodebuild", "-project", xcodeprojPath, "-showBuildSettings") + it.standardOutput = buildDirOutput + } + val buildSettings = buildDirOutput.toString("UTF-8") + val buildDirRegex = Regex("BUILD_DIR = (.+)") + val buildDirMatch = buildDirRegex.find(buildSettings) + val buildDir = + buildDirMatch?.groupValues?.get(1) + ?: throw GradleException("BUILD_DIR not found in xcodebuild output") + val derivedDataPath = buildDir.replace("/Build/Products", "") + return derivedDataPath } /** @@ -172,35 +178,35 @@ private fun Project.findDerivedDataPath(customXcodeprojPath: String? = null): St * [LinkerExtension] configuration. */ internal fun findXcodeprojFile(dir: File): File? { - val ignoredDirectories = listOf("build", "DerivedData") + val ignoredDirectories = listOf("build", "DerivedData") - fun searchDirectory(directory: File): File? { - val files = directory.listFiles() ?: return null + fun searchDirectory(directory: File): File? { + val files = directory.listFiles() ?: return null - for (file in files) { - if (file.name in ignoredDirectories) { - continue - } + for (file in files) { + if (file.name in ignoredDirectories) { + continue + } - // Recursively search the subdirectory - val result = searchDirectory(file) - if (result != null) { - return result - } + // Recursively search the subdirectory + val result = searchDirectory(file) + if (result != null) { + return result + } - if (file.extension == "xcodeproj") { - return file - } + if (file.extension == "xcodeproj") { + return file + } + } + return null } - return null - } - return searchDirectory(dir) + return searchDirectory(dir) } private fun KotlinMultiplatformExtension.appleTargets() = targets.withType(KotlinNativeTarget::class.java).matching { - it.konanTarget.family.isAppleFamily + it.konanTarget.family.isAppleFamily } /** @@ -208,11 +214,11 @@ private fun KotlinMultiplatformExtension.appleTargets() = * Sentry's framework directory. */ internal fun KotlinNativeTarget.toSentryFrameworkArchitecture(): String? { - return when (name) { - "iosSimulatorArm64" -> "ios-arm64_x86_64-simulator" - "iosX64" -> "ios-arm64_x86_64-simulator" - "iosArm64" -> "ios-arm64" - // todo: add more targets - else -> null - } + return when (name) { + "iosSimulatorArm64" -> "ios-arm64_x86_64-simulator" + "iosX64" -> "ios-arm64_x86_64-simulator" + "iosArm64" -> "ios-arm64" + // todo: add more targets + else -> null + } } diff --git a/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SourceSetAutoInstallExtension.kt b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SourceSetAutoInstallExtension.kt index 938b95de..c2dff135 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SourceSetAutoInstallExtension.kt +++ b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SourceSetAutoInstallExtension.kt @@ -1,28 +1,28 @@ package io.sentry.kotlin.multiplatform.gradle -import javax.inject.Inject import org.gradle.api.Project import org.gradle.api.provider.Property +import javax.inject.Inject @Suppress("UnnecessaryAbstractClass") abstract class SourceSetAutoInstallExtension @Inject constructor(project: Project) { - private val objects = project.objects + private val objects = project.objects - /** - * Enable auto-installation of the Sentry Kotlin Multiplatform SDK dependency in the commonMain - * source set. - * - * Defaults to true. - */ - val enabled: Property = objects.property(Boolean::class.java).convention(true) + /** + * Enable auto-installation of the Sentry Kotlin Multiplatform SDK dependency in the commonMain + * source set. + * + * Defaults to true. + */ + val enabled: Property = objects.property(Boolean::class.java).convention(true) - /** - * Overrides the default Sentry Kotlin Multiplatform SDK dependency version. - * - * Defaults to the latest version of the Sentry Kotlin Multiplatform SDK. - */ - val sentryKmpVersion: Property = - objects - .property(String::class.java) - .convention("latest.release") // Replace with the actual default version + /** + * Overrides the default Sentry Kotlin Multiplatform SDK dependency version. + * + * Defaults to the latest version of the Sentry Kotlin Multiplatform SDK. + */ + val sentryKmpVersion: Property = + objects + .property(String::class.java) + .convention("latest.release") // Replace with the actual default version } diff --git a/sentry-kotlin-multiplatform-gradle-plugin/src/test/java/io/sentry/kotlin/multiplatform/gradle/SentryPluginTest.kt b/sentry-kotlin-multiplatform-gradle-plugin/src/test/java/io/sentry/kotlin/multiplatform/gradle/SentryPluginTest.kt index b15e7ba8..5cfdc404 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/src/test/java/io/sentry/kotlin/multiplatform/gradle/SentryPluginTest.kt +++ b/sentry-kotlin-multiplatform-gradle-plugin/src/test/java/io/sentry/kotlin/multiplatform/gradle/SentryPluginTest.kt @@ -8,61 +8,61 @@ import org.jetbrains.kotlin.gradle.plugin.cocoapods.CocoapodsExtension import org.junit.Test class SentryPluginTest { - @Test - fun `plugin is applied correctly to the project`() { - val project = ProjectBuilder.builder().build() - project.pluginManager.apply("io.sentry.kotlin.multiplatform.gradle.plugin") + @Test + fun `plugin is applied correctly to the project`() { + val project = ProjectBuilder.builder().build() + project.pluginManager.apply("io.sentry.kotlin.multiplatform.gradle.plugin") - assert(project.plugins.hasPlugin(SentryPlugin::class.java)) - } + assert(project.plugins.hasPlugin(SentryPlugin::class.java)) + } - @Test - fun `extension sentry is created correctly`() { - val project = ProjectBuilder.builder().build() - project.pluginManager.apply("io.sentry.kotlin.multiplatform.gradle.plugin") + @Test + fun `extension sentry is created correctly`() { + val project = ProjectBuilder.builder().build() + project.pluginManager.apply("io.sentry.kotlin.multiplatform.gradle.plugin") - assertNotNull(project.extensions.getByName("sentry")) - } + assertNotNull(project.extensions.getByName("sentry")) + } - @Test - fun `extension linker is created correctly`() { - val project = ProjectBuilder.builder().build() - project.pluginManager.apply("io.sentry.kotlin.multiplatform.gradle.plugin") + @Test + fun `extension linker is created correctly`() { + val project = ProjectBuilder.builder().build() + project.pluginManager.apply("io.sentry.kotlin.multiplatform.gradle.plugin") - assertNotNull(project.extensions.getByName("linker")) - } + assertNotNull(project.extensions.getByName("linker")) + } - @Test - fun `install Sentry pod when cocoapods plugin is applied and no custom Sentry configuration exists`() { - val project = ProjectBuilder.builder().build() - project.pluginManager.apply("io.sentry.kotlin.multiplatform.gradle.plugin") - project.pluginManager.apply("org.jetbrains.kotlin.multiplatform") - project.pluginManager.apply("org.jetbrains.kotlin.native.cocoapods") + @Test + fun `install Sentry pod when cocoapods plugin is applied and no custom Sentry configuration exists`() { + val project = ProjectBuilder.builder().build() + project.pluginManager.apply("io.sentry.kotlin.multiplatform.gradle.plugin") + project.pluginManager.apply("org.jetbrains.kotlin.multiplatform") + project.pluginManager.apply("org.jetbrains.kotlin.native.cocoapods") - project.afterEvaluate { - val cocoapodsExtension = project.extensions.findByType(CocoapodsExtension::class.java) - assertNotNull(cocoapodsExtension?.pods?.findByName("Sentry")) + project.afterEvaluate { + val cocoapodsExtension = project.extensions.findByType(CocoapodsExtension::class.java) + assertNotNull(cocoapodsExtension?.pods?.findByName("Sentry")) + } } - } - @Test - fun `do not install Sentry pod when cocoapods plugin is applied and custom Sentry configuration exists`() { - val project = ProjectBuilder.builder().build() - project.pluginManager.apply("io.sentry.kotlin.multiplatform.gradle.plugin") - project.pluginManager.apply("org.jetbrains.kotlin.multiplatform") - project.pluginManager.apply("org.jetbrains.kotlin.native.cocoapods") + @Test + fun `do not install Sentry pod when cocoapods plugin is applied and custom Sentry configuration exists`() { + val project = ProjectBuilder.builder().build() + project.pluginManager.apply("io.sentry.kotlin.multiplatform.gradle.plugin") + project.pluginManager.apply("org.jetbrains.kotlin.multiplatform") + project.pluginManager.apply("org.jetbrains.kotlin.native.cocoapods") - val kmpExtension = project.extensions.findByName("kotlin") - (kmpExtension as ExtensionAware).extensions.configure(CocoapodsExtension::class.java) { - cocoapods -> - cocoapods.pod("Sentry") { version = "custom version" } - } + val kmpExtension = project.extensions.findByName("kotlin") + (kmpExtension as ExtensionAware).extensions.configure(CocoapodsExtension::class.java) { + cocoapods -> + cocoapods.pod("Sentry") { version = "custom version" } + } - // plugin does not configure sentry pod if there is already an existing configuration - project.afterEvaluate { - val cocoapodsExtension = project.extensions.findByType(CocoapodsExtension::class.java) - val pod = cocoapodsExtension?.pods?.findByName("Sentry") - assertEquals(pod?.version, "custom version") + // plugin does not configure sentry pod if there is already an existing configuration + project.afterEvaluate { + val cocoapodsExtension = project.extensions.findByType(CocoapodsExtension::class.java) + val pod = cocoapodsExtension?.pods?.findByName("Sentry") + assertEquals(pod?.version, "custom version") + } } - } } From e2b0937cd76004eec9d11a7885f6d359979d0adb Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Tue, 11 Jun 2024 03:31:02 +0200 Subject: [PATCH 53/78] Fix deps --- .../kmp-app-spm/iosApp.xcodeproj/project.pbxproj | 16 ++++++++-------- .../xcshareddata/swiftpm/Package.resolved | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/sentry-samples/kmp-app-spm/iosApp.xcodeproj/project.pbxproj b/sentry-samples/kmp-app-spm/iosApp.xcodeproj/project.pbxproj index 1275688a..cfe22a19 100644 --- a/sentry-samples/kmp-app-spm/iosApp.xcodeproj/project.pbxproj +++ b/sentry-samples/kmp-app-spm/iosApp.xcodeproj/project.pbxproj @@ -11,7 +11,7 @@ 058557D9273AAEEB004C7B11 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 058557D8273AAEEB004C7B11 /* Preview Assets.xcassets */; }; 2152FB042600AC8F00CF470E /* iOSApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2152FB032600AC8F00CF470E /* iOSApp.swift */; }; 243652EF29F34FF500FD902A /* sentry.png in Resources */ = {isa = PBXBuildFile; fileRef = 243652EE29F34FF500FD902A /* sentry.png */; }; - 24E1CB3C2C10780200F78D70 /* Sentry-Dynamic in Frameworks */ = {isa = PBXBuildFile; productRef = 24E1CB3B2C10780200F78D70 /* Sentry-Dynamic */; }; + 24E1CB3F2C17E00200F78D70 /* Sentry-Dynamic in Frameworks */ = {isa = PBXBuildFile; productRef = 24E1CB3E2C17E00200F78D70 /* Sentry-Dynamic */; }; 7555FF83242A565900829871 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7555FF82242A565900829871 /* ContentView.swift */; }; /* End PBXBuildFile section */ @@ -44,7 +44,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 24E1CB3C2C10780200F78D70 /* Sentry-Dynamic in Frameworks */, + 24E1CB3F2C17E00200F78D70 /* Sentry-Dynamic in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -117,7 +117,7 @@ ); name = iosApp; packageProductDependencies = ( - 24E1CB3B2C10780200F78D70 /* Sentry-Dynamic */, + 24E1CB3E2C17E00200F78D70 /* Sentry-Dynamic */, ); productName = NSExceptionKtSample; productReference = 7555FF7B242A565900829871 /* iosApp.app */; @@ -148,7 +148,7 @@ ); mainGroup = 7555FF72242A565900829871; packageReferences = ( - 24E1CB3A2C10780200F78D70 /* XCRemoteSwiftPackageReference "sentry-cocoa" */, + 24E1CB3D2C17E00200F78D70 /* XCRemoteSwiftPackageReference "sentry-cocoa" */, ); productRefGroup = 7555FF7C242A565900829871 /* Products */; projectDirPath = ""; @@ -419,20 +419,20 @@ /* End XCConfigurationList section */ /* Begin XCRemoteSwiftPackageReference section */ - 24E1CB3A2C10780200F78D70 /* XCRemoteSwiftPackageReference "sentry-cocoa" */ = { + 24E1CB3D2C17E00200F78D70 /* XCRemoteSwiftPackageReference "sentry-cocoa" */ = { isa = XCRemoteSwiftPackageReference; repositoryURL = "https://github.com/getsentry/sentry-cocoa.git"; requirement = { kind = upToNextMajorVersion; - minimumVersion = 8.27.0; + minimumVersion = 8.28.0; }; }; /* End XCRemoteSwiftPackageReference section */ /* Begin XCSwiftPackageProductDependency section */ - 24E1CB3B2C10780200F78D70 /* Sentry-Dynamic */ = { + 24E1CB3E2C17E00200F78D70 /* Sentry-Dynamic */ = { isa = XCSwiftPackageProductDependency; - package = 24E1CB3A2C10780200F78D70 /* XCRemoteSwiftPackageReference "sentry-cocoa" */; + package = 24E1CB3D2C17E00200F78D70 /* XCRemoteSwiftPackageReference "sentry-cocoa" */; productName = "Sentry-Dynamic"; }; /* End XCSwiftPackageProductDependency section */ diff --git a/sentry-samples/kmp-app-spm/iosApp.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/sentry-samples/kmp-app-spm/iosApp.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 79a363aa..9874955b 100644 --- a/sentry-samples/kmp-app-spm/iosApp.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/sentry-samples/kmp-app-spm/iosApp.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -6,8 +6,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/getsentry/sentry-cocoa.git", "state" : { - "revision" : "e6f9da251a4696eec602dd8da8fc689af0a4d8f7", - "version" : "8.27.0" + "revision" : "a62862c99f5bcb28fd78617fab1a5fe29607c06c", + "version" : "8.28.0" } } ], From 97eeefee1af65d51c29fe0348a6f6ea7d9321b34 Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Tue, 11 Jun 2024 03:35:59 +0200 Subject: [PATCH 54/78] update --- .../project.xcworkspace/xcshareddata/swiftpm/Package.resolved | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sentry-samples/kmp-app-spm/iosApp.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/sentry-samples/kmp-app-spm/iosApp.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 9874955b..e6d3b6ae 100644 --- a/sentry-samples/kmp-app-spm/iosApp.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/sentry-samples/kmp-app-spm/iosApp.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -11,5 +11,5 @@ } } ], - "version" : 3 + "version" : 2 } From f8a136626efec6822da936e5f083fc194924194a Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Wed, 31 Jul 2024 14:53:38 +0200 Subject: [PATCH 55/78] update --- .craft.yml | 2 +- .run/iosApp-spm.run.xml | 2 +- .../kotlin/multiplatform/gradle/AutoInstallExtension.kt | 3 ++- .../io/sentry/kotlin/multiplatform/gradle/SentryPlugin.kt | 5 ++--- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.craft.yml b/.craft.yml index f2ce1e96..900ba86a 100644 --- a/.craft.yml +++ b/.craft.yml @@ -29,5 +29,5 @@ targets: - name: registry sdks: maven:io.sentry:sentry-kotlin-multiplatform: - maven:io.sentry:sentry-kotlin-multiplatform-gradle-plugin: +# maven:io.sentry:sentry-kotlin-multiplatform-gradle-plugin: diff --git a/.run/iosApp-spm.run.xml b/.run/iosApp-spm.run.xml index 97e33f02..70ee7b23 100644 --- a/.run/iosApp-spm.run.xml +++ b/.run/iosApp-spm.run.xml @@ -1,5 +1,5 @@ - + diff --git a/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/AutoInstallExtension.kt b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/AutoInstallExtension.kt index a639afc5..9132450c 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/AutoInstallExtension.kt +++ b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/AutoInstallExtension.kt @@ -10,8 +10,9 @@ abstract class AutoInstallExtension @Inject constructor(project: Project) { /** * Enable auto-installation of the Sentry dependencies through [CocoapodsAutoInstallExtension] + * and [SourceSetAutoInstallExtension]. * - * Disabling this will prevent the plugin from auto installing anything. + * Disabling this will prevent the plugin from auto installing any dependency. * * Defaults to true. */ diff --git a/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryPlugin.kt b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryPlugin.kt index 1106740f..d3f72153 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryPlugin.kt +++ b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryPlugin.kt @@ -51,8 +51,7 @@ class SentryPlugin : Plugin { } // If the user is not using the cocoapods plugin, linking to the framework is not - // automatic - // so we have to take care of that + // automatic so we have to take care of that if (!hasCocoapodsPlugin) { configureLinkingOptions(sentryExtension.linker) } @@ -144,7 +143,7 @@ internal fun Project.configureLinkingOptions(linkerExtension: LinkerExtension) { if (binary is TestExecutable) { val frameworkPath = if (dynamicFrameworkExists) dynamicFrameworkPath else staticFrameworkPath - binary.linkerOpts("-rpath", "$path/Sentry.framework", "-F$frameworkPath") + binary.linkerOpts("-rpath", frameworkPath, "-F$frameworkPath") } if (binary is Framework) { From 56ab206b8541661727349195ded1b55ffabea3dd Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Wed, 31 Jul 2024 14:54:31 +0200 Subject: [PATCH 56/78] Update Changelog --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ca889bb9..d83ca880 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,9 +4,10 @@ ### Features -- Add plugin ([#230](https://github.com/getsentry/sentry-kotlin-multiplatform/pull/230)) +- New Sentry KMP Gradle plugin ([#230](https://github.com/getsentry/sentry-kotlin-multiplatform/pull/230)) - Install via `plugins { id("io.sentry.kotlin.multiplatform.gradle") version "{version}" }` - Enables auto installing of the KMP SDK to commonMain (if all targets are supported) + - Enables auto installing of the required Sentry Cocoa SDK with Cocoapods (if Cocoapods plugin is enabled) - Configures linking for SPM (both dynamic and static frameworks) ## 0.7.1 From 080ea921f7b8f999ac299a5e2eadb8e4256956ff Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Wed, 31 Jul 2024 14:55:43 +0200 Subject: [PATCH 57/78] add ~> to version --- .../multiplatform/gradle/CocoapodsAutoInstallExtension.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/CocoapodsAutoInstallExtension.kt b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/CocoapodsAutoInstallExtension.kt index 9bb1f7a1..e3877211 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/CocoapodsAutoInstallExtension.kt +++ b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/CocoapodsAutoInstallExtension.kt @@ -25,5 +25,5 @@ abstract class CocoapodsAutoInstallExtension @Inject constructor(project: Projec * Defaults to the version used in the latest KMP SDK. */ val sentryCocoaVersion: Property = - objects.property(String::class.java).convention(BuildConfig.SentryCocoaVersion) + objects.property(String::class.java).convention("~> ${BuildConfig.SentryCocoaVersion}") } From f17244aa37c80906fe5db0939877dcde72332c80 Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Wed, 31 Jul 2024 15:07:23 +0200 Subject: [PATCH 58/78] Add derived data value source for caching --- .../gradle/DerivedDataPathValueSource.kt | 43 +++++++++++++++++++ .../multiplatform/gradle/SentryPlugin.kt | 18 +++----- 2 files changed, 48 insertions(+), 13 deletions(-) create mode 100644 sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/DerivedDataPathValueSource.kt diff --git a/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/DerivedDataPathValueSource.kt b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/DerivedDataPathValueSource.kt new file mode 100644 index 00000000..12dbeafb --- /dev/null +++ b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/DerivedDataPathValueSource.kt @@ -0,0 +1,43 @@ +package io.sentry.kotlin.multiplatform.gradle + +import org.gradle.api.GradleException +import org.gradle.api.provider.Property +import org.gradle.api.provider.ValueSource +import org.gradle.api.provider.ValueSourceParameters +import org.gradle.api.tasks.Input +import org.gradle.process.ExecOperations +import java.io.ByteArrayOutputStream +import javax.inject.Inject + +internal abstract class DerivedDataPathValueSource : + ValueSource { + interface Parameters : ValueSourceParameters { + @get:Input + val xcodeprojPath: Property + } + + @get:Inject + abstract val execOperations: ExecOperations + + companion object { + private val buildDirRegex = Regex("BUILD_DIR = (.+)") + } + + override fun obtain(): String { + val buildDirOutput = ByteArrayOutputStream() + execOperations.exec { + it.commandLine = listOf( + "xcodebuild", + "-project", + parameters.xcodeprojPath.get(), + "-showBuildSettings" + ) + it.standardOutput = buildDirOutput + } + val buildSettings = buildDirOutput.toString("UTF-8") + val buildDirMatch = buildDirRegex.find(buildSettings) + val buildDir = buildDirMatch?.groupValues?.get(1) + ?: throw GradleException("BUILD_DIR not found in xcodebuild output") + return buildDir.replace("/Build/Products", "") + } +} diff --git a/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryPlugin.kt b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryPlugin.kt index d3f72153..2389bebb 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryPlugin.kt +++ b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryPlugin.kt @@ -156,19 +156,11 @@ internal fun Project.configureLinkingOptions(linkerExtension: LinkerExtension) { private fun Project.findDerivedDataPath(customXcodeprojPath: String? = null): String { val xcodeprojPath = customXcodeprojPath ?: findXcodeprojFile(rootDir)?.absolutePath - val buildDirOutput = ByteArrayOutputStream() - exec { - it.commandLine = listOf("xcodebuild", "-project", xcodeprojPath, "-showBuildSettings") - it.standardOutput = buildDirOutput - } - val buildSettings = buildDirOutput.toString("UTF-8") - val buildDirRegex = Regex("BUILD_DIR = (.+)") - val buildDirMatch = buildDirRegex.find(buildSettings) - val buildDir = - buildDirMatch?.groupValues?.get(1) - ?: throw GradleException("BUILD_DIR not found in xcodebuild output") - val derivedDataPath = buildDir.replace("/Build/Products", "") - return derivedDataPath + ?: throw GradleException("Xcode project file not found") + + return providers.of(DerivedDataPathValueSource::class.java) { + it.parameters.xcodeprojPath.set(xcodeprojPath) + }.get() } /** From 02f132d10bee3378e3553a5a87946480a8ef98f5 Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Wed, 31 Jul 2024 15:10:43 +0200 Subject: [PATCH 59/78] Run test during ci --- .github/workflows/kotlin-multiplatform-gradle-plugin.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/kotlin-multiplatform-gradle-plugin.yml b/.github/workflows/kotlin-multiplatform-gradle-plugin.yml index 12fb0bb7..6d84a07b 100644 --- a/.github/workflows/kotlin-multiplatform-gradle-plugin.yml +++ b/.github/workflows/kotlin-multiplatform-gradle-plugin.yml @@ -26,6 +26,10 @@ jobs: - name: Cached Gradle uses: gradle/gradle-build-action@842c587ad8aa4c68eeba24c396e15af4c2e9f30a + - name: Test + run: | + cd sentry-kotlin-multiplatform-gradle-plugin && ./gradlew test + - name: DistZip run: | cd sentry-kotlin-multiplatform-gradle-plugin && ./gradlew distZip From c446cb1d00d856ecd7863a61ba7f16f7d9fb24ae Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Thu, 1 Aug 2024 14:14:24 +0200 Subject: [PATCH 60/78] Update --- .../multiplatform/gradle/SentryPlugin.kt | 60 ++++++++++++------- .../kmp-app-spm/shared/build.gradle.kts | 4 ++ 2 files changed, 41 insertions(+), 23 deletions(-) diff --git a/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryPlugin.kt b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryPlugin.kt index 2389bebb..91ca0d32 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryPlugin.kt +++ b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryPlugin.kt @@ -10,8 +10,8 @@ import org.jetbrains.kotlin.gradle.plugin.cocoapods.KotlinCocoapodsPlugin import org.jetbrains.kotlin.gradle.plugin.mpp.Framework import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget import org.jetbrains.kotlin.gradle.plugin.mpp.TestExecutable -import java.io.ByteArrayOutputStream import java.io.File +import org.slf4j.LoggerFactory internal const val SENTRY_EXTENSION_NAME = "sentryKmp" internal const val LINKER_EXTENSION_NAME = "linker" @@ -25,7 +25,11 @@ class SentryPlugin : Plugin { override fun apply(project: Project): Unit = with(project) { val sentryExtension = - project.extensions.create(SENTRY_EXTENSION_NAME, SentryExtension::class.java, project) + project.extensions.create( + SENTRY_EXTENSION_NAME, + SentryExtension::class.java, + project + ) project.extensions.add(LINKER_EXTENSION_NAME, sentryExtension.linker) project.extensions.add(AUTO_INSTALL_EXTENSION_NAME, sentryExtension.autoInstall) project.extensions.add( @@ -57,6 +61,12 @@ class SentryPlugin : Plugin { } } } + + companion object { + internal val logger by lazy { + LoggerFactory.getLogger(SentryPlugin::class.java) + } + } } internal fun Project.installSentryForKmp( @@ -64,7 +74,7 @@ internal fun Project.installSentryForKmp( ) { val kmpExtension = extensions.findByName(KOTLIN_EXTENSION_NAME) if (kmpExtension !is KotlinMultiplatformExtension) { - // todo: log, not multiplatform found + logger.info("Kotlin Multiplatform plugin not found. Skipping Sentry installation.") return } @@ -73,9 +83,9 @@ internal fun Project.installSentryForKmp( if (unsupportedTargets.any { unsupported -> target.name.contains(unsupported) }) { throw GradleException( "Unsupported target: ${target.name}. " + - "Cannot auto install in commonMain. " + - "Please create an intermediate sourceSet with targets that the Sentry SDK " + - "supports (apple, jvm, android) and add the dependency manually." + "Cannot auto install in commonMain. " + + "Please create an intermediate sourceSet with targets that the Sentry SDK " + + "supports (apple, jvm, android) and add the dependency manually." ) } } @@ -111,7 +121,7 @@ internal fun Project.installSentryForCocoapods( internal fun Project.configureLinkingOptions(linkerExtension: LinkerExtension) { val kmpExtension = extensions.findByName(KOTLIN_EXTENSION_NAME) if (kmpExtension !is KotlinMultiplatformExtension) { - // todo: log, not multiplatform found + logger.info("Kotlin Multiplatform plugin not found. Skipping Sentry installation.") return } @@ -121,7 +131,7 @@ internal fun Project.configureLinkingOptions(linkerExtension: LinkerExtension) { kmpExtension.appleTargets().all { target -> val frameworkArchitecture = target.toSentryFrameworkArchitecture() if (frameworkArchitecture == null) { - // todo: log, unsupported architecture + logger.info("Skipping target ${target.name}. Unsupported architecture.") return@all } @@ -147,13 +157,31 @@ internal fun Project.configureLinkingOptions(linkerExtension: LinkerExtension) { } if (binary is Framework) { - val frameworkPath = if (binary.isStatic) staticFrameworkPath else dynamicFrameworkPath + val frameworkPath = + if (binary.isStatic) staticFrameworkPath else dynamicFrameworkPath binary.linkerOpts("-F$frameworkPath") } } } } +/** + * Transforms a Kotlin Multiplatform target name to the architecture name that is found inside + * Sentry's framework directory. + */ +internal fun KotlinNativeTarget.toSentryFrameworkArchitecture(): String? { + return when (name) { + "iosSimulatorArm64", "iosX64" -> "ios-arm64_x86_64-simulator" + "iosArm64" -> "ios-arm64" + "macosArm64", "macosX64" -> "macos-arm64_x86_64" + "tvosSimulatorArm64", "tvosX64" -> "tvos-arm64_x86_64-simulator" + "tvosArm64" -> "tvos-arm64" + "watchosArm32", "watchosArm64" -> "watchos-arm64_arm64_32_armv7k" + "watchosSimulatorArm64", "watchosX64" -> "watchos-arm64_i386_x86_64-simulator" + else -> null + } +} + private fun Project.findDerivedDataPath(customXcodeprojPath: String? = null): String { val xcodeprojPath = customXcodeprojPath ?: findXcodeprojFile(rootDir)?.absolutePath ?: throw GradleException("Xcode project file not found") @@ -199,17 +227,3 @@ private fun KotlinMultiplatformExtension.appleTargets() = targets.withType(KotlinNativeTarget::class.java).matching { it.konanTarget.family.isAppleFamily } - -/** - * Transforms a Kotlin Multiplatform target name to the architecture name that is found inside - * Sentry's framework directory. - */ -internal fun KotlinNativeTarget.toSentryFrameworkArchitecture(): String? { - return when (name) { - "iosSimulatorArm64" -> "ios-arm64_x86_64-simulator" - "iosX64" -> "ios-arm64_x86_64-simulator" - "iosArm64" -> "ios-arm64" - // todo: add more targets - else -> null - } -} diff --git a/sentry-samples/kmp-app-spm/shared/build.gradle.kts b/sentry-samples/kmp-app-spm/shared/build.gradle.kts index 5b235ad9..59935a37 100644 --- a/sentry-samples/kmp-app-spm/shared/build.gradle.kts +++ b/sentry-samples/kmp-app-spm/shared/build.gradle.kts @@ -50,3 +50,7 @@ android { minSdk = Config.Android.minSdkVersion } } + +sentryKmp { + autoInstall.commonMain.enabled = false +} \ No newline at end of file From a34cb65ae499c2432a64fdfad13641c41be63df3 Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Thu, 1 Aug 2024 14:15:26 +0200 Subject: [PATCH 61/78] formatting{ --- .../sentry/kotlin/multiplatform/gradle/SentryPlugin.kt | 10 +++++----- sentry-samples/kmp-app-spm/shared/build.gradle.kts | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryPlugin.kt b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryPlugin.kt index 91ca0d32..f8c0bbef 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryPlugin.kt +++ b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryPlugin.kt @@ -10,8 +10,8 @@ import org.jetbrains.kotlin.gradle.plugin.cocoapods.KotlinCocoapodsPlugin import org.jetbrains.kotlin.gradle.plugin.mpp.Framework import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget import org.jetbrains.kotlin.gradle.plugin.mpp.TestExecutable -import java.io.File import org.slf4j.LoggerFactory +import java.io.File internal const val SENTRY_EXTENSION_NAME = "sentryKmp" internal const val LINKER_EXTENSION_NAME = "linker" @@ -83,9 +83,9 @@ internal fun Project.installSentryForKmp( if (unsupportedTargets.any { unsupported -> target.name.contains(unsupported) }) { throw GradleException( "Unsupported target: ${target.name}. " + - "Cannot auto install in commonMain. " + - "Please create an intermediate sourceSet with targets that the Sentry SDK " + - "supports (apple, jvm, android) and add the dependency manually." + "Cannot auto install in commonMain. " + + "Please create an intermediate sourceSet with targets that the Sentry SDK " + + "supports (apple, jvm, android) and add the dependency manually." ) } } @@ -184,7 +184,7 @@ internal fun KotlinNativeTarget.toSentryFrameworkArchitecture(): String? { private fun Project.findDerivedDataPath(customXcodeprojPath: String? = null): String { val xcodeprojPath = customXcodeprojPath ?: findXcodeprojFile(rootDir)?.absolutePath - ?: throw GradleException("Xcode project file not found") + ?: throw GradleException("Xcode project file not found") return providers.of(DerivedDataPathValueSource::class.java) { it.parameters.xcodeprojPath.set(xcodeprojPath) diff --git a/sentry-samples/kmp-app-spm/shared/build.gradle.kts b/sentry-samples/kmp-app-spm/shared/build.gradle.kts index 59935a37..5c6e2395 100644 --- a/sentry-samples/kmp-app-spm/shared/build.gradle.kts +++ b/sentry-samples/kmp-app-spm/shared/build.gradle.kts @@ -53,4 +53,4 @@ android { sentryKmp { autoInstall.commonMain.enabled = false -} \ No newline at end of file +} From e846c9c8531afc4ad8f7425d6547438e10d945bb Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Thu, 1 Aug 2024 15:49:11 +0200 Subject: [PATCH 62/78] format --- .../multiplatform/gradle/SentryPlugin.kt | 37 ++++++++++--------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryPlugin.kt b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryPlugin.kt index f8c0bbef..a9c24a96 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryPlugin.kt +++ b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryPlugin.kt @@ -121,7 +121,7 @@ internal fun Project.installSentryForCocoapods( internal fun Project.configureLinkingOptions(linkerExtension: LinkerExtension) { val kmpExtension = extensions.findByName(KOTLIN_EXTENSION_NAME) if (kmpExtension !is KotlinMultiplatformExtension) { - logger.info("Kotlin Multiplatform plugin not found. Skipping Sentry installation.") + logger.info("Kotlin Multiplatform plugin not found. Skipping linker configuration.") return } @@ -131,10 +131,11 @@ internal fun Project.configureLinkingOptions(linkerExtension: LinkerExtension) { kmpExtension.appleTargets().all { target -> val frameworkArchitecture = target.toSentryFrameworkArchitecture() if (frameworkArchitecture == null) { - logger.info("Skipping target ${target.name}. Unsupported architecture.") + logger.warn("Skipping target ${target.name}. Unsupported architecture.") return@all } + @Suppress("MaxLineLength") val dynamicFrameworkPath = "$derivedDataPath/SourcePackages/artifacts/sentry-cocoa/Sentry-Dynamic/Sentry-Dynamic.xcframework/$frameworkArchitecture" val staticFrameworkPath = @@ -151,15 +152,23 @@ internal fun Project.configureLinkingOptions(linkerExtension: LinkerExtension) { target.binaries.all binaries@{ binary -> if (binary is TestExecutable) { + // both dynamic and static frameworks will work for tests val frameworkPath = if (dynamicFrameworkExists) dynamicFrameworkPath else staticFrameworkPath binary.linkerOpts("-rpath", frameworkPath, "-F$frameworkPath") } if (binary is Framework) { - val frameworkPath = - if (binary.isStatic) staticFrameworkPath else dynamicFrameworkPath + val frameworkPath = when { + binary.isStatic && staticFrameworkExists -> staticFrameworkPath + !binary.isStatic && dynamicFrameworkExists -> dynamicFrameworkPath + else -> { + logger.warn("Linking to framework failed, no sentry framework found for target ${target.name}") + return@binaries + } + } binary.linkerOpts("-F$frameworkPath") + logger.info("Linked framework from $frameworkPath") } } } @@ -202,22 +211,14 @@ internal fun findXcodeprojFile(dir: File): File? { fun searchDirectory(directory: File): File? { val files = directory.listFiles() ?: return null - for (file in files) { - if (file.name in ignoredDirectories) { - continue - } - - // Recursively search the subdirectory - val result = searchDirectory(file) - if (result != null) { - return result - } - - if (file.extension == "xcodeproj") { - return file + return files.firstNotNullOfOrNull { file -> + when { + file.name in ignoredDirectories -> null + file.extension == "xcodeproj" -> file + file.isDirectory -> searchDirectory(file) + else -> null } } - return null } return searchDirectory(dir) From 2c78dfd7c66e84eed0ea305c45b27a8e213f9fc6 Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Thu, 1 Aug 2024 16:11:51 +0200 Subject: [PATCH 63/78] Skip apple specific configs if there are not apple targets --- .../kotlin/multiplatform/gradle/SentryPlugin.kt | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryPlugin.kt b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryPlugin.kt index a9c24a96..2a65efbf 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryPlugin.kt +++ b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryPlugin.kt @@ -49,6 +49,7 @@ class SentryPlugin : Plugin { if (sentryExtension.autoInstall.commonMain.enabled.get()) { installSentryForKmp(sentryExtension.autoInstall.commonMain) } + if (hasCocoapodsPlugin && sentryExtension.autoInstall.cocoapods.enabled.get()) { installSentryForCocoapods(sentryExtension.autoInstall.cocoapods) } @@ -101,6 +102,12 @@ internal fun Project.installSentryForCocoapods( ) { val kmpExtension = extensions.findByName(KOTLIN_EXTENSION_NAME) if (kmpExtension !is KotlinMultiplatformExtension) { + logger.info("Kotlin Multiplatform plugin not found. Skipping Cocoapods installation.") + return + } + + if (kmpExtension.appleTargets().isEmpty()) { + logger.info("No Apple targets found. Skipping Cocoapods installation.") return } @@ -125,6 +132,11 @@ internal fun Project.configureLinkingOptions(linkerExtension: LinkerExtension) { return } + if (kmpExtension.appleTargets().isEmpty()) { + logger.info("No Apple targets found. Skipping linker configuration.") + return + } + val customXcodeprojPath = linkerExtension.xcodeprojPath.orNull val derivedDataPath = findDerivedDataPath(customXcodeprojPath) From bdf62f7446edb672371a139d4f6bd84374414894 Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Thu, 1 Aug 2024 16:28:48 +0200 Subject: [PATCH 64/78] Fix tests --- .../build.gradle.kts | 1 + .../kotlin/multiplatform/gradle/SentryPluginTest.kt | 12 ++++++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/sentry-kotlin-multiplatform-gradle-plugin/build.gradle.kts b/sentry-kotlin-multiplatform-gradle-plugin/build.gradle.kts index 4a2dd34d..6843303c 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/build.gradle.kts +++ b/sentry-kotlin-multiplatform-gradle-plugin/build.gradle.kts @@ -20,6 +20,7 @@ dependencies { compileOnly(gradleApi()) compileOnly(kotlin("gradle-plugin")) + testImplementation(kotlin("gradle-plugin")) testImplementation(libs.junit) } diff --git a/sentry-kotlin-multiplatform-gradle-plugin/src/test/java/io/sentry/kotlin/multiplatform/gradle/SentryPluginTest.kt b/sentry-kotlin-multiplatform-gradle-plugin/src/test/java/io/sentry/kotlin/multiplatform/gradle/SentryPluginTest.kt index 5cfdc404..f61d880e 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/src/test/java/io/sentry/kotlin/multiplatform/gradle/SentryPluginTest.kt +++ b/sentry-kotlin-multiplatform-gradle-plugin/src/test/java/io/sentry/kotlin/multiplatform/gradle/SentryPluginTest.kt @@ -11,7 +11,7 @@ class SentryPluginTest { @Test fun `plugin is applied correctly to the project`() { val project = ProjectBuilder.builder().build() - project.pluginManager.apply("io.sentry.kotlin.multiplatform.gradle.plugin") + project.pluginManager.apply("io.sentry.kotlin.multiplatform.gradle") assert(project.plugins.hasPlugin(SentryPlugin::class.java)) } @@ -19,15 +19,15 @@ class SentryPluginTest { @Test fun `extension sentry is created correctly`() { val project = ProjectBuilder.builder().build() - project.pluginManager.apply("io.sentry.kotlin.multiplatform.gradle.plugin") + project.pluginManager.apply("io.sentry.kotlin.multiplatform.gradle") - assertNotNull(project.extensions.getByName("sentry")) + assertNotNull(project.extensions.getByName("sentryKmp")) } @Test fun `extension linker is created correctly`() { val project = ProjectBuilder.builder().build() - project.pluginManager.apply("io.sentry.kotlin.multiplatform.gradle.plugin") + project.pluginManager.apply("io.sentry.kotlin.multiplatform.gradle") assertNotNull(project.extensions.getByName("linker")) } @@ -35,7 +35,7 @@ class SentryPluginTest { @Test fun `install Sentry pod when cocoapods plugin is applied and no custom Sentry configuration exists`() { val project = ProjectBuilder.builder().build() - project.pluginManager.apply("io.sentry.kotlin.multiplatform.gradle.plugin") + project.pluginManager.apply("io.sentry.kotlin.multiplatform.gradle") project.pluginManager.apply("org.jetbrains.kotlin.multiplatform") project.pluginManager.apply("org.jetbrains.kotlin.native.cocoapods") @@ -48,7 +48,7 @@ class SentryPluginTest { @Test fun `do not install Sentry pod when cocoapods plugin is applied and custom Sentry configuration exists`() { val project = ProjectBuilder.builder().build() - project.pluginManager.apply("io.sentry.kotlin.multiplatform.gradle.plugin") + project.pluginManager.apply("io.sentry.kotlin.multiplatform.gradle") project.pluginManager.apply("org.jetbrains.kotlin.multiplatform") project.pluginManager.apply("org.jetbrains.kotlin.native.cocoapods") From 87e9183c815416280c6bd925043b735eaa14d177 Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Thu, 1 Aug 2024 16:36:43 +0200 Subject: [PATCH 65/78] Update CI and skip linker and cocoapods if not macOS host --- .../kotlin-multiplatform-gradle-plugin.yml | 26 +++++++++++++++++-- .../multiplatform/gradle/SentryPlugin.kt | 19 +++++++++++--- 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/.github/workflows/kotlin-multiplatform-gradle-plugin.yml b/.github/workflows/kotlin-multiplatform-gradle-plugin.yml index 6d84a07b..6386fdca 100644 --- a/.github/workflows/kotlin-multiplatform-gradle-plugin.yml +++ b/.github/workflows/kotlin-multiplatform-gradle-plugin.yml @@ -11,8 +11,8 @@ concurrency: cancel-in-progress: true jobs: - archive-distribution: - runs-on: ubuntu-latest + build: + runs-on: macos-latest-xlarge steps: - uses: actions/checkout@v4 @@ -23,6 +23,13 @@ jobs: java-version: 17 distribution: temurin + - name: Cached Konan + uses: actions/cache@9b0c1fce7a93df8e3bb8926b0d6e9d89e92f20a7 #v3 + with: + path: ~/.konan + key: ${{ runner.os }}-konan-${{ hashFiles('**/*.gradle*') }}-${{ hashFiles('**/gradle/wrapper/gradle-wrapper.properties') }} + restore-keys: ${{ runner.os }}-konan- + - name: Cached Gradle uses: gradle/gradle-build-action@842c587ad8aa4c68eeba24c396e15af4c2e9f30a @@ -30,6 +37,21 @@ jobs: run: | cd sentry-kotlin-multiplatform-gradle-plugin && ./gradlew test + archive-distribution: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: JDK setup + uses: actions/setup-java@v3 + with: + java-version: 17 + distribution: temurin + + - name: Cached Gradle + uses: gradle/gradle-build-action@842c587ad8aa4c68eeba24c396e15af4c2e9f30a + - name: DistZip run: | cd sentry-kotlin-multiplatform-gradle-plugin && ./gradlew distZip diff --git a/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryPlugin.kt b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryPlugin.kt index 2a65efbf..fb97268b 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryPlugin.kt +++ b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryPlugin.kt @@ -10,6 +10,7 @@ import org.jetbrains.kotlin.gradle.plugin.cocoapods.KotlinCocoapodsPlugin import org.jetbrains.kotlin.gradle.plugin.mpp.Framework import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget import org.jetbrains.kotlin.gradle.plugin.mpp.TestExecutable +import org.jetbrains.kotlin.konan.target.HostManager import org.slf4j.LoggerFactory import java.io.File @@ -84,9 +85,9 @@ internal fun Project.installSentryForKmp( if (unsupportedTargets.any { unsupported -> target.name.contains(unsupported) }) { throw GradleException( "Unsupported target: ${target.name}. " + - "Cannot auto install in commonMain. " + - "Please create an intermediate sourceSet with targets that the Sentry SDK " + - "supports (apple, jvm, android) and add the dependency manually." + "Cannot auto install in commonMain. " + + "Please create an intermediate sourceSet with targets that the Sentry SDK " + + "supports (apple, jvm, android) and add the dependency manually." ) } } @@ -111,6 +112,11 @@ internal fun Project.installSentryForCocoapods( return } + if (!HostManager.hostIsMac) { + logger.info("Host is not macOS. Skipping Cocoapods installation.") + return + } + (kmpExtension as ExtensionAware).extensions.configure(CocoapodsExtension::class.java) { cocoapods -> val podName = "Sentry" @@ -137,6 +143,11 @@ internal fun Project.configureLinkingOptions(linkerExtension: LinkerExtension) { return } + if (!HostManager.hostIsMac) { + logger.info("Host is not macOS. Skipping linker configuration.") + return + } + val customXcodeprojPath = linkerExtension.xcodeprojPath.orNull val derivedDataPath = findDerivedDataPath(customXcodeprojPath) @@ -205,7 +216,7 @@ internal fun KotlinNativeTarget.toSentryFrameworkArchitecture(): String? { private fun Project.findDerivedDataPath(customXcodeprojPath: String? = null): String { val xcodeprojPath = customXcodeprojPath ?: findXcodeprojFile(rootDir)?.absolutePath - ?: throw GradleException("Xcode project file not found") + ?: throw GradleException("Xcode project file not found") return providers.of(DerivedDataPathValueSource::class.java) { it.parameters.xcodeprojPath.set(xcodeprojPath) From 8698be58897f1720df4605e048a8a4563bde578f Mon Sep 17 00:00:00 2001 From: Sentry Github Bot Date: Thu, 1 Aug 2024 14:39:16 +0000 Subject: [PATCH 66/78] Format code --- .../io/sentry/kotlin/multiplatform/gradle/SentryPlugin.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryPlugin.kt b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryPlugin.kt index fb97268b..404ccec5 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryPlugin.kt +++ b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryPlugin.kt @@ -85,9 +85,9 @@ internal fun Project.installSentryForKmp( if (unsupportedTargets.any { unsupported -> target.name.contains(unsupported) }) { throw GradleException( "Unsupported target: ${target.name}. " + - "Cannot auto install in commonMain. " + - "Please create an intermediate sourceSet with targets that the Sentry SDK " + - "supports (apple, jvm, android) and add the dependency manually." + "Cannot auto install in commonMain. " + + "Please create an intermediate sourceSet with targets that the Sentry SDK " + + "supports (apple, jvm, android) and add the dependency manually." ) } } @@ -216,7 +216,7 @@ internal fun KotlinNativeTarget.toSentryFrameworkArchitecture(): String? { private fun Project.findDerivedDataPath(customXcodeprojPath: String? = null): String { val xcodeprojPath = customXcodeprojPath ?: findXcodeprojFile(rootDir)?.absolutePath - ?: throw GradleException("Xcode project file not found") + ?: throw GradleException("Xcode project file not found") return providers.of(DerivedDataPathValueSource::class.java) { it.parameters.xcodeprojPath.set(xcodeprojPath) From c3615e0809505dc3b244fe88e4b775be0aef251b Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Thu, 1 Aug 2024 16:43:23 +0200 Subject: [PATCH 67/78] update --- .../java/io/sentry/kotlin/multiplatform/gradle/SentryPlugin.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryPlugin.kt b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryPlugin.kt index 404ccec5..3f9a88e9 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryPlugin.kt +++ b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryPlugin.kt @@ -57,7 +57,7 @@ class SentryPlugin : Plugin { } // If the user is not using the cocoapods plugin, linking to the framework is not - // automatic so we have to take care of that + // automatic so we have to configure it in the plugin. if (!hasCocoapodsPlugin) { configureLinkingOptions(sentryExtension.linker) } From 9de03d2745adbae2c648c2638564dbb98839adae Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Thu, 1 Aug 2024 17:01:55 +0200 Subject: [PATCH 68/78] Update --- .../config/detekt/detekt.yml | 9 +++++ .../multiplatform/gradle/SentryPlugin.kt | 34 ++++--------------- 2 files changed, 16 insertions(+), 27 deletions(-) create mode 100644 sentry-kotlin-multiplatform-gradle-plugin/config/detekt/detekt.yml diff --git a/sentry-kotlin-multiplatform-gradle-plugin/config/detekt/detekt.yml b/sentry-kotlin-multiplatform-gradle-plugin/config/detekt/detekt.yml new file mode 100644 index 00000000..f0a4e84e --- /dev/null +++ b/sentry-kotlin-multiplatform-gradle-plugin/config/detekt/detekt.yml @@ -0,0 +1,9 @@ +style: + UnnecessaryAbstractClass: + active: false + ForbiddenComment: + active: false +naming: + MatchingDeclarationName: + active: false +complexi diff --git a/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryPlugin.kt b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryPlugin.kt index 3f9a88e9..f157378e 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryPlugin.kt +++ b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryPlugin.kt @@ -102,18 +102,8 @@ internal fun Project.installSentryForCocoapods( cocoapodsAutoInstallExtension: CocoapodsAutoInstallExtension ) { val kmpExtension = extensions.findByName(KOTLIN_EXTENSION_NAME) - if (kmpExtension !is KotlinMultiplatformExtension) { - logger.info("Kotlin Multiplatform plugin not found. Skipping Cocoapods installation.") - return - } - - if (kmpExtension.appleTargets().isEmpty()) { - logger.info("No Apple targets found. Skipping Cocoapods installation.") - return - } - - if (!HostManager.hostIsMac) { - logger.info("Host is not macOS. Skipping Cocoapods installation.") + if (kmpExtension !is KotlinMultiplatformExtension || kmpExtension.targets.isEmpty() || !HostManager.hostIsMac) { + logger.info("Skipping Cocoapods installation.") return } @@ -131,20 +121,11 @@ internal fun Project.installSentryForCocoapods( } } +@Suppress("CyclomaticComplexMethod") internal fun Project.configureLinkingOptions(linkerExtension: LinkerExtension) { val kmpExtension = extensions.findByName(KOTLIN_EXTENSION_NAME) - if (kmpExtension !is KotlinMultiplatformExtension) { - logger.info("Kotlin Multiplatform plugin not found. Skipping linker configuration.") - return - } - - if (kmpExtension.appleTargets().isEmpty()) { - logger.info("No Apple targets found. Skipping linker configuration.") - return - } - - if (!HostManager.hostIsMac) { - logger.info("Host is not macOS. Skipping linker configuration.") + if (kmpExtension !is KotlinMultiplatformExtension || kmpExtension.targets.isEmpty() || !HostManager.hostIsMac) { + logger.info("Skipping linker configuration.") return } @@ -152,9 +133,8 @@ internal fun Project.configureLinkingOptions(linkerExtension: LinkerExtension) { val derivedDataPath = findDerivedDataPath(customXcodeprojPath) kmpExtension.appleTargets().all { target -> - val frameworkArchitecture = target.toSentryFrameworkArchitecture() - if (frameworkArchitecture == null) { - logger.warn("Skipping target ${target.name}. Unsupported architecture.") + val frameworkArchitecture = target.toSentryFrameworkArchitecture() ?: run { + logger.warn("Skipping target ${target.name} - unsupported architecture.") return@all } From af6385cd3b4a3596edf39f02356beff703c245b1 Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Thu, 1 Aug 2024 18:04:55 +0200 Subject: [PATCH 69/78] update --- .github/workflows/kotlin-multiplatform-gradle-plugin.yml | 4 ++-- .../config/detekt/detekt.yml | 9 --------- 2 files changed, 2 insertions(+), 11 deletions(-) delete mode 100644 sentry-kotlin-multiplatform-gradle-plugin/config/detekt/detekt.yml diff --git a/.github/workflows/kotlin-multiplatform-gradle-plugin.yml b/.github/workflows/kotlin-multiplatform-gradle-plugin.yml index 6386fdca..fd1306ab 100644 --- a/.github/workflows/kotlin-multiplatform-gradle-plugin.yml +++ b/.github/workflows/kotlin-multiplatform-gradle-plugin.yml @@ -33,9 +33,9 @@ jobs: - name: Cached Gradle uses: gradle/gradle-build-action@842c587ad8aa4c68eeba24c396e15af4c2e9f30a - - name: Test + - name: Build run: | - cd sentry-kotlin-multiplatform-gradle-plugin && ./gradlew test + cd sentry-kotlin-multiplatform-gradle-plugin && ./gradlew build archive-distribution: runs-on: ubuntu-latest diff --git a/sentry-kotlin-multiplatform-gradle-plugin/config/detekt/detekt.yml b/sentry-kotlin-multiplatform-gradle-plugin/config/detekt/detekt.yml deleted file mode 100644 index f0a4e84e..00000000 --- a/sentry-kotlin-multiplatform-gradle-plugin/config/detekt/detekt.yml +++ /dev/null @@ -1,9 +0,0 @@ -style: - UnnecessaryAbstractClass: - active: false - ForbiddenComment: - active: false -naming: - MatchingDeclarationName: - active: false -complexi From 6a981a80fb4212c40f1a831c41b0ca5442c7ffb7 Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Thu, 1 Aug 2024 20:58:18 +0200 Subject: [PATCH 70/78] Add compilation test through samples --- .github/workflows/kotlin-multiplatform.yml | 19 +++++++++++++++++++ scripts/build-jvm.sh | 2 +- .../kmp-app-cocoapods/shared/build.gradle.kts | 6 ++++++ .../src/commonTest/kotlin/CompilationTest.kt | 9 +++++++++ .../kmp-app-spm/shared/build.gradle.kts | 2 ++ .../src/commonTest/kotlin/CompilationTest.kt | 1 + 6 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 sentry-samples/kmp-app-cocoapods/shared/src/commonTest/kotlin/CompilationTest.kt diff --git a/.github/workflows/kotlin-multiplatform.yml b/.github/workflows/kotlin-multiplatform.yml index c8062d8b..b78e2182 100644 --- a/.github/workflows/kotlin-multiplatform.yml +++ b/.github/workflows/kotlin-multiplatform.yml @@ -95,6 +95,25 @@ jobs: name: sentry-kotlin-multiplatform token: ${{ secrets.CODECOV_TOKEN }} + test-samples: + runs-on: macos-latest-xlarge + + steps: + - uses: actions/checkout@v4 + + - name: JDK setup + uses: actions/setup-java@v3 + with: + java-version: 17 + distribution: temurin + + - name: Cached Gradle + uses: gradle/gradle-build-action@842c587ad8aa4c68eeba24c396e15af4c2e9f30a + + - name: Test samples + run: | + ./gradlew allTests -p sentry-samples/kmp-app-spm/shared + archive-distribution: runs-on: macos-latest-xlarge diff --git a/scripts/build-jvm.sh b/scripts/build-jvm.sh index 31ec07a0..37ab2138 100755 --- a/scripts/build-jvm.sh +++ b/scripts/build-jvm.sh @@ -6,7 +6,7 @@ if [ -z "$1" ]; then fi PROJECT_NAME="$1" -./gr + ./gradlew "testDebugUnitTest" \ "testReleaseUnitTest" \ "publishAndroidReleasePublicationToMavenLocal" \ diff --git a/sentry-samples/kmp-app-cocoapods/shared/build.gradle.kts b/sentry-samples/kmp-app-cocoapods/shared/build.gradle.kts index 6eeca01c..24c26567 100644 --- a/sentry-samples/kmp-app-cocoapods/shared/build.gradle.kts +++ b/sentry-samples/kmp-app-cocoapods/shared/build.gradle.kts @@ -65,3 +65,9 @@ android { minSdk = Config.Android.minSdkVersion } } + +// disabling autoInstall because we are using project(":sentry-kotlin-multiplatform") directly +// for our sample apps +sentryKmp { + autoInstall.commonMain.enabled = false +} diff --git a/sentry-samples/kmp-app-cocoapods/shared/src/commonTest/kotlin/CompilationTest.kt b/sentry-samples/kmp-app-cocoapods/shared/src/commonTest/kotlin/CompilationTest.kt new file mode 100644 index 00000000..6b9d1f34 --- /dev/null +++ b/sentry-samples/kmp-app-cocoapods/shared/src/commonTest/kotlin/CompilationTest.kt @@ -0,0 +1,9 @@ +import kotlin.test.Test + +// Simple compilation check that is run during CI +class CompilationTest { + @Test + fun test() { + print("see if this runs") + } +} diff --git a/sentry-samples/kmp-app-spm/shared/build.gradle.kts b/sentry-samples/kmp-app-spm/shared/build.gradle.kts index 5c6e2395..44a3aaf5 100644 --- a/sentry-samples/kmp-app-spm/shared/build.gradle.kts +++ b/sentry-samples/kmp-app-spm/shared/build.gradle.kts @@ -51,6 +51,8 @@ android { } } +// disabling autoInstall because we are using project(":sentry-kotlin-multiplatform") directly +// for our sample apps sentryKmp { autoInstall.commonMain.enabled = false } diff --git a/sentry-samples/kmp-app-spm/shared/src/commonTest/kotlin/CompilationTest.kt b/sentry-samples/kmp-app-spm/shared/src/commonTest/kotlin/CompilationTest.kt index c821abec..6b9d1f34 100644 --- a/sentry-samples/kmp-app-spm/shared/src/commonTest/kotlin/CompilationTest.kt +++ b/sentry-samples/kmp-app-spm/shared/src/commonTest/kotlin/CompilationTest.kt @@ -1,5 +1,6 @@ import kotlin.test.Test +// Simple compilation check that is run during CI class CompilationTest { @Test fun test() { From a6cf25826cf1e7154d6016096bd107d9ce1e0cca Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Thu, 1 Aug 2024 20:59:34 +0200 Subject: [PATCH 71/78] run allTests for every sample project --- .github/workflows/kotlin-multiplatform.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/kotlin-multiplatform.yml b/.github/workflows/kotlin-multiplatform.yml index b78e2182..e13f35da 100644 --- a/.github/workflows/kotlin-multiplatform.yml +++ b/.github/workflows/kotlin-multiplatform.yml @@ -112,7 +112,7 @@ jobs: - name: Test samples run: | - ./gradlew allTests -p sentry-samples/kmp-app-spm/shared + ./gradlew allTests -p sentry-samples archive-distribution: runs-on: macos-latest-xlarge From 2ddc1cd5656dbde7b6ac114f6c8d56a916afb289 Mon Sep 17 00:00:00 2001 From: Giancarlo Buenaflor Date: Thu, 1 Aug 2024 21:05:11 +0200 Subject: [PATCH 72/78] Update CHANGELOG.md --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 58fcb522..9a0b3f61 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,8 @@ - Install via `plugins { id("io.sentry.kotlin.multiplatform.gradle") version "{version}" }` - Enables auto installing of the KMP SDK to commonMain (if all targets are supported) - Enables auto installing of the required Sentry Cocoa SDK with Cocoapods (if Cocoapods plugin is enabled) - - Configures linking for SPM (both dynamic and static frameworks) + - Configures linking for SPM (needed if you want to compile a dynamic framework) + - Configure via the `sentryKmp` configuration block in your build file ### Dependencies From ca8830038c7f187f331014f934955d6f80066033 Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Thu, 1 Aug 2024 23:46:46 +0200 Subject: [PATCH 73/78] Upload codecov report --- .github/workflows/kotlin-multiplatform-gradle-plugin.yml | 8 +++++++- .../build.gradle.kts | 1 + .../gradle/libs.versions.toml | 2 ++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/.github/workflows/kotlin-multiplatform-gradle-plugin.yml b/.github/workflows/kotlin-multiplatform-gradle-plugin.yml index fd1306ab..a20aa946 100644 --- a/.github/workflows/kotlin-multiplatform-gradle-plugin.yml +++ b/.github/workflows/kotlin-multiplatform-gradle-plugin.yml @@ -35,7 +35,13 @@ jobs: - name: Build run: | - cd sentry-kotlin-multiplatform-gradle-plugin && ./gradlew build + cd sentry-kotlin-multiplatform-gradle-plugin && ./gradlew build && ./gradlew koverXmlReport + + - name: Upload coverage to Codecov + uses: codecov/codecov-action@5ecb98a3c6b747ed38dc09f787459979aebb39be # pin@v4 + with: + name: sentry-kotlin-multiplatform-gradle-plugin + token: ${{ secrets.CODECOV_TOKEN }} archive-distribution: runs-on: ubuntu-latest diff --git a/sentry-kotlin-multiplatform-gradle-plugin/build.gradle.kts b/sentry-kotlin-multiplatform-gradle-plugin/build.gradle.kts index 6843303c..4af768f8 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/build.gradle.kts +++ b/sentry-kotlin-multiplatform-gradle-plugin/build.gradle.kts @@ -9,6 +9,7 @@ plugins { alias(libs.plugins.vanniktech.publish) id("distribution") alias(libs.plugins.buildConfig) + alias(libs.plugins.kover) } version = property("versionName").toString() diff --git a/sentry-kotlin-multiplatform-gradle-plugin/gradle/libs.versions.toml b/sentry-kotlin-multiplatform-gradle-plugin/gradle/libs.versions.toml index 45d8f474..721e36ec 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/gradle/libs.versions.toml +++ b/sentry-kotlin-multiplatform-gradle-plugin/gradle/libs.versions.toml @@ -4,6 +4,7 @@ kotlin = "1.9.23" pluginPublish = "1.2.1" buildConfig = "5.3.5" vanniktechPublish = "0.18.0" +kover = "0.8.3" [plugins] detekt = { id = "io.gitlab.arturbosch.detekt", version.ref = "detekt"} @@ -11,6 +12,7 @@ kotlin = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin"} pluginPublish = { id = "com.gradle.plugin-publish", version.ref = "pluginPublish"} vanniktech-publish = { id = "com.vanniktech.maven.publish", version.ref = "vanniktechPublish"} buildConfig = { id = "com.github.gmazzo.buildconfig", version.ref = "buildConfig"} +kover = { id = "org.jetbrains.kotlinx.kover", version.ref = "kover"} [libraries] junit = "junit:junit:4.13.2" From d140c9a60e591ac2150f28cf3f43e6fdd05c4f20 Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Thu, 1 Aug 2024 23:48:25 +0200 Subject: [PATCH 74/78] Default working directory --- .github/workflows/kotlin-multiplatform-gradle-plugin.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/kotlin-multiplatform-gradle-plugin.yml b/.github/workflows/kotlin-multiplatform-gradle-plugin.yml index a20aa946..719a3a58 100644 --- a/.github/workflows/kotlin-multiplatform-gradle-plugin.yml +++ b/.github/workflows/kotlin-multiplatform-gradle-plugin.yml @@ -13,6 +13,9 @@ concurrency: jobs: build: runs-on: macos-latest-xlarge + defaults: + run: + working-directory: sentry-kotlin-multiplatform-gradle-plugin steps: - uses: actions/checkout@v4 @@ -35,7 +38,8 @@ jobs: - name: Build run: | - cd sentry-kotlin-multiplatform-gradle-plugin && ./gradlew build && ./gradlew koverXmlReport + ./gradlew build + ./gradlew koverXmlReport - name: Upload coverage to Codecov uses: codecov/codecov-action@5ecb98a3c6b747ed38dc09f787459979aebb39be # pin@v4 From 97f9bddd09943eeaa42e49f6c3e35922e3419c25 Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Fri, 2 Aug 2024 00:09:20 +0200 Subject: [PATCH 75/78] Use kover 0.7.3 --- .../gradle/libs.versions.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sentry-kotlin-multiplatform-gradle-plugin/gradle/libs.versions.toml b/sentry-kotlin-multiplatform-gradle-plugin/gradle/libs.versions.toml index 721e36ec..2b7170c6 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/gradle/libs.versions.toml +++ b/sentry-kotlin-multiplatform-gradle-plugin/gradle/libs.versions.toml @@ -4,7 +4,7 @@ kotlin = "1.9.23" pluginPublish = "1.2.1" buildConfig = "5.3.5" vanniktechPublish = "0.18.0" -kover = "0.8.3" +kover = "0.7.3" [plugins] detekt = { id = "io.gitlab.arturbosch.detekt", version.ref = "detekt"} From d48a901b1abd5d584a75d0f8dd4515c491875139 Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Fri, 2 Aug 2024 16:13:16 +0200 Subject: [PATCH 76/78] Update --- .../build.gradle.kts | 12 +++-- .../gradle/libs.versions.toml | 4 +- .../multiplatform/gradle/LinkerExtension.kt | 10 ++++ .../multiplatform/gradle/SentryPlugin.kt | 32 +++++++++---- .../gradle/SentryFrameworkArchitectureTest.kt | 44 +++++++++++++++++ .../multiplatform/gradle/SentryPluginTest.kt | 47 +++++++++++++++++-- 6 files changed, 132 insertions(+), 17 deletions(-) create mode 100644 sentry-kotlin-multiplatform-gradle-plugin/src/test/java/io/sentry/kotlin/multiplatform/gradle/SentryFrameworkArchitectureTest.kt diff --git a/sentry-kotlin-multiplatform-gradle-plugin/build.gradle.kts b/sentry-kotlin-multiplatform-gradle-plugin/build.gradle.kts index 4af768f8..6789a439 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/build.gradle.kts +++ b/sentry-kotlin-multiplatform-gradle-plugin/build.gradle.kts @@ -23,14 +23,20 @@ dependencies { testImplementation(kotlin("gradle-plugin")) testImplementation(libs.junit) + testImplementation(libs.junit.params) + testImplementation(libs.mockk) +} + +tasks.test { + useJUnitPlatform() } java { - sourceCompatibility = JavaVersion.VERSION_1_8 - targetCompatibility = JavaVersion.VERSION_1_8 + sourceCompatibility = JavaVersion.VERSION_11 + targetCompatibility = JavaVersion.VERSION_11 } -tasks.withType { kotlinOptions { jvmTarget = JavaVersion.VERSION_1_8.toString() } } +tasks.withType { kotlinOptions { jvmTarget = JavaVersion.VERSION_11.toString() } } gradlePlugin { plugins { diff --git a/sentry-kotlin-multiplatform-gradle-plugin/gradle/libs.versions.toml b/sentry-kotlin-multiplatform-gradle-plugin/gradle/libs.versions.toml index 2b7170c6..42893a18 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/gradle/libs.versions.toml +++ b/sentry-kotlin-multiplatform-gradle-plugin/gradle/libs.versions.toml @@ -15,4 +15,6 @@ buildConfig = { id = "com.github.gmazzo.buildconfig", version.ref = "buildConfig kover = { id = "org.jetbrains.kotlinx.kover", version.ref = "kover"} [libraries] -junit = "junit:junit:4.13.2" +junit = "org.junit.jupiter:junit-jupiter-api:5.10.3" +junit-params = "org.junit.jupiter:junit-jupiter-params:5.10.3" +mockk = "io.mockk:mockk:1.13.12" diff --git a/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/LinkerExtension.kt b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/LinkerExtension.kt index e8d21e9b..81505a7f 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/LinkerExtension.kt +++ b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/LinkerExtension.kt @@ -8,5 +8,15 @@ import javax.inject.Inject abstract class LinkerExtension @Inject constructor(project: Project) { private val objects = project.objects + /** + * Path to the Xcode project that will be used to link the framework. + * This is used to find the derived data path in which the framework is stored for SPM. + */ val xcodeprojPath: Property = objects.property(String::class.java) + + /** + * Path to the framework that will be linked. + * Takes precedence over [xcodeprojPath] if both are set. + */ + val frameworkPath: Property = objects.property(String::class.java) } diff --git a/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryPlugin.kt b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryPlugin.kt index f157378e..f59bdb4e 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryPlugin.kt +++ b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryPlugin.kt @@ -122,6 +122,7 @@ internal fun Project.installSentryForCocoapods( } @Suppress("CyclomaticComplexMethod") +// todo: write test internal fun Project.configureLinkingOptions(linkerExtension: LinkerExtension) { val kmpExtension = extensions.findByName(KOTLIN_EXTENSION_NAME) if (kmpExtension !is KotlinMultiplatformExtension || kmpExtension.targets.isEmpty() || !HostManager.hostIsMac) { @@ -129,8 +130,14 @@ internal fun Project.configureLinkingOptions(linkerExtension: LinkerExtension) { return } - val customXcodeprojPath = linkerExtension.xcodeprojPath.orNull - val derivedDataPath = findDerivedDataPath(customXcodeprojPath) + var derivedDataPath = "" + val frameworkPath = linkerExtension.frameworkPath.orNull + if (frameworkPath == null) { + val customXcodeprojPath = linkerExtension.xcodeprojPath.orNull + derivedDataPath = findDerivedDataPath(customXcodeprojPath) + } + + logger.warn("framework path: $frameworkPath") kmpExtension.appleTargets().all { target -> val frameworkArchitecture = target.toSentryFrameworkArchitecture() ?: run { @@ -138,12 +145,21 @@ internal fun Project.configureLinkingOptions(linkerExtension: LinkerExtension) { return@all } - @Suppress("MaxLineLength") - val dynamicFrameworkPath = - "$derivedDataPath/SourcePackages/artifacts/sentry-cocoa/Sentry-Dynamic/Sentry-Dynamic.xcframework/$frameworkArchitecture" - val staticFrameworkPath = - "$derivedDataPath/SourcePackages/artifacts/sentry-cocoa/Sentry/Sentry.xcframework/$frameworkArchitecture" + val dynamicFrameworkPath: String + val staticFrameworkPath: String + + if (frameworkPath?.isNotEmpty() == false) { + dynamicFrameworkPath = frameworkPath + staticFrameworkPath = frameworkPath + } else { + @Suppress("MaxLineLength") + dynamicFrameworkPath = + "$derivedDataPath/SourcePackages/artifacts/sentry-cocoa/Sentry-Dynamic/Sentry-Dynamic.xcframework/$frameworkArchitecture" + staticFrameworkPath = + "$derivedDataPath/SourcePackages/artifacts/sentry-cocoa/Sentry/Sentry.xcframework/$frameworkArchitecture" + } + assert(frameworkPath == "haha") val dynamicFrameworkExists = File(dynamicFrameworkPath).exists() val staticFrameworkExists = File(staticFrameworkPath).exists() @@ -227,7 +243,7 @@ internal fun findXcodeprojFile(dir: File): File? { return searchDirectory(dir) } -private fun KotlinMultiplatformExtension.appleTargets() = +internal fun KotlinMultiplatformExtension.appleTargets() = targets.withType(KotlinNativeTarget::class.java).matching { it.konanTarget.family.isAppleFamily } diff --git a/sentry-kotlin-multiplatform-gradle-plugin/src/test/java/io/sentry/kotlin/multiplatform/gradle/SentryFrameworkArchitectureTest.kt b/sentry-kotlin-multiplatform-gradle-plugin/src/test/java/io/sentry/kotlin/multiplatform/gradle/SentryFrameworkArchitectureTest.kt new file mode 100644 index 00000000..01737d51 --- /dev/null +++ b/sentry-kotlin-multiplatform-gradle-plugin/src/test/java/io/sentry/kotlin/multiplatform/gradle/SentryFrameworkArchitectureTest.kt @@ -0,0 +1,44 @@ +package io.sentry.kotlin.multiplatform.gradle + +import io.mockk.every +import io.mockk.mockk +import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.params.ParameterizedTest +import org.junit.jupiter.params.provider.Arguments +import org.junit.jupiter.params.provider.MethodSource + +class SentryFrameworkArchitectureTest { + companion object { + @JvmStatic + fun architectureData(): List = listOf( + Arguments.of("iosSimulatorArm64", "ios-arm64_x86_64-simulator"), + Arguments.of("iosX64", "ios-arm64_x86_64-simulator"), + Arguments.of("iosArm64", "ios-arm64"), + Arguments.of("macosArm64", "macos-arm64_x86_64"), + Arguments.of("macosX64", "macos-arm64_x86_64"), + Arguments.of("tvosSimulatorArm64", "tvos-arm64_x86_64-simulator"), + Arguments.of("tvosX64", "tvos-arm64_x86_64-simulator"), + Arguments.of("tvosArm64", "tvos-arm64"), + Arguments.of("watchosArm32", "watchos-arm64_arm64_32_armv7k"), + Arguments.of("watchosArm64", "watchos-arm64_arm64_32_armv7k"), + Arguments.of("watchosSimulatorArm64", "watchos-arm64_i386_x86_64-simulator"), + Arguments.of("watchosX64", "watchos-arm64_i386_x86_64-simulator"), + Arguments.of("unsupportedTarget", null) + ) + } + + @ParameterizedTest(name = "Target {0} should return {1}") + @MethodSource("architectureData") + fun `toSentryFrameworkArchitecture returns correct architecture for all targets`( + targetName: String, + expectedArchitecture: String? + ) { + val target = mockk() + every { target.name } returns targetName + + val result = target.toSentryFrameworkArchitecture() + + assertEquals(expectedArchitecture, result) + } +} diff --git a/sentry-kotlin-multiplatform-gradle-plugin/src/test/java/io/sentry/kotlin/multiplatform/gradle/SentryPluginTest.kt b/sentry-kotlin-multiplatform-gradle-plugin/src/test/java/io/sentry/kotlin/multiplatform/gradle/SentryPluginTest.kt index f61d880e..7810e95d 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/src/test/java/io/sentry/kotlin/multiplatform/gradle/SentryPluginTest.kt +++ b/sentry-kotlin-multiplatform-gradle-plugin/src/test/java/io/sentry/kotlin/multiplatform/gradle/SentryPluginTest.kt @@ -1,11 +1,12 @@ package io.sentry.kotlin.multiplatform.gradle -import junit.framework.TestCase.assertEquals -import junit.framework.TestCase.assertNotNull import org.gradle.api.plugins.ExtensionAware import org.gradle.testfixtures.ProjectBuilder import org.jetbrains.kotlin.gradle.plugin.cocoapods.CocoapodsExtension -import org.junit.Test +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Assertions.assertNotNull +import org.junit.jupiter.api.Assertions.assertTrue +import org.junit.jupiter.api.Test class SentryPluginTest { @Test @@ -53,8 +54,7 @@ class SentryPluginTest { project.pluginManager.apply("org.jetbrains.kotlin.native.cocoapods") val kmpExtension = project.extensions.findByName("kotlin") - (kmpExtension as ExtensionAware).extensions.configure(CocoapodsExtension::class.java) { - cocoapods -> + (kmpExtension as ExtensionAware).extensions.configure(CocoapodsExtension::class.java) { cocoapods -> cocoapods.pod("Sentry") { version = "custom version" } } @@ -65,4 +65,41 @@ class SentryPluginTest { assertEquals(pod?.version, "custom version") } } + + @Test + fun `plugin applies extensions correctly`() { + val project = ProjectBuilder.builder().build() + project.pluginManager.apply("io.sentry.kotlin.multiplatform.gradle") + + assertNotNull(project.extensions.getByName("sentryKmp")) + assertNotNull(project.extensions.getByName("linker")) + assertNotNull(project.extensions.getByName("autoInstall")) + assertNotNull(project.extensions.getByName("cocoapods")) + assertNotNull(project.extensions.getByName("commonMain")) + } + + @Test + fun `installSentryForKmp adds dependency to commonMain`() { + val project = ProjectBuilder.builder().build() + project.pluginManager.apply("org.jetbrains.kotlin.multiplatform") + project.pluginManager.apply("io.sentry.kotlin.multiplatform.gradle") + + project.installSentryForKmp(project.extensions.getByName("commonMain") as SourceSetAutoInstallExtension) + + val sentryDependencies = project.configurations + .flatMap { it.dependencies } + .filter { it.group == "io.sentry" && it.name == "sentry-kotlin-multiplatform" } + .toList() + + assertTrue(sentryDependencies.isNotEmpty()) + + val sentryDependency = sentryDependencies.first() + assertEquals("io.sentry", sentryDependency.group) + assertEquals("sentry-kotlin-multiplatform", sentryDependency.name) + + val commonMainConfiguration = + project.configurations.find { it.name.contains("commonMain", ignoreCase = true) } + assertNotNull(commonMainConfiguration) + assertTrue(commonMainConfiguration!!.dependencies.contains(sentryDependency)) + } } From 690eb1bc78d0160ad7d6d5e2d55961f2f43a283c Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Mon, 5 Aug 2024 12:10:58 +0200 Subject: [PATCH 77/78] Update --- .../multiplatform/gradle/SentryPlugin.kt | 17 ++- .../gradle/DerivedDataPathTest.kt | 109 ++++++++++++++++++ .../multiplatform/gradle/SentryPluginTest.kt | 36 ++++++ 3 files changed, 152 insertions(+), 10 deletions(-) create mode 100644 sentry-kotlin-multiplatform-gradle-plugin/src/test/java/io/sentry/kotlin/multiplatform/gradle/DerivedDataPathTest.kt diff --git a/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryPlugin.kt b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryPlugin.kt index f59bdb4e..edf96df4 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryPlugin.kt +++ b/sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/SentryPlugin.kt @@ -122,7 +122,6 @@ internal fun Project.installSentryForCocoapods( } @Suppress("CyclomaticComplexMethod") -// todo: write test internal fun Project.configureLinkingOptions(linkerExtension: LinkerExtension) { val kmpExtension = extensions.findByName(KOTLIN_EXTENSION_NAME) if (kmpExtension !is KotlinMultiplatformExtension || kmpExtension.targets.isEmpty() || !HostManager.hostIsMac) { @@ -137,8 +136,6 @@ internal fun Project.configureLinkingOptions(linkerExtension: LinkerExtension) { derivedDataPath = findDerivedDataPath(customXcodeprojPath) } - logger.warn("framework path: $frameworkPath") - kmpExtension.appleTargets().all { target -> val frameworkArchitecture = target.toSentryFrameworkArchitecture() ?: run { logger.warn("Skipping target ${target.name} - unsupported architecture.") @@ -148,18 +145,18 @@ internal fun Project.configureLinkingOptions(linkerExtension: LinkerExtension) { val dynamicFrameworkPath: String val staticFrameworkPath: String - if (frameworkPath?.isNotEmpty() == false) { + if (frameworkPath?.isNotEmpty() == true) { dynamicFrameworkPath = frameworkPath staticFrameworkPath = frameworkPath } else { @Suppress("MaxLineLength") dynamicFrameworkPath = "$derivedDataPath/SourcePackages/artifacts/sentry-cocoa/Sentry-Dynamic/Sentry-Dynamic.xcframework/$frameworkArchitecture" + @Suppress("MaxLineLength") staticFrameworkPath = "$derivedDataPath/SourcePackages/artifacts/sentry-cocoa/Sentry/Sentry.xcframework/$frameworkArchitecture" } - assert(frameworkPath == "haha") val dynamicFrameworkExists = File(dynamicFrameworkPath).exists() val staticFrameworkExists = File(staticFrameworkPath).exists() @@ -172,13 +169,13 @@ internal fun Project.configureLinkingOptions(linkerExtension: LinkerExtension) { target.binaries.all binaries@{ binary -> if (binary is TestExecutable) { // both dynamic and static frameworks will work for tests - val frameworkPath = + val finalFrameworkPath = if (dynamicFrameworkExists) dynamicFrameworkPath else staticFrameworkPath - binary.linkerOpts("-rpath", frameworkPath, "-F$frameworkPath") + binary.linkerOpts("-rpath", finalFrameworkPath, "-F$finalFrameworkPath") } if (binary is Framework) { - val frameworkPath = when { + val finalFrameworkPath = when { binary.isStatic && staticFrameworkExists -> staticFrameworkPath !binary.isStatic && dynamicFrameworkExists -> dynamicFrameworkPath else -> { @@ -186,8 +183,8 @@ internal fun Project.configureLinkingOptions(linkerExtension: LinkerExtension) { return@binaries } } - binary.linkerOpts("-F$frameworkPath") - logger.info("Linked framework from $frameworkPath") + binary.linkerOpts("-F$finalFrameworkPath") + logger.info("Linked framework from $finalFrameworkPath") } } } diff --git a/sentry-kotlin-multiplatform-gradle-plugin/src/test/java/io/sentry/kotlin/multiplatform/gradle/DerivedDataPathTest.kt b/sentry-kotlin-multiplatform-gradle-plugin/src/test/java/io/sentry/kotlin/multiplatform/gradle/DerivedDataPathTest.kt new file mode 100644 index 00000000..7e6007e9 --- /dev/null +++ b/sentry-kotlin-multiplatform-gradle-plugin/src/test/java/io/sentry/kotlin/multiplatform/gradle/DerivedDataPathTest.kt @@ -0,0 +1,109 @@ +package io.sentry.kotlin.multiplatform.gradle + +import io.mockk.every +import io.mockk.mockk +import org.gradle.api.Action +import org.gradle.api.GradleException +import org.gradle.process.ExecOperations +import org.gradle.process.ExecResult +import org.gradle.process.ExecSpec +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertThrows +import java.io.ByteArrayOutputStream + +class DerivedDataPathTest { + + private lateinit var valueSource: DerivedDataPathValueSource + private lateinit var execOperations: ExecOperations + private lateinit var parameters: DerivedDataPathValueSource.Parameters + + @BeforeEach + fun setup() { + execOperations = mockk() + parameters = mockk() + + valueSource = object : DerivedDataPathValueSource() { + override val execOperations: ExecOperations = this@DerivedDataPathTest.execOperations + override fun getParameters(): Parameters { + return this@DerivedDataPathTest.parameters + } + } + } + + @Test + fun `obtain should return correct derived data path`() { + val xcodebuildOutput = """ + Build settings for action build and target MyTarget: + BUILD_DIR = /DerivedData/Example/Build/Products + """.trimIndent() + + every { parameters.xcodeprojPath } returns mockk { + every { get() } returns "/path/to/project.xcodeproj" + } + + every { execOperations.exec(any()) } answers { + val execSpecLambda = it.invocation.args[0] as Action + val mockExecSpec = mockk(relaxed = true) + + val buildDirOutput = ByteArrayOutputStream() + buildDirOutput.write(xcodebuildOutput.toByteArray()) + + var capturedOutputStream: ByteArrayOutputStream? = null + every { mockExecSpec.commandLine }.returns(listOf()) + every { mockExecSpec.setStandardOutput(any()) } answers { + capturedOutputStream = firstArg() + mockExecSpec + } + + execSpecLambda.execute(mockExecSpec) + + capturedOutputStream?.write(xcodebuildOutput.toByteArray()) + + mockk { + every { exitValue } returns 0 + } + } + + val result = valueSource.obtain() + + assertEquals("/DerivedData/Example", result) + } + + @Test + fun `obtain should throw GradleException when BUILD_DIR is not found`() { + val xcodebuildOutput = "Some output without BUILD_DIR" + + every { parameters.xcodeprojPath } returns mockk { + every { get() } returns "/path/to/project.xcodeproj" + } + + every { execOperations.exec(any()) } answers { + val execSpecLambda = it.invocation.args[0] as Action + val mockExecSpec = mockk(relaxed = true) + + val buildDirOutput = ByteArrayOutputStream() + buildDirOutput.write(xcodebuildOutput.toByteArray()) + + var capturedOutputStream: ByteArrayOutputStream? = null + every { mockExecSpec.commandLine }.returns(listOf()) + every { mockExecSpec.setStandardOutput(any()) } answers { + capturedOutputStream = firstArg() + mockExecSpec + } + + execSpecLambda.execute(mockExecSpec) + + capturedOutputStream?.write(xcodebuildOutput.toByteArray()) + + mockk { + every { exitValue } returns 0 + } + } + + assertThrows { + valueSource.obtain() + } + } +} diff --git a/sentry-kotlin-multiplatform-gradle-plugin/src/test/java/io/sentry/kotlin/multiplatform/gradle/SentryPluginTest.kt b/sentry-kotlin-multiplatform-gradle-plugin/src/test/java/io/sentry/kotlin/multiplatform/gradle/SentryPluginTest.kt index 7810e95d..8bd7bdfc 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/src/test/java/io/sentry/kotlin/multiplatform/gradle/SentryPluginTest.kt +++ b/sentry-kotlin-multiplatform-gradle-plugin/src/test/java/io/sentry/kotlin/multiplatform/gradle/SentryPluginTest.kt @@ -2,11 +2,14 @@ package io.sentry.kotlin.multiplatform.gradle import org.gradle.api.plugins.ExtensionAware import org.gradle.testfixtures.ProjectBuilder +import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension import org.jetbrains.kotlin.gradle.plugin.cocoapods.CocoapodsExtension import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertNotNull import org.junit.jupiter.api.Assertions.assertTrue import org.junit.jupiter.api.Test +import org.junit.jupiter.api.io.TempDir +import java.io.File class SentryPluginTest { @Test @@ -102,4 +105,37 @@ class SentryPluginTest { assertNotNull(commonMainConfiguration) assertTrue(commonMainConfiguration!!.dependencies.contains(sentryDependency)) } + + @Test + fun `configureLinkingOptions sets up linker options for apple targets`(@TempDir tempDir: File) { + val project = ProjectBuilder.builder().build() + + project.pluginManager.apply { + apply("org.jetbrains.kotlin.multiplatform") + apply("io.sentry.kotlin.multiplatform.gradle") + } + + val kmpExtension = project.extensions.getByName("kotlin") as KotlinMultiplatformExtension + kmpExtension.apply { + listOf( + iosX64(), + iosArm64(), + iosSimulatorArm64() + ).forEach { + it.binaries.framework { + baseName = "shared" + isStatic = false + } + } + } + + val file = + tempDir.resolve("test/path") + file.mkdirs() + + val linkerExtension = project.extensions.getByName("linker") as LinkerExtension + linkerExtension.frameworkPath.set(file.absolutePath) + + project.configureLinkingOptions(linkerExtension) + } } From 5720a9a066ee8226b9d88c3599cd39e713b3caa7 Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Mon, 5 Aug 2024 14:54:12 +0200 Subject: [PATCH 78/78] Update --- .../multiplatform/gradle/SentryPluginTest.kt | 152 +++++++++++++++--- 1 file changed, 132 insertions(+), 20 deletions(-) diff --git a/sentry-kotlin-multiplatform-gradle-plugin/src/test/java/io/sentry/kotlin/multiplatform/gradle/SentryPluginTest.kt b/sentry-kotlin-multiplatform-gradle-plugin/src/test/java/io/sentry/kotlin/multiplatform/gradle/SentryPluginTest.kt index 8bd7bdfc..dfa841aa 100644 --- a/sentry-kotlin-multiplatform-gradle-plugin/src/test/java/io/sentry/kotlin/multiplatform/gradle/SentryPluginTest.kt +++ b/sentry-kotlin-multiplatform-gradle-plugin/src/test/java/io/sentry/kotlin/multiplatform/gradle/SentryPluginTest.kt @@ -4,8 +4,10 @@ import org.gradle.api.plugins.ExtensionAware import org.gradle.testfixtures.ProjectBuilder import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension import org.jetbrains.kotlin.gradle.plugin.cocoapods.CocoapodsExtension +import org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertNotNull +import org.junit.jupiter.api.Assertions.assertNull import org.junit.jupiter.api.Assertions.assertTrue import org.junit.jupiter.api.Test import org.junit.jupiter.api.io.TempDir @@ -37,36 +39,27 @@ class SentryPluginTest { } @Test - fun `install Sentry pod when cocoapods plugin is applied and no custom Sentry configuration exists`() { + fun `extension autoInstall is created correctly`() { val project = ProjectBuilder.builder().build() project.pluginManager.apply("io.sentry.kotlin.multiplatform.gradle") - project.pluginManager.apply("org.jetbrains.kotlin.multiplatform") - project.pluginManager.apply("org.jetbrains.kotlin.native.cocoapods") - project.afterEvaluate { - val cocoapodsExtension = project.extensions.findByType(CocoapodsExtension::class.java) - assertNotNull(cocoapodsExtension?.pods?.findByName("Sentry")) - } + assertNotNull(project.extensions.getByName("autoInstall")) } @Test - fun `do not install Sentry pod when cocoapods plugin is applied and custom Sentry configuration exists`() { + fun `extension cocoapods is created correctly`() { val project = ProjectBuilder.builder().build() project.pluginManager.apply("io.sentry.kotlin.multiplatform.gradle") - project.pluginManager.apply("org.jetbrains.kotlin.multiplatform") - project.pluginManager.apply("org.jetbrains.kotlin.native.cocoapods") - val kmpExtension = project.extensions.findByName("kotlin") - (kmpExtension as ExtensionAware).extensions.configure(CocoapodsExtension::class.java) { cocoapods -> - cocoapods.pod("Sentry") { version = "custom version" } - } + assertNotNull(project.extensions.getByName("cocoapods")) + } - // plugin does not configure sentry pod if there is already an existing configuration - project.afterEvaluate { - val cocoapodsExtension = project.extensions.findByType(CocoapodsExtension::class.java) - val pod = cocoapodsExtension?.pods?.findByName("Sentry") - assertEquals(pod?.version, "custom version") - } + @Test + fun `extension commonMain is created correctly`() { + val project = ProjectBuilder.builder().build() + project.pluginManager.apply("io.sentry.kotlin.multiplatform.gradle") + + assertNotNull(project.extensions.getByName("commonMain")) } @Test @@ -81,6 +74,26 @@ class SentryPluginTest { assertNotNull(project.extensions.getByName("commonMain")) } + @Test + fun `when autoInstall is disabled, no installations are performed`() { + val project = ProjectBuilder.builder().build() + + project.pluginManager.apply("io.sentry.kotlin.multiplatform.gradle") + + val autoInstallExtension = project.extensions.getByName("autoInstall") as AutoInstallExtension + autoInstallExtension.enabled.set(false) + + project.afterEvaluate { + val commonMainConfiguration = + project.configurations.find { it.name.contains("commonMain", ignoreCase = true) } + assertNull(commonMainConfiguration) + + val cocoapodsExtension = project.extensions.getByName("cocoapods") as CocoapodsExtension + val sentryPod = cocoapodsExtension.pods.findByName("Sentry") + assertNull(sentryPod) + } + } + @Test fun `installSentryForKmp adds dependency to commonMain`() { val project = ProjectBuilder.builder().build() @@ -106,6 +119,43 @@ class SentryPluginTest { assertTrue(commonMainConfiguration!!.dependencies.contains(sentryDependency)) } + @Test + fun `install Sentry pod if not already exists`() { + val project = ProjectBuilder.builder().build() + project.pluginManager.apply("org.jetbrains.kotlin.multiplatform") + project.pluginManager.apply("io.sentry.kotlin.multiplatform.gradle") + project.pluginManager.apply("org.jetbrains.kotlin.native.cocoapods") + + project.installSentryForCocoapods(project.extensions.getByName("cocoapods") as CocoapodsAutoInstallExtension) + + project.afterEvaluate { + val cocoapodsExtension = project.extensions.findByType(CocoapodsExtension::class.java) + val sentryPod = cocoapodsExtension?.pods?.findByName("Sentry") + assertTrue(sentryPod != null) + assertTrue(sentryPod!!.linkOnly) + } + } + + @Test + fun `do not install Sentry pod when cocoapods plugin when Sentry cocoapods configuration exists`() { + val project = ProjectBuilder.builder().build() + project.pluginManager.apply("io.sentry.kotlin.multiplatform.gradle") + project.pluginManager.apply("org.jetbrains.kotlin.multiplatform") + project.pluginManager.apply("org.jetbrains.kotlin.native.cocoapods") + + val kmpExtension = project.extensions.findByName("kotlin") + (kmpExtension as ExtensionAware).extensions.configure(CocoapodsExtension::class.java) { cocoapods -> + cocoapods.pod("Sentry") { version = "custom version" } + } + + // plugin does not configure sentry pod if there is already an existing configuration + project.afterEvaluate { + val cocoapodsExtension = project.extensions.findByType(CocoapodsExtension::class.java) + val pod = cocoapodsExtension?.pods?.findByName("Sentry") + assertEquals(pod?.version, "custom version") + } + } + @Test fun `configureLinkingOptions sets up linker options for apple targets`(@TempDir tempDir: File) { val project = ProjectBuilder.builder().build() @@ -137,5 +187,67 @@ class SentryPluginTest { linkerExtension.frameworkPath.set(file.absolutePath) project.configureLinkingOptions(linkerExtension) + + kmpExtension.apply { + val frameworks = appleTargets().map { + it.binaries.findFramework(NativeBuildType.DEBUG) + } + frameworks.forEach { + assertTrue(it?.linkerOpts?.contains("-F${file.absolutePath}") ?: false) + } + } + } + + @Test + fun `findXcodeprojFile returns xcodeproj file when it exists`(@TempDir tempDir: File) { + val xcodeprojFile = File(tempDir, "TestProject.xcodeproj") + xcodeprojFile.mkdir() + + val result = findXcodeprojFile(tempDir) + + assertEquals(xcodeprojFile, result) + } + + @Test + fun `findXcodeprojFile returns null when no xcodeproj file exists`(@TempDir tempDir: File) { + val result = findXcodeprojFile(tempDir) + + assertNull(result) + } + + @Test + fun `findXcodeprojFile ignores build and DerivedData directories`(@TempDir tempDir: File) { + File(tempDir, "build").mkdir() + File(tempDir, "DerivedData").mkdir() + val xcodeprojFile = File(tempDir, "TestProject.xcodeproj") + xcodeprojFile.mkdir() + + val result = findXcodeprojFile(tempDir) + + assertEquals(xcodeprojFile, result) + } + + @Test + fun `findXcodeprojFile searches subdirectories`(@TempDir tempDir: File) { + val subDir = File(tempDir, "subdir") + subDir.mkdir() + val xcodeprojFile = File(subDir, "TestProject.xcodeproj") + xcodeprojFile.mkdir() + + val result = findXcodeprojFile(tempDir) + + assertEquals(xcodeprojFile, result) + } + + @Test + fun `findXcodeprojFile returns first xcodeproj file found`(@TempDir tempDir: File) { + val xcodeprojFile1 = File(tempDir, "TestProject1.xcodeproj") + xcodeprojFile1.mkdir() + val xcodeprojFile2 = File(tempDir, "TestProject2.xcodeproj") + xcodeprojFile2.mkdir() + + val result = findXcodeprojFile(tempDir) + + assertEquals(xcodeprojFile1, result) } }