[Dependency Scanning] Filter out '-Xcc' search paths from Swift module compilation commands

These search paths will not get used during Swift module compilation and can only hinder module sharing among different targets.

Resolves rdar://119217774
This commit is contained in:
Artem Chikin
2023-12-07 17:03:25 -08:00
parent 452c624c96
commit f5e2b24912
4 changed files with 123 additions and 28 deletions

View File

@@ -1756,17 +1756,32 @@ InterfaceSubContextDelegateImpl::InterfaceSubContextDelegateImpl(
clangImporterOpts.DetailedPreprocessingRecord;
subClangImporterOpts.CASOpts = clangImporterOpts.CASOpts;
// If the compiler has been asked to be strict with ensuring downstream dependencies
// get the parent invocation's context, or this is an Explicit build, inherit the
// extra Clang arguments also.
if (LoaderOpts.strictImplicitModuleContext || LoaderOpts.disableImplicitSwiftModule ||
LoaderOpts.requestedAction == FrontendOptions::ActionType::ScanDependencies) {
// Inherit any clang-specific state of the compilation (macros, clang flags, etc.)
subClangImporterOpts.ExtraArgs = clangImporterOpts.ExtraArgs;
for (auto arg : subClangImporterOpts.ExtraArgs) {
GenericArgs.push_back("-Xcc");
GenericArgs.push_back(ArgSaver.save(arg));
}
std::vector<std::string> inheritedParentContextClangArgs;
if (LoaderOpts.requestedAction ==
FrontendOptions::ActionType::ScanDependencies) {
// For a dependency scanning action, interface build command generation must
// inherit
// `-Xcc` flags used for configuration of the building instance's
// `ClangImporter`. However, we can ignore Clang search path flags because
// explicit Swift module build tasks will not rely on them and they may be
// source-target-context-specific and hinder module sharing across
// compilation source targets.
// Clang module dependecies of this Swift dependency will be distinguished by
// their context hash for different variants, so would still cause a difference
// in the Swift compile commands, when different.
inheritedParentContextClangArgs =
clangImporterOpts.getReducedExtraArgsForSwiftModuleDependency();
} else if (LoaderOpts.strictImplicitModuleContext) {
// If the compiler has been asked to be strict with ensuring downstream
// dependencies get the parent invocation's context, inherit the extra Clang
// arguments also. Inherit any clang-specific state of the compilation
// (macros, clang flags, etc.)
inheritedParentContextClangArgs = clangImporterOpts.ExtraArgs;
}
subClangImporterOpts.ExtraArgs = inheritedParentContextClangArgs;
for (auto arg : subClangImporterOpts.ExtraArgs) {
GenericArgs.push_back("-Xcc");
GenericArgs.push_back(ArgSaver.save(arg));
}
subClangImporterOpts.EnableClangSPI = clangImporterOpts.EnableClangSPI;