Skip to content

Commit 9dbfd27

Browse files
authored
Merge pull request #36294 from artemcm/BatchScanRememberEntryArgs
[Dependency Scanning] When re-using a CompilerInvocation in batch scanning, update it with the entry-specific arguments.
2 parents 1451960 + 799bef5 commit 9dbfd27

File tree

2 files changed

+28
-12
lines changed

2 files changed

+28
-12
lines changed

lib/DependencyScan/ScanDependencies.cpp

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
#include "llvm/Support/YAMLParser.h"
4141
#include "llvm/Support/YAMLTraits.h"
4242
#include <set>
43+
#include <string>
44+
#include <sstream>
4345

4446
using namespace swift;
4547
using namespace swift::dependencies;
@@ -916,16 +918,30 @@ using CompilerArgInstanceCacheMap =
916918
llvm::StringMap<std::pair<std::unique_ptr<CompilerInstance>,
917919
std::unique_ptr<ModuleDependenciesCache>>>;
918920

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) {
922924
cachedInstance.getASTContext().SearchPathOpts =
923925
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)
927931
cachedInstance.getASTContext().ClangImporterOpts =
928932
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+
}
929945
}
930946

931947
static bool
@@ -964,7 +980,7 @@ forEachBatchEntry(CompilerInstance &invocationInstance,
964980
pCache = (*subInstanceMap)[entry.arguments].second.get();
965981
// We must update the search paths of this instance to instead reflect
966982
// those of the current scanner invocation.
967-
updateCachedInstanceSearchPaths(*pInstance, invocationInstance);
983+
updateCachedInstanceOpts(*pInstance, invocationInstance, entry.arguments);
968984
} else {
969985
// Create a new instance by the arguments and save it in the map.
970986
subInstanceMap->insert(

test/ScanDependencies/batch_module_scan_versioned.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55

66
// RUN: echo "[{" > %/t/inputs/input.json
77
// RUN: echo "\"clangModuleName\": \"G\"," >> %/t/inputs/input.json
8-
// RUN: echo "\"arguments\": \"-Xcc -target -Xcc x86_64-apple-macosx10.9\"," >> %/t/inputs/input.json
9-
// RUN: echo "\"output\": \"%/t/outputs/G_109.pcm.json\"" >> %/t/inputs/input.json
8+
// RUN: echo "\"arguments\": \"-Xcc -target -Xcc x86_64-apple-macosx11.0\"," >> %/t/inputs/input.json
9+
// RUN: echo "\"output\": \"%/t/outputs/G_110.pcm.json\"" >> %/t/inputs/input.json
1010
// RUN: echo "}," >> %/t/inputs/input.json
1111
// RUN: echo "{" >> %/t/inputs/input.json
1212
// RUN: echo "\"clangModuleName\": \"G\"," >> %/t/inputs/input.json
13-
// RUN: echo "\"arguments\": \"-Xcc -target -Xcc x86_64-apple-macosx11.0\"," >> %/t/inputs/input.json
14-
// RUN: echo "\"output\": \"%/t/outputs/G_110.pcm.json\"" >> %/t/inputs/input.json
13+
// RUN: echo "\"arguments\": \"-Xcc -target -Xcc x86_64-apple-macosx10.9\"," >> %/t/inputs/input.json
14+
// RUN: echo "\"output\": \"%/t/outputs/G_109.pcm.json\"" >> %/t/inputs/input.json
1515
// RUN: echo "}]" >> %/t/inputs/input.json
1616

17-
// RUN: %target-swift-frontend -scan-dependencies -module-cache-path %t/clang-module-cache %s -o %t/deps.json -I %S/Inputs/CHeaders -I %S/Inputs/Swift -emit-dependencies -emit-dependencies-path %t/deps.d -import-objc-header %S/Inputs/CHeaders/Bridging.h -swift-version 4 -batch-scan-input-file %/t/inputs/input.json
17+
// RUN: %target-swift-frontend -scan-dependencies -target x86_64-apple-macosx11.0 -module-cache-path %t/clang-module-cache %s -o %t/deps.json -I %S/Inputs/CHeaders -I %S/Inputs/Swift -emit-dependencies -emit-dependencies-path %t/deps.d -import-objc-header %S/Inputs/CHeaders/Bridging.h -swift-version 4 -batch-scan-input-file %/t/inputs/input.json
1818

1919
// Check the contents of the JSON output
2020
// RUN: %FileCheck %s -check-prefix=CHECK-PCM109 < %t/outputs/G_109.pcm.json

0 commit comments

Comments
 (0)