From 6a5604f4b0750b5d6f7f5f188ce4dfbbaa1db60b Mon Sep 17 00:00:00 2001 From: Joseph Colicchio Date: Tue, 1 Dec 2020 20:46:39 -0600 Subject: [PATCH] Project Reference LegacyTarget Crash Fix (#982) * Avoid force-unwrapping and allow `.none` type target to continue * Add changelog entry --- CHANGELOG.md | 3 +++ Sources/XcodeGenKit/PBXProjGenerator.swift | 8 ++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ed6127e6..b9a46585 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,9 @@ #### Internal - Updated to Yams 4.0.0 [#984](https://github.com/yonaskolb/XcodeGen/pull/984) @swiftty +#### Fixed +- Remove force-unwrapping causing crash for `LegacyTarget`s [#982](https://github.com/yonaskolb/XcodeGen/pull/982) @jcolicchio + ## 2.18.0 #### Added diff --git a/Sources/XcodeGenKit/PBXProjGenerator.swift b/Sources/XcodeGenKit/PBXProjGenerator.swift index 8cce6abf..55e13ce7 100644 --- a/Sources/XcodeGenKit/PBXProjGenerator.swift +++ b/Sources/XcodeGenKit/PBXProjGenerator.swift @@ -402,7 +402,7 @@ public class PBXProjGenerator { let productProxy = addObject( PBXContainerItemProxy( containerPortal: .fileReference(projectFileReference), - remoteGlobalID: .object(targetObject.product!), + remoteGlobalID: targetObject.product.flatMap(PBXContainerItemProxy.RemoteGlobalID.object), proxyType: .reference, remoteInfo: target ) @@ -417,7 +417,7 @@ public class PBXProjGenerator { let productReferenceProxy = addObject( PBXReferenceProxy( - fileType: Xcode.fileType(path: Path(targetObject.productNameWithExtension()!)), + fileType: targetObject.productNameWithExtension().flatMap { Xcode.fileType(path: Path($0)) }, path: path, remote: productProxy, sourceTree: .buildProductsDir @@ -433,14 +433,14 @@ public class PBXProjGenerator { ) ) - guard let productType = targetObject.productType, - let buildConfigurations = targetObject.buildConfigurationList?.buildConfigurations, + guard let buildConfigurations = targetObject.buildConfigurationList?.buildConfigurations, let defaultConfigurationName = targetObject.buildConfigurationList?.defaultConfigurationName, let defaultConfiguration = buildConfigurations.first(where: { $0.name == defaultConfigurationName }) ?? buildConfigurations.first else { fatalError("Missing target info") } + let productType: PBXProductType = targetObject.productType ?? .none let buildSettings = defaultConfiguration.buildSettings let settings = Settings(buildSettings: buildSettings, configSettings: [:], groups: []) let deploymentTargetString = buildSettings[platform.deploymentTargetSetting] as? String