From be9a4cd57edf1916609e43624854d9ae1abe8adf Mon Sep 17 00:00:00 2001 From: maximkrouk Date: Tue, 30 Jan 2024 17:57:58 +0100 Subject: [PATCH] feat: Derive macro declarations into a separate target --- .../xcschemes/InterceptionTests.xcscheme | 53 --------------- ... _InterceptionMacrosDeclarations.xcscheme} | 12 ++-- ..._SwiftInterceptionCustomSelectors.xcscheme | 66 ------------------- ...ceptionCustomSelectorsMacrosTests.xcscheme | 53 --------------- .../_SwiftInterceptionUtils.xcscheme | 66 ------------------- Package.swift | 17 ++++- README.md | 2 +- Sources/InterceptionMacros/Exports.swift | 1 + .../Macros.swift | 31 +++++---- .../MethodSelectorTests.swift | 2 +- .../PropertySelectorTests.swift | 2 +- 11 files changed, 43 insertions(+), 262 deletions(-) delete mode 100644 .swiftpm/xcode/xcshareddata/xcschemes/InterceptionTests.xcscheme rename .swiftpm/xcode/xcshareddata/xcschemes/{Interception.xcscheme => _InterceptionMacrosDeclarations.xcscheme} (83%) delete mode 100644 .swiftpm/xcode/xcshareddata/xcschemes/_SwiftInterceptionCustomSelectors.xcscheme delete mode 100644 .swiftpm/xcode/xcshareddata/xcschemes/_SwiftInterceptionCustomSelectorsMacrosTests.xcscheme delete mode 100644 .swiftpm/xcode/xcshareddata/xcschemes/_SwiftInterceptionUtils.xcscheme rename Sources/{InterceptionMacros => _InterceptionMacrosDeclarations}/Macros.swift (63%) diff --git a/.swiftpm/xcode/xcshareddata/xcschemes/InterceptionTests.xcscheme b/.swiftpm/xcode/xcshareddata/xcschemes/InterceptionTests.xcscheme deleted file mode 100644 index 2c211d8..0000000 --- a/.swiftpm/xcode/xcshareddata/xcschemes/InterceptionTests.xcscheme +++ /dev/null @@ -1,53 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - diff --git a/.swiftpm/xcode/xcshareddata/xcschemes/Interception.xcscheme b/.swiftpm/xcode/xcshareddata/xcschemes/_InterceptionMacrosDeclarations.xcscheme similarity index 83% rename from .swiftpm/xcode/xcshareddata/xcschemes/Interception.xcscheme rename to .swiftpm/xcode/xcshareddata/xcschemes/_InterceptionMacrosDeclarations.xcscheme index 56e193c..05d8170 100644 --- a/.swiftpm/xcode/xcshareddata/xcschemes/Interception.xcscheme +++ b/.swiftpm/xcode/xcshareddata/xcschemes/_InterceptionMacrosDeclarations.xcscheme @@ -14,9 +14,9 @@ buildForAnalyzing = "YES"> @@ -49,9 +49,9 @@ diff --git a/.swiftpm/xcode/xcshareddata/xcschemes/_SwiftInterceptionCustomSelectors.xcscheme b/.swiftpm/xcode/xcshareddata/xcschemes/_SwiftInterceptionCustomSelectors.xcscheme deleted file mode 100644 index 1695afb..0000000 --- a/.swiftpm/xcode/xcshareddata/xcschemes/_SwiftInterceptionCustomSelectors.xcscheme +++ /dev/null @@ -1,66 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/.swiftpm/xcode/xcshareddata/xcschemes/_SwiftInterceptionCustomSelectorsMacrosTests.xcscheme b/.swiftpm/xcode/xcshareddata/xcschemes/_SwiftInterceptionCustomSelectorsMacrosTests.xcscheme deleted file mode 100644 index 352ae6c..0000000 --- a/.swiftpm/xcode/xcshareddata/xcschemes/_SwiftInterceptionCustomSelectorsMacrosTests.xcscheme +++ /dev/null @@ -1,53 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - diff --git a/.swiftpm/xcode/xcshareddata/xcschemes/_SwiftInterceptionUtils.xcscheme b/.swiftpm/xcode/xcshareddata/xcschemes/_SwiftInterceptionUtils.xcscheme deleted file mode 100644 index 2127e55..0000000 --- a/.swiftpm/xcode/xcshareddata/xcschemes/_SwiftInterceptionUtils.xcscheme +++ /dev/null @@ -1,66 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Package.swift b/Package.swift index b70c1aa..34ae40c 100644 --- a/Package.swift +++ b/Package.swift @@ -17,12 +17,17 @@ let package = Package( name: "InterceptionMacros", type: .static, targets: ["InterceptionMacros"] + ), + .library( + name: "_InterceptionMacrosDeclarations", + type: .static, + targets: ["_InterceptionMacrosDeclarations"] ) ], dependencies: [ .package( url: "https://github.com/capturecontext/swift-interception.git", - .upToNextMinor(from: "0.1.0") + .upToNextMinor(from: "0.2.0") ), .package( url: "https://github.com/stackotter/swift-macro-toolkit.git", @@ -45,9 +50,17 @@ let package = Package( ), .target( - name: "InterceptionMacros", + name: "_InterceptionMacrosDeclarations", dependencies: [ .target(name: "_InterceptionMacros"), + .product(name: "_InterceptionCustomSelectors", package: "swift-interception") + ] + ), + + .target( + name: "InterceptionMacros", + dependencies: [ + .target(name: "_InterceptionMacrosDeclarations"), .product(name: "Interception", package: "swift-interception") ] ), diff --git a/README.md b/README.md index 8344abb..4237f4e 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ If you use SwiftPM for your project, you can add CombineInterception to your pac ```swift .package( url: "https://github.com/capturecontext/swift-interception-macros.git", - .upToNextMinor(from: "0.1.0") + .upToNextMinor(from: "0.2.0") ) ``` diff --git a/Sources/InterceptionMacros/Exports.swift b/Sources/InterceptionMacros/Exports.swift index a731c32..fe8ad13 100644 --- a/Sources/InterceptionMacros/Exports.swift +++ b/Sources/InterceptionMacros/Exports.swift @@ -1 +1,2 @@ @_exported import Interception +@_exported import _InterceptionMacrosDeclarations diff --git a/Sources/InterceptionMacros/Macros.swift b/Sources/_InterceptionMacrosDeclarations/Macros.swift similarity index 63% rename from Sources/InterceptionMacros/Macros.swift rename to Sources/_InterceptionMacrosDeclarations/Macros.swift index 9d12dee..021e148 100644 --- a/Sources/InterceptionMacros/Macros.swift +++ b/Sources/_InterceptionMacrosDeclarations/Macros.swift @@ -1,5 +1,10 @@ -import _InterceptionsMacros import Foundation +import _InterceptionCustomSelectors + +// In case some linker bug won't let +// macros to be linked +#if canImport(_InterceptionMacros) +import _InterceptionMacros // MARK: - PropertySelectors @@ -7,13 +12,13 @@ import Foundation public macro propertySelector( _: KeyPath ) -> _ReadonlyPropertySelector = -#externalMacro(module: "_InterceptionsMacros", type: "PropertySelectorMacro") +#externalMacro(module: "_InterceptionMacros", type: "PropertySelectorMacro") @freestanding(expression) public macro propertySelector( _: WritableKeyPath ) -> _MutablePropertySelector = -#externalMacro(module: "_InterceptionsMacros", type: "PropertySelectorMacro") +#externalMacro(module: "_InterceptionMacros", type: "PropertySelectorMacro") // MARK: - MethodSelectors @@ -21,53 +26,53 @@ public macro propertySelector( public macro methodSelector( _: (() -> Output)? ) -> _MethodSelector = -#externalMacro(module: "_InterceptionsMacros", type: "MethodSelectorMacro") +#externalMacro(module: "_InterceptionMacros", type: "MethodSelectorMacro") @freestanding(expression) public macro methodSelector( _: ((Arg) -> Output)? ) -> _MethodSelector = -#externalMacro(module: "_InterceptionsMacros", type: "MethodSelectorMacro") +#externalMacro(module: "_InterceptionMacros", type: "MethodSelectorMacro") @freestanding(expression) public macro methodSelector( _: ((repeat each Arg) -> Output)? ) -> _MethodSelector<(repeat each Arg), Output> = -#externalMacro(module: "_InterceptionsMacros", type: "MethodSelectorMacro") +#externalMacro(module: "_InterceptionMacros", type: "MethodSelectorMacro") @freestanding(expression) public macro methodSelector( _: (Object) -> (() -> Output)? ) -> _MethodSelector = -#externalMacro(module: "_InterceptionsMacros", type: "MethodSelectorMacro") +#externalMacro(module: "_InterceptionMacros", type: "MethodSelectorMacro") @freestanding(expression) public macro methodSelector( _: (Object) -> ((Arg) -> Output)? ) -> _MethodSelector = -#externalMacro(module: "_InterceptionsMacros", type: "MethodSelectorMacro") +#externalMacro(module: "_InterceptionMacros", type: "MethodSelectorMacro") @freestanding(expression) public macro methodSelector( _: (Object) -> ((repeat each Arg) -> Output)? ) -> _MethodSelector<(repeat each Arg), Output> = -#externalMacro(module: "_InterceptionsMacros", type: "MethodSelectorMacro") +#externalMacro(module: "_InterceptionMacros", type: "MethodSelectorMacro") @freestanding(expression) public macro methodSelector( _: (Object) -> () -> Output ) -> _MethodSelector = -#externalMacro(module: "_InterceptionsMacros", type: "MethodSelectorMacro") +#externalMacro(module: "_InterceptionMacros", type: "MethodSelectorMacro") @freestanding(expression) public macro methodSelector( _: (Object) -> (Arg) -> Output ) -> _MethodSelector = -#externalMacro(module: "_InterceptionsMacros", type: "MethodSelectorMacro") +#externalMacro(module: "_InterceptionMacros", type: "MethodSelectorMacro") @freestanding(expression) public macro methodSelector( _: (Object) -> (repeat each Arg) -> Output ) -> _MethodSelector<(repeat each Arg), Output> = -#externalMacro(module: "_InterceptionsMacros", type: "MethodSelectorMacro") - +#externalMacro(module: "_InterceptionMacros", type: "MethodSelectorMacro") +#endif diff --git a/Tests/_InterceptionMacrosTests/MethodSelectorTests.swift b/Tests/_InterceptionMacrosTests/MethodSelectorTests.swift index 6eee673..53ef22e 100644 --- a/Tests/_InterceptionMacrosTests/MethodSelectorTests.swift +++ b/Tests/_InterceptionMacrosTests/MethodSelectorTests.swift @@ -1,6 +1,6 @@ import XCTest import MacroTesting -import _SwiftInterceptionCustomSelectorsMacros +import _InterceptionMacros final class MethodSelectorTests: XCTestCase { override func invokeTest() { diff --git a/Tests/_InterceptionMacrosTests/PropertySelectorTests.swift b/Tests/_InterceptionMacrosTests/PropertySelectorTests.swift index 8963af4..1c7ab80 100644 --- a/Tests/_InterceptionMacrosTests/PropertySelectorTests.swift +++ b/Tests/_InterceptionMacrosTests/PropertySelectorTests.swift @@ -1,6 +1,6 @@ import XCTest import MacroTesting -import _SwiftInterceptionCustomSelectorsMacros +import _InterceptionMacros final class PropertySelectorTests: XCTestCase { override func invokeTest() {