forked from swiftlang/swift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmacro_plugin_searchorder.swift
132 lines (113 loc) · 4.41 KB
/
macro_plugin_searchorder.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
// REQUIRES: swift_swift_parser
// RUN: %empty-directory(%t)
// RUN: mkdir -p %t/src
// RUN: mkdir -p %t/bin
// RUN: mkdir -p %t/lib/tmp
// RUN: mkdir -p %t/lib/plugins
// RUN: mkdir -p %t/external
// RUN: mkdir -p %t/libexec
// RUN: split-file %s %t/src
//#-- For -plugin-path
// RUN: %host-build-swift \
// RUN: -swift-version 5 \
// RUN: -emit-library -o %t/lib/plugins/%target-library-name(MacroDefinition) \
// RUN: -module-name MacroDefinition \
// RUN: -D PLUGIN_PATH \
// RUN: %t/src/MacroDefinition.swift \
// RUN: -g -no-toolchain-stdlib-rpath
//#-- For -load-plugin-library
// RUN: %host-build-swift \
// RUN: -swift-version 5 \
// RUN: -emit-library -o %t/lib/tmp/%target-library-name(MacroDefinition) \
// RUN: -module-name MacroDefinition \
// RUN: -D LOAD_PLUGIN_LIBRARY \
// RUN: %t/src/MacroDefinition.swift \
// RUN: -g -no-toolchain-stdlib-rpath
//#-- For -external-plugin-path
// RUN: %host-build-swift \
// RUN: -swift-version 5 \
// RUN: -emit-library -o %t/external/%target-library-name(MacroDefinition) \
// RUN: -module-name MacroDefinition \
// RUN: -D EXTERNAL_PLUGIN_PATH \
// RUN: %t/src/MacroDefinition.swift \
// RUN: -g -no-toolchain-stdlib-rpath
//#-- For -load-plugin-executable
// RUN: %clang \
// RUN: -isysroot %host_sdk \
// RUN: -I %swift_src_root/include \
// RUN: -L %swift-lib-dir -l_swiftMockPlugin \
// RUN: -Wl,-rpath,%swift-lib-dir \
// RUN: -o %t/libexec/MacroDefinitionPlugin \
// RUN: %t/src/MacroDefinition.c
//#-- Expect -load-plugin-library
// RUN: %target-build-swift %t/src/test.swift \
// RUN: -o %t/main1 \
// RUN: -module-name test \
// RUN: -plugin-path %t/lib/plugins \
// RUN: -external-plugin-path %t/external#%swift-plugin-server \
// RUN: -load-plugin-library %t/lib/tmp/%target-library-name(MacroDefinition) \
// RUN: -load-plugin-executable %t/libexec/MacroDefinitionPlugin#MacroDefinition
// RUN: %target-codesign %t/main1
// RUN: %target-run %t/main1 | %FileCheck --check-prefix=CHECK_LOAD_PLUGIN_LIBRARY %s
//#-- Expect -load-plugin-executable
// RUN: %target-build-swift %t/src/test.swift \
// RUN: -o %t/main2 \
// RUN: -module-name test \
// RUN: -plugin-path %t/lib/plugins \
// RUN: -external-plugin-path %t/external#%swift-plugin-server \
// RUN: -load-plugin-executable %t/libexec/MacroDefinitionPlugin#MacroDefinition
// RUN: %target-codesign %t/main2
// RUN: %target-run %t/main2 | %FileCheck --check-prefix=CHECK_LOAD_PLUGIN_EXECUTABLE %s
//#-- Expect -plugin-path
// RUN: %target-build-swift %t/src/test.swift \
// RUN: -o %t/main3 \
// RUN: -module-name test \
// RUN: -plugin-path %t/lib/plugins \
// RUN: -external-plugin-path %t/external#%swift-plugin-server
// RUN: %target-codesign %t/main3
// RUN: %target-run %t/main3 | %FileCheck --check-prefix=CHECK_PLUGIN_PATH %s
//#-- Expect -external-plugin-path
// RUN: %target-build-swift %t/src/test.swift \
// RUN: -o %t/main4 \
// RUN: -module-name test \
// RUN: -external-plugin-path %t/external#%swift-plugin-server
// RUN: %target-codesign %t/main4
// RUN: %target-run %t/main4 | %FileCheck --check-prefix=CHECK_EXTERNAL_PLUGIN_PATH %s
// CHECK_LOAD_PLUGIN_LIBRARY: load-plugin-library
// CHECK_LOAD_PLUGIN_EXECUTABLE: load-plugin-executable
// CHECK_PLUGIN_PATH: plugin-path
// CHECK_EXTERNAL_PLUGIN_PATH: external-plugin-path
//--- test.swift
@freestanding(expression) macro testMacro() -> String = #externalMacro(module: "MacroDefinition", type: "TestMacro")
print(#testMacro)
//--- MacroDefinition.swift
import SwiftSyntax
import SwiftSyntaxMacros
public struct TestMacro: ExpressionMacro {
public static func expansion(
of node: some FreestandingMacroExpansionSyntax,
in context: some MacroExpansionContext
) throws -> ExprSyntax {
#if PLUGIN_PATH
return #""plugin-path""#
#elseif LOAD_PLUGIN_LIBRARY
return #""load-plugin-library""#
#elseif EXTERNAL_PLUGIN_PATH
return #""external-plugin-path""#
#endif
}
}
//--- MacroDefinition.c
#include "swift-c/MockPlugin/MockPlugin.h"
MOCK_PLUGIN([
{
"expect": {"getCapability": {}},
"response": {"getCapabilityResult": {"capability": {"protocolVersion": 1}}}
},
{
"expect": {"expandFreestandingMacro": {
"macro": {"moduleName": "MacroDefinition", "typeName": "TestMacro"},
"syntax": {"kind": "expression", "source": "#testMacro"}}},
"response": {"expandFreestandingMacroResult": {"expandedSource": "\"load-plugin-executable\"", "diagnostics": []}}
}
])