diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2021-07-20 15:17:52 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-07-20 12:17:52 -0700 |
| commit | e57ea944c4aba0cf385f0f3db6b6ddc7760b8ffa (patch) | |
| tree | 3d1c563a4c4879fd3f2b5b22f07cea61ef419c08 /source | |
| parent | f9f8d3ec5c749bcbdab5a8fc2d2f919350f2423c (diff) | |
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.
Diffstat (limited to 'source')
| -rw-r--r-- | source/slang/slang-options.cpp | 95 |
1 files changed, 95 insertions, 0 deletions
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<String> 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<slang::ICompileRequest> request; + SLANG_RETURN_ON_FAIL(session->createCompileRequest(request.writeRef())); + + auto requestImpl = asInternal(request); + + List<uint8_t> 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<ISlangFileSystem> 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<ISlangWriter> 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; |
