Skip to content

Commit 91156ab

Browse files
committed
Fix mixed target builds when public headers path includes directories
- When constructing the VFSOverlay for the all-product-headers.yaml, the code did not recursively search all paths in the public headers directory.
1 parent 2d2d3fc commit 91156ab

File tree

2 files changed

+47
-11
lines changed

2 files changed

+47
-11
lines changed

Sources/Basics/VFSOverlay.swift

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ public struct VFSOverlay: Encodable {
5050
case contents
5151
}
5252

53-
private let contents: [File]
53+
private let contents: [Resource]
5454

55-
public init(name: String, contents: [File]) {
55+
public init(name: String, contents: [Resource]) {
5656
self.contents = contents
5757
super.init(name: name, type: "directory")
5858
}
@@ -89,3 +89,44 @@ public struct VFSOverlay: Encodable {
8989
try JSONEncoder.makeWithDefaults(prettified: false).encode(path: path, fileSystem: fileSystem, self)
9090
}
9191
}
92+
93+
public extension VFSOverlay {
94+
/// Returns a tree of `VFSOverlay` resources for a given directory in the form of an array. Each item
95+
/// in this array will be a resource (either file or directory) from the top most level of the given directory.
96+
/// - Parameters:
97+
/// - directoryPath: The directory to recursively search for resources in.
98+
/// - fileSystem: The file system to search.
99+
/// - Returns: An array of `VFSOverlay.Resource`s from the given directory.
100+
/// - Throws: An error if the given path is a not a directory.
101+
/// - Note: This API will recursively scan all subpaths of the given path.
102+
static func overlayResources(
103+
directoryPath: AbsolutePath,
104+
fileSystem: FileSystem
105+
) throws -> [VFSOverlay.Resource] {
106+
return
107+
// Absolute path to each resource in the directory.
108+
try fileSystem.getDirectoryContents(directoryPath).map(directoryPath.appending(component:))
109+
// Map each path to a corresponding VFSOverlay, recursing for directories.
110+
.compactMap { resourcePath in
111+
if fileSystem.isDirectory(resourcePath) {
112+
return VFSOverlay.Directory(
113+
name: resourcePath.basename,
114+
contents:
115+
try overlayResources(
116+
directoryPath: resourcePath,
117+
fileSystem: fileSystem
118+
)
119+
)
120+
} else if fileSystem.isFile(resourcePath) {
121+
return VFSOverlay.File(
122+
name: resourcePath.basename,
123+
externalContents: resourcePath.pathString
124+
)
125+
} else {
126+
// This case is not expected to be reached as a resource
127+
// should be either a file or directory.
128+
return nil
129+
}
130+
}
131+
}
132+
}

Sources/Build/BuildPlan.swift

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1453,15 +1453,10 @@ public final class MixedTargetBuildDescription {
14531453
name: publicHeadersPath.pathString,
14541454
contents:
14551455
// Public headers
1456-
try Set(fileSystem.getDirectoryContents(publicHeadersPath)
1457-
.map(publicHeadersPath.appending(component:)))
1458-
.filter(publicHeadersPath.isAncestor(of:))
1459-
.map { headerPath in
1460-
VFSOverlay.File(
1461-
name: headerPath.basename,
1462-
externalContents: headerPath.pathString
1463-
)
1464-
}
1456+
try VFSOverlay.overlayResources(
1457+
directoryPath: publicHeadersPath,
1458+
fileSystem: fileSystem
1459+
)
14651460
),
14661461
VFSOverlay.Directory(
14671462
name: buildArtifactDirectory.pathString,

0 commit comments

Comments
 (0)