Skip to content

Commit

Permalink
Embed ExtensionKit Extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
mtj0928 committed Jul 17, 2022
1 parent c1d5c65 commit 0371a6c
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 2 deletions.
15 changes: 13 additions & 2 deletions Sources/XcodeGenKit/PBXProjGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,7 @@ public class PBXProjGenerator {
var copyWatchReferences: [PBXBuildFile] = []
var packageDependencies: [XCSwiftPackageProductDependency] = []
var extensions: [PBXBuildFile] = []
var extensionKitExtensions: [PBXBuildFile] = []
var systemExtensions: [PBXBuildFile] = []
var appClips: [PBXBuildFile] = []
var carthageFrameworksToEmbed: [String] = []
Expand Down Expand Up @@ -735,9 +736,11 @@ public class PBXProjGenerator {
if dependency.copyPhase != nil {
// custom copy takes precedence
customCopyDependenciesReferences.append(embedFile)
} else if dependencyTarget.type.isExtension {
} else if dependencyTarget.type.isExtension && dependencyTarget.type != .extensionKitExtension {
// embed app extension
extensions.append(embedFile)
} else if dependencyTarget.type == .extensionKitExtension {
extensionKitExtensions.append(embedFile)
} else if dependencyTarget.type.isSystemExtension {
// embed system extension
systemExtensions.append(embedFile)
Expand Down Expand Up @@ -1156,13 +1159,21 @@ public class PBXProjGenerator {

if !extensions.isEmpty {

let copyFilesPhase = addObject(
let copyFilesPhase = addObject(
getPBXCopyFilesBuildPhase(dstSubfolderSpec: .plugins, name: "Embed App Extensions", files: extensions)
)

buildPhases.append(copyFilesPhase)
}

if !extensionKitExtensions.isEmpty {

let copyFilesPhase = addObject(
getPBXCopyFilesBuildPhase(dstSubfolderSpec: .productsDirectory, dstPath: "$(EXTENSIONS_FOLDER_PATH)", name: "Embed ExtensionKit Extensions", files: extensionKitExtensions)
)
buildPhases.append(copyFilesPhase)
}

if !systemExtensions.isEmpty {

let copyFilesPhase = addObject(
Expand Down
44 changes: 44 additions & 0 deletions Tests/XcodeGenKitTests/ProjectGeneratorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2094,6 +2094,50 @@ class ProjectGeneratorTests: XCTestCase {
try expectCopyPhase(in: pbxProject, withFilePaths: ["extA.appex"], toSubFolder: .executables, dstPath: "test")
}
}

$0.context("extensionKit") {

let extA = Target(
name: "extA",
type: .extensionKitExtension,
platform: .macOS
)
let extB = Target(
name: "extB",
type: .extensionKitExtension,
platform: .macOS
)

$0.it("embeds them into plugins without copy phase spec") {

// given
let dependencies = [
Dependency(type: .target, reference: extA.name, embed: true),
Dependency(type: .target, reference: extB.name, embed: false),
]

// when
let pbxProject = try generateProjectForApp(withDependencies: dependencies, targets: [extA, extB])

// then
try expectCopyPhase(in: pbxProject, withFilePaths: ["extA.appex"], toSubFolder: .productsDirectory, dstPath: "$(EXTENSIONS_FOLDER_PATH)")
}

$0.it("embeds them into custom location with copy phase spec") {

// given
let dependencies = [
Dependency(type: .target, reference: extA.name, embed: true, copyPhase: BuildPhaseSpec.CopyFilesSettings(destination: .productsDirectory, subpath: "test", phaseOrder: .postCompile)),
Dependency(type: .target, reference: extB.name, embed: false, copyPhase: BuildPhaseSpec.CopyFilesSettings(destination: .productsDirectory, subpath: "test", phaseOrder: .postCompile)),
]

// when
let pbxProject = try generateProjectForApp(withDependencies: dependencies, targets: [extA, extB])

// then
try expectCopyPhase(in: pbxProject, withFilePaths: ["extA.appex"], toSubFolder: .productsDirectory, dstPath: "test")
}
}

$0.context("commandLineTool") {

Expand Down

0 comments on commit 0371a6c

Please sign in to comment.