summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-state-serialize.cpp
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2019-10-24 21:14:12 -0400
committerGitHub <noreply@github.com>2019-10-24 21:14:12 -0400
commit3c57c86cdb2ae301441cf26a5bbe137e0b3bd512 (patch)
tree5d54121b3ca83790be8e89efc5fcd3faa1cc0134 /source/slang/slang-state-serialize.cpp
parent89ddb50eaccc1b7b590dbde55032721762711fb2 (diff)
* Functionality to dump repo if there is a failure throught the -dump-repro-on-failure option (#1095)
* Small typo fix
Diffstat (limited to 'source/slang/slang-state-serialize.cpp')
-rw-r--r--source/slang/slang-state-serialize.cpp74
1 files changed, 72 insertions, 2 deletions
diff --git a/source/slang/slang-state-serialize.cpp b/source/slang/slang-state-serialize.cpp
index 2d40e78ef..4c2651475 100644
--- a/source/slang/slang-state-serialize.cpp
+++ b/source/slang/slang-state-serialize.cpp
@@ -3,6 +3,8 @@
#include "../core/slang-text-io.h"
+#include "../core/slang-stream.h"
+
#include "../core/slang-math.h"
#include "slang-source-loc.h"
@@ -1166,8 +1168,6 @@ struct LoadContext
case CompressedResult::CannotOpen: builder << "[cannot open]"; break;
case CompressedResult::Fail: builder << "[fail]"; break;
}
-
-
}
builder << "\n";
@@ -1177,4 +1177,74 @@ struct LoadContext
return SLANG_OK;
}
+static SlangResult _findFirstSourcePath(EndToEndCompileRequest* request, String& outFilename)
+{
+ // We are going to look through all of the srcTranlationUnits, looking for the first filename
+
+ auto frontEndReq = request->getFrontEndReq();
+ const auto& srcTranslationUnits = frontEndReq->translationUnits;
+
+ for (Index i = 0; i < srcTranslationUnits.getCount(); ++i)
+ {
+ TranslationUnitRequest* srcTranslationUnit = srcTranslationUnits[i];
+ const auto& srcSourceFiles = srcTranslationUnit->getSourceFiles();
+
+ for (Index j = 0; j < srcSourceFiles.getCount(); ++j)
+ {
+ SourceFile* sourceFile = srcSourceFiles[j];
+
+ const PathInfo& pathInfo = sourceFile->getPathInfo();
+
+ if (pathInfo.foundPath.getLength())
+ {
+ outFilename = pathInfo.foundPath;
+ return SLANG_OK;
+ }
+ }
+ }
+ return SLANG_FAIL;
+}
+
+/* static */SlangResult StateSerializeUtil::findUniqueReproDumpStream(EndToEndCompileRequest* request, String& outFileName, RefPtr<Stream>& outStream)
+{
+ String sourcePath;
+
+ if (SLANG_FAILED(_findFirstSourcePath(request, sourcePath)))
+ {
+ sourcePath = "unknown.slang";
+ }
+
+ String sourceFileName = Path::getFileName(sourcePath);
+ String sourceBaseName = Path::getFileNameWithoutExt(sourceFileName);
+
+ // Okay we need a unique number to make sure the name is unique
+ const int maxTries = 100;
+ for (int triesCount = 0; triesCount < maxTries; ++triesCount)
+ {
+ // We could include the count in some way perhaps, but for now let's just go with ticks
+ auto tick = ProcessUtil::getClockTick();
+
+ StringBuilder builder;
+ builder << sourceBaseName << "-" << tick << ".slang-repro";
+
+ // We write out the file name tried even if it fails, as might be useful in reporting
+ outFileName = builder;
+
+ // We could have clashes, as we use ticks, we should get to a point where the clashes stop
+ try
+ {
+ outStream = new FileStream(builder, FileMode::CreateNew, FileAccess::Write, FileShare::WriteOnly);
+ return SLANG_OK;
+ }
+ catch (IOException&)
+ {
+ }
+
+ // TODO(JS):
+ // Might make sense to sleep here - but don't seem to have cross platform func for that yet.
+ }
+
+ return SLANG_FAIL;
+}
+
} // namespace Slang