|
40 | 40 | #include "llvm/Support/YAMLParser.h"
|
41 | 41 | #include "llvm/Support/YAMLTraits.h"
|
42 | 42 | #include <set>
|
| 43 | +#include <string> |
| 44 | +#include <sstream> |
43 | 45 |
|
44 | 46 | using namespace swift;
|
45 | 47 | using namespace swift::dependencies;
|
@@ -916,16 +918,30 @@ using CompilerArgInstanceCacheMap =
|
916 | 918 | llvm::StringMap<std::pair<std::unique_ptr<CompilerInstance>,
|
917 | 919 | std::unique_ptr<ModuleDependenciesCache>>>;
|
918 | 920 |
|
919 |
| -static void |
920 |
| -updateCachedInstanceSearchPaths(CompilerInstance &cachedInstance, |
921 |
| - const CompilerInstance &invocationInstance) { |
| 921 | +static void updateCachedInstanceOpts(CompilerInstance &cachedInstance, |
| 922 | + const CompilerInstance &invocationInstance, |
| 923 | + llvm::StringRef entryArguments) { |
922 | 924 | cachedInstance.getASTContext().SearchPathOpts =
|
923 | 925 | invocationInstance.getASTContext().SearchPathOpts;
|
924 |
| - // The Clang Importer arguments must also match those of the current |
925 |
| - // invocation instead of the cached one because they include search |
926 |
| - // path directives for Clang. |
| 926 | + |
| 927 | + // The Clang Importer arguments must consiste of a combination of |
| 928 | + // Clang Importer arguments of the current invocation to inherit its Clang-specific |
| 929 | + // search path options, followed by the options speicific to the given batch-entry, |
| 930 | + // which may overload some of the invocation's options (e.g. target) |
927 | 931 | cachedInstance.getASTContext().ClangImporterOpts =
|
928 | 932 | invocationInstance.getASTContext().ClangImporterOpts;
|
| 933 | + std::istringstream iss(entryArguments.str()); |
| 934 | + std::vector<std::string> splitArguments( |
| 935 | + std::istream_iterator<std::string>{iss}, |
| 936 | + std::istream_iterator<std::string>()); |
| 937 | + for (auto it = splitArguments.begin(), end = splitArguments.end(); it != end; |
| 938 | + ++it) { |
| 939 | + if ((*it) == "-Xcc") { |
| 940 | + assert((it + 1 != end) && "Expected option following '-Xcc'"); |
| 941 | + cachedInstance.getASTContext().ClangImporterOpts.ExtraArgs.push_back( |
| 942 | + *(it + 1)); |
| 943 | + } |
| 944 | + } |
929 | 945 | }
|
930 | 946 |
|
931 | 947 | static bool
|
@@ -964,7 +980,7 @@ forEachBatchEntry(CompilerInstance &invocationInstance,
|
964 | 980 | pCache = (*subInstanceMap)[entry.arguments].second.get();
|
965 | 981 | // We must update the search paths of this instance to instead reflect
|
966 | 982 | // those of the current scanner invocation.
|
967 |
| - updateCachedInstanceSearchPaths(*pInstance, invocationInstance); |
| 983 | + updateCachedInstanceOpts(*pInstance, invocationInstance, entry.arguments); |
968 | 984 | } else {
|
969 | 985 | // Create a new instance by the arguments and save it in the map.
|
970 | 986 | subInstanceMap->insert(
|
|
0 commit comments