Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ObjC AnyPromise and SwiftPackageManager (SPM) #1193

Open
wants to merge 17 commits into
base: v6
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 30 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ import PackageDescription

let pkg = Package(name: "PromiseKit")
pkg.products = [
.library(name: "PromiseKit", targets: ["PromiseKit"]),
.library(name: "PromiseKit", targets: ["PromiseKit", "PromiseKitObjC"])
]

let pmk: Target = .target(name: "PromiseKit")
pmk.path = "Sources"
pmk.exclude = [
"AnyPromise.swift",
"AnyPromise.m",
"PMKCallVariadicBlock.m",
"dispatch_promise.m",
Expand All @@ -22,9 +21,37 @@ pmk.exclude = [
"race.m",
"Deprecations.swift"
]
pkg.swiftLanguageVersions = [3, 4, 5]

let pmkObjc: Target = .target(name: "PromiseKitObjC")
pmkObjc.dependencies = ["PromiseKit"]
pmkObjc.path = "Sources"
pmkObjc.publicHeadersPath = "."
pmkObjc.exclude = [
"PMKCallVariadicBlock.m",
"after.swift",
"AnyPromise.swift",
"Box.swift",
"Catchable.swift",
"Configuration.swift",
"CustomStringConvertible.swift",
"Deprecations.swift",
"Error.swift",
"firstly.swift",
"Guarantee.swift",
"hang.swift",
"Info.plist",
"LogEvent.swift",
"Promise.swift",
"race.swift",
"Resolver.swift",
"Thenable.swift",
"when.swift"
]

pkg.swiftLanguageVersions = [3, 4]
pkg.targets = [
pmk,
pmkObjc,
.testTarget(name: "APlus", dependencies: ["PromiseKit"], path: "Tests/A+"),
.testTarget(name: "CorePromise", dependencies: ["PromiseKit"], path: "Tests/CorePromise"),
]
51 changes: 39 additions & 12 deletions Package@swift-4.2.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,54 @@ import PackageDescription

let pkg = Package(name: "PromiseKit")
pkg.products = [
.library(name: "PromiseKit", targets: ["PromiseKit"]),
.library(name: "PromiseKit", targets: ["PromiseKit", "PromiseKitObjC"])
]

let pmk: Target = .target(name: "PromiseKit")
pmk.path = "Sources"
pmk.exclude = [
"AnyPromise.swift",
"AnyPromise.m",
"PMKCallVariadicBlock.m",
"dispatch_promise.m",
"join.m",
"when.m",
"NSMethodSignatureForBlock.m",
"after.m",
"hang.m",
"race.m",
"Deprecations.swift"
"AnyPromise.m",
"PMKCallVariadicBlock.m",
"dispatch_promise.m",
"join.m",
"when.m",
"NSMethodSignatureForBlock.m",
"after.m",
"hang.m",
"race.m",
"Deprecations.swift"
]

let pmkObjc: Target = .target(name: "PromiseKitObjC")
pmkObjc.dependencies = ["PromiseKit"]
pmkObjc.path = "Sources"
pmkObjc.publicHeadersPath = "."
pmkObjc.exclude = [
"PMKCallVariadicBlock.m",
"after.swift",
"AnyPromise.swift",
"Box.swift",
"Catchable.swift",
"Configuration.swift",
"CustomStringConvertible.swift",
"Deprecations.swift",
"Error.swift",
"firstly.swift",
"Guarantee.swift",
"hang.swift",
"Info.plist",
"LogEvent.swift",
"Promise.swift",
"race.swift",
"Resolver.swift",
"Thenable.swift",
"when.swift"
]

pkg.swiftLanguageVersions = [.v3, .v4, .v4_2]
pkg.targets = [
pmk,
pmkObjc,
.testTarget(name: "APlus", dependencies: ["PromiseKit"], path: "Tests/A+"),
.testTarget(name: "CorePromise", dependencies: ["PromiseKit"], path: "Tests/CorePromise"),
]
54 changes: 39 additions & 15 deletions Package@swift-5.0.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,55 @@
import PackageDescription

let pkg = Package(name: "PromiseKit")
pkg.platforms = [
.macOS(.v10_10), .iOS(.v8), .tvOS(.v9), .watchOS(.v2)
]
pkg.products = [
.library(name: "PromiseKit", targets: ["PromiseKit"]),
.library(name: "PromiseKit", targets: ["PromiseKit", "PromiseKitObjC"])
]

let pmk: Target = .target(name: "PromiseKit")
pmk.path = "Sources"
pmk.exclude = [
"AnyPromise.swift",
"AnyPromise.m",
"PMKCallVariadicBlock.m",
"dispatch_promise.m",
"join.m",
"when.m",
"NSMethodSignatureForBlock.m",
"after.m",
"hang.m",
"race.m",
"Deprecations.swift"
"AnyPromise.m",
"PMKCallVariadicBlock.m",
"dispatch_promise.m",
"join.m",
"when.m",
"NSMethodSignatureForBlock.m",
"after.m",
"hang.m",
"race.m",
"Deprecations.swift"
]

let pmkObjc: Target = .target(name: "PromiseKitObjC")
pmkObjc.dependencies = ["PromiseKit"]
pmkObjc.path = "Sources"
pmkObjc.publicHeadersPath = "."
pmkObjc.exclude = [
"PMKCallVariadicBlock.m",
"after.swift",
"AnyPromise.swift",
"Box.swift",
"Catchable.swift",
"Configuration.swift",
"CustomStringConvertible.swift",
"Deprecations.swift",
"Error.swift",
"firstly.swift",
"Guarantee.swift",
"hang.swift",
"Info.plist",
"LogEvent.swift",
"Promise.swift",
"race.swift",
"Resolver.swift",
"Thenable.swift",
"when.swift"
]

pkg.swiftLanguageVersions = [.v4, .v4_2, .v5]
pkg.targets = [
pmk,
pmkObjc,
.testTarget(name: "APlus", dependencies: ["PromiseKit"], path: "Tests/A+"),
.testTarget(name: "CorePromise", dependencies: ["PromiseKit"], path: "Tests/CorePromise"),
]
51 changes: 39 additions & 12 deletions Package@swift-5.3.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,55 @@ pkg.platforms = [
.macOS(.v10_10), .iOS(.v9), .tvOS(.v9), .watchOS(.v2)
]
pkg.products = [
.library(name: "PromiseKit", targets: ["PromiseKit"]),
.library(name: "PromiseKit", targets: ["PromiseKit", "PromiseKitObjC"])
]

let pmk: Target = .target(name: "PromiseKit")
pmk.path = "Sources"
pmk.exclude = [
"AnyPromise.swift",
"AnyPromise.m",
"PMKCallVariadicBlock.m",
"dispatch_promise.m",
"join.m",
"when.m",
"NSMethodSignatureForBlock.m",
"after.m",
"hang.m",
"race.m",
"Deprecations.swift",
"AnyPromise.m",
"PMKCallVariadicBlock.m",
"dispatch_promise.m",
"join.m",
"when.m",
"NSMethodSignatureForBlock.m",
"after.m",
"hang.m",
"race.m",
"Deprecations.swift",
"Info.plist"
]

let pmkObjc: Target = .target(name: "PromiseKitObjC")
pmkObjc.dependencies = ["PromiseKit"]
pmkObjc.path = "Sources"
pmkObjc.publicHeadersPath = "."
pmkObjc.exclude = [
"PMKCallVariadicBlock.m",
"after.swift",
"AnyPromise.swift",
"Box.swift",
"Catchable.swift",
"Configuration.swift",
"CustomStringConvertible.swift",
"Deprecations.swift",
"Error.swift",
"firstly.swift",
"Guarantee.swift",
"hang.swift",
"Info.plist",
"LogEvent.swift",
"Promise.swift",
"race.swift",
"Resolver.swift",
"Thenable.swift",
"when.swift"
]

pkg.swiftLanguageVersions = [.v4, .v4_2, .v5]
pkg.targets = [
pmk,
pmkObjc,
.testTarget(name: "APlus", dependencies: ["PromiseKit"], path: "Tests/A+", exclude: ["README.md"]),
.testTarget(name: "CorePromise", dependencies: ["PromiseKit"], path: "Tests/CorePromise"),
]
16 changes: 8 additions & 8 deletions PromiseKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
632FBBE51F33B338008F8FBB /* CatchableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 632FBBE41F33B338008F8FBB /* CatchableTests.swift */; };
633027E6203CC0060037E136 /* PromiseKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 63B0AC571D595E1B00FA21D9 /* PromiseKit.framework */; };
6330B5E11F2E991200D60528 /* Configuration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6330B5E01F2E991200D60528 /* Configuration.swift */; };
634AAD2B1EAE517C00B17855 /* fwd.h in Headers */ = {isa = PBXBuildFile; fileRef = 634AAD2A1EAE517C00B17855 /* fwd.h */; settings = {ATTRIBUTES = (Public, ); }; };
635D641D1D59635300BC0AF5 /* PromiseTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 635D64081D59635300BC0AF5 /* PromiseTests.swift */; };
635D641E1D59635300BC0AF5 /* CancellableErrorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 635D64091D59635300BC0AF5 /* CancellableErrorTests.swift */; };
635D64221D59635300BC0AF5 /* ZalgoTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 635D640D1D59635300BC0AF5 /* ZalgoTests.swift */; };
Expand All @@ -60,15 +59,13 @@
639BF757203DF03100FA577B /* Utilities.swift in Sources */ = {isa = PBXBuildFile; fileRef = 639BF755203DF02C00FA577B /* Utilities.swift */; };
63B0AC7F1D595E6300FA21D9 /* after.m in Sources */ = {isa = PBXBuildFile; fileRef = 63B0AC611D595E6300FA21D9 /* after.m */; };
63B0AC801D595E6300FA21D9 /* after.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63B0AC621D595E6300FA21D9 /* after.swift */; };
63B0AC811D595E6300FA21D9 /* AnyPromise.h in Headers */ = {isa = PBXBuildFile; fileRef = 63B0AC631D595E6300FA21D9 /* AnyPromise.h */; settings = {ATTRIBUTES = (Public, ); }; };
63B0AC821D595E6300FA21D9 /* AnyPromise.m in Sources */ = {isa = PBXBuildFile; fileRef = 63B0AC641D595E6300FA21D9 /* AnyPromise.m */; };
63B0AC831D595E6300FA21D9 /* AnyPromise.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63B0AC651D595E6300FA21D9 /* AnyPromise.swift */; };
63B0AC841D595E6300FA21D9 /* AnyPromise+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 63B0AC661D595E6300FA21D9 /* AnyPromise+Private.h */; settings = {ATTRIBUTES = (Private, ); }; };
63B0AC851D595E6300FA21D9 /* dispatch_promise.m in Sources */ = {isa = PBXBuildFile; fileRef = 63B0AC671D595E6300FA21D9 /* dispatch_promise.m */; };
63B0AC871D595E6300FA21D9 /* Error.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63B0AC691D595E6300FA21D9 /* Error.swift */; };
63B0AC891D595E6300FA21D9 /* hang.m in Sources */ = {isa = PBXBuildFile; fileRef = 63B0AC6B1D595E6300FA21D9 /* hang.m */; };
63B0AC8B1D595E6300FA21D9 /* join.m in Sources */ = {isa = PBXBuildFile; fileRef = 63B0AC6D1D595E6300FA21D9 /* join.m */; };
63B0AC931D595E6300FA21D9 /* PromiseKit.h in Headers */ = {isa = PBXBuildFile; fileRef = 63B0AC761D595E6300FA21D9 /* PromiseKit.h */; settings = {ATTRIBUTES = (Public, ); }; };
63B0AC991D595E6300FA21D9 /* when.m in Sources */ = {isa = PBXBuildFile; fileRef = 63B0AC7C1D595E6300FA21D9 /* when.m */; };
63B0AC9A1D595E6300FA21D9 /* when.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63B0AC7D1D595E6300FA21D9 /* when.swift */; };
63B18AEC1F2D205C00B79E37 /* CustomStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63B18AEB1F2D205C00B79E37 /* CustomStringConvertible.swift */; };
Expand All @@ -80,6 +77,9 @@
63CF6D80203CD19200EC8927 /* ThenableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63CF6D7F203CD19200EC8927 /* ThenableTests.swift */; };
63D9B2EF203385FD0075C00B /* race.m in Sources */ = {isa = PBXBuildFile; fileRef = 63D9B2EE203385FD0075C00B /* race.m */; };
63D9B2F120338D5D0075C00B /* Deprecations.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63D9B2F020338D5D0075C00B /* Deprecations.swift */; };
797714D2260296910076AAD8 /* PromiseKit.h in Headers */ = {isa = PBXBuildFile; fileRef = 63B0AC761D595E6300FA21D9 /* PromiseKit.h */; settings = {ATTRIBUTES = (Public, ); }; };
797714E52602992E0076AAD8 /* AnyPromise.h in Headers */ = {isa = PBXBuildFile; fileRef = 63B0AC631D595E6300FA21D9 /* AnyPromise.h */; settings = {ATTRIBUTES = (Public, ); }; };
797714F2260299AA0076AAD8 /* fwd.h in Headers */ = {isa = PBXBuildFile; fileRef = 634AAD2A1EAE517C00B17855 /* fwd.h */; settings = {ATTRIBUTES = (Public, ); }; };
C013F7382048E3B6006B57B1 /* MockNodeEnvironment.swift in Sources */ = {isa = PBXBuildFile; fileRef = C013F7372048E3B6006B57B1 /* MockNodeEnvironment.swift */; };
C013F73A2049076A006B57B1 /* JSPromise.swift in Sources */ = {isa = PBXBuildFile; fileRef = C013F7392049076A006B57B1 /* JSPromise.swift */; };
C013F73C20494291006B57B1 /* JSAdapter.swift in Sources */ = {isa = PBXBuildFile; fileRef = C013F73B20494291006B57B1 /* JSAdapter.swift */; };
Expand Down Expand Up @@ -432,6 +432,7 @@
isa = PBXGroup;
children = (
636A29191F1C156B001229C2 /* Promise.swift */,
63B0AC651D595E6300FA21D9 /* AnyPromise.swift */,
636A29221F1C17A6001229C2 /* Guarantee.swift */,
636A29201F1C1716001229C2 /* Thenable.swift */,
632FBBE21F33B273008F8FBB /* Catchable.swift */,
Expand Down Expand Up @@ -461,7 +462,6 @@
isa = PBXGroup;
children = (
63B0AC641D595E6300FA21D9 /* AnyPromise.m */,
63B0AC651D595E6300FA21D9 /* AnyPromise.swift */,
63B0AC671D595E6300FA21D9 /* dispatch_promise.m */,
630B60C01F2F73B000A1AEFE /* Headers */,
630B60BF1F2F739E00A1AEFE /* Features */,
Expand Down Expand Up @@ -501,9 +501,9 @@
isa = PBXHeadersBuildPhase;
buildActionMask = 2147483647;
files = (
63B0AC931D595E6300FA21D9 /* PromiseKit.h in Headers */,
634AAD2B1EAE517C00B17855 /* fwd.h in Headers */,
63B0AC811D595E6300FA21D9 /* AnyPromise.h in Headers */,
797714D2260296910076AAD8 /* PromiseKit.h in Headers */,
797714E52602992E0076AAD8 /* AnyPromise.h in Headers */,
797714F2260299AA0076AAD8 /* fwd.h in Headers */,
63B0AC841D595E6300FA21D9 /* AnyPromise+Private.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -741,6 +741,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
63B0AC831D595E6300FA21D9 /* AnyPromise.swift in Sources */,
636A29251F1C3089001229C2 /* race.swift in Sources */,
63B0AC9A1D595E6300FA21D9 /* when.swift in Sources */,
636A29271F1C3927001229C2 /* Resolver.swift in Sources */,
Expand All @@ -760,7 +761,6 @@
636A291A1F1C156B001229C2 /* Promise.swift in Sources */,
63B0AC8B1D595E6300FA21D9 /* join.m in Sources */,
63B0AC891D595E6300FA21D9 /* hang.m in Sources */,
63B0AC831D595E6300FA21D9 /* AnyPromise.swift in Sources */,
63D9B2F120338D5D0075C00B /* Deprecations.swift in Sources */,
63B0AC871D595E6300FA21D9 /* Error.swift in Sources */,
0CC3AF2B1FCF84F7000E98C9 /* hang.swift in Sources */,
Expand Down
4 changes: 0 additions & 4 deletions Sources/AnyPromise+Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,3 @@
#import "AnyPromise.h"

@class PMKArray;

@interface AnyPromise ()
- (void)__pipe:(void(^ __nonnull)(__nullable id))block NS_REFINED_FOR_SWIFT;
@end
33 changes: 25 additions & 8 deletions Sources/AnyPromise.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,36 @@
#import <Foundation/Foundation.h>
#import <dispatch/dispatch.h>
#import <PromiseKit/fwd.h>

/// INTERNAL DO NOT USE
@class __AnyPromise;
#import <fwd.h>

// Different ways to make AnyPromise available
//
// Import the Swift-Module if it was created already
//
// If building a Swift-Package just import PromiseKit
//
// In all other cases AnyPromise is still just a foward
// declaration and needs to be defined. This is just to
// silence a compile error which would avoid building
// the Swift-Module on first builds.

#if __has_include("PromiseKit-Swift.h")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC having this in the header is a race condition that thus will fail sometimes, which is the main reason for all the self->d stuff.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Problem here was, that AnyPromise was not always defined at this point. But it must be defined here, because otherwise I could not declare a category on it. The include path is always different depending on what is currently build. Tests, Package, Xcode Project, etc. So I figured out that this seemed to work. I'm not very satisfied with it but finally it worked. Would appreciate a better solution.

self->d isn't used anymore. The idea I was following was defining AnyPromise in Swift and declaring a category in ObjC on that and delegate from the category to the Swift implementation.

#import "PromiseKit-Swift.h"
#elif __has_include("PromiseKit/PromiseKit-Swift.h")
#import <PromiseKit/PromiseKit-Swift.h>
#elif SWIFT_PACKAGE
@import PromiseKit;
#else
@interface AnyPromise
@end
#endif

/// Provided to simplify some usage sites
typedef void (^PMKResolver)(id __nullable) NS_REFINED_FOR_SWIFT;


/// An Objective-C implementation of the promise pattern.
@interface AnyPromise: NSObject
@interface AnyPromise (ObjC)


/**
Create a new promise that resolves with the provided block.
Expand All @@ -34,9 +54,6 @@ typedef void (^PMKResolver)(id __nullable) NS_REFINED_FOR_SWIFT;
+ (instancetype __nonnull)promiseWithResolverBlock:(void (^ __nonnull)(__nonnull PMKResolver))resolveBlock NS_REFINED_FOR_SWIFT;


/// INTERNAL DO NOT USE
- (instancetype __nonnull)initWith__D:(__AnyPromise * __nonnull)d;

/**
Creates a resolved promise.

Expand Down
Loading