Skip to content

[Macros] Serialize plugin search paths for LLDB use #65370

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions include/swift/Serialization/SerializationOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ namespace swift {
StringRef ModuleLinkName;
StringRef ModuleInterface;
std::vector<std::string> ExtraClangOptions;
std::vector<std::string> PluginSearchPaths;
std::vector<std::string> ExternalPluginSearchPaths;
std::vector<std::string> CompilerPluginLibraryPaths;
std::vector<std::string> CompilerPluginExecutablePaths;

/// Path prefixes that should be rewritten in debug info.
PathRemapper DebuggingOptionsPrefixMap;
Expand Down
34 changes: 34 additions & 0 deletions include/swift/Serialization/Validation.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ struct ValidationInfo {
/// \sa validateSerializedAST()
class ExtendedValidationInfo {
SmallVector<StringRef, 4> ExtraClangImporterOpts;

SmallVector<StringRef, 1> PluginSearchPaths;
SmallVector<StringRef, 1> ExternalPluginSearchPaths;
SmallVector<StringRef, 1> CompilerPluginLibraryPaths;
SmallVector<StringRef, 1> CompilerPluginExecutablePaths;

std::string SDKPath;
StringRef ModuleABIName;
StringRef ModulePackageName;
Expand Down Expand Up @@ -138,6 +144,34 @@ class ExtendedValidationInfo {
ExtraClangImporterOpts.push_back(option);
}

ArrayRef<StringRef> getPluginSearchPaths() const {
return PluginSearchPaths;
}
void addPluginSearchPath(StringRef path) {
PluginSearchPaths.push_back(path);
}

ArrayRef<StringRef> getExternalPluginSearchPaths() const {
return ExternalPluginSearchPaths;
}
void addExternalPluginSearchPath(StringRef path) {
ExternalPluginSearchPaths.push_back(path);
}

ArrayRef<StringRef> getCompilerPluginLibraryPaths() const {
return CompilerPluginLibraryPaths;
}
void addCompilerPluginLibraryPath(StringRef path) {
CompilerPluginLibraryPaths.push_back(path);
}

ArrayRef<StringRef> getCompilerPluginExecutablePaths() const {
return CompilerPluginExecutablePaths;
}
void addCompilerPluginExecutablePath(StringRef path) {
CompilerPluginExecutablePaths.push_back(path);
}

bool isSIB() const { return Bits.IsSIB; }
void setIsSIB(bool val) {
Bits.IsSIB = val;
Expand Down
26 changes: 26 additions & 0 deletions lib/Frontend/Frontend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,32 @@ SerializationOptions CompilerInvocation::computeSerializationOptions(
serializationOpts.ExtraClangOptions = getClangImporterOptions().ExtraArgs;
}

// '-plugin-path' options.
for (const auto &path : getSearchPathOptions().PluginSearchPaths) {
serializationOpts.PluginSearchPaths.push_back(path);
}
// '-external-plugin-path' options.
for (const ExternalPluginSearchPathAndServerPath &pair :
getSearchPathOptions().ExternalPluginSearchPaths) {
serializationOpts.ExternalPluginSearchPaths.push_back(
pair.SearchPath + "#" +
pair.ServerPath);
}
// '-load-plugin-library' options.
for (const auto &path :
getSearchPathOptions().getCompilerPluginLibraryPaths()) {
serializationOpts.CompilerPluginLibraryPaths.push_back(path);
}
// '-load-plugin-executable' options.
for (const PluginExecutablePathAndModuleNames &pair :
getSearchPathOptions().getCompilerPluginExecutablePaths()) {
std::string optStr = pair.ExecutablePath + "#";
llvm::interleave(
pair.ModuleNames, [&](auto &name) { optStr += name; },
[&]() { optStr += ","; });
serializationOpts.CompilerPluginLibraryPaths.push_back(optStr);
}

serializationOpts.DisableCrossModuleIncrementalInfo =
opts.DisableCrossModuleIncrementalBuild;

Expand Down
12 changes: 12 additions & 0 deletions lib/Serialization/ModuleFileSharedCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,18 @@ static bool readOptionsBlock(llvm::BitstreamCursor &cursor,
case options_block::XCC:
extendedInfo.addExtraClangImporterOption(blobData);
break;
case options_block::PLUGIN_SEARCH_PATH:
extendedInfo.addPluginSearchPath(blobData);
break;
case options_block::EXTERNAL_SEARCH_PLUGIN_PATH:
extendedInfo.addExternalPluginSearchPath(blobData);
break;
case options_block::COMPILER_PLUGIN_LIBRARY_PATH:
extendedInfo.addCompilerPluginLibraryPath(blobData);
break;
case options_block::COMPILER_PLUGIN_EXECUTABLE_PATH:
extendedInfo.addCompilerPluginExecutablePath(blobData);
break;
case options_block::IS_SIB:
bool IsSIB;
options_block::IsSIBLayout::readRecord(scratch, IsSIB);
Expand Down
24 changes: 24 additions & 0 deletions lib/Serialization/ModuleFormat.h
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,10 @@ namespace options_block {
IS_CONCURRENCY_CHECKED,
MODULE_PACKAGE_NAME,
MODULE_EXPORT_AS_NAME,
PLUGIN_SEARCH_PATH,
EXTERNAL_SEARCH_PLUGIN_PATH,
COMPILER_PLUGIN_LIBRARY_PATH,
COMPILER_PLUGIN_EXECUTABLE_PATH,
};

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

using PluginSearchPathLayout = BCRecordLayout<
PLUGIN_SEARCH_PATH,
BCBlob // -plugin-path value
>;

using ExternalPluginSearchPathLayout = BCRecordLayout<
EXTERNAL_SEARCH_PLUGIN_PATH,
BCBlob // -external-plugin-path value
>;

using CompilerPluginLibraryPathLayout = BCRecordLayout<
COMPILER_PLUGIN_LIBRARY_PATH,
BCBlob // -load-plugin-library value
>;

using CompilerPluginExecutablePathLayout = BCRecordLayout<
COMPILER_PLUGIN_EXECUTABLE_PATH,
BCBlob // -load-plugin-executable value
>;

using IsSIBLayout = BCRecordLayout<
IS_SIB,
BCFixed<1> // Is this an intermediate file?
Expand Down
29 changes: 29 additions & 0 deletions lib/Serialization/Serialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,11 @@ void Serializer::writeBlockInfoBlock() {
BLOCK_RECORD(options_block, MODULE_ABI_NAME);
BLOCK_RECORD(options_block, IS_CONCURRENCY_CHECKED);
BLOCK_RECORD(options_block, MODULE_PACKAGE_NAME);
BLOCK_RECORD(options_block, MODULE_EXPORT_AS_NAME);
BLOCK_RECORD(options_block, PLUGIN_SEARCH_PATH);
BLOCK_RECORD(options_block, EXTERNAL_SEARCH_PLUGIN_PATH);
BLOCK_RECORD(options_block, COMPILER_PLUGIN_LIBRARY_PATH);
BLOCK_RECORD(options_block, COMPILER_PLUGIN_EXECUTABLE_PATH);

BLOCK(INPUT_BLOCK);
BLOCK_RECORD(input_block, IMPORTED_MODULE);
Expand Down Expand Up @@ -1119,6 +1124,30 @@ void Serializer::writeHeader(const SerializationOptions &options) {
}
XCC.emit(ScratchRecord, arg);
}

// Macro plugins
options_block::PluginSearchPathLayout PluginSearchPath(Out);
for (auto Arg : options.PluginSearchPaths) {
PluginSearchPath.emit(ScratchRecord, Arg);
}

options_block::ExternalPluginSearchPathLayout
ExternalPluginSearchPath(Out);
for (auto Arg : options.ExternalPluginSearchPaths) {
ExternalPluginSearchPath.emit(ScratchRecord, Arg);
}

options_block::CompilerPluginLibraryPathLayout
CompilerPluginLibraryPath(Out);
for (auto Arg : options.CompilerPluginLibraryPaths) {
CompilerPluginLibraryPath.emit(ScratchRecord, Arg);
}

options_block::CompilerPluginExecutablePathLayout
CompilerPluginExecutablePath(Out);
for (auto Arg : options.CompilerPluginLibraryPaths) {
CompilerPluginExecutablePath.emit(ScratchRecord, Arg);
}
}
}
}
Expand Down
21 changes: 21 additions & 0 deletions test/Macros/serialize_plugin_search_paths.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// RUN: %empty-directory(%t)

// RUN: %target-build-swift %s -g -o %t/a.out \
// RUN: -emit-executable -emit-module \
// RUN: -Xfrontend -serialize-debugging-options \
// RUN: -module-name MyApp \
// RUN: -swift-version 5 -enable-experimental-feature Macros \
// RUN: -plugin-path %t/plugins \
// RUN: -external-plugin-path %t/plugins#%swift-plugin-server \
// RUN: -load-plugin-library %t/%target-library-name(MacroDefinition) \
// RUN: -load-plugin-executable %t/mock-plugin#TestPlugin

// RUN: %lldb-moduleimport-test -verbose -dump-module %t/a.out | %FileCheck %s
// CHECK: - Macro Search Paths:
// CHECK: -plugin-path: {{.*}}plugins
// CHECK: -plugin-path: {{.*}}plugins
// CHECK: -plugin-path: {{.*}}plugins
// CHECK: -external-plugin-path: {{.*}}plugins#{{.*}}swift-plugin-server
// CHECK: -load-plugin-library: {{.*}}MacroDefinition.{{dylib|so|dll}}
// CHECK: -load-plugin-executable: {{.*}}MacroDefinition.{{dylib|so|dll}}
// CHECK: -load-plugin-executable: {{.*}}mock-plugin#TestPlugin
9 changes: 9 additions & 0 deletions tools/lldb-moduleimport-test/lldb-moduleimport-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,15 @@ static bool validateModule(
llvm::outs() << ", system=" << (searchPath.IsSystem ? "true" : "false")
<< "\n";
}
llvm::outs() << "- Macro Search Paths:\n";
for (auto path : extendedInfo.getPluginSearchPaths())
llvm::outs() << " -plugin-path: " << path << "\n";
for (auto path : extendedInfo.getExternalPluginSearchPaths())
llvm::outs() << " -external-plugin-path: " << path << "\n";
for (auto path : extendedInfo.getCompilerPluginLibraryPaths())
llvm::outs() << " -load-plugin-library: " << path << "\n";
for (auto path : extendedInfo.getCompilerPluginExecutablePaths())
llvm::outs() << " -load-plugin-executable: " << path << "\n";
}

return true;
Expand Down