Skip to content

Commit a2128cb

Browse files
authored
Fix use of resources when using XCBuild (#5932)
We were not embedding the resource bundle correctly when using XCBuild. This also fixes the delegate so that target and task diagnostics get emitted to the console. rdar://102785735
1 parent f157ff9 commit a2128cb

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

Sources/SPMTestSupport/PIFTester.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public final class PIFProjectTester {
5555
fileprivate init(project: PIF.Project, targetMap: [PIF.GUID: PIF.BaseTarget]) throws {
5656
self.project = project
5757
self.targetMap = targetMap
58-
self.fileMap = try collectFiles(from: project.groupTree, parentPath: project.path, projectPath: project.path)
58+
self.fileMap = try collectFiles(from: project.groupTree, parentPath: project.path, projectPath: project.path, builtProductsPath: project.path)
5959
}
6060

6161
public func checkTarget(_ guid: PIF.GUID, file: StaticString = #file, line: UInt = #line, body: ((PIFTargetTester) -> Void)? = nil) {
@@ -291,7 +291,8 @@ public final class PIFBuildSettingsTester {
291291
private func collectFiles(
292292
from reference: PIF.Reference,
293293
parentPath: AbsolutePath,
294-
projectPath: AbsolutePath
294+
projectPath: AbsolutePath,
295+
builtProductsPath: AbsolutePath
295296
) throws -> [PIF.GUID: String] {
296297
let referencePath: AbsolutePath
297298
switch reference.sourceTree {
@@ -302,7 +303,7 @@ private func collectFiles(
302303
case .sourceRoot:
303304
referencePath = try AbsolutePath(validating: reference.path, relativeTo: projectPath)
304305
case .builtProductsDir:
305-
return [:]
306+
referencePath = try AbsolutePath(validating: reference.path, relativeTo: builtProductsPath)
306307
}
307308

308309
var files: [PIF.GUID: String] = [:]
@@ -312,7 +313,7 @@ private func collectFiles(
312313
files[reference.guid] = referencePath.pathString
313314
} else if let group = reference as? PIF.Group {
314315
for child in group.children {
315-
let childFiles = try collectFiles(from: child, parentPath: referencePath, projectPath: projectPath)
316+
let childFiles = try collectFiles(from: child, parentPath: referencePath, projectPath: projectPath, builtProductsPath: builtProductsPath)
316317
files.merge(childFiles, uniquingKeysWith: { _, _ in fatalError("non-unique GUID") })
317318
}
318319
}

Sources/XCBuildSupport/PIFBuilder.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -852,6 +852,9 @@ final class PackagePIFProjectBuilder: PIFProjectBuilder {
852852
resourcesTarget.addResourceFile(resourceFile)
853853
}
854854

855+
let targetGroup = groupTree.addGroup(path: "/", sourceTree: .group)
856+
pifTarget.addResourceFile(targetGroup.addFileReference(path: "\(bundleName).bundle", sourceTree: .builtProductsDir))
857+
855858
return bundleName
856859
}
857860

Sources/XCBuildSupport/XCBuildDelegate.swift

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,20 @@ extension XCBuildDelegate: XCBuildOutputParserDelegate {
8989
self.outputStream <<< "\n"
9090
self.outputStream.flush()
9191
}
92+
case .taskDiagnostic(let info):
93+
queue.async {
94+
self.progressAnimation.clear()
95+
self.outputStream <<< info.message
96+
self.outputStream <<< "\n"
97+
self.outputStream.flush()
98+
}
99+
case .targetDiagnostic(let info):
100+
queue.async {
101+
self.progressAnimation.clear()
102+
self.outputStream <<< info.message
103+
self.outputStream <<< "\n"
104+
self.outputStream.flush()
105+
}
92106
case .buildOutput(let info):
93107
queue.async {
94108
self.progressAnimation.clear()
@@ -116,7 +130,7 @@ extension XCBuildDelegate: XCBuildOutputParserDelegate {
116130
self.buildSystem.delegate?.buildSystem(self.buildSystem, didFinishWithResult: true)
117131
}
118132
}
119-
default:
133+
case .buildStarted, .preparationComplete, .targetUpToDate, .targetStarted, .targetComplete, .taskUpToDate:
120134
break
121135
}
122136
}

0 commit comments

Comments
 (0)