Skip to content

Commit 421042e

Browse files
authored
Merge pull request #65370 from xymus/serial-macro-paths
[Macros] Serialize plugin search paths for LLDB use
2 parents 29fad35 + 3ef6087 commit 421042e

File tree

8 files changed

+159
-0
lines changed

8 files changed

+159
-0
lines changed

include/swift/Serialization/SerializationOptions.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ namespace swift {
4343
StringRef ModuleLinkName;
4444
StringRef ModuleInterface;
4545
std::vector<std::string> ExtraClangOptions;
46+
std::vector<std::string> PluginSearchPaths;
47+
std::vector<std::string> ExternalPluginSearchPaths;
48+
std::vector<std::string> CompilerPluginLibraryPaths;
49+
std::vector<std::string> CompilerPluginExecutablePaths;
4650

4751
/// Path prefixes that should be rewritten in debug info.
4852
PathRemapper DebuggingOptionsPrefixMap;

include/swift/Serialization/Validation.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@ struct ValidationInfo {
106106
/// \sa validateSerializedAST()
107107
class ExtendedValidationInfo {
108108
SmallVector<StringRef, 4> ExtraClangImporterOpts;
109+
110+
SmallVector<StringRef, 1> PluginSearchPaths;
111+
SmallVector<StringRef, 1> ExternalPluginSearchPaths;
112+
SmallVector<StringRef, 1> CompilerPluginLibraryPaths;
113+
SmallVector<StringRef, 1> CompilerPluginExecutablePaths;
114+
109115
std::string SDKPath;
110116
StringRef ModuleABIName;
111117
StringRef ModulePackageName;
@@ -138,6 +144,34 @@ class ExtendedValidationInfo {
138144
ExtraClangImporterOpts.push_back(option);
139145
}
140146

147+
ArrayRef<StringRef> getPluginSearchPaths() const {
148+
return PluginSearchPaths;
149+
}
150+
void addPluginSearchPath(StringRef path) {
151+
PluginSearchPaths.push_back(path);
152+
}
153+
154+
ArrayRef<StringRef> getExternalPluginSearchPaths() const {
155+
return ExternalPluginSearchPaths;
156+
}
157+
void addExternalPluginSearchPath(StringRef path) {
158+
ExternalPluginSearchPaths.push_back(path);
159+
}
160+
161+
ArrayRef<StringRef> getCompilerPluginLibraryPaths() const {
162+
return CompilerPluginLibraryPaths;
163+
}
164+
void addCompilerPluginLibraryPath(StringRef path) {
165+
CompilerPluginLibraryPaths.push_back(path);
166+
}
167+
168+
ArrayRef<StringRef> getCompilerPluginExecutablePaths() const {
169+
return CompilerPluginExecutablePaths;
170+
}
171+
void addCompilerPluginExecutablePath(StringRef path) {
172+
CompilerPluginExecutablePaths.push_back(path);
173+
}
174+
141175
bool isSIB() const { return Bits.IsSIB; }
142176
void setIsSIB(bool val) {
143177
Bits.IsSIB = val;

lib/Frontend/Frontend.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,32 @@ SerializationOptions CompilerInvocation::computeSerializationOptions(
209209
serializationOpts.ExtraClangOptions = getClangImporterOptions().ExtraArgs;
210210
}
211211

212+
// '-plugin-path' options.
213+
for (const auto &path : getSearchPathOptions().PluginSearchPaths) {
214+
serializationOpts.PluginSearchPaths.push_back(path);
215+
}
216+
// '-external-plugin-path' options.
217+
for (const ExternalPluginSearchPathAndServerPath &pair :
218+
getSearchPathOptions().ExternalPluginSearchPaths) {
219+
serializationOpts.ExternalPluginSearchPaths.push_back(
220+
pair.SearchPath + "#" +
221+
pair.ServerPath);
222+
}
223+
// '-load-plugin-library' options.
224+
for (const auto &path :
225+
getSearchPathOptions().getCompilerPluginLibraryPaths()) {
226+
serializationOpts.CompilerPluginLibraryPaths.push_back(path);
227+
}
228+
// '-load-plugin-executable' options.
229+
for (const PluginExecutablePathAndModuleNames &pair :
230+
getSearchPathOptions().getCompilerPluginExecutablePaths()) {
231+
std::string optStr = pair.ExecutablePath + "#";
232+
llvm::interleave(
233+
pair.ModuleNames, [&](auto &name) { optStr += name; },
234+
[&]() { optStr += ","; });
235+
serializationOpts.CompilerPluginLibraryPaths.push_back(optStr);
236+
}
237+
212238
serializationOpts.DisableCrossModuleIncrementalInfo =
213239
opts.DisableCrossModuleIncrementalBuild;
214240

lib/Serialization/ModuleFileSharedCore.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,18 @@ static bool readOptionsBlock(llvm::BitstreamCursor &cursor,
126126
case options_block::XCC:
127127
extendedInfo.addExtraClangImporterOption(blobData);
128128
break;
129+
case options_block::PLUGIN_SEARCH_PATH:
130+
extendedInfo.addPluginSearchPath(blobData);
131+
break;
132+
case options_block::EXTERNAL_SEARCH_PLUGIN_PATH:
133+
extendedInfo.addExternalPluginSearchPath(blobData);
134+
break;
135+
case options_block::COMPILER_PLUGIN_LIBRARY_PATH:
136+
extendedInfo.addCompilerPluginLibraryPath(blobData);
137+
break;
138+
case options_block::COMPILER_PLUGIN_EXECUTABLE_PATH:
139+
extendedInfo.addCompilerPluginExecutablePath(blobData);
140+
break;
129141
case options_block::IS_SIB:
130142
bool IsSIB;
131143
options_block::IsSIBLayout::readRecord(scratch, IsSIB);

lib/Serialization/ModuleFormat.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -883,6 +883,10 @@ namespace options_block {
883883
IS_CONCURRENCY_CHECKED,
884884
MODULE_PACKAGE_NAME,
885885
MODULE_EXPORT_AS_NAME,
886+
PLUGIN_SEARCH_PATH,
887+
EXTERNAL_SEARCH_PLUGIN_PATH,
888+
COMPILER_PLUGIN_LIBRARY_PATH,
889+
COMPILER_PLUGIN_EXECUTABLE_PATH,
886890
};
887891

888892
using SDKPathLayout = BCRecordLayout<
@@ -895,6 +899,26 @@ namespace options_block {
895899
BCBlob // -Xcc flag, as string
896900
>;
897901

902+
using PluginSearchPathLayout = BCRecordLayout<
903+
PLUGIN_SEARCH_PATH,
904+
BCBlob // -plugin-path value
905+
>;
906+
907+
using ExternalPluginSearchPathLayout = BCRecordLayout<
908+
EXTERNAL_SEARCH_PLUGIN_PATH,
909+
BCBlob // -external-plugin-path value
910+
>;
911+
912+
using CompilerPluginLibraryPathLayout = BCRecordLayout<
913+
COMPILER_PLUGIN_LIBRARY_PATH,
914+
BCBlob // -load-plugin-library value
915+
>;
916+
917+
using CompilerPluginExecutablePathLayout = BCRecordLayout<
918+
COMPILER_PLUGIN_EXECUTABLE_PATH,
919+
BCBlob // -load-plugin-executable value
920+
>;
921+
898922
using IsSIBLayout = BCRecordLayout<
899923
IS_SIB,
900924
BCFixed<1> // Is this an intermediate file?

lib/Serialization/Serialization.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -844,6 +844,11 @@ void Serializer::writeBlockInfoBlock() {
844844
BLOCK_RECORD(options_block, MODULE_ABI_NAME);
845845
BLOCK_RECORD(options_block, IS_CONCURRENCY_CHECKED);
846846
BLOCK_RECORD(options_block, MODULE_PACKAGE_NAME);
847+
BLOCK_RECORD(options_block, MODULE_EXPORT_AS_NAME);
848+
BLOCK_RECORD(options_block, PLUGIN_SEARCH_PATH);
849+
BLOCK_RECORD(options_block, EXTERNAL_SEARCH_PLUGIN_PATH);
850+
BLOCK_RECORD(options_block, COMPILER_PLUGIN_LIBRARY_PATH);
851+
BLOCK_RECORD(options_block, COMPILER_PLUGIN_EXECUTABLE_PATH);
847852

848853
BLOCK(INPUT_BLOCK);
849854
BLOCK_RECORD(input_block, IMPORTED_MODULE);
@@ -1124,6 +1129,30 @@ void Serializer::writeHeader(const SerializationOptions &options) {
11241129
}
11251130
XCC.emit(ScratchRecord, arg);
11261131
}
1132+
1133+
// Macro plugins
1134+
options_block::PluginSearchPathLayout PluginSearchPath(Out);
1135+
for (auto Arg : options.PluginSearchPaths) {
1136+
PluginSearchPath.emit(ScratchRecord, Arg);
1137+
}
1138+
1139+
options_block::ExternalPluginSearchPathLayout
1140+
ExternalPluginSearchPath(Out);
1141+
for (auto Arg : options.ExternalPluginSearchPaths) {
1142+
ExternalPluginSearchPath.emit(ScratchRecord, Arg);
1143+
}
1144+
1145+
options_block::CompilerPluginLibraryPathLayout
1146+
CompilerPluginLibraryPath(Out);
1147+
for (auto Arg : options.CompilerPluginLibraryPaths) {
1148+
CompilerPluginLibraryPath.emit(ScratchRecord, Arg);
1149+
}
1150+
1151+
options_block::CompilerPluginExecutablePathLayout
1152+
CompilerPluginExecutablePath(Out);
1153+
for (auto Arg : options.CompilerPluginLibraryPaths) {
1154+
CompilerPluginExecutablePath.emit(ScratchRecord, Arg);
1155+
}
11271156
}
11281157
}
11291158
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// RUN: %empty-directory(%t)
2+
3+
// RUN: %target-build-swift %s -g -o %t/a.out \
4+
// RUN: -emit-executable -emit-module \
5+
// RUN: -Xfrontend -serialize-debugging-options \
6+
// RUN: -module-name MyApp \
7+
// RUN: -swift-version 5 -enable-experimental-feature Macros \
8+
// RUN: -plugin-path %t/plugins \
9+
// RUN: -external-plugin-path %t/plugins#%swift-plugin-server \
10+
// RUN: -load-plugin-library %t/%target-library-name(MacroDefinition) \
11+
// RUN: -load-plugin-executable %t/mock-plugin#TestPlugin
12+
13+
// RUN: %lldb-moduleimport-test -verbose -dump-module %t/a.out | %FileCheck %s
14+
// CHECK: - Macro Search Paths:
15+
// CHECK: -plugin-path: {{.*}}plugins
16+
// CHECK: -plugin-path: {{.*}}plugins
17+
// CHECK: -plugin-path: {{.*}}plugins
18+
// CHECK: -external-plugin-path: {{.*}}plugins#{{.*}}swift-plugin-server
19+
// CHECK: -load-plugin-library: {{.*}}MacroDefinition.{{dylib|so|dll}}
20+
// CHECK: -load-plugin-executable: {{.*}}MacroDefinition.{{dylib|so|dll}}
21+
// CHECK: -load-plugin-executable: {{.*}}mock-plugin#TestPlugin

tools/lldb-moduleimport-test/lldb-moduleimport-test.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,15 @@ static bool validateModule(
8989
llvm::outs() << ", system=" << (searchPath.IsSystem ? "true" : "false")
9090
<< "\n";
9191
}
92+
llvm::outs() << "- Macro Search Paths:\n";
93+
for (auto path : extendedInfo.getPluginSearchPaths())
94+
llvm::outs() << " -plugin-path: " << path << "\n";
95+
for (auto path : extendedInfo.getExternalPluginSearchPaths())
96+
llvm::outs() << " -external-plugin-path: " << path << "\n";
97+
for (auto path : extendedInfo.getCompilerPluginLibraryPaths())
98+
llvm::outs() << " -load-plugin-library: " << path << "\n";
99+
for (auto path : extendedInfo.getCompilerPluginExecutablePaths())
100+
llvm::outs() << " -load-plugin-executable: " << path << "\n";
92101
}
93102

94103
return true;

0 commit comments

Comments
 (0)