Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
36 changes: 23 additions & 13 deletions StandAlone/DirStackFileIncluder.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
// Can be overridden to customize.
class DirStackFileIncluder : public glslang::TShader::Includer {
public:
DirStackFileIncluder() : externalLocalDirectoryCount(0) { }
DirStackFileIncluder() { }

virtual IncludeResult* includeLocal(const char* headerName,
const char* includerName,
Expand All @@ -69,12 +69,13 @@ class DirStackFileIncluder : public glslang::TShader::Includer {
// - Most-recently pushed are checked first.
// - All these are checked after the parse-time stack of local directories
// is checked.
// - This only applies to the "local" form of #include.
// - Makes its own copy of the path.
virtual void pushExternalLocalDirectory(const std::string& dir)
// - Search paths are processed similar to GCC: "local" inclusions will
// search in the current directory and external directories, while
// <system> inclusions will search external directories only.
virtual void pushExternalDirectory(const std::string& dir)
{
directoryStack.push_back(dir);
externalLocalDirectoryCount = (int)directoryStack.size();
externalDirectoryList.push_back(dir);
}

virtual void releaseInclude(IncludeResult* result) override
Expand All @@ -94,8 +95,8 @@ class DirStackFileIncluder : public glslang::TShader::Includer {

protected:
typedef char tUserDataElement;
std::vector<std::string> directoryStack;
int externalLocalDirectoryCount;
std::vector<std::string> localDirectoryStack;
std::vector<std::string> externalDirectoryList;
std::set<std::string> includedFiles;

// Search for a valid "local" path based on combining the stack of include
Expand All @@ -104,17 +105,17 @@ class DirStackFileIncluder : public glslang::TShader::Includer {
{
// Discard popped include directories, and
// initialize when at parse-time first level.
directoryStack.resize(depth + externalLocalDirectoryCount);
localDirectoryStack.resize(depth);
if (depth == 1)
directoryStack.back() = getDirectory(includerName);
localDirectoryStack.back() = getDirectory(includerName);

// Find a directory that works, using a reverse search of the include stack.
for (auto it = directoryStack.rbegin(); it != directoryStack.rend(); ++it) {
for (auto it = localDirectoryStack.rbegin(); it != localDirectoryStack.rend(); ++it) {
std::string path = *it + '/' + headerName;
std::replace(path.begin(), path.end(), '\\', '/');
std::ifstream file(path, std::ios_base::binary | std::ios_base::ate);
if (file) {
directoryStack.push_back(getDirectory(path));
localDirectoryStack.push_back(getDirectory(path));
includedFiles.insert(path);
return newIncludeResult(path, file, (int)file.tellg());
}
Expand All @@ -124,9 +125,18 @@ class DirStackFileIncluder : public glslang::TShader::Includer {
}

// Search for a valid <system> path.
// Not implemented yet; returning nullptr signals failure to find.
virtual IncludeResult* readSystemPath(const char* /*headerName*/) const
virtual IncludeResult* readSystemPath(const char* headerName)
{
// Search for external diectories only.
for (auto it = externalDirectoryList.begin(); it != externalDirectoryList.end(); ++it) {
std::string path = *it + '/' + headerName;
std::replace(path.begin(), path.end(), '\\', '/');
std::ifstream file(path, std::ios_base::binary | std::ios_base::ate);
if (file) {
includedFiles.insert(path);
return newIncludeResult(path, file, (int)file.tellg());
}
}
return nullptr;
}

Expand Down
4 changes: 2 additions & 2 deletions StandAlone/StandAlone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1351,8 +1351,8 @@ void CompileAndLinkShaderUnits(std::vector<ShaderCompUnit> compUnits)
SetMessageOptions(messages);

DirStackFileIncluder includer;
std::for_each(IncludeDirectoryList.rbegin(), IncludeDirectoryList.rend(), [&includer](const std::string& dir) {
includer.pushExternalLocalDirectory(dir); });
std::for_each(IncludeDirectoryList.begin(), IncludeDirectoryList.end(), [&includer](const std::string& dir) {
includer.pushExternalDirectory(dir); });

std::vector<std::string> sources;

Expand Down