From 94a0fc630f28d3fbed70805ccccc78b2f09cb34d Mon Sep 17 00:00:00 2001 From: Sho Ikeda Date: Fri, 13 Oct 2017 23:36:07 +0900 Subject: [PATCH] Fix CocoaPods-generated projects support when running `archive` action Such projects have unexpected `CONFIGURATION_BUILD_DIR` build setting which is appending a target name to a common `CONFIGURATION_BUILD_DIR` value. That is problematic for our path building. --- Source/CarthageKit/BuildSettings.swift | 39 ++++++++++++++++++-------- 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/Source/CarthageKit/BuildSettings.swift b/Source/CarthageKit/BuildSettings.swift index 4a38e5a0a2..6c3de2fbe2 100644 --- a/Source/CarthageKit/BuildSettings.swift +++ b/Source/CarthageKit/BuildSettings.swift @@ -187,18 +187,33 @@ public struct BuildSettings { let r1 = self["TARGET_NAME"] guard let schemeOrTarget = arguments.scheme?.name ?? r1.value else { return r1 } - let r2 = self["CONFIGURATION"] - guard let configuration = r2.value else { return r2 } - - // A value almost certainly beginning with `-` or (lacking said value) an - // empty string to append without effect in the path below because Xcode - // expects the path like that. - let effectivePlatformName = self["EFFECTIVE_PLATFORM_NAME"].value ?? "" - - // e.g., - // - ArchiveIntermediates/Archimedes Mac/BuildProductsPath/Release - // - ArchiveIntermediates/Archimedes iOS/BuildProductsPath/Release-iphoneos - let path = "ArchiveIntermediates/\(schemeOrTarget)/BuildProductsPath/\(configuration)\(effectivePlatformName)" + let basePath = "ArchiveIntermediates/\(schemeOrTarget)/BuildProductsPath" + let pathComponent: String + + if + let buildDir = self["BUILD_DIR"].value, + let builtProductsDir = self["BUILT_PRODUCTS_DIR"].value, + builtProductsDir.hasPrefix(buildDir) + { + // This is required to support CocoaPods-generated projects. + // See https://github.com/AliSoftware/Reusable/issues/50#issuecomment-336434345 for the details. + pathComponent = String(builtProductsDir[buildDir.endIndex...]) // e.g., /Release-iphoneos/Reusable-iOS + } else { + let r2 = self["CONFIGURATION"] + guard let configuration = r2.value else { return r2 } + + // A value almost certainly beginning with `-` or (lacking said value) an + // empty string to append without effect in the path below because Xcode + // expects the path like that. + let effectivePlatformName = self["EFFECTIVE_PLATFORM_NAME"].value ?? "" + + // e.g., + // - Release + // - Release-iphoneos + pathComponent = "\(configuration)\(effectivePlatformName)" + } + + let path = (basePath as NSString).appendingPathComponent(pathComponent) return .success(path) }