From e57ea944c4aba0cf385f0f3db6b6ddc7760b8ffa Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Tue, 20 Jul 2021 15:17:52 -0400 Subject: Option to build all slang-repro in a directory (#1911) * #include an absolute path didn't work - because paths were taken to always be relative. * Add repro-directory feature. * Added writer support to repro-directory. * Upgrade glslang to 11.5.0 * Add -load-repro-directory option * Improve repro doc. --- source/slang/slang-options.cpp | 95 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) (limited to 'source') diff --git a/source/slang/slang-options.cpp b/source/slang/slang-options.cpp index 00372ca3c..73ccaab55 100644 --- a/source/slang/slang-options.cpp +++ b/source/slang/slang-options.cpp @@ -399,6 +399,94 @@ struct OptionsParser } } + class ReproPathVisitor : public Slang::Path::Visitor + { + public: + virtual void accept(Slang::Path::Type type, const Slang::UnownedStringSlice& filename) SLANG_OVERRIDE + { + if (type == Path::Type::File && Path::getPathExt(filename) == "slang-repro") + { + m_filenames.add(filename); + } + } + + Slang::List m_filenames; + }; + + static SlangResult _compileReproDirectory(SlangSession* session, EndToEndCompileRequest* originalRequest, const String& dir) + { + auto stdOut = originalRequest->getWriter(WriterChannel::StdOutput); + + ReproPathVisitor visitor; + Path::find(dir, nullptr, &visitor); + + for (auto filename : visitor.m_filenames) + { + auto path = Path::combine(dir, filename); + + ComPtr request; + SLANG_RETURN_ON_FAIL(session->createCompileRequest(request.writeRef())); + + auto requestImpl = asInternal(request); + + List buffer; + SLANG_RETURN_ON_FAIL(ReproUtil::loadState(path, buffer)); + + auto requestState = ReproUtil::getRequest(buffer); + MemoryOffsetBase base; + base.set(buffer.getBuffer(), buffer.getCount()); + + // If we can find a directory, that exists, we will set up a file system to load from that directory + ComPtr fileSystem; + String dirPath; + if (SLANG_SUCCEEDED(ReproUtil::calcDirectoryPathFromFilename(path, dirPath))) + { + SlangPathType pathType; + if (SLANG_SUCCEEDED(Path::getPathType(dirPath, &pathType)) && pathType == SLANG_PATH_TYPE_DIRECTORY) + { + fileSystem = new RelativeFileSystem(OSFileSystem::getExtSingleton(), dirPath); + } + } + + SLANG_RETURN_ON_FAIL(ReproUtil::load(base, requestState, fileSystem, requestImpl)); + + if (stdOut) + { + StringBuilder buf; + buf << filename << "\n"; + stdOut->write(buf.getBuffer(), buf.getLength()); + } + + StringBuilder bufs[Index(WriterChannel::CountOf)]; + ComPtr writers[Index(WriterChannel::CountOf)]; + for (Index i = 0; i < Index(WriterChannel::CountOf); ++i) + { + writers[i] = new StringWriter(&bufs[0], 0); + requestImpl->setWriter(WriterChannel(i), writers[i]); + } + + if (SLANG_FAILED(requestImpl->compile())) + { + const char failed[] = "FAILED!\n"; + stdOut->write(failed, SLANG_COUNT_OF(failed) - 1); + + const auto& diagnostics = bufs[Index(WriterChannel::Diagnostic)]; + + stdOut->write(diagnostics.getBuffer(), diagnostics.getLength()); + + return SLANG_FAIL; + } + } + + if (stdOut) + { + const char end[] = "(END)\n"; + stdOut->write(end, SLANG_COUNT_OF(end) - 1); + } + + return SLANG_OK; + } + SlangResult parse( int argc, char const* const* argv) @@ -620,6 +708,13 @@ struct OptionsParser hasLoadedRepro = true; } + else if (argValue == "-load-repro-directory") + { + CommandLineArg reproDirectory; + SLANG_RETURN_ON_FAIL(reader.expectArg(reproDirectory)); + + SLANG_RETURN_ON_FAIL(_compileReproDirectory(session, requestImpl, reproDirectory.value)); + } else if (argValue == "-repro-file-system") { CommandLineArg reproName; -- cgit v1.2.3