Skip to content

Commit 4f0a757

Browse files
rintaroxymus
authored andcommitted
[Macros] Serialize plugin search paths for LLDB use
rdar://107030743
1 parent 08af8a6 commit 4f0a757

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
@@ -203,6 +203,32 @@ SerializationOptions CompilerInvocation::computeSerializationOptions(
203203
serializationOpts.ExtraClangOptions = getClangImporterOptions().ExtraArgs;
204204
}
205205

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

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
@@ -868,6 +868,10 @@ namespace options_block {
868868
IS_CONCURRENCY_CHECKED,
869869
MODULE_PACKAGE_NAME,
870870
MODULE_EXPORT_AS_NAME,
871+
PLUGIN_SEARCH_PATH,
872+
EXTERNAL_SEARCH_PLUGIN_PATH,
873+
COMPILER_PLUGIN_LIBRARY_PATH,
874+
COMPILER_PLUGIN_EXECUTABLE_PATH,
871875
};
872876

873877
using SDKPathLayout = BCRecordLayout<
@@ -880,6 +884,26 @@ namespace options_block {
880884
BCBlob // -Xcc flag, as string
881885
>;
882886

887+
using PluginSearchPathLayout = BCRecordLayout<
888+
PLUGIN_SEARCH_PATH,
889+
BCBlob // -plugin-path value
890+
>;
891+
892+
using ExternalPluginSearchPathLayout = BCRecordLayout<
893+
EXTERNAL_SEARCH_PLUGIN_PATH,
894+
BCBlob // -external-plugin-path value
895+
>;
896+
897+
using CompilerPluginLibraryPathLayout = BCRecordLayout<
898+
COMPILER_PLUGIN_LIBRARY_PATH,
899+
BCBlob // -load-plugin-library value
900+
>;
901+
902+
using CompilerPluginExecutablePathLayout = BCRecordLayout<
903+
COMPILER_PLUGIN_EXECUTABLE_PATH,
904+
BCBlob // -load-plugin-executable value
905+
>;
906+
883907
using IsSIBLayout = BCRecordLayout<
884908
IS_SIB,
885909
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
@@ -843,6 +843,11 @@ void Serializer::writeBlockInfoBlock() {
843843
BLOCK_RECORD(options_block, MODULE_ABI_NAME);
844844
BLOCK_RECORD(options_block, IS_CONCURRENCY_CHECKED);
845845
BLOCK_RECORD(options_block, MODULE_PACKAGE_NAME);
846+
BLOCK_RECORD(options_block, MODULE_EXPORT_AS_NAME);
847+
BLOCK_RECORD(options_block, PLUGIN_SEARCH_PATH);
848+
BLOCK_RECORD(options_block, EXTERNAL_SEARCH_PLUGIN_PATH);
849+
BLOCK_RECORD(options_block, COMPILER_PLUGIN_LIBRARY_PATH);
850+
BLOCK_RECORD(options_block, COMPILER_PLUGIN_EXECUTABLE_PATH);
846851

847852
BLOCK(INPUT_BLOCK);
848853
BLOCK_RECORD(input_block, IMPORTED_MODULE);
@@ -1119,6 +1124,30 @@ void Serializer::writeHeader(const SerializationOptions &options) {
11191124
}
11201125
XCC.emit(ScratchRecord, arg);
11211126
}
1127+
1128+
// Macro plugins
1129+
options_block::PluginSearchPathLayout PluginSearchPath(Out);
1130+
for (auto Arg : options.PluginSearchPaths) {
1131+
PluginSearchPath.emit(ScratchRecord, Arg);
1132+
}
1133+
1134+
options_block::ExternalPluginSearchPathLayout
1135+
ExternalPluginSearchPath(Out);
1136+
for (auto Arg : options.ExternalPluginSearchPaths) {
1137+
ExternalPluginSearchPath.emit(ScratchRecord, Arg);
1138+
}
1139+
1140+
options_block::CompilerPluginLibraryPathLayout
1141+
CompilerPluginLibraryPath(Out);
1142+
for (auto Arg : options.CompilerPluginLibraryPaths) {
1143+
CompilerPluginLibraryPath.emit(ScratchRecord, Arg);
1144+
}
1145+
1146+
options_block::CompilerPluginExecutablePathLayout
1147+
CompilerPluginExecutablePath(Out);
1148+
for (auto Arg : options.CompilerPluginLibraryPaths) {
1149+
CompilerPluginExecutablePath.emit(ScratchRecord, Arg);
1150+
}
11221151
}
11231152
}
11241153
}
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: {{.*}}/lib/swift/host/plugins
17+
// CHECK: -plugin-path: {{.*}}/local/lib/swift/host/plugins
18+
// CHECK: -external-plugin-path: {{.*}}/plugins#{{.*}}/swift-plugin-server
19+
// CHECK: -load-plugin-library: {{.*}}/libMacroDefinition.dylib
20+
// CHECK: -load-plugin-executable: {{.*}}/libMacroDefinition.dylib
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)