Skip to content

Commit

Permalink
Local.xcconfig is read by Package.swift (#4368)
Browse files Browse the repository at this point in the history
  • Loading branch information
JayShortway authored Oct 15, 2024
1 parent 20e1be5 commit d275ba8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
3 changes: 2 additions & 1 deletion Local.xcconfig.SAMPLE
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
// 3. If there's any new build setting you think others can benefit from, please update the
// .SAMPLE file and open a pull request.
//
// Note that this file is read by the RevenueCat, PurchaseTester and PaywallsTester projects.
// Note that this file is read by the RevenueCat, PurchaseTester and PaywallsTester projects,
// as well as by Package.swift.
// ======

// Uncomment to enable the PAYWALL_COMPONENTS flag.
Expand Down
29 changes: 26 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,29 @@

import PackageDescription
import class Foundation.ProcessInfo
import struct Foundation.URL

/// This looks for a file named `Local.xcconfig` in the root of the purchases-ios[-spm] repo, and reads any compiler
/// flags defined in it. It does nothing if this file does not exist in this exact folder. This file does not exist on
/// a clean checkout. It has to be created manually by a developer.
var additionalCompilerFlags: [PackageDescription.SwiftSetting] = {
guard let config = try? String(
contentsOf: URL(fileURLWithPath: #filePath)
.deletingLastPathComponent()
.appendingPathComponent("Local.xcconfig")
) else {
return []
}
// We split the capture group by space and remove any special flags, such as $(inherited).
return config
.firstMatch(of: #/^SWIFT_ACTIVE_COMPILATION_CONDITIONS *= *(.*)$/#.anchorsMatchLineEndings())?
.output
.1
.split(whereSeparator: \.isWhitespace)
.filter { !$0.isEmpty && !$0.hasPrefix("$") }
.map { .define(String($0)) }
?? []
}()

// Only add DocC Plugin when building docs, so that clients of this library won't
// unnecessarily also get the DocC Plugin
Expand Down Expand Up @@ -52,7 +75,7 @@ let package = Package(
resources: [
.copy("../Sources/PrivacyInfo.xcprivacy")
],
swiftSettings: [visionOSSetting]),
swiftSettings: [visionOSSetting] + additionalCompilerFlags),
.target(name: "RevenueCat_CustomEntitlementComputation",
path: "CustomEntitlementComputation",
exclude: ["Info.plist", "LocalReceiptParsing/ReceiptParser-only-files"],
Expand All @@ -62,7 +85,7 @@ let package = Package(
swiftSettings: [
.define("ENABLE_CUSTOM_ENTITLEMENT_COMPUTATION"),
visionOSSetting
]),
] + additionalCompilerFlags),
// Receipt Parser
.target(name: "ReceiptParser",
path: "LocalReceiptParsing"),
Expand All @@ -78,7 +101,7 @@ let package = Package(
.copy("Resources/background.jpg"),
.process("Resources/icons.xcassets")
],
swiftSettings: []),
swiftSettings: additionalCompilerFlags),
.testTarget(name: "RevenueCatUITests",
dependencies: [
"RevenueCatUI",
Expand Down

0 comments on commit d275ba8

Please sign in to comment.