mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[Macros] Emit plugin dependencies to loaded module trace. (#63367)
Emit plugins loaded with `-load-plugin-library` to loaded module trace. Resolves rdar://102212316.
This commit is contained in:
@@ -386,6 +386,11 @@ void CompilerInstance::setupDependencyTrackerIfNeeded() {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
DepTracker = std::make_unique<DependencyTracker>(*collectionMode);
|
DepTracker = std::make_unique<DependencyTracker>(*collectionMode);
|
||||||
|
|
||||||
|
// Collect compiler plugin dependencies.
|
||||||
|
auto &searchPathOpts = Invocation.getSearchPathOptions();
|
||||||
|
for (auto &path : searchPathOpts.getCompilerPluginLibraryPaths())
|
||||||
|
DepTracker->addDependency(path, /*isSystem=*/false);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CompilerInstance::setup(const CompilerInvocation &Invoke,
|
bool CompilerInstance::setup(const CompilerInvocation &Invoke,
|
||||||
|
|||||||
@@ -552,6 +552,7 @@ void ABIDependencyEvaluator::printABIExportMap(llvm::raw_ostream &os) const {
|
|||||||
// FIXME: Use the VFS instead of handling paths directly. We are particularly
|
// FIXME: Use the VFS instead of handling paths directly. We are particularly
|
||||||
// sloppy about handling relative paths in the dependency tracker.
|
// sloppy about handling relative paths in the dependency tracker.
|
||||||
static void computeSwiftModuleTraceInfo(
|
static void computeSwiftModuleTraceInfo(
|
||||||
|
ASTContext &ctx,
|
||||||
const SmallPtrSetImpl<ModuleDecl *> &abiDependencies,
|
const SmallPtrSetImpl<ModuleDecl *> &abiDependencies,
|
||||||
const llvm::DenseMap<StringRef, ModuleDecl *> &pathToModuleDecl,
|
const llvm::DenseMap<StringRef, ModuleDecl *> &pathToModuleDecl,
|
||||||
const DependencyTracker &depTracker, StringRef prebuiltCachePath,
|
const DependencyTracker &depTracker, StringRef prebuiltCachePath,
|
||||||
@@ -569,6 +570,8 @@ static void computeSwiftModuleTraceInfo(
|
|||||||
SmallVector<std::string, 16> dependencies{deps.begin(), deps.end()};
|
SmallVector<std::string, 16> dependencies{deps.begin(), deps.end()};
|
||||||
auto incrDeps = depTracker.getIncrementalDependencyPaths();
|
auto incrDeps = depTracker.getIncrementalDependencyPaths();
|
||||||
dependencies.append(incrDeps.begin(), incrDeps.end());
|
dependencies.append(incrDeps.begin(), incrDeps.end());
|
||||||
|
auto sharedLibraryExtRegex =
|
||||||
|
llvm::Regex("dylib|so|dll", llvm::Regex::IgnoreCase);
|
||||||
for (const auto &depPath : dependencies) {
|
for (const auto &depPath : dependencies) {
|
||||||
|
|
||||||
// Decide if this is a swiftmodule based on the extension of the raw
|
// Decide if this is a swiftmodule based on the extension of the raw
|
||||||
@@ -580,8 +583,10 @@ static void computeSwiftModuleTraceInfo(
|
|||||||
auto isSwiftmodule = moduleFileType == file_types::TY_SwiftModuleFile;
|
auto isSwiftmodule = moduleFileType == file_types::TY_SwiftModuleFile;
|
||||||
auto isSwiftinterface =
|
auto isSwiftinterface =
|
||||||
moduleFileType == file_types::TY_SwiftModuleInterfaceFile;
|
moduleFileType == file_types::TY_SwiftModuleInterfaceFile;
|
||||||
|
auto isSharedLibrary =
|
||||||
|
sharedLibraryExtRegex.match(llvm::sys::path::extension(depPath));
|
||||||
|
|
||||||
if (!(isSwiftmodule || isSwiftinterface))
|
if (!(isSwiftmodule || isSwiftinterface || isSharedLibrary))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
auto dep = pathToModuleDecl.find(depPath);
|
auto dep = pathToModuleDecl.find(depPath);
|
||||||
@@ -637,6 +642,34 @@ static void computeSwiftModuleTraceInfo(
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If we found a shared library, it must be a compiler plugin dependency.
|
||||||
|
if (isSharedLibrary) {
|
||||||
|
// Infer the module name by dropping the library prefix and extension.
|
||||||
|
// e.g "/path/to/lib/libPlugin.dylib" -> "Plugin"
|
||||||
|
auto moduleName = llvm::sys::path::stem(depPath);
|
||||||
|
#if !defined(_WIN32)
|
||||||
|
moduleName.consume_front("lib");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
StringRef realDepPath =
|
||||||
|
fs::real_path(depPath, buffer, /*expand_tile*/ true)
|
||||||
|
? StringRef(depPath)
|
||||||
|
: buffer.str();
|
||||||
|
|
||||||
|
traceInfo.push_back(
|
||||||
|
{/*Name=*/
|
||||||
|
ctx.getIdentifier(moduleName),
|
||||||
|
/*Path=*/
|
||||||
|
realDepPath.str(),
|
||||||
|
/*IsImportedDirectly=*/
|
||||||
|
false,
|
||||||
|
/*SupportsLibraryEvolution=*/
|
||||||
|
false});
|
||||||
|
buffer.clear();
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// Skip cached modules in the prebuilt cache. We will add the corresponding
|
// Skip cached modules in the prebuilt cache. We will add the corresponding
|
||||||
// swiftinterface from the SDK directly, but this isn't checked. :-/
|
// swiftinterface from the SDK directly, but this isn't checked. :-/
|
||||||
//
|
//
|
||||||
@@ -731,8 +764,9 @@ bool swift::emitLoadedModuleTraceIfNeeded(ModuleDecl *mainModule,
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::vector<SwiftModuleTraceInfo> swiftModules;
|
std::vector<SwiftModuleTraceInfo> swiftModules;
|
||||||
computeSwiftModuleTraceInfo(abiDependencies, pathToModuleDecl, *depTracker,
|
computeSwiftModuleTraceInfo(ctxt, abiDependencies, pathToModuleDecl,
|
||||||
opts.PrebuiltModuleCachePath, swiftModules);
|
*depTracker, opts.PrebuiltModuleCachePath,
|
||||||
|
swiftModules);
|
||||||
|
|
||||||
LoadedModuleTraceFormat trace = {
|
LoadedModuleTraceFormat trace = {
|
||||||
/*version=*/LoadedModuleTraceFormat::CurrentVersion,
|
/*version=*/LoadedModuleTraceFormat::CurrentVersion,
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
// Don't need anything here, just for the module to exist.
|
||||||
@@ -2,7 +2,8 @@
|
|||||||
// RUN: %empty-directory(%t/cache)
|
// RUN: %empty-directory(%t/cache)
|
||||||
// RUN: %target-build-swift -emit-module -module-name Module %S/Inputs/loaded_module_trace_empty.swift -o %t/Module.swiftmodule -module-cache-path %t/cache
|
// RUN: %target-build-swift -emit-module -module-name Module %S/Inputs/loaded_module_trace_empty.swift -o %t/Module.swiftmodule -module-cache-path %t/cache
|
||||||
// RUN: %target-build-swift -emit-module -module-name Module2 %S/Inputs/loaded_module_trace_imports_module.swift -o %t/Module2.swiftmodule -I %t -module-cache-path %t/cache
|
// RUN: %target-build-swift -emit-module -module-name Module2 %S/Inputs/loaded_module_trace_imports_module.swift -o %t/Module2.swiftmodule -I %t -module-cache-path %t/cache
|
||||||
// RUN: %target-build-swift %s -emit-loaded-module-trace -o %t/loaded_module_trace -I %t -module-cache-path %t/cache
|
// RUN: %target-build-swift -emit-library -module-name Plugin %S/Inputs/loaded_module_trace_compiler_plugin.swift -o %t/%target-library-name(Plugin) -module-cache-path %t/cache
|
||||||
|
// RUN: %target-build-swift %s -emit-loaded-module-trace -o %t/loaded_module_trace -I %t -module-cache-path %t/cache -load-plugin-library %t/%target-library-name(Plugin)
|
||||||
// RUN: %FileCheck -check-prefix=CHECK %s < %t/loaded_module_trace.trace.json
|
// RUN: %FileCheck -check-prefix=CHECK %s < %t/loaded_module_trace.trace.json
|
||||||
// RUN: %FileCheck -check-prefix=CHECK-CONFIRM-ONELINE %s < %t/loaded_module_trace.trace.json
|
// RUN: %FileCheck -check-prefix=CHECK-CONFIRM-ONELINE %s < %t/loaded_module_trace.trace.json
|
||||||
|
|
||||||
@@ -25,6 +26,7 @@
|
|||||||
// CHECK-DAG: {"name":"Swift","path":"{{[^"]*\\[/\\]}}Swift.swiftmodule{{(\\[/\\][^"]+[.]swiftmodule)?}}","isImportedDirectly":true,"supportsLibraryEvolution":true}
|
// CHECK-DAG: {"name":"Swift","path":"{{[^"]*\\[/\\]}}Swift.swiftmodule{{(\\[/\\][^"]+[.]swiftmodule)?}}","isImportedDirectly":true,"supportsLibraryEvolution":true}
|
||||||
// CHECK-DAG: {"name":"SwiftOnoneSupport","path":"{{[^"]*\\[/\\]}}SwiftOnoneSupport.swiftmodule{{(\\[/\\][^"]+[.]swiftmodule)?}}","isImportedDirectly":true,"supportsLibraryEvolution":true}
|
// CHECK-DAG: {"name":"SwiftOnoneSupport","path":"{{[^"]*\\[/\\]}}SwiftOnoneSupport.swiftmodule{{(\\[/\\][^"]+[.]swiftmodule)?}}","isImportedDirectly":true,"supportsLibraryEvolution":true}
|
||||||
// CHECK-DAG: {"name":"Module","path":"{{[^"]*\\[/\\]}}Module.swiftmodule","isImportedDirectly":false,"supportsLibraryEvolution":false}
|
// CHECK-DAG: {"name":"Module","path":"{{[^"]*\\[/\\]}}Module.swiftmodule","isImportedDirectly":false,"supportsLibraryEvolution":false}
|
||||||
|
// CHECK-DAG: {"name":"Plugin","path":"{{[^"]*\\[/\\]}}{{libPlugin.dylib|libPlugin.so|Plugin.dll}}","isImportedDirectly":false,"supportsLibraryEvolution":false}
|
||||||
// CHECK: ]
|
// CHECK: ]
|
||||||
// CHECK: }
|
// CHECK: }
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user