|
46 | 46 | #include "swift/Basic/Version.h" |
47 | 47 | #include "swift/ClangImporter/ClangImporterRequests.h" |
48 | 48 | #include "swift/ClangImporter/ClangModule.h" |
| 49 | +#include "swift/Option/Options.h" |
49 | 50 | #include "swift/Parse/Lexer.h" |
50 | 51 | #include "swift/Parse/ParseVersion.h" |
51 | 52 | #include "swift/Parse/Parser.h" |
|
65 | 66 | #include "clang/CodeGen/ObjectFilePCHContainerOperations.h" |
66 | 67 | #include "clang/Frontend/CompilerInvocation.h" |
67 | 68 | #include "clang/Frontend/FrontendActions.h" |
| 69 | +#include "clang/Frontend/FrontendOptions.h" |
68 | 70 | #include "clang/Frontend/IncludeTreePPActions.h" |
69 | 71 | #include "clang/Frontend/TextDiagnosticPrinter.h" |
70 | 72 | #include "clang/Frontend/Utils.h" |
@@ -753,31 +755,6 @@ void importer::getNormalInvocationArguments( |
753 | 755 | invocationArgStrs.push_back((llvm::Twine(searchPathOpts.RuntimeResourcePath) + |
754 | 756 | llvm::sys::path::get_separator() + |
755 | 757 | "apinotes").str()); |
756 | | - |
757 | | - auto CASOpts = ctx.CASOpts; |
758 | | - if (CASOpts.EnableCaching) { |
759 | | - invocationArgStrs.push_back("-Xclang"); |
760 | | - invocationArgStrs.push_back("-fno-pch-timestamp"); |
761 | | - if (!CASOpts.CASOpts.CASPath.empty()) { |
762 | | - invocationArgStrs.push_back("-Xclang"); |
763 | | - invocationArgStrs.push_back("-fcas-path"); |
764 | | - invocationArgStrs.push_back("-Xclang"); |
765 | | - invocationArgStrs.push_back(CASOpts.CASOpts.CASPath); |
766 | | - } |
767 | | - if (!CASOpts.CASOpts.PluginPath.empty()) { |
768 | | - invocationArgStrs.push_back("-Xclang"); |
769 | | - invocationArgStrs.push_back("-fcas-plugin-path"); |
770 | | - invocationArgStrs.push_back("-Xclang"); |
771 | | - invocationArgStrs.push_back(CASOpts.CASOpts.PluginPath); |
772 | | - for (auto Opt : CASOpts.CASOpts.PluginOptions) { |
773 | | - invocationArgStrs.push_back("-Xclang"); |
774 | | - invocationArgStrs.push_back("-fcas-plugin-option"); |
775 | | - invocationArgStrs.push_back("-Xclang"); |
776 | | - invocationArgStrs.push_back( |
777 | | - (llvm::Twine(Opt.first) + "=" + Opt.second).str()); |
778 | | - } |
779 | | - } |
780 | | - } |
781 | 758 | } |
782 | 759 |
|
783 | 760 | static void |
@@ -1154,8 +1131,21 @@ std::optional<std::vector<std::string>> ClangImporter::getClangCC1Arguments( |
1154 | 1131 | // to reduce the number of argument passing on the command-line and swift |
1155 | 1132 | // compiler can be more efficient to compute swift cache key without having |
1156 | 1133 | // the knowledge about clang command-line options. |
1157 | | - if (ctx.CASOpts.EnableCaching) |
| 1134 | + if (ctx.CASOpts.EnableCaching) { |
1158 | 1135 | CI->getCASOpts() = ctx.CASOpts.CASOpts; |
| 1136 | + // When clangImporter is used to compile (generate .pcm or .pch), need to |
| 1137 | + // inherit the include tree from swift args (last one wins) and clear the |
| 1138 | + // input file. |
| 1139 | + if ((CI->getFrontendOpts().ProgramAction == |
| 1140 | + clang::frontend::ActionKind::GenerateModule || |
| 1141 | + CI->getFrontendOpts().ProgramAction == |
| 1142 | + clang::frontend::ActionKind::GeneratePCH) && |
| 1143 | + ctx.ClangImporterOpts.HasClangIncludeTreeRoot) { |
| 1144 | + CI->getFrontendOpts().CASIncludeTreeID = |
| 1145 | + ctx.CASOpts.ClangIncludeTrees.back(); |
| 1146 | + CI->getFrontendOpts().Inputs.clear(); |
| 1147 | + } |
| 1148 | + } |
1159 | 1149 |
|
1160 | 1150 | // If clang target is ignored, using swift target. |
1161 | 1151 | if (ignoreClangTarget) |
|
0 commit comments