-
-
Notifications
You must be signed in to change notification settings - Fork 20
Implement conditional Cocoa linking for targets #421
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
buenaflor
merged 20 commits into
main
from
cursor/implement-conditional-cocoa-linking-for-targets-aebb
Jul 16, 2025
Merged
Changes from 17 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
b96e48a
Optimize Cocoa framework linking by deferring configuration to task g…
cursoragent 329c9bb
Add fallback framework search and lazy linking tests for Cocoa targets
cursoragent e753757
Revert
buenaflor 24c509f
Tests
buenaflor 3ceb048
Update
buenaflor 23e51bb
Update
buenaflor 77fd9e6
Update CHANGELOG
buenaflor b5dab90
Update CHANGELOG
buenaflor d45ff55
Update class name
buenaflor a3a62e0
Update
buenaflor 8c3a4bc
Update
buenaflor 796bd45
Update
buenaflor 8ff1763
Fix analyze
buenaflor 906f8ab
Update
buenaflor d4945ce
Update libs.versions.toml
buenaflor f429eda
Update
buenaflor b851097
Fix analyze
buenaflor 4ad4d2b
Add try/catch
buenaflor 79b61c7
Fix analyze
buenaflor 449c203
Fix analyze
buenaflor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
130 changes: 130 additions & 0 deletions
130
...rc/test/java/io/sentry/kotlin/multiplatform/gradle/CocoaFrameworkLinkerIntegrationTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,130 @@ | ||
| package io.sentry.kotlin.multiplatform.gradle | ||
|
|
||
| import com.google.common.truth.Truth.assertThat | ||
| import org.gradle.testkit.runner.GradleRunner | ||
| import org.gradle.testkit.runner.internal.PluginUnderTestMetadataReading | ||
| import org.gradle.testkit.runner.internal.io.SynchronizedOutputStream | ||
| import org.junit.jupiter.api.Test | ||
| import org.junit.jupiter.api.condition.EnabledOnOs | ||
| import org.junit.jupiter.api.condition.OS | ||
| import org.junit.jupiter.api.io.TempDir | ||
| import java.io.ByteArrayOutputStream | ||
| import java.io.File | ||
| import java.io.OutputStreamWriter | ||
|
|
||
| @EnabledOnOs(OS.MAC) | ||
| class CocoaFrameworkLinkerIntegrationTest { | ||
| /** | ||
| * Verifies that the Cocoa linker is **not** configured when the task graph | ||
| * contains only non-Apple targets. | ||
| */ | ||
| @Test | ||
| fun `linker is not configured when only non-Apple tasks are requested`(@TempDir projectDir: File) { | ||
| writeBuildFiles(projectDir) | ||
|
|
||
| val output = ByteArrayOutputStream() | ||
| defaultRunner(projectDir, output) | ||
| .withArguments("compileKotlinJvm", "--dry-run", "--info") | ||
| .build() | ||
|
|
||
| assertThat(output.toString()) | ||
| .contains("No Apple compile task scheduled for this build - skipping Sentry Cocoa framework linking") | ||
| } | ||
|
|
||
| /** | ||
| * Verifies that the Cocoa linker **is** configured when at least one Apple | ||
| * task is present in the task graph. | ||
| */ | ||
| @Test | ||
| fun `linker is configured when an Apple task is requested`(@TempDir projectDir: File) { | ||
| writeBuildFiles(projectDir) | ||
|
|
||
| val output = ByteArrayOutputStream() | ||
| defaultRunner(projectDir, output) | ||
| .withArguments("compileKotlinIosSimulatorArm64", "--dry-run", "--info") | ||
| .build() | ||
|
|
||
| assertThat(output.toString()) | ||
| .contains("Set up Sentry Cocoa linking for target: iosSimulatorArm64") | ||
| assertThat(output.toString()) | ||
| .contains("Start resolving Sentry Cocoa framework paths for target: iosSimulatorArm64") | ||
| } | ||
|
|
||
| // --------------------------------------------------------------------- | ||
| // test-fixture helpers | ||
| // --------------------------------------------------------------------- | ||
|
|
||
| private fun writeBuildFiles(dir: File) { | ||
| // ----------------------------------------------------------------- | ||
| // Create a fake XCFramework on disk so that the CustomPathStrategy | ||
| // can resolve a valid framework path even on CI machines where SPM | ||
| // (and hence DerivedData) is not available. | ||
| // ----------------------------------------------------------------- | ||
| val fakeFrameworkDir = File(dir, "Sentry-Dynamic.xcframework").apply { | ||
| // Create minimal structure that satisfies path validation logic | ||
| val archDirName = "ios-arm64_x86_64-simulator" // architecture used for iosSimulatorArm64 | ||
| val archDir = File(this, archDirName) | ||
| archDir.mkdirs() | ||
| } | ||
|
|
||
| File(dir, "settings.gradle").writeText("""rootProject.name = "fixture"""") | ||
|
|
||
| val pluginClasspath = PluginUnderTestMetadataReading | ||
| .readImplementationClasspath() | ||
| .joinToString(", ") { "\"${it.absolutePath.replace('\\', '/')}\"" } | ||
|
|
||
| File(dir, "build.gradle").writeText( | ||
| """ | ||
| buildscript { | ||
| repositories { | ||
| google() | ||
| mavenCentral() | ||
| gradlePluginPortal() | ||
| } | ||
| dependencies { | ||
| classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$KOTLIN_VERSION" | ||
| classpath files($pluginClasspath) | ||
| } | ||
| } | ||
|
|
||
| apply plugin: 'org.jetbrains.kotlin.multiplatform' | ||
| apply plugin: 'io.sentry.kotlin.multiplatform.gradle' | ||
|
|
||
| repositories { | ||
| google() | ||
| mavenCentral() | ||
| } | ||
|
|
||
| kotlin { | ||
| jvm() // non-Apple target | ||
| iosSimulatorArm64() // Apple target used in tests | ||
| } | ||
|
|
||
| // ----------------------------------------------------------------- | ||
| // Configure the plugin to use the fake framework path created above. | ||
| // This makes the CustomPathStrategy succeed immediately, bypassing the | ||
| // DerivedData and manual search strategies that rely on an SPM setup. | ||
| // ----------------------------------------------------------------- | ||
| sentryKmp { | ||
| linker { | ||
| frameworkPath.set("${fakeFrameworkDir.absolutePath.replace('\\', '/')}") | ||
| } | ||
| } | ||
| """.trimIndent() | ||
| ) | ||
| } | ||
|
|
||
| /** Returns a pre-configured [GradleRunner] that logs into [out]. */ | ||
| private fun defaultRunner(projectDir: File, out: ByteArrayOutputStream): GradleRunner = | ||
| GradleRunner.create() | ||
| .withProjectDir(projectDir) | ||
| .withPluginClasspath() | ||
| .withGradleVersion(org.gradle.util.GradleVersion.current().version) | ||
| .forwardStdOutput(OutputStreamWriter(SynchronizedOutputStream(out))) | ||
| .forwardStdError(OutputStreamWriter(SynchronizedOutputStream(out))) | ||
| .withArguments("--stacktrace") | ||
|
|
||
| private companion object { | ||
| private const val KOTLIN_VERSION = "2.1.21" | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.