[CAS][DependencyScanning] Don't keep a shared state of common file deps

Unlike `swift-frontend -scan-dependencies` option, when dependency
scanner is used as a library by swift driver, the SwiftScanningService
is shared for multiple driver invocations. It can't keep states (like
common file dependencies) that can change from one invocation to
another.

Instead, the clang/SDK file dependencies are computed from each driver
invocations to avoid out-of-date information when scanning service is
reused.

The test case for a shared Service will be added to swift-driver repo
since there is no tool to test it within swift compiler.
This commit is contained in:
Steven Wu
2023-06-26 15:41:55 -07:00
parent 50d2f4d3ed
commit bed01ade89
6 changed files with 115 additions and 23 deletions

View File

@@ -18,8 +18,9 @@
#ifndef SWIFT_AST_MODULE_DEPENDENCIES_H
#define SWIFT_AST_MODULE_DEPENDENCIES_H
#include "swift/Basic/LLVM.h"
#include "swift/AST/Import.h"
#include "swift/AST/SearchPathOptions.h"
#include "swift/Basic/LLVM.h"
#include "clang/CAS/CASOptions.h"
#include "clang/Tooling/DependencyScanning/DependencyScanningService.h"
#include "clang/Tooling/DependencyScanning/DependencyScanningTool.h"
@@ -31,12 +32,12 @@
#include "llvm/CAS/CASReference.h"
#include "llvm/CAS/CachingOnDiskFileSystem.h"
#include "llvm/CAS/ObjectStore.h"
#include "llvm/Support/Mutex.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/Mutex.h"
#include "llvm/Support/VirtualFileSystem.h"
#include <string>
#include <vector>
#include <unordered_map>
#include <vector>
namespace swift {
@@ -733,17 +734,16 @@ using ModuleDependenciesKindRefMap =
/// Track swift dependency
class SwiftDependencyTracker {
public:
SwiftDependencyTracker(llvm::cas::CachingOnDiskFileSystem &FS,
const std::vector<std::string> &CommonFiles)
: FS(FS.createProxyFS()), Files(CommonFiles) {}
SwiftDependencyTracker(llvm::cas::CachingOnDiskFileSystem &FS)
: FS(FS.createProxyFS()) {}
void startTracking();
void addCommonSearchPathDeps(const SearchPathOptions& Opts);
void trackFile(const Twine &path) { (void)FS->status(path); }
llvm::Expected<llvm::cas::ObjectProxy> createTreeFromDependencies();
private:
llvm::IntrusiveRefCntPtr<llvm::cas::CachingOnDiskFileSystem> FS;
const std::vector<std::string> &Files;
};
// MARK: SwiftDependencyScanningService
@@ -848,7 +848,7 @@ public:
if (!CacheFS)
return None;
return SwiftDependencyTracker(*CacheFS, CommonDependencyFiles);
return SwiftDependencyTracker(*CacheFS);
}
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> getClangScanningFS() const {