-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for relative file paths in debug symbols.
- Loading branch information
1 parent
d893073
commit e498c10
Showing
13 changed files
with
207 additions
and
10 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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
50 changes: 50 additions & 0 deletions
50
...plugin/src/kgp_1.9.0..2.1.0/kotlin/co/touchlab/skie/entrypoint/CodegenPhaseInterceptor.kt
This file contains 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,50 @@ | ||
@file:Suppress("invisible_reference", "invisible_member") | ||
|
||
package co.touchlab.skie.entrypoint | ||
|
||
import co.touchlab.skie.compilerinject.compilerplugin.mainSkieContext | ||
import co.touchlab.skie.compilerinject.interceptor.PhaseInterceptor | ||
import co.touchlab.skie.configuration.SkieConfigurationFlag | ||
import org.jetbrains.kotlin.backend.konan.KonanConfigKeys | ||
import org.jetbrains.kotlin.backend.konan.NativeGenerationState | ||
import org.jetbrains.kotlin.backend.konan.driver.phases.CodegenInput | ||
import org.jetbrains.kotlin.backend.konan.driver.phases.CodegenPhase | ||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity | ||
|
||
internal class CodegenPhaseInterceptor : PhaseInterceptor<NativeGenerationState, CodegenInput, Unit> { | ||
override fun getInterceptedPhase(): Any = CodegenPhase | ||
|
||
override fun intercept(context: NativeGenerationState, input: CodegenInput, next: (NativeGenerationState, CodegenInput) -> Unit) { | ||
val mainSkieContext = context.config.configuration.mainSkieContext | ||
with(mainSkieContext) { | ||
if (SkieConfigurationFlag.Build_RelativeSourcePathsInDebugSymbols.isEnabled) { | ||
workaroundRelativeDebugPrefixMapBug(context) | ||
} | ||
} | ||
|
||
next(context, input) | ||
} | ||
|
||
private fun workaroundRelativeDebugPrefixMapBug(context: NativeGenerationState) { | ||
if (context.hasDebugInfo()) { | ||
context.context.messageCollector.report( | ||
severity = CompilerMessageSeverity.ERROR, | ||
message = "NativeGenerationState.debugInfo was initialized before debug-prefix-map workaround was applied! " + | ||
"Please disable the debug-prefix-map SKIE feature and report this issue to the SKIE GitHub at https://github.com/touchlab/SKIE", | ||
) | ||
} else { | ||
/* | ||
* This piece of code removes | ||
*/ | ||
val existingMap = context.config.configuration.getMap(KonanConfigKeys.DEBUG_PREFIX_MAP) | ||
context.config.configuration.put(KonanConfigKeys.DEBUG_PREFIX_MAP, emptyMap()) | ||
|
||
// Touch the `debugInfo` to create it while the `DEBUG_PREFIX_MAP` is empty. | ||
@Suppress("UNUSED_VARIABLE") | ||
val debugInfo = context.debugInfo | ||
|
||
// Set the `DEBUG_PREFIX_MAP` back to original value so the .kt source files can get remapped correctly. | ||
context.config.configuration.put(KonanConfigKeys.DEBUG_PREFIX_MAP, existingMap) | ||
} | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
.../resources/META-INF/services/co.touchlab.skie.compilerinject.interceptor.PhaseInterceptor
This file contains 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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
co.touchlab.skie.entrypoint.CreateObjCExportCodeSpecPhaseInterceptor | ||
co.touchlab.skie.entrypoint.LinkerPhaseInterceptor | ||
co.touchlab.skie.entrypoint.ProduceObjCExportInterfacePhaseInterceptor | ||
co.touchlab.skie.entrypoint.CodegenPhaseInterceptor |
This file contains 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 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
13 changes: 13 additions & 0 deletions
13
...gin-impl/src/main/kotlin/co/touchlab/skie/plugin/relativepaths/ConfigureDebugPrefixMap.kt
This file contains 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,13 @@ | ||
package co.touchlab.skie.plugin.relativepaths | ||
|
||
import co.touchlab.skie.plugin.SkieTarget | ||
|
||
fun SkieTarget.configureDebugPrefixMap() { | ||
if (!project.isRelativeSourcePathsPreviewEnabled) { | ||
return | ||
} | ||
|
||
addFreeCompilerArgs( | ||
"-Xdebug-prefix-map=${project.rootDir.absolutePath}=." | ||
) | ||
} |
7 changes: 7 additions & 0 deletions
7
.../main/kotlin/co/touchlab/skie/plugin/relativepaths/IsRelativeSourcePathsPreviewEnabled.kt
This file contains 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,7 @@ | ||
package co.touchlab.skie.plugin.relativepaths | ||
|
||
import co.touchlab.skie.plugin.configuration.skieExtension | ||
import org.gradle.api.Project | ||
|
||
val Project.isRelativeSourcePathsPreviewEnabled: Boolean | ||
get() = project.skieExtension.build.enableRelativeSourcePathsInDebugSymbols.get() |
This file contains 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
84 changes: 84 additions & 0 deletions
84
.../test/kotlin/co/touchlab/skie/test/suite/gradle/relativepaths/RelativeSourcePathsTests.kt
This file contains 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,84 @@ | ||
package co.touchlab.skie.test.suite.gradle.relativepaths | ||
|
||
import co.touchlab.skie.test.annotation.MatrixTest | ||
import co.touchlab.skie.test.annotation.filter.Smoke | ||
import co.touchlab.skie.test.annotation.type.GradleTests | ||
import co.touchlab.skie.test.base.BaseGradleTests | ||
import co.touchlab.skie.test.runner.BuildConfiguration | ||
import co.touchlab.skie.test.template.Templates | ||
import co.touchlab.skie.test.util.KotlinTarget | ||
import co.touchlab.skie.test.util.KotlinVersion | ||
import co.touchlab.skie.test.util.LinkMode | ||
import co.touchlab.skie.test.util.execute | ||
import kotlin.test.assertContains | ||
import kotlin.test.assertEquals | ||
|
||
@Smoke | ||
@GradleTests | ||
class RelativeSourcePathsTests: BaseGradleTests() { | ||
|
||
@MatrixTest | ||
fun `basic`( | ||
kotlinVersion: KotlinVersion, | ||
linkMode: LinkMode, | ||
configuration: BuildConfiguration, | ||
) { | ||
rootBuildFile(kotlinVersion) { | ||
kotlin { | ||
allIos() | ||
|
||
registerNativeFrameworks( | ||
kotlinVersion = kotlinVersion, | ||
buildConfiguration = configuration, | ||
linkMode = linkMode, | ||
) | ||
} | ||
|
||
+""" | ||
skie { | ||
build { | ||
enableRelativeSourcePathsInDebugSymbols = true | ||
} | ||
} | ||
""".trimIndent() | ||
} | ||
|
||
copyToCommonMain(Templates.basic) | ||
|
||
runGradle() | ||
|
||
KotlinTarget.Native.Ios.targets.forEach { target -> | ||
val frameworkDir = builtFrameworkParentDir(target, configuration, isArtifactDsl = false) | ||
val dwarfContainingBinary = when (linkMode) { | ||
LinkMode.Dynamic -> "$frameworkDir/gradle_test.framework.dSYM/Contents/Resources/DWARF/gradle_test" | ||
LinkMode.Static -> "$frameworkDir/gradle_test.framework/gradle_test" | ||
} | ||
|
||
val debugSources = debugSourcesOf(dwarfContainingBinary) | ||
val expectedSources = listOf( | ||
"./src/commonMain/kotlin/templates/basic/BasicSkieFeatures.kt", | ||
"./bundled/gradle-test/bundled.gradle-test.BundledSwift.swift", | ||
"./generated/GradleTest/GradleTest.BasicEnum.swift", | ||
"./generated/GradleTest/GradleTest.SealedClass.swift", | ||
"./generated/GradleTest/GradleTest.SealedInterface.swift", | ||
"./generated/Skie/Skie.Namespace.swift", | ||
) | ||
expectedSources.forEach { | ||
assertContains(debugSources, it) | ||
} | ||
} | ||
} | ||
|
||
private fun debugSourcesOf(dwarfContainingBinary: String): Set<String> { | ||
val command = listOf( | ||
"/usr/bin/dwarfdump", | ||
"--show-sources", | ||
dwarfContainingBinary, | ||
) | ||
|
||
val result = command.joinToString(" ").execute(testProjectDir) | ||
assertEquals(0, result.exitCode) | ||
return result.stdOut.lines().toSet() | ||
} | ||
|
||
} |