From d6b4566b3cc540e993d740380750fdd78e82064e Mon Sep 17 00:00:00 2001 From: Brentley Jones Date: Fri, 20 Jul 2018 12:30:46 -0500 Subject: [PATCH] Move config generation to after dependency handling Allows config to reference targer dependencies. --- Sources/XcodeGenKit/PBXProjGenerator.swift | 139 ++++++++++----------- 1 file changed, 69 insertions(+), 70 deletions(-) diff --git a/Sources/XcodeGenKit/PBXProjGenerator.swift b/Sources/XcodeGenKit/PBXProjGenerator.swift index 776a171b..dd967522 100644 --- a/Sources/XcodeGenKit/PBXProjGenerator.swift +++ b/Sources/XcodeGenKit/PBXProjGenerator.swift @@ -419,76 +419,6 @@ public class PBXProjGenerator { var plistPath: Path? var searchForPlist = true - let configs: [ObjectReference] = project.configs.map { config in - var buildSettings = project.getTargetBuildSettings(target: target, config: config) - - // automatically set INFOPLIST_FILE path - if !project.targetHasBuildSetting("INFOPLIST_FILE", basePath: project.basePath, target: target, config: config) { - if searchForPlist { - plistPath = getInfoPlist(target.sources) - searchForPlist = false - } - if let plistPath = plistPath { - buildSettings["INFOPLIST_FILE"] = plistPath.byRemovingBase(path: project.basePath) - } - } - - // automatically calculate bundle id - if let bundleIdPrefix = project.options.bundleIdPrefix, - !project.targetHasBuildSetting("PRODUCT_BUNDLE_IDENTIFIER", basePath: project.basePath, target: target, config: config) { - let characterSet = CharacterSet.alphanumerics.union(CharacterSet(charactersIn: "-.")).inverted - let escapedTargetName = target.name - .replacingOccurrences(of: "_", with: "-") - .components(separatedBy: characterSet) - .joined(separator: "") - buildSettings["PRODUCT_BUNDLE_IDENTIFIER"] = bundleIdPrefix + "." + escapedTargetName - } - - // automatically set test target name - if target.type == .uiTestBundle, - !project.targetHasBuildSetting("TEST_TARGET_NAME", basePath: project.basePath, target: target, config: config) { - for dependency in target.dependencies { - if dependency.type == .target, - let dependencyTarget = project.getTarget(dependency.reference), - dependencyTarget.type == .application { - buildSettings["TEST_TARGET_NAME"] = dependencyTarget.name - break - } - } - } - - // set Carthage search paths - if !carthageDependencies.isEmpty { - let frameworkSearchPaths = "FRAMEWORK_SEARCH_PATHS" - let carthagePlatformBuildPath = "$(PROJECT_DIR)/" + getCarthageBuildPath(platform: target.platform) - var newSettings: [String] = [] - if var array = buildSettings[frameworkSearchPaths] as? [String] { - array.append(carthagePlatformBuildPath) - buildSettings[frameworkSearchPaths] = array - } else if let string = buildSettings[frameworkSearchPaths] as? String { - buildSettings[frameworkSearchPaths] = [string, carthagePlatformBuildPath] - } else { - buildSettings[frameworkSearchPaths] = ["$(inherited)", carthagePlatformBuildPath] - } - } - - var baseConfigurationReference: String? - if let configPath = target.configFiles[config.name] { - baseConfigurationReference = sourceGenerator.getContainedFileReference(path: project.basePath + configPath) - } - let buildConfig = XCBuildConfiguration( - name: config.name, - baseConfigurationReference: baseConfigurationReference, - buildSettings: buildSettings - ) - return createObject(id: config.name + target.name, buildConfig) - } - - let buildConfigList = createObject(id: target.name, XCConfigurationList( - buildConfigurations: configs.map { $0.reference }, - defaultConfigurationName: "" - )) - var dependencies: [String] = [] var targetFrameworkBuildFiles: [String] = [] var copyFrameworksReferences: [String] = [] @@ -753,6 +683,75 @@ public class PBXProjGenerator { } buildPhases += try target.postbuildScripts.map { try generateBuildScript(targetName: target.name, buildScript: $0) } + + let configs: [ObjectReference] = project.configs.map { config in + var buildSettings = project.getTargetBuildSettings(target: target, config: config) + + // automatically set INFOPLIST_FILE path + if !project.targetHasBuildSetting("INFOPLIST_FILE", basePath: project.basePath, target: target, config: config) { + if searchForPlist { + plistPath = getInfoPlist(target.sources) + searchForPlist = false + } + if let plistPath = plistPath { + buildSettings["INFOPLIST_FILE"] = plistPath.byRemovingBase(path: project.basePath) + } + } + + // automatically calculate bundle id + if let bundleIdPrefix = project.options.bundleIdPrefix, + !project.targetHasBuildSetting("PRODUCT_BUNDLE_IDENTIFIER", basePath: project.basePath, target: target, config: config) { + let characterSet = CharacterSet.alphanumerics.union(CharacterSet(charactersIn: "-.")).inverted + let escapedTargetName = target.name + .replacingOccurrences(of: "_", with: "-") + .components(separatedBy: characterSet) + .joined(separator: "") + buildSettings["PRODUCT_BUNDLE_IDENTIFIER"] = bundleIdPrefix + "." + escapedTargetName + } + + // automatically set test target name + if target.type == .uiTestBundle, + !project.targetHasBuildSetting("TEST_TARGET_NAME", basePath: project.basePath, target: target, config: config) { + for dependency in target.dependencies { + if dependency.type == .target, + let dependencyTarget = project.getTarget(dependency.reference), + dependencyTarget.type == .application { + buildSettings["TEST_TARGET_NAME"] = dependencyTarget.name + break + } + } + } + + // set Carthage search paths + if !carthageDependencies.isEmpty { + let frameworkSearchPaths = "FRAMEWORK_SEARCH_PATHS" + let carthagePlatformBuildPath = "$(PROJECT_DIR)/" + getCarthageBuildPath(platform: target.platform) + if var array = buildSettings[frameworkSearchPaths] as? [String] { + array.append(carthagePlatformBuildPath) + buildSettings[frameworkSearchPaths] = array + } else if let string = buildSettings[frameworkSearchPaths] as? String { + buildSettings[frameworkSearchPaths] = [string, carthagePlatformBuildPath] + } else { + buildSettings[frameworkSearchPaths] = ["$(inherited)", carthagePlatformBuildPath] + } + } + + var baseConfigurationReference: String? + if let configPath = target.configFiles[config.name] { + baseConfigurationReference = sourceGenerator.getContainedFileReference(path: project.basePath + configPath) + } + let buildConfig = XCBuildConfiguration( + name: config.name, + baseConfigurationReference: baseConfigurationReference, + buildSettings: buildSettings + ) + return createObject(id: config.name + target.name, buildConfig) + } + + let buildConfigList = createObject(id: target.name, XCConfigurationList( + buildConfigurations: configs.map { $0.reference }, + defaultConfigurationName: "" + )) let targetObject = targetObjects[target.name]!.object