summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2020-09-21 15:45:35 -0400
committerGitHub <noreply@github.com>2020-09-21 12:45:35 -0700
commita5b0cde056af9e97824a9aaca6773bfd879a7934 (patch)
tree2a187ae8bbd0b0f8cdc7c53d0f688f2e1b1f2a07 /source
parent83514bd25160a9af91abc1b9acd7e44657447526 (diff)
Allow #include of absolute paths (#1555)
* #include an absolute path didn't work - because paths were taken to always be relative. * Improve comments. * Small comment improvement.
Diffstat (limited to 'source')
-rw-r--r--source/slang/slang-include-system.cpp31
1 files changed, 25 insertions, 6 deletions
diff --git a/source/slang/slang-include-system.cpp b/source/slang/slang-include-system.cpp
index 66aeb3f67..891d376f6 100644
--- a/source/slang/slang-include-system.cpp
+++ b/source/slang/slang-include-system.cpp
@@ -9,15 +9,26 @@ namespace Slang
SlangResult IncludeSystem::findFile(SlangPathType fromPathType, const String& fromPath, const String& path, PathInfo& outPathInfo)
{
- // Get relative path
- ComPtr<ISlangBlob> combinedPathBlob;
- SLANG_RETURN_ON_FAIL(m_fileSystemExt->calcCombinedPath(fromPathType, fromPath.begin(), path.begin(), combinedPathBlob.writeRef()));
- String combinedPath(StringUtil::getString(combinedPathBlob));
- if (combinedPath.getLength() <= 0)
+ String combinedPath;
+
+ if (fromPath.getLength() == 0 || Path::isAbsolute(path))
{
- return SLANG_FAIL;
+ // If the path is absolute or the fromPath is empty, the combined path is just the path
+ combinedPath = path;
+ }
+ else
+ {
+ // Get relative path
+ ComPtr<ISlangBlob> combinedPathBlob;
+ SLANG_RETURN_ON_FAIL(m_fileSystemExt->calcCombinedPath(fromPathType, fromPath.begin(), path.begin(), combinedPathBlob.writeRef()));
+ combinedPath = StringUtil::getString(combinedPathBlob);
+ if (combinedPath.getLength() <= 0)
+ {
+ return SLANG_FAIL;
+ }
}
+ // This checks the path exists
SlangPathType pathType;
SLANG_RETURN_ON_FAIL(m_fileSystemExt->getPathType(combinedPath.begin(), &pathType));
if (pathType != SLANG_PATH_TYPE_FILE)
@@ -55,6 +66,14 @@ SlangResult IncludeSystem::findFile(String const& pathToInclude, String const& p
{
outPathInfo.type = PathInfo::Type::Unknown;
+ // If it's absolute we only have to try and find if it's there - no need to look at search paths
+ if (Path::isAbsolute(pathToInclude))
+ {
+ // We pass in "" as the from path, so ensure no from path is taken into account
+ // and to allow easy identification that this is in effect absolute
+ return findFile(SLANG_PATH_TYPE_DIRECTORY, UnownedStringSlice::fromLiteral(""), pathToInclude, outPathInfo);
+ }
+
// Try just relative to current path
{
SlangResult res = findFile(SLANG_PATH_TYPE_FILE, pathIncludedFrom, pathToInclude, outPathInfo);