mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 10:12:06 +00:00
Revert "Implement INCLUDE_ONCE directive (#1481)"
This reverts commit 5f07095f6d.
This commit is contained in:
@@ -6,11 +6,9 @@
|
||||
#include <errno.h>
|
||||
#include <inttypes.h>
|
||||
#include <memory>
|
||||
#include <set>
|
||||
#include <stack>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <utility>
|
||||
|
||||
#include "error.hpp"
|
||||
#include "helpers.hpp"
|
||||
@@ -47,8 +45,8 @@ size_t maxRecursionDepth;
|
||||
|
||||
// The first include path for `fstk_FindFile` to try is none at all
|
||||
static std::vector<std::string> includePaths = {""};
|
||||
|
||||
static std::string preIncludeName;
|
||||
static std::set<std::pair<dev_t, ino_t>> includedFiles;
|
||||
|
||||
std::string const &FileStackNode::dump(uint32_t curLineNo) const {
|
||||
if (data.holds<std::vector<uint32_t>>()) {
|
||||
@@ -293,11 +291,11 @@ static Context &newReptContext(int32_t reptLineNo, ContentSpan const &span, uint
|
||||
return context;
|
||||
}
|
||||
|
||||
void fstk_RunInclude(std::string const &path, IncludeType type) {
|
||||
void fstk_RunInclude(std::string const &path, bool preInclude) {
|
||||
std::optional<std::string> fullPath = fstk_FindFile(path);
|
||||
|
||||
if (!fullPath) {
|
||||
if (generatedMissingIncludes && type != INCLUDE_PRE) {
|
||||
if (generatedMissingIncludes && !preInclude) {
|
||||
if (verbose)
|
||||
printf("Aborting (-MG) on INCLUDE file '%s' (%s)\n", path.c_str(), strerror(errno));
|
||||
failedOnMissingInclude = true;
|
||||
@@ -307,24 +305,6 @@ void fstk_RunInclude(std::string const &path, IncludeType type) {
|
||||
return;
|
||||
}
|
||||
|
||||
// The pair of device ID and serial number uniquely identify a file, with `stat()`
|
||||
// following symbolic links to identify the actual file.
|
||||
struct stat statBuf;
|
||||
if (stat(fullPath->c_str(), &statBuf) != 0) {
|
||||
error("Failed to stat file '%s': %s\n", fullPath->c_str(), strerror(errno));
|
||||
return;
|
||||
}
|
||||
std::pair<dev_t, ino_t> inode{statBuf.st_dev, statBuf.st_ino};
|
||||
|
||||
if (type == INCLUDE_ONCE && includedFiles.find(inode) != includedFiles.end()) {
|
||||
if (verbose) {
|
||||
printf("File '%s' already included, skipping INCLUDE_ONCE", path.c_str());
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
includedFiles.insert(inode);
|
||||
|
||||
if (!newFileContext(*fullPath, false))
|
||||
fatalerror("Failed to set up lexer for file include\n");
|
||||
}
|
||||
@@ -415,5 +395,5 @@ void fstk_Init(std::string const &mainPath, size_t maxDepth) {
|
||||
maxRecursionDepth = maxDepth;
|
||||
|
||||
if (!preIncludeName.empty())
|
||||
fstk_RunInclude(preIncludeName, INCLUDE_PRE);
|
||||
fstk_RunInclude(preIncludeName, true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user