|
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
|
@@ -1170,8 +1147,21 @@ std::optional<std::vector<std::string>> ClangImporter::getClangCC1Arguments(
|
1170 | 1147 | // to reduce the number of argument passing on the command-line and swift
|
1171 | 1148 | // compiler can be more efficient to compute swift cache key without having
|
1172 | 1149 | // the knowledge about clang command-line options.
|
1173 |
| - if (ctx.CASOpts.EnableCaching) |
| 1150 | + if (ctx.CASOpts.EnableCaching) { |
1174 | 1151 | CI->getCASOpts() = ctx.CASOpts.CASOpts;
|
| 1152 | + // When clangImporter is used to compile (generate .pcm or .pch), need to |
| 1153 | + // inherit the include tree from swift args (last one wins) and clear the |
| 1154 | + // input file. |
| 1155 | + if ((CI->getFrontendOpts().ProgramAction == |
| 1156 | + clang::frontend::ActionKind::GenerateModule || |
| 1157 | + CI->getFrontendOpts().ProgramAction == |
| 1158 | + clang::frontend::ActionKind::GeneratePCH) && |
| 1159 | + ctx.ClangImporterOpts.HasClangIncludeTreeRoot) { |
| 1160 | + CI->getFrontendOpts().CASIncludeTreeID = |
| 1161 | + ctx.CASOpts.ClangIncludeTrees.back(); |
| 1162 | + CI->getFrontendOpts().Inputs.clear(); |
| 1163 | + } |
| 1164 | + } |
1175 | 1165 |
|
1176 | 1166 | // If clang target is ignored, using swift target.
|
1177 | 1167 | if (ignoreClangTarget)
|
|
0 commit comments