tikhop / TPInAppReceipt

Reading and Validating In App Purchase Receipt Locally.
MIT License
635 stars 95 forks source link

Active Compilation Condition Problem #81

Closed yosshi4486 closed 3 years ago

yosshi4486 commented 3 years ago

About

Hi.

I found a problem about active compilation condition with SwiftPM. A project side's active compilation conditions are not used without defining them in package side's Package.swift. It is mentioned in this swift forum post: https://forums.swift.org/t/compilation-conditions-and-swift-packages/34627

Additionally, I observed a strange behavior of Xcode. When a Package.swift doesn't define its compilation conditions, Xcode decides actual branch based on whether a configuration name is prefix matching or not.

Related API

SwiftSetting.define https://github.com/apple/swift-package-manager/blob/11ae0a7bbfaab580c5695eea2c76db9ab092b8a4/Documentation/PackageDescription.md#methods-9

Reproduce

  1. Create sample iOS project in Xcode12.
  2. Add package dependency of this package(TPInAppReceipt).
  3. Add new configuration named "Test".
  4. Edit a scheme Run's configuration to the "Test".
  5. Add breakpoints to TPInAppReceipt/Sources/Validation.swift L93 and L95.
  6. Implement localReceipt and verify in ViewController.
  7. Run the project.

L93 will be executed if DEBUG compilation condition in the project configuration is active, but L95 is executed. (Cleaning package may be required)

Solution Proposal

Define "DEBUG" compilation condition in Package.swift.

I will submit the PR soon.