Files
Jan SvobodaandMichael Spencer 6029005938 [clang][scan-deps] Add option to disable caching stat failures (#200484)
While the source code isn't supposed to change during a build, in some
environments it does. This adds an option that disables caching of stat
failures, meaning that source files can be added to the build during
scanning.

This adds a `-no-cache-negative-stats` option to clang-scan-deps to
enable this behavior. There are no tests for clang-scan-deps as there's
no reliable way to do so from it. A unit test has been added that
modifies the filesystem between scans to test it.

Co-authored-by: Michael Spencer <bigcheesegs@gmail.com>
2026-05-29 14:17:25 -07:00

45 lines
1.5 KiB
C++

//===- DependencyScanningService.cpp - Scanning Service -------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "clang/DependencyScanning/DependencyScanningService.h"
#include "llvm/Support/Chrono.h"
#include "llvm/Support/Process.h"
using namespace clang;
using namespace dependencies;
bool dependencies::shouldCacheNegativeStatsDefault() {
if (std::optional<std::string> MaybeNegStats =
llvm::sys::Process::GetEnv("CLANG_SCAN_CACHE_NEGATIVE_STATS")) {
if (MaybeNegStats->empty())
return true;
return llvm::StringSwitch<bool>(*MaybeNegStats)
.Case("1", true)
.Case("0", false)
.Default(false);
}
return false;
}
// Negative caching directories can cause build failures due to incorrectly
// configured projects.
bool dependencies::shouldCacheNegativeStatsForPath(StringRef Path) {
StringRef Ext = llvm::sys::path::extension(Path);
if (Ext.empty())
return false;
if (Ext == ".framework")
return false;
return true;
}
DependencyScanningServiceOptions::DependencyScanningServiceOptions()
: MakeVFS([] { return llvm::vfs::createPhysicalFileSystem(); }),
BuildSessionTimestamp(
llvm::sys::toTimeT(std::chrono::system_clock::now())) {}