@@ -1922,8 +1922,26 @@ public final class LibtoolLinkerSpec : GenericLinkerSpec, SpecIdentifierType, @u
19221922public func discoveredLinkerToolsInfo( _ producer: any CommandProducer , _ delegate: any CoreClientTargetDiagnosticProducingDelegate , at toolPath: Path ) async -> ( any DiscoveredCommandLineToolSpecInfo ) ? {
19231923 do {
19241924 do {
1925+ // -version_details is an Apple ld specific option providing parseable output; try that first
19251926 let commandLine = [ toolPath. str, " -version_details " ]
19261927 return try await producer. discoveredCommandLineToolSpecInfo ( delegate, nil , commandLine, { executionResult in
1928+ struct LDVersionDetails : Decodable {
1929+ let version : Version
1930+ let architectures : Set < String >
1931+ }
1932+
1933+ let details : LDVersionDetails
1934+ do {
1935+ details = try JSONDecoder ( ) . decode ( LDVersionDetails . self, from: executionResult. stdout)
1936+ } catch {
1937+ throw CommandLineOutputJSONParsingError ( commandLine: commandLine, data: executionResult. stdout, hostOS: producer. hostOperatingSystem)
1938+ }
1939+
1940+ return DiscoveredLdLinkerToolSpecInfo ( linker: . ld64, toolPath: toolPath, toolVersion: details. version, architectures: details. architectures)
1941+ } )
1942+ } catch let e as CommandLineOutputJSONParsingError {
1943+ let vCommandLine = [ toolPath. str, " -v " ]
1944+ return try await producer. discoveredCommandLineToolSpecInfo ( delegate, nil , vCommandLine, { executionResult in
19271945 let gnuLD = [
19281946 #/GNU ld version (?<version>[\d.]+)-.*/# ,
19291947 #/GNU ld \(GNU Binutils.*\) (?<version>[\d.]+)/# ,
@@ -1934,8 +1952,8 @@ public func discoveredLinkerToolsInfo(_ producer: any CommandProducer, _ delegat
19341952
19351953 let goLD = [
19361954 #/GNU gold version (?<version>[\d.]+)-.*/# ,
1937- #/GNU gold \(GNU Binutils.*\) (?<version>[\d.]+)/# , // Ubuntu "GNU gold (GNU Binutils for Ubuntu 2.38) 1.16", Debian "GNU gold (GNU Binutils for Debian 2.40) 1.16"
1938- #/GNU gold \(version .*\) (?<version>[\d.]+)/# , // Fedora "GNU gold (version 2.40-14.fc39) 1.16", RHEL "GNU gold (version 2.35.2-54.el9) 1.16", Amazon "GNU gold (version 2.29.1-31.amzn2.0.1) 1.14"
1955+ #/GNU gold \(GNU Binutils.*\) (?<version>[\d.]+)/# , // Ubuntu "GNU gold (GNU Binutils for Ubuntu 2.38) 1.16", Debian "GNU gold (GNU Binutils for Debian 2.40) 1.16"
1956+ #/GNU gold \(version .*\) (?<version>[\d.]+)/# , // Fedora "GNU gold (version 2.40-14.fc39) 1.16", RHEL "GNU gold (version 2.35.2-54.el9) 1.16", Amazon "GNU gold (version 2.29.1-31.amzn2.0.1) 1.14"
19391957 ]
19401958
19411959 if let match = try goLD. compactMap ( { try $0. firstMatch ( in: String ( decoding: executionResult. stdout, as: UTF8 . self) ) } ) . first {
@@ -1950,23 +1968,6 @@ public func discoveredLinkerToolsInfo(_ producer: any CommandProducer, _ delegat
19501968 return DiscoveredLdLinkerToolSpecInfo ( linker: . linkExe, toolPath: toolPath, toolVersion: try Version ( String ( match. output. version) ) , architectures: Set ( ) )
19511969 }
19521970
1953- struct LDVersionDetails : Decodable {
1954- let version : Version
1955- let architectures : Set < String >
1956- }
1957-
1958- let details : LDVersionDetails
1959- do {
1960- details = try JSONDecoder ( ) . decode ( LDVersionDetails . self, from: executionResult. stdout)
1961- } catch {
1962- throw CommandLineOutputJSONParsingError ( commandLine: commandLine, data: executionResult. stdout, hostOS: producer. hostOperatingSystem)
1963- }
1964-
1965- return DiscoveredLdLinkerToolSpecInfo ( linker: . ld64, toolPath: toolPath, toolVersion: details. version, architectures: details. architectures)
1966- } )
1967- } catch let e as CommandLineOutputJSONParsingError {
1968- let vCommandLine = [ toolPath. str, " -v " ]
1969- return try await producer. discoveredCommandLineToolSpecInfo ( delegate, nil , vCommandLine, { executionResult in
19701971 let lld = [
19711972 #/LLD (?<version>[\d.]+).*/# ,
19721973 ]
0 commit comments