@@ -1298,10 +1298,10 @@ public class BuildPlan {
1298
1298
private var pkgConfigCache = [ SystemLibraryTarget: ( cFlags: [ String] , libs: [ String] ) ] ( )
1299
1299
1300
1300
/// Cache for library information.
1301
- private var externalLibrariesCache = [ BinaryTarget: LibraryInfo] ( )
1301
+ private var externalLibrariesCache = [ BinaryTarget: [ LibraryInfo] ] ( )
1302
1302
1303
1303
/// Cache for tools information.
1304
- private var externalToolsCache = [ BinaryTarget: [ ToolInfo ] ] ( )
1304
+ private var externalExecutablesCache = [ BinaryTarget: [ ExecutableInfo ] ] ( )
1305
1305
1306
1306
private static func makeTestManifestTargets(
1307
1307
_ buildParameters: BuildParameters ,
@@ -1640,11 +1640,13 @@ public class BuildPlan {
1640
1640
}
1641
1641
switch binaryTarget. kind {
1642
1642
case . xcframework:
1643
- let library = try self . parseXCFramework ( for: binaryTarget)
1644
- libraryBinaryPaths. insert ( library. binaryPath)
1645
- case . toolsArchive:
1646
- let tools = try self . parseToolsArchive ( for: binaryTarget)
1647
- tools. forEach { availableTools [ $0. name] = $0. binaryPath }
1643
+ let libraries = try self . parseXCFramework ( for: binaryTarget)
1644
+ libraries. forEach { library in
1645
+ libraryBinaryPaths. insert ( library. libraryPath)
1646
+ }
1647
+ case . artifactsArchive:
1648
+ let tools = try self . parseArtifactsArchive ( for: binaryTarget)
1649
+ tools. forEach { availableTools [ $0. name] = $0. executablePath }
1648
1650
}
1649
1651
case . extension:
1650
1652
continue
@@ -1694,11 +1696,13 @@ public class BuildPlan {
1694
1696
clangTarget. additionalFlags += pkgConfig ( for: target) . cFlags
1695
1697
case let target as BinaryTarget :
1696
1698
if case . xcframework = target. kind {
1697
- let library = try self . parseXCFramework ( for: target)
1698
- if let headersPath = library. headersPath {
1699
- clangTarget. additionalFlags += [ " -I " , headersPath. pathString]
1699
+ let libraries = try self . parseXCFramework ( for: target)
1700
+ libraries. forEach { library in
1701
+ if let headersPath = library. headersPath {
1702
+ clangTarget. additionalFlags += [ " -I " , headersPath. pathString]
1703
+ }
1704
+ clangTarget. libraryBinaryPaths. insert ( library. libraryPath)
1700
1705
}
1701
- clangTarget. libraryBinaryPaths. insert ( library. binaryPath)
1702
1706
}
1703
1707
default : continue
1704
1708
}
@@ -1729,11 +1733,13 @@ public class BuildPlan {
1729
1733
swiftTarget. additionalFlags += pkgConfig ( for: target) . cFlags
1730
1734
case let target as BinaryTarget :
1731
1735
if case . xcframework = target. kind {
1732
- let library = try self . parseXCFramework ( for: target)
1733
- if let headersPath = library. headersPath {
1734
- swiftTarget. additionalFlags += [ " -Xcc " , " -I " , " -Xcc " , headersPath. pathString]
1736
+ let libraries = try self . parseXCFramework ( for: target)
1737
+ libraries. forEach { library in
1738
+ if let headersPath = library. headersPath {
1739
+ swiftTarget. additionalFlags += [ " -Xcc " , " -I " , " -Xcc " , headersPath. pathString]
1740
+ }
1741
+ swiftTarget. libraryBinaryPaths. insert ( library. libraryPath)
1735
1742
}
1736
- swiftTarget. libraryBinaryPaths. insert ( library. binaryPath)
1737
1743
}
1738
1744
default :
1739
1745
break
@@ -1853,7 +1859,7 @@ public class BuildPlan {
1853
1859
}
1854
1860
1855
1861
/// Extracts the library information from an XCFramework.
1856
- private func parseXCFramework( for target: BinaryTarget ) throws -> LibraryInfo {
1862
+ private func parseXCFramework( for target: BinaryTarget ) throws -> [ LibraryInfo ] {
1857
1863
try self . externalLibrariesCache. memoize ( key: target) {
1858
1864
let metadata = try XCFrameworkMetadata . parse ( fileSystem: self . fileSystem, rootPath: target. artifactPath)
1859
1865
@@ -1868,26 +1874,30 @@ public class BuildPlan {
1868
1874
}
1869
1875
1870
1876
let libraryDirectory = target. artifactPath. appending ( component: library. libraryIdentifier)
1871
- let binaryPath = libraryDirectory. appending ( component: library. libraryPath)
1877
+ let libraryPath = libraryDirectory. appending ( component: library. libraryPath)
1872
1878
let headersPath = library. headersPath. map ( { libraryDirectory. appending ( component: $0) } )
1873
1879
1874
- return LibraryInfo ( binaryPath : binaryPath , headersPath: headersPath)
1880
+ return [ LibraryInfo ( libraryPath : libraryPath , headersPath: headersPath) ]
1875
1881
}
1876
1882
}
1877
1883
1878
- /// Extracts the executables info from an executablesArchive
1879
- private func parseToolsArchive ( for target: BinaryTarget ) throws -> [ ToolInfo ] {
1880
- try self . externalToolsCache . memoize ( key: target) {
1881
- let metadata = try ToolsArchiveMetadata . parse ( fileSystem: self . fileSystem, rootPath: target. artifactPath)
1884
+ /// Extracts the artifacts from an artifactsArchive
1885
+ private func parseArtifactsArchive ( for target: BinaryTarget ) throws -> [ ExecutableInfo ] {
1886
+ try self . externalExecutablesCache . memoize ( key: target) {
1887
+ let metadata = try ArtifactsArchiveMetadata . parse ( fileSystem: self . fileSystem, rootPath: target. artifactPath)
1882
1888
1883
- // filter the tools that are relevant to the triple
1884
- let supportedTools = metadata. tools. filter { $0. value. contains ( where: { $0. supportedTriplets. contains ( buildParameters. triple) } ) }
1885
- // flatten the tools for each access
1886
- return supportedTools. reduce ( into: [ ToolInfo] ( ) , { partial, entry in
1887
- let tools = entry. value. map {
1888
- ToolInfo ( name: entry. key, binaryPath: target. artifactPath. appending ( RelativePath ( $0. path) ) )
1889
+ // filter the artifacts that are relevant to the triple
1890
+ // FIXME: this filter needs to become more sophisticated
1891
+ let supportedArtifacts = metadata. artifacts. filter { $0. value. variants. contains ( where: { $0. supportedTriplets. contains ( buildParameters. triple) } ) }
1892
+ // TODO: add support for libraries
1893
+ let executables = supportedArtifacts. filter { $0. value. type == . executable }
1894
+
1895
+ // flatten the results for easy access
1896
+ return executables. reduce ( into: [ ExecutableInfo] ( ) , { partial, entry in
1897
+ let executables = entry. value. variants. map {
1898
+ ExecutableInfo ( name: entry. key, executablePath: target. artifactPath. appending ( RelativePath ( $0. path) ) )
1889
1899
}
1890
- partial. append ( contentsOf: tools )
1900
+ partial. append ( contentsOf: executables )
1891
1901
} )
1892
1902
}
1893
1903
}
@@ -1896,18 +1906,19 @@ public class BuildPlan {
1896
1906
/// Information about a library from a binary dependency.
1897
1907
private struct LibraryInfo : Equatable {
1898
1908
/// The path to the binary.
1899
- let binaryPath : AbsolutePath
1909
+ let libraryPath : AbsolutePath
1900
1910
1901
1911
/// The path to the headers directory, if one exists.
1902
1912
let headersPath : AbsolutePath ?
1903
1913
}
1904
1914
1905
1915
/// Information about an executable from a binary dependency.
1906
- private struct ToolInfo : Equatable {
1916
+ private struct ExecutableInfo : Equatable {
1907
1917
/// The tool name
1908
1918
let name : String
1909
- /// The path to the binary.
1910
- let binaryPath : AbsolutePath
1919
+
1920
+ /// The path to the executable.
1921
+ let executablePath : AbsolutePath
1911
1922
}
1912
1923
1913
1924
private extension Diagnostic . Message {
0 commit comments