Skip to content

Commit c6f94c8

Browse files
authored
Merge pull request #6 from amplitude/skip-binary-targets
Add an option to skip project generation for binary targets (vs throwing an error)
2 parents 15ba81b + 9bb228b commit c6f94c8

File tree

5 files changed

+19
-5
lines changed

5 files changed

+19
-5
lines changed

Sources/CreateXCFramework/Command+Options.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ extension Command {
7777
@Flag(help: .hidden)
7878
var githubAction: Bool = false
7979

80+
@Flag(help: "Skip binary targets for project generation. Useful for creating and distributing a library from one Package.swift")
81+
var skipBinaryTargets: Bool = false
8082

8183
// MARK: - Targets
8284

Sources/CreateXCFramework/PackageInfo.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ struct PackageInfo {
147147

148148
// check the graph for binary targets
149149
let binary = self.graph.allTargets.filter { $0.type == .binary }
150-
if binary.isEmpty == false {
150+
if !options.skipBinaryTargets, binary.isEmpty == false {
151151
errors.append(.containsBinaryTargets(binary.map(\.name)))
152152
}
153153

Sources/CreateXCFramework/ProjectGenerator.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ struct ProjectGenerator {
8484
extraFiles: [],
8585
options: XcodeprojOptions (
8686
xcconfigOverrides: (self.package.overridesXcconfig?.path).flatMap { try AbsolutePath(validating: $0) },
87-
useLegacySchemeGenerator: true
87+
useLegacySchemeGenerator: true,
88+
skipBinaryTargets: package.options.skipBinaryTargets
8889
),
8990
fileSystem: localFileSystem,
9091
observabilityScope: self.package.observabilitySystem.topScope
@@ -97,7 +98,8 @@ struct ProjectGenerator {
9798
extraFiles: [],
9899
options: XcodeprojOptions (
99100
xcconfigOverrides: (self.package.overridesXcconfig?.path).flatMap { AbsolutePath($0) },
100-
useLegacySchemeGenerator: true
101+
useLegacySchemeGenerator: true,
102+
skipBinaryTargets: package.options.skipBinaryTargets
101103
),
102104
diagnostics: self.package.diagnostics
103105
)

Sources/Xcodeproj/generate.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,24 @@ public struct XcodeprojOptions {
4545
/// Reference to manifest loader, if present.
4646
public var manifestLoader: ManifestLoader?
4747

48+
public var skipBinaryTargets: Bool
49+
4850
public init(
4951
flags: PackageModel.BuildFlags = PackageModel.BuildFlags(),
5052
xcconfigOverrides: AbsolutePath? = nil,
5153
isCodeCoverageEnabled: Bool? = nil,
5254
useLegacySchemeGenerator: Bool? = nil,
5355
enableAutogeneration: Bool? = nil,
54-
addExtraFiles: Bool? = nil
56+
addExtraFiles: Bool? = nil,
57+
skipBinaryTargets: Bool? = nil
5558
) {
5659
self.flags = flags
5760
self.xcconfigOverrides = xcconfigOverrides
5861
self.isCodeCoverageEnabled = isCodeCoverageEnabled ?? false
5962
self.useLegacySchemeGenerator = useLegacySchemeGenerator ?? false
6063
self.enableAutogeneration = enableAutogeneration ?? false
6164
self.addExtraFiles = addExtraFiles ?? true
65+
self.skipBinaryTargets = skipBinaryTargets ?? false
6266
}
6367
}
6468

Sources/Xcodeproj/pbxproj.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,13 @@ public func xcodeProject(
396396
productType = .framework
397397
case .test:
398398
productType = .unitTest
399-
case .systemModule, .binary, .plugin, .macro:
399+
case .binary:
400+
if options.skipBinaryTargets {
401+
continue
402+
} else {
403+
fallthrough
404+
}
405+
case .systemModule, .plugin, .macro:
400406
throw InternalError("\(target.type) not supported")
401407
}
402408

0 commit comments

Comments
 (0)