Skip to content

Commit fac1c64

Browse files
committed
fixup
1 parent 7045818 commit fac1c64

File tree

3 files changed

+29
-17
lines changed

3 files changed

+29
-17
lines changed

Sources/Build/LLBuildManifestBuilder.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,18 +171,18 @@ extension LLBuildManifestBuilder {
171171
/// Returns the virtual node that will build the entire bundle.
172172
private func createResourcesBundle(
173173
for target: TargetBuildDescription
174-
) -> Node? {
174+
) throws -> Node? {
175175
guard let bundlePath = target.bundlePath else { return nil }
176176

177177
var outputs: [Node] = []
178178

179-
let infoPlistDestination = try! RelativePath(validating: "Info.plist") // try! safe
179+
let infoPlistDestination = try RelativePath(validating: "Info.plist")
180180

181181
// Create a copy command for each resource file.
182182
for resource in target.resources {
183183
switch resource.rule {
184184
case .copy, .process:
185-
let destination = bundlePath.appending(resource.destination)
185+
let destination = try bundlePath.appending(resource.destination)
186186
let (_, output) = addCopyCommand(from: resource.path, to: destination)
187187
outputs.append(output)
188188
case .embedInCode:
@@ -604,7 +604,7 @@ extension LLBuildManifestBuilder {
604604
// don't need to block building of a module until its resources are assembled but
605605
// we don't currently have a good way to express that resources should be built
606606
// whenever a module is being built.
607-
if let resourcesNode = createResourcesBundle(for: .swift(target)) {
607+
if let resourcesNode = try createResourcesBundle(for: .swift(target)) {
608608
inputs.append(resourcesNode)
609609
}
610610

@@ -798,7 +798,7 @@ extension LLBuildManifestBuilder {
798798
// don't need to block building of a module until its resources are assembled but
799799
// we don't currently have a good way to express that resources should be built
800800
// whenever a module is being built.
801-
if let resourcesNode = createResourcesBundle(for: .clang(target)) {
801+
if let resourcesNode = try createResourcesBundle(for: .clang(target)) {
802802
inputs.append(resourcesNode)
803803
}
804804

Sources/PackageLoading/TargetSourcesBuilder.swift

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,10 @@ public struct TargetSourcesBuilder {
174174
let ignored = pathToRule.filter { $0.value == .ignored }.map { $0.key }
175175
let others = pathToRule.filter { $0.value == .none }.map { $0.key }
176176

177-
diagnoseConflictingResources(in: resources)
177+
try diagnoseConflictingResources(in: resources)
178178
diagnoseCopyConflictsWithLocalizationDirectories(in: resources)
179179
diagnoseLocalizedAndUnlocalizedVariants(in: resources)
180-
diagnoseInfoPlistConflicts(in: resources)
180+
try diagnoseInfoPlistConflicts(in: resources)
181181
diagnoseInvalidResource(in: target.resources)
182182

183183
// It's an error to contain mixed language source files.
@@ -309,10 +309,10 @@ public struct TargetSourcesBuilder {
309309
return Self.resource(for: path, with: rule, defaultLocalization: defaultLocalization, targetName: target.name, targetPath: targetPath, observabilityScope: observabilityScope)
310310
}
311311

312-
private func diagnoseConflictingResources(in resources: [Resource]) {
313-
let duplicateResources = resources.spm_findDuplicateElements(by: \.destination)
312+
private func diagnoseConflictingResources(in resources: [Resource]) throws {
313+
let duplicateResources = resources.spm_findDuplicateElements(by: \.destinationForGrouping)
314314
for resources in duplicateResources {
315-
self.observabilityScope.emit(.conflictingResource(path: resources[0].destination, targetName: target.name))
315+
try self.observabilityScope.emit(.conflictingResource(path: resources[0].destination, targetName: target.name))
316316

317317
for resource in resources {
318318
let relativePath = resource.path.relative(to: targetPath)
@@ -346,9 +346,9 @@ public struct TargetSourcesBuilder {
346346
}
347347
}
348348

349-
private func diagnoseInfoPlistConflicts(in resources: [Resource]) {
349+
private func diagnoseInfoPlistConflicts(in resources: [Resource]) throws {
350350
for resource in resources {
351-
if try! resource.destination == RelativePath(validating: "Info.plist") /* try! safe */ {
351+
if try resource.destination == RelativePath(validating: "Info.plist") {
352352
self.observabilityScope.emit(.infoPlistResourceConflict(
353353
path: resource.path.relative(to: targetPath),
354354
targetName: target.name))
@@ -770,3 +770,13 @@ extension PackageReference.Kind {
770770
}
771771
}
772772
}
773+
774+
extension PackageModel.Resource {
775+
fileprivate var destinationForGrouping: RelativePath? {
776+
do {
777+
return try self.destination
778+
} catch {
779+
return .none
780+
}
781+
}
782+
}

Sources/PackageModel/Resource.swift

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,13 @@ public struct Resource: Codable, Equatable {
2424

2525
/// The relative location of the resource in the resource bundle.
2626
public var destination: RelativePath {
27-
switch self.rule {
28-
case .process(.some(let localization)):
29-
return try! RelativePath(validating: "\(localization).\(Self.localizationDirectoryExtension)/\(path.basename)") // try! safe
30-
default:
31-
return try! RelativePath(validating: path.basename) // try! safe
27+
get throws {
28+
switch self.rule {
29+
case .process(.some(let localization)):
30+
return try RelativePath(validating: "\(localization).\(Self.localizationDirectoryExtension)/\(path.basename)")
31+
default:
32+
return try RelativePath(validating: path.basename)
33+
}
3234
}
3335
}
3436

0 commit comments

Comments
 (0)