Skip to content

Commit

Permalink
Locate Windows SDK WinMDs using WindowsMetadata logic.
Browse files Browse the repository at this point in the history
  • Loading branch information
tristanlabelle committed Aug 19, 2024
1 parent 5e1db60 commit 770301a
Showing 1 changed file with 14 additions and 23 deletions.
37 changes: 14 additions & 23 deletions Generator/Sources/SwiftWinRT/createProjection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,35 +75,26 @@ internal func createProjection(commandLineArguments: CommandLineArguments, proje
}

fileprivate func getWindowsSdkWinMDPaths(sdkVersion: String) throws -> [String] {
let programFilesX86Path = ProcessInfo.processInfo.environment["ProgramFiles(x86)"]
?? (ProcessInfo.processInfo.environment["SystemDrive"].map { "\($0)\\Program Files (x86)" })
?? "C:\\Program Files (x86)"
let windowsKits10Path = "\(programFilesX86Path)\\Windows Kits\\10"
let sdkReferencesPath = "\(windowsKits10Path)\\References\\\(sdkVersion)"

var winmdPaths = [String]()
if let enumerator = FileManager.default.enumerator(atPath: sdkReferencesPath) {
for case let path as String in enumerator {
if path.hasSuffix(".winmd") {
winmdPaths.append("\(sdkReferencesPath)\\\(path)")
}
}
}
else {
let windowsWinMDPath = "\(windowsKits10Path)\\UnionMetadata\\\(sdkVersion)\\Windows.winmd"
if FileManager.default.fileExists(atPath: windowsWinMDPath) {
winmdPaths.append(windowsWinMDPath)
let sdkVersion = try FourPartVersion(parsing: sdkVersion)
guard let windowsKit = try WindowsKit.getInstalled().first(where: { $0.version == sdkVersion }) else {
enum WindowsSDKError: Error {
case notFound(version: String)
}
throw WindowsSDKError.notFound(version: sdkVersion.description)
}

if winmdPaths.isEmpty {
enum WindowsSDKError: Error {
case notFound(version: String)
let applicationPlatform = try windowsKit.readApplicationPlatform()
var apiContracts = applicationPlatform.apiContracts

if let desktopExtension = windowsKit.extensions.first(where: { $0.name == "WindowsDesktop" }) {
for extensionApiContract in try desktopExtension.readManifest().apiContracts {
apiContracts[extensionApiContract.key] = extensionApiContract.value
}
throw WindowsSDKError.notFound(version: sdkVersion)
}

return winmdPaths
return apiContracts.map {
windowsKit.getAPIContractPath(name: $0.key, version: $0.value)
}
}

fileprivate func tryLoadDocumentation(assemblyPath: String, locales: [String]) throws -> AssemblyDocumentation? {
Expand Down

0 comments on commit 770301a

Please sign in to comment.