From d1efa9ac6414effa5007523360eaba43df2f2cd7 Mon Sep 17 00:00:00 2001 From: mironal Date: Wed, 4 Oct 2017 14:46:18 +0900 Subject: [PATCH 1/2] Add outputpaths to carthage copy-framewors script According to Carthage README, the Output Files should be set to `carthage copy-frameworks` script. https://github.com/Carthage/Carthage#if-youre-building-for-ios-tvos-or-watchos --- .../project.pbxproj | 74 +++++++++++++++++++ Fixtures/TestProject/spec.yml | 1 + Sources/XcodeGenKit/PBXProjGenerator.swift | 3 +- 3 files changed, 77 insertions(+), 1 deletion(-) diff --git a/Fixtures/TestProject/GeneratedProject.xcodeproj/project.pbxproj b/Fixtures/TestProject/GeneratedProject.xcodeproj/project.pbxproj index 14a7e34a..59524070 100644 --- a/Fixtures/TestProject/GeneratedProject.xcodeproj/project.pbxproj +++ b/Fixtures/TestProject/GeneratedProject.xcodeproj/project.pbxproj @@ -17,6 +17,7 @@ BF3862341101 /* MyFramework.framework in Copy Files */ = {isa = PBXBuildFile; fileRef = FR2993497801 /* MyFramework.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; BF4946816301 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = VG1473702401 /* Main.storyboard */; }; BF5986511201 = {isa = PBXBuildFile; fileRef = FR6523263101 /* TestProject.app */; }; + BF6182896901 /* Result.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FR9215298301 /* Result.framework */; }; BF9001417701 /* TestProjectTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FR6877173101 /* TestProjectTests.swift */; }; BF9155249601 /* FrameworkFile.swift in Sources */ = {isa = PBXBuildFile; fileRef = FR7078510801 /* FrameworkFile.swift */; }; /* End PBXBuildFile section */ @@ -68,9 +69,29 @@ FR6877173101 /* TestProjectTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestProjectTests.swift; sourceTree = ""; }; FR7078510801 /* FrameworkFile.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FrameworkFile.swift; sourceTree = ""; }; FR7740960501 /* MyFramework.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MyFramework.h; sourceTree = ""; }; + FR9215298301 /* Result.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Result.framework; sourceTree = ""; }; /* End PBXFileReference section */ +/* Begin PBXFrameworksBuildPhase section */ + FBP652326301 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + BF6182896901 /* Result.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + /* Begin PBXGroup section */ + G19527407101 /* Frameworks */ = { + isa = PBXGroup; + children = ( + G28836901501 /* Carthage */, + ); + name = Frameworks; + sourceTree = ""; + }; G26536595301 /* TestProjectTests */ = { isa = PBXGroup; children = ( @@ -81,6 +102,15 @@ path = TestProjectTests; sourceTree = ""; }; + G28836901501 /* Carthage */ = { + isa = PBXGroup; + children = ( + G47994500501 /* iOS */, + ); + name = Carthage; + path = Carthage/Build; + sourceTree = ""; + }; G29934978701 /* MyFramework */ = { isa = PBXGroup; children = ( @@ -92,6 +122,15 @@ path = MyFramework; sourceTree = ""; }; + G47994500501 /* iOS */ = { + isa = PBXGroup; + children = ( + FR9215298301 /* Result.framework */, + ); + name = iOS; + path = iOS; + sourceTree = ""; + }; G65232631501 /* TestProject */ = { isa = PBXGroup; children = ( @@ -124,6 +163,7 @@ G65232631501 /* TestProject */, G26536595301 /* TestProjectTests */, G86202385201 /* Products */, + G19527407101 /* Frameworks */, ); sourceTree = ""; }; @@ -206,7 +246,9 @@ SBP652326301 /* Sources */, RBP652326301 /* Resources */, HBP652326301 /* Headers */, + FBP652326301 /* Frameworks */, CFBP50493301 /* CopyFiles */, + SSBP58567701 /* Carthage */, SSBP24648001 /* Strip Unused Architectures from Frameworks */, SSBP19207501 /* Swiftlint */, ); @@ -313,6 +355,22 @@ shellPath = /bin/sh; shellScript = "if which swiftlint >/dev/null; then\n swiftlint\nelse\n echo \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi\n"; }; + SSBP58567701 /* Carthage */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + "$(SRCROOT)/Carthage/Build/iOS/Result.framework", + ); + name = Carthage; + outputPaths = ( + "$(BUILT_PRODUCTS_DIR)/$(FRAMEWORKS_FOLDER_PATH)/Result.framework", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "/usr/local/bin/carthage copy-frameworks\n"; + }; /* End PBXShellScriptBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ @@ -409,6 +467,10 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + FRAMEWORK_SEARCH_PATHS = ( + "$(inherited)", + "$(PROJECT_DIR)/Carthage/Build/iOS", + ); INFOPLIST_FILE = TestProject/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 10.0; LD_RUNPATH_SEARCH_PATHS = ( @@ -482,6 +544,10 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; BUNDLE_LOADER = "$(TEST_HOST)"; + FRAMEWORK_SEARCH_PATHS = ( + "$(inherited)", + "$(PROJECT_DIR)/Carthage/Build/iOS", + ); INFOPLIST_FILE = TestProjectTests/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 10.0; LD_RUNPATH_SEARCH_PATHS = ( @@ -501,6 +567,10 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + FRAMEWORK_SEARCH_PATHS = ( + "$(inherited)", + "$(PROJECT_DIR)/Carthage/Build/iOS", + ); INFOPLIST_FILE = TestProject/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 10.0; LD_RUNPATH_SEARCH_PATHS = ( @@ -566,6 +636,10 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; BUNDLE_LOADER = "$(TEST_HOST)"; + FRAMEWORK_SEARCH_PATHS = ( + "$(inherited)", + "$(PROJECT_DIR)/Carthage/Build/iOS", + ); INFOPLIST_FILE = TestProjectTests/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 10.0; LD_RUNPATH_SEARCH_PATHS = ( diff --git a/Fixtures/TestProject/spec.yml b/Fixtures/TestProject/spec.yml index da59c0a8..05680d63 100644 --- a/Fixtures/TestProject/spec.yml +++ b/Fixtures/TestProject/spec.yml @@ -12,6 +12,7 @@ targets: INFOPLIST_FILE: TestProject/Info.plist dependencies: - target: MyFramework + - carthage: Result scheme: testTargets: - TestProjectTests diff --git a/Sources/XcodeGenKit/PBXProjGenerator.swift b/Sources/XcodeGenKit/PBXProjGenerator.swift index d169b08f..65a47ad5 100644 --- a/Sources/XcodeGenKit/PBXProjGenerator.swift +++ b/Sources/XcodeGenKit/PBXProjGenerator.swift @@ -388,7 +388,8 @@ public class PBXProjGenerator { if target.type.isApp && target.platform != .macOS { let inputPaths = Set(carthageFrameworksToEmbed).map { "$(SRCROOT)/\(carthageBuildPath)/\(target.platform)/\($0)\($0.contains(".") ? "" : ".framework")" } - let carthageScript = PBXShellScriptBuildPhase(reference: generateUUID(PBXShellScriptBuildPhase.self, "Carthage" + target.name), files: [], name: "Carthage", inputPaths: inputPaths, outputPaths: [], shellPath: "/bin/sh", shellScript: "/usr/local/bin/carthage copy-frameworks\n") + let outputPaths = Set(carthageFrameworksToEmbed).map { "$(BUILT_PRODUCTS_DIR)/$(FRAMEWORKS_FOLDER_PATH)/\($0)\($0.contains(".") ? "" : ".framework")" } + let carthageScript = PBXShellScriptBuildPhase(reference: generateUUID(PBXShellScriptBuildPhase.self, "Carthage" + target.name), files: [], name: "Carthage", inputPaths: inputPaths, outputPaths: outputPaths, shellPath: "/bin/sh", shellScript: "/usr/local/bin/carthage copy-frameworks\n") addObject(carthageScript) buildPhases.append(carthageScript.reference) } From f6d6f17f1b0015c8ca467c8b1b6b5160b1e198c4 Mon Sep 17 00:00:00 2001 From: mironal Date: Thu, 5 Oct 2017 10:53:08 +0900 Subject: [PATCH 2/2] sort carthage dependencies --- Sources/XcodeGenKit/PBXProjGenerator.swift | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Sources/XcodeGenKit/PBXProjGenerator.swift b/Sources/XcodeGenKit/PBXProjGenerator.swift index 65a47ad5..22c09654 100644 --- a/Sources/XcodeGenKit/PBXProjGenerator.swift +++ b/Sources/XcodeGenKit/PBXProjGenerator.swift @@ -381,14 +381,16 @@ public class PBXProjGenerator { buildPhases.append(copyFilesPhase.reference) } - let carthageFrameworksToEmbed = carthageDependencies - .filter { ($0.embed ?? true) } - .map { $0.reference } + let carthageFrameworksToEmbed = Array(Set(carthageDependencies + .filter { $0.embed ?? true } + .map { $0.reference })) + .sorted() + if !carthageFrameworksToEmbed.isEmpty { if target.type.isApp && target.platform != .macOS { - let inputPaths = Set(carthageFrameworksToEmbed).map { "$(SRCROOT)/\(carthageBuildPath)/\(target.platform)/\($0)\($0.contains(".") ? "" : ".framework")" } - let outputPaths = Set(carthageFrameworksToEmbed).map { "$(BUILT_PRODUCTS_DIR)/$(FRAMEWORKS_FOLDER_PATH)/\($0)\($0.contains(".") ? "" : ".framework")" } + let inputPaths = carthageFrameworksToEmbed.map { "$(SRCROOT)/\(carthageBuildPath)/\(target.platform)/\($0)\($0.contains(".") ? "" : ".framework")" } + let outputPaths = carthageFrameworksToEmbed.map { "$(BUILT_PRODUCTS_DIR)/$(FRAMEWORKS_FOLDER_PATH)/\($0)\($0.contains(".") ? "" : ".framework")" } let carthageScript = PBXShellScriptBuildPhase(reference: generateUUID(PBXShellScriptBuildPhase.self, "Carthage" + target.name), files: [], name: "Carthage", inputPaths: inputPaths, outputPaths: outputPaths, shellPath: "/bin/sh", shellScript: "/usr/local/bin/carthage copy-frameworks\n") addObject(carthageScript) buildPhases.append(carthageScript.reference)