mirror of
https://github.com/apple/swift.git
synced 2026-02-27 18:26:24 +01:00
Reapply "[DependencyScan] Correct setup clang VFS for dependency scanning"
This reverts commit e60ae24052 and fix
non-deterministic failures introduced by the commit.
Fix two issues when attempting to testing parallel scanning using
`swift-scan-test` tools:
* Make sure the BumpPtrAllocator in ScanningService is thread-safe so
there are no race condition when a new slab is allocated.
* Make sure the output of `swift-scan-test` only written from one
thread. This prevents some race conditions when writing to the same
raw_fd_ostream.
rdar://167760262
This commit is contained in:
@@ -194,16 +194,19 @@ static std::vector<std::string> inputSpecificClangScannerCommand(
|
||||
}
|
||||
|
||||
static llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>
|
||||
getClangScanningFS(std::shared_ptr<llvm::cas::ObjectStore> cas,
|
||||
getClangScanningFS(SwiftDependencyScanningService &service,
|
||||
std::shared_ptr<llvm::cas::ObjectStore> cas,
|
||||
ASTContext &ctx) {
|
||||
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> baseFileSystem =
|
||||
llvm::vfs::createPhysicalFileSystem();
|
||||
ClangInvocationFileMapping fileMapping =
|
||||
applyClangInvocationMapping(ctx, nullptr, baseFileSystem, false);
|
||||
auto *importer = static_cast<ClangImporter *>(ctx.getClangModuleLoader());
|
||||
// Dependency scanner needs to create its own file system per worker.
|
||||
auto fs = ClangImporter::computeClangImporterFileSystem(
|
||||
ctx, importer->getClangFileMapping(),
|
||||
llvm::vfs::createPhysicalFileSystem(), true,
|
||||
[&](StringRef str) { return service.save(str); });
|
||||
|
||||
if (cas)
|
||||
return llvm::cas::createCASProvidingFileSystem(cas, baseFileSystem);
|
||||
return baseFileSystem;
|
||||
return llvm::cas::createCASProvidingFileSystem(cas, fs);
|
||||
return fs;
|
||||
}
|
||||
|
||||
ModuleDependencyScanningWorker::ModuleDependencyScanningWorker(
|
||||
@@ -217,8 +220,9 @@ ModuleDependencyScanningWorker::ModuleDependencyScanningWorker(
|
||||
llvm::PrefixMapper *Mapper)
|
||||
: workerCompilerInvocation(
|
||||
std::make_unique<CompilerInvocation>(ScanCompilerInvocation)),
|
||||
clangScanningTool(*globalScanningService.ClangScanningService,
|
||||
getClangScanningFS(CAS, ScanASTContext)),
|
||||
clangScanningTool(
|
||||
*globalScanningService.ClangScanningService,
|
||||
getClangScanningFS(globalScanningService, CAS, ScanASTContext)),
|
||||
CAS(CAS), ActionCache(ActionCache),
|
||||
diagnosticReporter(DiagnosticReporter) {
|
||||
// Instantiate a worker-specific diagnostic engine and copy over
|
||||
@@ -2097,10 +2101,16 @@ ModuleDependencyInfo ModuleDependencyScanner::bridgeClangModuleDependency(
|
||||
invocation.getMutCASOpts() = clang::CASOptions();
|
||||
invocation.getMutFrontendOpts().CASIncludeTreeID.clear();
|
||||
|
||||
// FIXME: workaround for rdar://105684525: find the -ivfsoverlay option
|
||||
// from clang scanner and pass to swift.
|
||||
if (!ScanASTContext.CASOpts.EnableCaching) {
|
||||
auto &overlayFiles = invocation.getMutHeaderSearchOpts().VFSOverlayFiles;
|
||||
|
||||
// clang system overlay file is a virtual file that is not an actual file.
|
||||
auto clangSystemOverlayFile =
|
||||
ClangImporter::getClangSystemOverlayFile(ScanASTContext.SearchPathOpts);
|
||||
llvm::erase(overlayFiles, clangSystemOverlayFile);
|
||||
|
||||
// FIXME: workaround for rdar://105684525: find the -ivfsoverlay option
|
||||
// from clang scanner and pass to swift.
|
||||
for (auto overlay : overlayFiles) {
|
||||
swiftArgs.push_back("-vfsoverlay");
|
||||
swiftArgs.push_back(overlay);
|
||||
|
||||
Reference in New Issue
Block a user