Skip to content

Commit

Permalink
* Do not invoke link.exe with invalid args, execution
Browse files Browse the repository at this point in the history
  with no arguments, will output the version string.
* Use proper path seperator based on running host for
  environment variable seperator.
* Check host arch to determine which subpath to check
  for visual studio installed binaries
  • Loading branch information
kcieplak committed Feb 18, 2025
1 parent f8e55fc commit fc25b1e
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Sources/SWBCore/Core.swift
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ public final class Core: Sendable {
}
}
if let additionalPlatformSearchPaths = getEnvironmentVariable("XCODE_EXTRA_PLATFORM_FOLDERS") {
for searchPath in additionalPlatformSearchPaths.split(separator: ":") {
for searchPath in additionalPlatformSearchPaths.split(separator: Path.pathEnvironmentSeparator) {
searchPaths.append(Path(searchPath))
}
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/SWBCore/Specs/Tools/LinkerTools.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1553,7 +1553,7 @@ public final class LibtoolLinkerSpec : GenericLinkerSpec, SpecIdentifierType, @u
public func discoveredLinkerToolsInfo(_ producer: any CommandProducer, _ delegate: any CoreClientTargetDiagnosticProducingDelegate, at toolPath: Path) async -> (any DiscoveredCommandLineToolSpecInfo)? {
do {
do {
let commandLine = [toolPath.str, producer.hostOperatingSystem == .windows ? "/VERSION" : "-version_details"]
let commandLine = [toolPath.str] + (producer.hostOperatingSystem == .windows ? [] : ["-version_details"])
return try await producer.discoveredCommandLineToolSpecInfo(delegate, nil, commandLine, { executionResult in
let gnuLD = [
#/GNU ld version (?<version>[\d.]+)-.*/#,
Expand All @@ -1569,7 +1569,7 @@ public func discoveredLinkerToolsInfo(_ producer: any CommandProducer, _ delegat
if let match = try goLD.compactMap({ try $0.firstMatch(in: String(decoding: executionResult.stdout, as: UTF8.self)) }).first {
return DiscoveredLdLinkerToolSpecInfo(linker: .gold, toolPath: toolPath, toolVersion: try Version(String(match.output.version)), architectures: Set())
}
// link.exe has no option to simply dump the version, but if you pass an invalid argument, the program will dump a header that contains the version.
// link.exe has no option to simply dump the version, running, the program will no arguments will dump a header that contains the version.
let linkExe = [
#/Microsoft \(R\) Incremental Linker Version (?<version>[\d.]+)/#
]
Expand Down
2 changes: 1 addition & 1 deletion Sources/SWBTestSupport/TaskPlanningTestSupport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ open class MockTestTaskPlanningClientDelegate: TaskPlanningClientDelegate, @unch
return .deferred
case "ld" where args == ["-version_details"]:
return .deferred
case "link" where args == ["/VERSION"]:
case "link":
return .deferred
case "libtool" where args == ["-V"] || args == ["--version"]:
return .deferred
Expand Down
6 changes: 5 additions & 1 deletion Sources/SWBWindowsPlatform/Plugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ struct WindowsPlatformExtension: PlatformInfoExtension {
guard let dir = try? await findLatestInstallDirectory(fs: fs) else {
return []
}
return [dir.join("bin/Hostarm64/arm64"), dir.join("bin/Hostx64/x64") ]
if Architecture.host.stringValue == "aarch64" {
return [dir.join("bin/Hostarm64/arm64")]
} else {
return [dir.join("bin/Hostx64/x64")]
}
}
}

0 comments on commit fc25b1e

Please sign in to comment.