Avoid generating phony dependencies for files that don't exist (#1708)

This commit is contained in:
Rangi
2025-06-29 16:42:24 -04:00
committed by GitHub
parent e7a3b9d90e
commit 5942117ac3

View File

@@ -126,20 +126,20 @@ void fstk_SetPreIncludeFile(std::string const &path) {
// LCOV_EXCL_STOP // LCOV_EXCL_STOP
} }
static void printDep(std::string const &path) {
if (dependFile) {
fprintf(dependFile, "%s: %s\n", targetFileName.c_str(), path.c_str());
if (generatePhonyDeps) {
fprintf(dependFile, "%s:\n", path.c_str());
}
}
}
static bool isValidFilePath(std::string const &path) { static bool isValidFilePath(std::string const &path) {
struct stat statBuf; struct stat statBuf;
return stat(path.c_str(), &statBuf) == 0 && !S_ISDIR(statBuf.st_mode); // Reject directories return stat(path.c_str(), &statBuf) == 0 && !S_ISDIR(statBuf.st_mode); // Reject directories
} }
static void printDep(std::string const &path) {
if (dependFile) {
fprintf(dependFile, "%s: %s\n", targetFileName.c_str(), path.c_str());
if (generatePhonyDeps && isValidFilePath(path)) {
fprintf(dependFile, "%s:\n", path.c_str());
}
}
}
std::optional<std::string> fstk_FindFile(std::string const &path) { std::optional<std::string> fstk_FindFile(std::string const &path) {
for (std::string &incPath : includePaths) { for (std::string &incPath : includePaths) {
if (std::string fullPath = incPath + path; isValidFilePath(fullPath)) { if (std::string fullPath = incPath + path; isValidFilePath(fullPath)) {