summaryrefslogtreecommitdiffstats
path: root/source/core/slang-test-tool-util.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/core/slang-test-tool-util.cpp')
-rw-r--r--source/core/slang-test-tool-util.cpp86
1 files changed, 43 insertions, 43 deletions
diff --git a/source/core/slang-test-tool-util.cpp b/source/core/slang-test-tool-util.cpp
index 7c972d099..f06095ada 100644
--- a/source/core/slang-test-tool-util.cpp
+++ b/source/core/slang-test-tool-util.cpp
@@ -37,7 +37,7 @@ namespace Slang
}
}
-static SlangResult _calcIncludePath(const String& parentPath, const char* path, String& outIncludePath)
+/* static */SlangResult TestToolUtil::getIncludePath(const String& parentPath, const char* path, String& outIncludePath)
{
String includePath;
SLANG_RETURN_ON_FAIL(Path::getCanonical(Path::combine(parentPath, path), includePath));
@@ -55,73 +55,73 @@ static SlangResult _calcIncludePath(const String& parentPath, const char* path,
return SLANG_OK;
}
-static SlangResult _addCPPPrelude(const String& parentPath, slang::IGlobalSession* session)
+static SlangResult _addCPPPrelude(const String& rootPath, slang::IGlobalSession* session)
{
String includePath;
- SLANG_RETURN_ON_FAIL(_calcIncludePath(parentPath, "../../../prelude/slang-cpp-prelude.h", includePath));
+ SLANG_RETURN_ON_FAIL(TestToolUtil::getIncludePath(rootPath, "prelude/slang-cpp-prelude.h", includePath));
StringBuilder prelude;
prelude << "#include \"" << includePath << "\"\n\n";
session->setLanguagePrelude(SLANG_SOURCE_LANGUAGE_CPP, prelude.getBuffer());
return SLANG_OK;
}
-static SlangResult _addCUDAPrelude(const String& parentPath, slang::IGlobalSession* session)
+static SlangResult _addCUDAPrelude(const String& rootPath, slang::IGlobalSession* session)
{
String includePath;
- SLANG_RETURN_ON_FAIL(_calcIncludePath(parentPath, "../../../prelude/slang-cuda-prelude.h", includePath));
+ SLANG_RETURN_ON_FAIL(TestToolUtil::getIncludePath(rootPath, "prelude/slang-cuda-prelude.h", includePath));
StringBuilder prelude;
prelude << "#include \"" << includePath << "\"\n\n";
session->setLanguagePrelude(SLANG_SOURCE_LANGUAGE_CUDA, prelude.getBuffer());
return SLANG_OK;
}
-/* static */SlangResult TestToolUtil::setSessionDefaultPrelude(const PreludeInfo& info, slang::IGlobalSession* session)
+/* static */SlangResult TestToolUtil::getExeDirectoryPath(const char* exePath, String& outExeDirectoryPath)
{
- // Set the prelude to a path
- if (info.exePath)
- {
- String exePath(info.exePath);
+ String canonicalPath;
+ SLANG_RETURN_ON_FAIL(Path::getCanonical(exePath, canonicalPath));
+ // Get the directory
+ outExeDirectoryPath = Path::getParentDirectory(canonicalPath);
+ return SLANG_OK;
+}
- String canonicalPath;
- if (SLANG_SUCCEEDED(Path::getCanonical(exePath, canonicalPath)))
- {
- // Get the directory
- String parentPath = Path::getParentDirectory(canonicalPath);
-
- if (SLANG_FAILED(_addCPPPrelude(parentPath, session)))
- {
- SLANG_ASSERT(!"Couldn't find the C++ prelude relative to the executable");
- }
-
- if (SLANG_FAILED(_addCUDAPrelude(parentPath, session)))
- {
- SLANG_ASSERT(!"Couldn't find the CUDA prelude relative to the executable");
- }
- }
- }
- // If the nvAPI path is set, and we find nvHLSLExtns.h, put that in the HLSL prelude
- if (info.nvapiPath)
- {
- String includePath;
- if (SLANG_SUCCEEDED(_calcIncludePath(info.nvapiPath, "nvHLSLExtns.h", includePath)))
- {
- StringBuilder buf;
+/* static */SlangResult TestToolUtil::getRootPath(const char* inExePath, String& outExePath)
+{
+ // Get the directory holding the exe
+ String parentPath;
+ SLANG_RETURN_ON_FAIL(getExeDirectoryPath(inExePath, parentPath));
- buf << "#include \"" << includePath << "\"\n";
+ // From directory to the root is ../../..
+ // Work out the relative path to the root
+ String rootRelPath = Path::combine(parentPath, "../../../");
- session->setLanguagePrelude(SLANG_SOURCE_LANGUAGE_HLSL, buf.getBuffer());
- return SLANG_OK;
- }
- }
+ // We want the absolute path to the root
+ SLANG_RETURN_ON_FAIL(Path::getCanonical(rootRelPath, outExePath));
+ return SLANG_OK;
+}
+/* static */SlangResult TestToolUtil::setSessionDefaultPreludeFromExePath(const char* inExePath, slang::IGlobalSession* session)
+{
+ String rootPath;
+ SLANG_RETURN_ON_FAIL(getRootPath(inExePath, rootPath));
+ SLANG_RETURN_ON_FAIL(setSessionDefaultPreludeFromRootPath(rootPath, session));
return SLANG_OK;
}
-/* static */SlangResult TestToolUtil::setSessionDefaultPrelude(const char* exePath, slang::IGlobalSession* session)
+/* static */SlangResult TestToolUtil::setSessionDefaultPreludeFromRootPath(const String& rootPath, slang::IGlobalSession* session)
{
- PreludeInfo info;
- info.exePath = exePath;
- return setSessionDefaultPrelude(info, session);
+ // Set the prelude to a path
+
+ if (SLANG_FAILED(_addCPPPrelude(rootPath, session)))
+ {
+ SLANG_ASSERT(!"Couldn't find the C++ prelude relative to the executable");
+ }
+
+ if (SLANG_FAILED(_addCUDAPrelude(rootPath, session)))
+ {
+ SLANG_ASSERT(!"Couldn't find the CUDA prelude relative to the executable");
+ }
+
+ return SLANG_OK;
}
}