From a784a0d2b96208a0fc232484dc437281fd586af9 Mon Sep 17 00:00:00 2001 From: Brentley Jones Date: Mon, 30 Jul 2018 16:17:42 -0500 Subject: [PATCH] Automatically copy public headers for static libraries --- CHANGELOG.md | 1 + Sources/XcodeGenKit/SourceGenerator.swift | 18 ++++++++++++++++-- .../Project.xcodeproj/project.pbxproj | 3 ++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f4768965..95dddbf7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ - Changed default group sorting to be after files [356](https://github.com/yonaskolb/XcodeGen/pull/356) @yonaskolb - Moved `Frameworks` and `Products` top level groups to bottom [356](https://github.com/yonaskolb/XcodeGen/pull/356) @yonaskolb - `modulemap` files are automatically copied to the products directory for static library targets [346](https://github.com/yonaskolb/XcodeGen/pull/346) @brentleyjones +- Public header files are automatically copied to the products directory for static library targets [365](https://github.com/yonaskolb/XcodeGen/pull/365) @brentleyjones #### Internal - Moved brew formula to homebrew core diff --git a/Sources/XcodeGenKit/SourceGenerator.swift b/Sources/XcodeGenKit/SourceGenerator.swift index ad98a97e..d886903f 100644 --- a/Sources/XcodeGenKit/SourceGenerator.swift +++ b/Sources/XcodeGenKit/SourceGenerator.swift @@ -55,7 +55,9 @@ class SourceGenerator { func generateSourceFile(targetType: PBXProductType, targetSource: TargetSource, path: Path, buildPhase: TargetSource.BuildPhase? = nil) -> SourceFile { let fileReference = fileReferencesByPath[path.string.lowercased()]! var settings: [String: Any] = [:] - let chosenBuildPhase: TargetSource.BuildPhase? + var chosenBuildPhase: TargetSource.BuildPhase? + + let headerVisibility = targetSource.headerVisibility ?? .public if let buildPhase = buildPhase { chosenBuildPhase = buildPhase @@ -64,9 +66,21 @@ class SourceGenerator { } else { chosenBuildPhase = getDefaultBuildPhase(for: path, targetType: targetType) } + + if chosenBuildPhase == .headers && targetType == .staticLibrary { + // Static libraries don't support the header build phase + // For public headers they need to be copied + if headerVisibility == .public { + chosenBuildPhase = .copyFiles(TargetSource.BuildPhase.CopyFilesSettings( + destination: .productsDirectory, + subpath: "include/$(PRODUCT_NAME)" + )) + } else { + chosenBuildPhase = nil + } + } if chosenBuildPhase == .headers { - let headerVisibility = targetSource.headerVisibility ?? .public if headerVisibility != .project { // Xcode doesn't write the default of project settings["ATTRIBUTES"] = [headerVisibility.settingName] diff --git a/Tests/Fixtures/TestProject/Project.xcodeproj/project.pbxproj b/Tests/Fixtures/TestProject/Project.xcodeproj/project.pbxproj index fc05f598..66888ee2 100644 --- a/Tests/Fixtures/TestProject/Project.xcodeproj/project.pbxproj +++ b/Tests/Fixtures/TestProject/Project.xcodeproj/project.pbxproj @@ -65,7 +65,7 @@ BF_538515166673 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = VG_256263906698 /* LaunchScreen.storyboard */; }; BF_561304997165 /* Standalone.swift in Sources */ = {isa = PBXBuildFile; fileRef = FR_675266829517 /* Standalone.swift */; }; BF_563614389392 = {isa = PBXBuildFile; fileRef = FR_618687462494 /* iMessageExtension.appex */; }; - BF_607543323797 = {isa = PBXBuildFile; fileRef = FR_698230898030 /* StaticLibrary_ObjC.h */; settings = {ATTRIBUTES = (Public, ); }; }; + BF_607543323797 /* StaticLibrary_ObjC.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = FR_698230898030 /* StaticLibrary_ObjC.h */; }; BF_612351978356 /* Interface.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = VG_264279911176 /* Interface.storyboard */; }; BF_624802436672 /* FrameworkFile.swift in Sources */ = {isa = PBXBuildFile; fileRef = FR_172952167809 /* FrameworkFile.swift */; }; BF_632297340262 /* StaticLibrary_ObjC.m in Sources */ = {isa = PBXBuildFile; fileRef = "FR_698230898030-1" /* StaticLibrary_ObjC.m */; }; @@ -214,6 +214,7 @@ dstPath = "include/$(PRODUCT_NAME)"; dstSubfolderSpec = 16; files = ( + BF_607543323797 /* StaticLibrary_ObjC.h in CopyFiles */, BF_755064703081 /* module.modulemap in CopyFiles */, ); runOnlyForDeploymentPostprocessing = 0;