Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,50 +78,56 @@ enum class ScanningOptimizations {

#undef DSS_LAST_BITMASK_ENUM

struct DependencyScanningServiceOptions {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a separate type from the service so that service still only exposes const getters and cannot be mutated?

DependencyScanningServiceOptions(ScanningMode Mode,
ScanningOutputFormat Format)
: Mode(Mode), Format(Format) {}

ScanningMode Mode;
ScanningOutputFormat Format;
/// How to optimize the modules' command-line arguments.
ScanningOptimizations OptimizeArgs = ScanningOptimizations::Default;
/// Whether to set up command-lines to load PCM files eagerly.
bool EagerLoadModules = false;
/// Whether to trace VFS accesses.
bool TraceVFS = false;
std::time_t BuildSessionTimestamp =
llvm::sys::toTimeT(std::chrono::system_clock::now());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we could move this into the .cpp to lose the dependency on the chrono header. Probably doesn't matter much.

};

/// The dependency scanning service contains shared configuration and state that
/// is used by the individual dependency scanning workers.
class DependencyScanningService {
public:
DependencyScanningService(
ScanningMode Mode, ScanningOutputFormat Format,
ScanningOptimizations OptimizeArgs = ScanningOptimizations::Default,
bool EagerLoadModules = false, bool TraceVFS = false,
std::time_t BuildSessionTimestamp =
llvm::sys::toTimeT(std::chrono::system_clock::now()));
DependencyScanningService(const DependencyScanningServiceOptions &Options);

ScanningMode getMode() const { return Mode; }
ScanningMode getMode() const { return Options.Mode; }

ScanningOutputFormat getFormat() const { return Format; }
ScanningOutputFormat getFormat() const { return Options.Format; }

ScanningOptimizations getOptimizeArgs() const { return OptimizeArgs; }
ScanningOptimizations getOptimizeArgs() const { return Options.OptimizeArgs; }

bool shouldEagerLoadModules() const { return EagerLoadModules; }
bool shouldEagerLoadModules() const { return Options.EagerLoadModules; }

bool shouldTraceVFS() const { return TraceVFS; }
bool shouldTraceVFS() const { return Options.TraceVFS; }

DependencyScanningFilesystemSharedCache &getSharedCache() {
return SharedCache;
}

ModuleCacheEntries &getModuleCacheEntries() { return ModCacheEntries; }

std::time_t getBuildSessionTimestamp() const { return BuildSessionTimestamp; }
std::time_t getBuildSessionTimestamp() const {
return Options.BuildSessionTimestamp;
}

private:
const ScanningMode Mode;
const ScanningOutputFormat Format;
/// Whether to optimize the modules' command-line arguments.
const ScanningOptimizations OptimizeArgs;
/// Whether to set up command-lines to load PCM files eagerly.
const bool EagerLoadModules;
/// Whether to trace VFS accesses.
const bool TraceVFS;
const DependencyScanningServiceOptions Options;

/// The global file system cache.
DependencyScanningFilesystemSharedCache SharedCache;
/// The global module cache entries.
ModuleCacheEntries ModCacheEntries;
/// The build session timestamp.
std::time_t BuildSessionTimestamp;
};

} // end namespace dependencies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,5 @@ using namespace tooling;
using namespace dependencies;

DependencyScanningService::DependencyScanningService(
ScanningMode Mode, ScanningOutputFormat Format,
ScanningOptimizations OptimizeArgs, bool EagerLoadModules, bool TraceVFS,
std::time_t BuildSessionTimestamp)
: Mode(Mode), Format(Format), OptimizeArgs(OptimizeArgs),
EagerLoadModules(EagerLoadModules), TraceVFS(TraceVFS),
BuildSessionTimestamp(BuildSessionTimestamp) {}
const DependencyScanningServiceOptions &Options)
: Options(Options) {}
7 changes: 5 additions & 2 deletions clang/tools/clang-scan-deps/ClangScanDeps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1171,8 +1171,11 @@ int clang_scan_deps_main(int argc, char **argv, const llvm::ToolContext &) {
});
};

DependencyScanningService Service(ScanMode, Format, OptimizeArgs,
EagerLoadModules, /*TraceVFS=*/Verbose);
DependencyScanningServiceOptions Options{ScanMode, Format};
Options.OptimizeArgs = OptimizeArgs;
Options.EagerLoadModules = EagerLoadModules;
Options.TraceVFS = Verbose;
DependencyScanningService Service(Options);

llvm::Timer T;
T.startTimer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,8 @@ TEST(DependencyScanner, ScanDepsWithFS) {
VFS->addFile(TestPath, 0,
llvm::MemoryBuffer::getMemBuffer("#include \"header.h\"\n"));

DependencyScanningService Service(ScanningMode::DependencyDirectivesScan,
ScanningOutputFormat::Make);
DependencyScanningService Service(
{ScanningMode::DependencyDirectivesScan, ScanningOutputFormat::Make});
DependencyScanningTool ScanTool(Service, VFS);

std::string DepFile;
Expand Down Expand Up @@ -289,8 +289,8 @@ TEST(DependencyScanner, ScanDepsWithModuleLookup) {

auto InterceptFS = llvm::makeIntrusiveRefCnt<InterceptorFS>(VFS);

DependencyScanningService Service(ScanningMode::DependencyDirectivesScan,
ScanningOutputFormat::Make);
DependencyScanningService Service(
{ScanningMode::DependencyDirectivesScan, ScanningOutputFormat::Make});
DependencyScanningTool ScanTool(Service, InterceptFS);

// This will fail with "fatal error: module 'Foo' not found" but it doesn't
Expand Down Expand Up @@ -321,8 +321,8 @@ TEST(DependencyScanner, ScanDepsWithDiagConsumer) {
llvm::MemoryBuffer::getMemBuffer("#include \"header.h\"\n"));
VFS->addFile(AsmPath, 0, llvm::MemoryBuffer::getMemBuffer(""));

DependencyScanningService Service(ScanningMode::DependencyDirectivesScan,
ScanningOutputFormat::Make);
DependencyScanningService Service(
{ScanningMode::DependencyDirectivesScan, ScanningOutputFormat::Make});
DependencyScanningWorker Worker(Service, VFS);

llvm::DenseSet<ModuleID> AlreadySeen;
Expand Down
Loading