mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[Macros] Serialize plugin search paths for LLDB use
rdar://107030743
This commit is contained in:
committed by
Alexis Laferrière
parent
08af8a657f
commit
3ef6087d32
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
@@ -138,6 +144,34 @@ public:
|
||||
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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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<
|
||||
@@ -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?
|
||||
|
||||
@@ -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);
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
21
test/Macros/serialize_plugin_search_paths.swift
Normal file
21
test/Macros/serialize_plugin_search_paths.swift
Normal file
@@ -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
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user