Skip to content

Commit 2d204f8

Browse files
[ScanDependency] Teach dependency scanner to use resolved macros option
Teach dependency scanner to construct build commands using resolved plugin search path option. This ensures the modules that do not have access to the macro plugins will not have a different variant due to different plugin search path. rdar://136682810
1 parent 47b3efd commit 2d204f8

File tree

3 files changed

+14
-65
lines changed

3 files changed

+14
-65
lines changed

lib/DependencyScan/ScanDependencies.cpp

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -160,25 +160,6 @@ parseBatchScanInputFile(ASTContext &ctx, StringRef batchInputPath,
160160
return result;
161161
}
162162

163-
static void removeMacroSearchPaths(std::vector<std::string> &cmd) {
164-
// Macro search path options.
165-
static const llvm::StringSet<> macroSearchOptions = {
166-
"-plugin-path",
167-
"-external-plugin-path",
168-
"-load-plugin-library",
169-
"-load-plugin-executable",
170-
"-in-process-plugin-server-path",
171-
};
172-
173-
// Remove macro search path option and its argument.
174-
for (auto it = cmd.begin(); it != cmd.end();) {
175-
if (macroSearchOptions.contains(*it) && it + 1 != cmd.end())
176-
it = cmd.erase(it, it + 2);
177-
else
178-
++it;
179-
}
180-
}
181-
182163
class ExplicitModuleDependencyResolver {
183164
public:
184165
ExplicitModuleDependencyResolver(
@@ -302,6 +283,13 @@ class ExplicitModuleDependencyResolver {
302283
depInfo.addMacroDependency(
303284
macro.first(), macro.second.LibraryPath, macro.second.ExecutablePath);
304285

286+
for (auto &macro : depInfo.getMacroDependencies()) {
287+
std::string arg = macro.second.LibraryPath + "#" +
288+
macro.second.ExecutablePath + "#" + macro.first;
289+
commandline.push_back("-load-resolved-plugin");
290+
commandline.push_back(arg);
291+
}
292+
305293
// Update CAS dependencies.
306294
if (auto err = collectCASDependencies(depInfo))
307295
return err;
@@ -529,11 +517,6 @@ class ExplicitModuleDependencyResolver {
529517
// Update build command line.
530518
if (resolvingDepInfo.isSwiftInterfaceModule() ||
531519
resolvingDepInfo.isSwiftSourceModule()) {
532-
// If there are no external macro dependencies, drop all plugin search
533-
// paths.
534-
if (resolvingDepInfo.getMacroDependencies().empty() && macros.empty())
535-
removeMacroSearchPaths(commandline);
536-
537520
// Update with casfs option.
538521
for (auto rootID : rootIDs) {
539522
commandline.push_back("-cas-fs");

lib/Frontend/ModuleInterfaceLoader.cpp

Lines changed: 3 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1723,47 +1723,9 @@ void InterfaceSubContextDelegateImpl::inheritOptionsForBuildingInterface(
17231723
genericSubInvocation.setPlatformAvailabilityInheritanceMapPath(*SearchPathOpts.PlatformAvailabilityInheritanceMapPath);
17241724
}
17251725

1726-
for (auto &entry : SearchPathOpts.PluginSearchOpts) {
1727-
switch (entry.getKind()) {
1728-
case PluginSearchOption::Kind::LoadPluginLibrary: {
1729-
auto &val = entry.get<PluginSearchOption::LoadPluginLibrary>();
1730-
GenericArgs.push_back("-load-plugin-library");
1731-
GenericArgs.push_back(ArgSaver.save(val.LibraryPath));
1732-
break;
1733-
}
1734-
case PluginSearchOption::Kind::LoadPluginExecutable: {
1735-
auto &val = entry.get<PluginSearchOption::LoadPluginExecutable>();
1736-
for (auto &moduleName : val.ModuleNames) {
1737-
GenericArgs.push_back("-load-plugin-executable");
1738-
GenericArgs.push_back(
1739-
ArgSaver.save(val.ExecutablePath + "#" + moduleName));
1740-
}
1741-
break;
1742-
}
1743-
case PluginSearchOption::Kind::PluginPath: {
1744-
auto &val = entry.get<PluginSearchOption::PluginPath>();
1745-
GenericArgs.push_back("-plugin-path");
1746-
GenericArgs.push_back(ArgSaver.save(val.SearchPath));
1747-
break;
1748-
}
1749-
case PluginSearchOption::Kind::ExternalPluginPath: {
1750-
auto &val = entry.get<PluginSearchOption::ExternalPluginPath>();
1751-
GenericArgs.push_back("-external-plugin-path");
1752-
GenericArgs.push_back(
1753-
ArgSaver.save(val.SearchPath + "#" + val.ServerPath));
1754-
break;
1755-
}
1756-
case PluginSearchOption::Kind::ResolvedPluginConfig: {
1757-
auto &val = entry.get<PluginSearchOption::ResolvedPluginConfig>();
1758-
for (auto &moduleName : val.ModuleNames) {
1759-
GenericArgs.push_back("-load-plugin-executable");
1760-
GenericArgs.push_back(ArgSaver.save(
1761-
val.LibraryPath + "#" + val.ExecutablePath + "#" + moduleName));
1762-
}
1763-
break;
1764-
}
1765-
}
1766-
}
1726+
// Inherit the plugin search opts but do not inherit the arguments.
1727+
genericSubInvocation.getSearchPathOptions().PluginSearchOpts =
1728+
SearchPathOpts.PluginSearchOpts;
17671729

17681730
genericSubInvocation.getFrontendOptions().InputMode
17691731
= FrontendOptions::ParseInputMode::SwiftModuleInterface;

test/CAS/macro_deps.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@
4444
// RUN: %{python} %S/Inputs/GenerateExplicitModuleMap.py %t/deps.json > %t/map.json
4545
// RUN: llvm-cas --cas %t/cas --make-blob --data %t/map.json > %t/map.casid
4646

47+
// RUN: %FileCheck %s --check-prefix=PLUGIN_SEARCH --check-prefix=RESOLVED --input-file=%t/MyApp.cmd
48+
// PLUGIN_SEARCH-NOT: -external-plugin-path
49+
// RESOLVED-COUNT-2: -load-resolved-plugin
50+
4751
// RUN: %target-swift-frontend -diagnostic-style=swift \
4852
// RUN: -emit-module -o %t/Test.swiftmodule -cache-compile-job -cas-path %t/cas \
4953
// RUN: -swift-version 5 -disable-implicit-swift-modules \

0 commit comments

Comments
 (0)