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.cpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/source/core/slang-test-tool-util.cpp b/source/core/slang-test-tool-util.cpp
index 20ba2fc47..9bf404e5e 100644
--- a/source/core/slang-test-tool-util.cpp
+++ b/source/core/slang-test-tool-util.cpp
@@ -1,6 +1,11 @@
#include "slang-test-tool-util.h"
+#include "../../slang-com-helper.h"
+
+#include "slang-io.h"
+#include "slang-string-util.h"
+
namespace Slang
{
@@ -32,6 +37,46 @@ namespace Slang
}
}
+/* static */SlangResult TestToolUtil::setSessionDefaultPrelude(const char* exePath, slang::IGlobalSession* session)
+{
+ // Set the prelude to a path
+ String canonicalPath;
+ if (SLANG_SUCCEEDED(Path::getCanonical(exePath, canonicalPath)))
+ {
+ // Get the directory
+ canonicalPath = Path::getParentDirectory(canonicalPath);
+
+ String path = Path::combine(canonicalPath, "../../../prelude/slang-cpp-prelude.h");
+ if (SLANG_SUCCEEDED(Path::getCanonical(path, canonicalPath)))
+ {
+ // Use forward slashes, to avoid escaping the path
+ canonicalPath = StringUtil::calcCharReplaced(canonicalPath, '\\', '/');
+
+ // It must exist!
+ if (!File::exists(canonicalPath))
+ {
+ SLANG_ASSERT(!"Couldn't find the prelude relative to the executable");
+ return SLANG_FAIL;
+ }
+
+ StringBuilder prelude;
+ prelude << "#include \"" << canonicalPath << "\"\n\n";
+ const SlangPassThrough downstreamCompilers[] = {
+ SLANG_PASS_THROUGH_CLANG, ///< Clang C/C++ compiler
+ SLANG_PASS_THROUGH_VISUAL_STUDIO, ///< Visual studio C/C++ compiler
+ SLANG_PASS_THROUGH_GCC, ///< GCC C/C++ compiler
+ SLANG_PASS_THROUGH_GENERIC_C_CPP,
+ };
+ for (auto downstreamCompiler : downstreamCompilers)
+ {
+ session->setDownstreamCompilerPrelude(downstreamCompiler, prelude.getBuffer());
+ }
+ }
+ }
+
+ return SLANG_OK;
+}
+
}