Skip to content

Commit cc01e02

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 36d394b commit cc01e02

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
@@ -159,25 +159,6 @@ parseBatchScanInputFile(ASTContext &ctx, StringRef batchInputPath,
159159
return result;
160160
}
161161

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

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

lib/Frontend/ModuleInterfaceLoader.cpp

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

1714-
for (auto &entry : SearchPathOpts.PluginSearchOpts) {
1715-
switch (entry.getKind()) {
1716-
case PluginSearchOption::Kind::LoadPluginLibrary: {
1717-
auto &val = entry.get<PluginSearchOption::LoadPluginLibrary>();
1718-
GenericArgs.push_back("-load-plugin-library");
1719-
GenericArgs.push_back(ArgSaver.save(val.LibraryPath));
1720-
break;
1721-
}
1722-
case PluginSearchOption::Kind::LoadPluginExecutable: {
1723-
auto &val = entry.get<PluginSearchOption::LoadPluginExecutable>();
1724-
for (auto &moduleName : val.ModuleNames) {
1725-
GenericArgs.push_back("-load-plugin-executable");
1726-
GenericArgs.push_back(
1727-
ArgSaver.save(val.ExecutablePath + "#" + moduleName));
1728-
}
1729-
break;
1730-
}
1731-
case PluginSearchOption::Kind::PluginPath: {
1732-
auto &val = entry.get<PluginSearchOption::PluginPath>();
1733-
GenericArgs.push_back("-plugin-path");
1734-
GenericArgs.push_back(ArgSaver.save(val.SearchPath));
1735-
break;
1736-
}
1737-
case PluginSearchOption::Kind::ExternalPluginPath: {
1738-
auto &val = entry.get<PluginSearchOption::ExternalPluginPath>();
1739-
GenericArgs.push_back("-external-plugin-path");
1740-
GenericArgs.push_back(
1741-
ArgSaver.save(val.SearchPath + "#" + val.ServerPath));
1742-
break;
1743-
}
1744-
case PluginSearchOption::Kind::ResolvedPluginConfig: {
1745-
auto &val = entry.get<PluginSearchOption::ResolvedPluginConfig>();
1746-
for (auto &moduleName : val.ModuleNames) {
1747-
GenericArgs.push_back("-load-plugin-executable");
1748-
GenericArgs.push_back(ArgSaver.save(
1749-
val.LibraryPath + "#" + val.ExecutablePath + "#" + moduleName));
1750-
}
1751-
break;
1752-
}
1753-
}
1754-
}
1714+
// Inherit the plugin search opts but do not inherit the arguments.
1715+
genericSubInvocation.getSearchPathOptions().PluginSearchOpts =
1716+
SearchPathOpts.PluginSearchOpts;
17551717

17561718
genericSubInvocation.getFrontendOptions().InputMode
17571719
= 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)