| 1 | //===- DependencyScanningService.cpp - Scanning Service -------------------===// |
|---|---|
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #include "clang/DependencyScanning/DependencyScanningService.h" |
| 10 | |
| 11 | #include "llvm/Support/Chrono.h" |
| 12 | #include "llvm/Support/Process.h" |
| 13 | |
| 14 | using namespace clang; |
| 15 | using namespace dependencies; |
| 16 | |
| 17 | bool dependencies::shouldCacheNegativeStatsDefault() { |
| 18 | if (std::optional<std::string> MaybeNegStats = |
| 19 | llvm::sys::Process::GetEnv(name: "CLANG_SCAN_CACHE_NEGATIVE_STATS")) { |
| 20 | if (MaybeNegStats->empty()) |
| 21 | return true; |
| 22 | return llvm::StringSwitch<bool>(*MaybeNegStats) |
| 23 | .Case(S: "1", Value: true) |
| 24 | .Case(S: "0", Value: false) |
| 25 | .Default(Value: false); |
| 26 | } |
| 27 | return false; |
| 28 | } |
| 29 | |
| 30 | // Negative caching directories can cause build failures due to incorrectly |
| 31 | // configured projects. |
| 32 | bool dependencies::shouldCacheNegativeStatsForPath(StringRef Path) { |
| 33 | StringRef Ext = llvm::sys::path::extension(path: Path); |
| 34 | if (Ext.empty()) |
| 35 | return false; |
| 36 | if (Ext == ".framework") |
| 37 | return false; |
| 38 | return true; |
| 39 | } |
| 40 | |
| 41 | DependencyScanningServiceOptions::DependencyScanningServiceOptions() |
| 42 | : MakeVFS([] { return llvm::vfs::createPhysicalFileSystem(); }), |
| 43 | BuildSessionTimestamp( |
| 44 | llvm::sys::toTimeT(TP: std::chrono::system_clock::now())) {} |
| 45 |