From 80ff45f095db5a08db264921fda2db210788d529 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Fri, 3 Dec 2021 09:46:08 -0500 Subject: Improvements to repro diagnostics (#2039) * #include an absolute path didn't work - because paths were taken to always be relative. * Improvements to repro diagnostics. * Fix typo. --- source/slang/slang-repro.cpp | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) (limited to 'source/slang/slang-repro.cpp') diff --git a/source/slang/slang-repro.cpp b/source/slang/slang-repro.cpp index d7ddd6aa8..a5591e68b 100644 --- a/source/slang/slang-repro.cpp +++ b/source/slang/slang-repro.cpp @@ -1087,40 +1087,54 @@ struct LoadContext return saveState(request, stream); } -/* static */ SlangResult ReproUtil::loadState(const String& filename, List& outBuffer) +/* static */ SlangResult ReproUtil::loadState(const String& filename, DiagnosticSink* sink, List& outBuffer) { RefPtr stream = new FileStream; SLANG_RETURN_ON_FAIL(stream->init(filename, FileMode::Open, FileAccess::Read, FileShare::ReadWrite)); - return loadState(stream, outBuffer); + return loadState(stream, sink, outBuffer); } -/* static */ SlangResult ReproUtil::loadState(Stream* stream, List& buffer) +/* static */ SlangResult ReproUtil::loadState(Stream* stream, DiagnosticSink* sink, List& buffer) { Header header; - SLANG_RETURN_ON_FAIL(RiffUtil::readData(stream, &header.m_chunk, sizeof(header), buffer)); + { + Result res = RiffUtil::readData(stream, &header.m_chunk, sizeof(header), buffer); + if (SLANG_FAILED(res)) + { + sink->diagnose(SourceLoc(), Diagnostics::unableToReadRiff); + return res; + } + } if (header.m_chunk.type != kSlangStateFourCC) { + sink->diagnose(SourceLoc(), Diagnostics::expectingSlangRiffContainer); return SLANG_FAIL; } if (!RiffSemanticVersion::areCompatible(g_semanticVersion, header.m_semanticVersion)) { + StringBuilder headerBuf, currentBuf; + header.m_semanticVersion.asSemanticVersion().append(headerBuf); + g_semanticVersion.asSemanticVersion().append(currentBuf); + + sink->diagnose(SourceLoc(), Diagnostics::incompatibleRiffSemanticVersion, headerBuf, currentBuf); return SLANG_FAIL; } if (header.m_typeHash != uint32_t(_getTypeHash())) { + sink->diagnose(SourceLoc(), Diagnostics::riffHashMismatch); return SLANG_FAIL; } return SLANG_OK; } -/* static */SlangResult ReproUtil::loadState(const uint8_t* data, size_t size, List& outBuffer) +/* static */SlangResult ReproUtil::loadState(const uint8_t* data, size_t size, DiagnosticSink* sink, List& outBuffer) { MemoryStreamBase stream(FileAccess::Read, data, size); - return loadState(&stream, outBuffer); + return loadState(&stream, sink, outBuffer); } /* static */ ReproUtil::RequestState* ReproUtil::getRequest(const List& buffer) @@ -1149,10 +1163,10 @@ struct LoadContext return SLANG_OK; } -/* static */SlangResult ReproUtil::extractFilesToDirectory(const String& filename) +/* static */SlangResult ReproUtil::extractFilesToDirectory(const String& filename, DiagnosticSink* sink) { List buffer; - SLANG_RETURN_ON_FAIL(ReproUtil::loadState(filename, buffer)); + SLANG_RETURN_ON_FAIL(ReproUtil::loadState(filename, sink, buffer)); MemoryOffsetBase base; base.set(buffer.getBuffer(), buffer.getCount()); @@ -1162,7 +1176,12 @@ struct LoadContext String dirPath; SLANG_RETURN_ON_FAIL(ReproUtil::calcDirectoryPathFromFilename(filename, dirPath)); - Path::createDirectory(dirPath); + if (!Path::createDirectory(dirPath)) + { + sink->diagnose(SourceLoc(), Diagnostics::unableToCreateDirectory, dirPath); + return SLANG_FAIL; + } + // Set up a file system to write into this directory RelativeFileSystem relFileSystem(OSFileSystem::getMutableSingleton(), dirPath); -- cgit v1.2.3