Skip to content

Commit

Permalink
Add a temporary workaround for nested SDK modules.
Browse files Browse the repository at this point in the history
  • Loading branch information
TadeasKriz committed May 21, 2024
1 parent 9577aa1 commit 4158c2b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ import co.touchlab.skie.sir.element.SirModule
import co.touchlab.skie.util.cache.writeTextIfDifferent

object GenerateFakeObjCDependenciesPhase : SirPhase {

context(SirPhase.Context)
override suspend fun execute() {
oirProvider.externalClassesAndProtocols
.groupBy { it.originalSirClass.module }
// TODO: Replace with two types of external modules (fake and SDK) and handle available SDK modules properly.
.filterKeys { it is SirModule.External && it.name !in knownSdkModules }
.filterKeys { it is SirModule.External && !isKnownSdkModule(it.name) }
.mapKeys { it.key as SirModule.External }
.forEach { (module, types) ->
generateFakeFramework(module, types)
Expand Down Expand Up @@ -74,7 +73,7 @@ private fun OirClass.getProtocolHeaderEntry(): String =
find *.platform/Developer/SDKs/*.sdk/System/Library/Frameworks -name '*.framework' -prune -type d -exec basename {} '.framework' \; | sort | uniq | pbcopy
``` // this is to match a comment "opening" in the find command: */
*/
private val knownSdkModules = setOf(
private val knownTopLevelSdkModules = setOf(
"AGL",
"ARKit",
"AVFAudio",
Expand Down Expand Up @@ -384,3 +383,16 @@ private val knownSdkModules = setOf(
"iTunesLibrary",
"vmnet",
)

/*
This is a limited list of nested modules that's currently needed to pass all library tests.
It's needed because Kotlin imports nested modules directly in the `platform` package,
so SKIE has no way to know they are nested.
*/
val knownNestedSdkModules = mapOf(
"EAGL" to "OpenGLES",
)

private fun isKnownSdkModule(moduleName: String): Boolean {
return moduleName in knownNestedSdkModules.keys || moduleName in knownTopLevelSdkModules
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,11 @@ object ImportFakeObjCDependenciesPhase : SirPhase {

context(SirPhase.Context)
private fun importFakeFrameworks(fakeExternalModules: List<SirModule.External>, originalHeader: String) {
val fakeImports = fakeExternalModules.joinToString("\n") {
"#import <${it.name}/${it.name}.h>"
val fakeImports = fakeExternalModules.joinToString("\n") { module ->
// TODO: Properly fix this for nested modules as part of work to add distinction between the fake and SDK modules.
knownNestedSdkModules[module.name]?.let { parentName ->
"#import <$parentName/${module.name}.h>"
} ?: "#import <${module.name}/${module.name}.h>"
}

val updatedContent = originalHeader + "\n$fakeImports"
Expand Down

0 comments on commit 4158c2b

Please sign in to comment.