2
2
3
3
// RUN: %empty-directory(%t)
4
4
// RUN: %empty-directory(%t/plugin)
5
+ // RUN: %empty-directory(%t/external-plugin)
5
6
// RUN: %empty-directory(%t/lib)
6
7
// RUN: %empty-directory(%t/src)
7
8
8
9
// RUN: split-file %s %t/src
9
10
10
- //#-- Prepare the macro shared library plugin.
11
+ //#-- Prepare the macro shared library plugin for -plugin-path .
11
12
// RUN: %host-build-swift \
12
13
// RUN: -swift-version 5 \
13
- // RUN: -emit-library -o %t/plugin/%target-library-name(MacroDefinition ) \
14
- // RUN: -module-name MacroDefinition \
15
- // RUN: %S/Inputs/syntax_macro_definitions .swift
14
+ // RUN: -emit-library -o %t/plugin/%target-library-name(StringifyPlugin ) \
15
+ // RUN: -module-name StringifyPlugin \
16
+ // RUN: %t/src/StringifyPlugin .swift
16
17
17
- //#-- Prepare the macro executable plugin.
18
+ //#-- Prepare the macro shared library plugin for -external-plugin-path.
19
+ // RUN: %host-build-swift \
20
+ // RUN: -swift-version 5 \
21
+ // RUN: -emit-library -o %t/external-plugin/%target-library-name(AssertPlugin) \
22
+ // RUN: -module-name AssertPlugin \
23
+ // RUN: %t/src/AssertPlugin.swift
24
+
25
+ //#-- Prepare the macro executable plugin for -load-plugin-executable.
18
26
// RUN: %swift-build-c-plugin -o %t/mock-plugin %t/src/plugin.c
19
27
20
28
//#-- Prepare the macro library.
23
31
// RUN: -emit-module -o %t/lib/MacroLib.swiftmodule \
24
32
// RUN: -module-name MacroLib \
25
33
// RUN: -plugin-path %t/plugin \
34
+ // RUN: -external-plugin-path %t/external-plugin#%swift-plugin-server \
26
35
// RUN: -load-plugin-executable %t/mock-plugin#TestPlugin \
27
36
// RUN: -primary-file %t/src/macro_library.swift \
28
37
// RUN: -emit-reference-dependencies-path %t/macro_library.swiftdeps \
35
44
// RUN: -swift-version 5 -typecheck \
36
45
// RUN: -primary-file %t/src/test.swift \
37
46
// RUN: %t/src/other.swift \
38
- // RUN: -I %t/lib -plugin-path %t/plugin \
47
+ // RUN: -I %t/lib \
48
+ // RUN: -plugin-path %t/plugin \
49
+ // RUN: -external-plugin-path %t/external-plugin#%swift-plugin-server \
39
50
// RUN: -load-plugin-executable %t/mock-plugin#TestPlugin \
40
51
// RUN: -emit-reference-dependencies-path %t/without_macro.swiftdeps \
41
52
// RUN: -emit-dependencies-path %t/without_macro.d
48
59
// RUN: -swift-version 5 -typecheck \
49
60
// RUN: -primary-file %t/src/test.swift \
50
61
// RUN: %t/src/other.swift \
51
- // RUN: -I %t/lib -plugin-path %t/plugin \
62
+ // RUN: -I %t/lib \
63
+ // RUN: -plugin-path %t/plugin \
64
+ // RUN: -external-plugin-path %t/external-plugin#%swift-plugin-server \
52
65
// RUN: -load-plugin-executable %t/mock-plugin#TestPlugin \
53
66
// RUN: -emit-reference-dependencies-path %t/with_macro_primary.swiftdeps \
54
67
// RUN: -emit-dependencies-path %t/with_macro_primary.d
61
74
// RUN: -swift-version 5 -typecheck \
62
75
// RUN: %t/src/test.swift \
63
76
// RUN: -primary-file %t/src/other.swift \
64
- // RUN: -I %t/lib -plugin-path %t/plugin \
77
+ // RUN: -I %t/lib \
78
+ // RUN: -plugin-path %t/plugin \
79
+ // RUN: -external-plugin-path %t/external-plugin#%swift-plugin-server \
65
80
// RUN: -load-plugin-executable %t/mock-plugin#TestPlugin \
66
81
// RUN: -emit-reference-dependencies-path %t/with_macro_nonprimary.swiftdeps \
67
82
// RUN: -emit-dependencies-path %t/with_macro_nonprimary.d
68
83
// RUN: %{python} %S/../Inputs/process_fine_grained_swiftdeps.py %swift-dependency-tool %t/with_macro_nonprimary.swiftdeps > %t/with_macro_nonprimary.swiftdeps.processed
69
84
// RUN: %FileCheck --check-prefix WITHOUT_PLUGIN %s < %t/with_macro_nonprimary.swiftdeps.processed
70
85
71
- // WITH_PLUGIN: externalDepend interface '' '{{.*}}mock-plugin' false
72
- // WITH_PLUGIN: externalDepend interface '' '{{.*}}MacroDefinition.{{(dylib|so|dll)}}' false
86
+ // WITH_PLUGIN-DAG: externalDepend interface '' '{{.*}}mock-plugin' false
87
+ // WITH_PLUGIN-DAG: externalDepend interface '' '{{.*}}StringifyPlugin.{{(dylib|so|dll)}}' false
88
+ // WITH_PLUGIN-DAG: externalDepend interface '' '{{.*}}AssertPlugin.{{(dylib|so|dll)}}' false
73
89
74
- // WITHOUT_PLUGIN-NOT: MacroDefinition
90
+ // WITHOUT_PLUGIN-NOT: StringifyPlugin
91
+ // WITHOUT_PLUGIN-NOT: AssertPlugin
75
92
// WITHOUT_PLUGIN-NOT: mock-plugin
76
93
77
94
//--- macro_library.swift
78
- @freestanding ( expression) public macro stringify< T> ( _ value: T ) -> ( T , String ) = #externalMacro( module: " MacroDefinition " , type: " StringifyMacro " )
95
+ @freestanding ( expression) public macro stringify< T> ( _ value: T ) -> ( T , String ) = #externalMacro( module: " StringifyPlugin " , type: " StringifyMacro " )
96
+ @freestanding ( expression) public macro assert( _ value: Bool ) = #externalMacro( module: " AssertPlugin " , type: " AssertMacro " )
79
97
@freestanding ( expression) public macro testString( _: Any ) -> String = #externalMacro( module: " TestPlugin " , type: " TestStringMacro " )
80
98
81
99
public func funcInMacroLib( ) { }
@@ -90,6 +108,7 @@ func test(a: Int, b: Int) {
90
108
#if USE_MACRO
91
109
_ = #stringify ( a + b)
92
110
_ = #testString( 123 )
111
+ #assert( true )
93
112
#endif
94
113
}
95
114
@@ -101,6 +120,42 @@ func test() {
101
120
funcInMacroLib ( )
102
121
}
103
122
123
+ //--- StringifyPlugin.swift
124
+ import SwiftSyntax
125
+ import SwiftSyntaxBuilder
126
+ import SwiftSyntaxMacros
127
+
128
+ public struct StringifyMacro : ExpressionMacro {
129
+ public static func expansion(
130
+ of macro: some FreestandingMacroExpansionSyntax ,
131
+ in context: some MacroExpansionContext
132
+ ) -> ExprSyntax {
133
+ guard let argument = macro. arguments. first? . expression else {
134
+ fatalError ( " boom " )
135
+ }
136
+
137
+ return " ( \( argument) , \( StringLiteralExprSyntax ( content: argument. description) ) ) "
138
+ }
139
+ }
140
+
141
+ //--- AssertPlugin.swift
142
+ import SwiftSyntax
143
+ import SwiftSyntaxBuilder
144
+ import SwiftSyntaxMacros
145
+
146
+ public struct AssertMacro : ExpressionMacro {
147
+ public static func expansion(
148
+ of macro: some FreestandingMacroExpansionSyntax ,
149
+ in context: some MacroExpansionContext
150
+ ) -> ExprSyntax {
151
+ guard let argument = macro. arguments. first? . expression else {
152
+ fatalError ( " boom " )
153
+ }
154
+
155
+ return " assert( \( argument) ) "
156
+ }
157
+ }
158
+
104
159
//--- plugin.c
105
160
#include " swift-c/MockPlugin/MockPlugin.h "
106
161
0 commit comments