Skip to content

Commit

Permalink
Locate Windows SDK WinMDs using WindowsMetadata logic. (#239)
Browse files Browse the repository at this point in the history
  • Loading branch information
tristanlabelle authored Aug 19, 2024
1 parent 7d367c9 commit 83ed540
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 83ed540

Please sign in to comment.