diff options
author | Cary Clark <caryclark@skia.org> | 2017-12-11 16:03:17 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-12-11 21:47:38 +0000 |
commit | 2f466242c7289b246d7ef665aa50006cfd11aa36 (patch) | |
tree | f41d3ac2559c624a132fa74e3334ccbc5cfd1ceb /tools/bookmaker/parserCommon.cpp | |
parent | bb091a08d1c60ccf3d014d94490c5b4134586ee2 (diff) |
working on image and nightly housekeeping bot
Add more examples and docs for SkImage; still a ways to go.
Fix bit-rotted examples.
Add typedef support.
Add json driver to pick files to work on; remove special-casing.
Fix unordered map traversal that made md output unreliable.
TBR=rmistry@google.com
Docs-Preview: https://skia.org/?cl=80060
Bug: skia:6898
Change-Id: Ib8eb9fdfa5a9db61c8332e657fa2e2f4b96a665f
Reviewed-on: https://skia-review.googlesource.com/80060
Reviewed-by: Cary Clark <caryclark@skia.org>
Commit-Queue: Cary Clark <caryclark@skia.org>
Diffstat (limited to 'tools/bookmaker/parserCommon.cpp')
-rw-r--r-- | tools/bookmaker/parserCommon.cpp | 119 |
1 files changed, 117 insertions, 2 deletions
diff --git a/tools/bookmaker/parserCommon.cpp b/tools/bookmaker/parserCommon.cpp index 79503a66b3..af1031ac43 100644 --- a/tools/bookmaker/parserCommon.cpp +++ b/tools/bookmaker/parserCommon.cpp @@ -16,7 +16,6 @@ static void debug_out(int len, const char* data) { } bool ParserCommon::parseFile(const char* fileOrPath, const char* suffix) { -// this->reset(); if (!sk_isdir(fileOrPath)) { if (!this->parseFromFile(fileOrPath)) { SkDebugf("failed to parse %s\n", fileOrPath); @@ -39,9 +38,23 @@ bool ParserCommon::parseFile(const char* fileOrPath, const char* suffix) { return true; } +bool ParserCommon::parseStatus(const char* statusFile, const char* suffix, StatusFilter filter) { + StatusIter iter(statusFile, suffix, filter); + if (iter.empty()) { + return false; + } + for (string file; iter.next(&file); ) { + SkString p = SkOSPath::Join(iter.baseDir().c_str(), file.c_str()); + const char* hunk = p.c_str(); + if (!this->parseFromFile(hunk)) { + SkDebugf("failed to parse %s\n", hunk); + return false; + } + } + return true; +} bool ParserCommon::parseSetup(const char* path) { -// this->reset(); sk_sp<SkData> data = SkData::MakeFromFileName(path); if (nullptr == data.get()) { SkDebugf("%s missing\n", path); @@ -210,3 +223,105 @@ void ParserCommon::writeString(const char* str) { fLinefeeds = 0; fMaxLF = 2; } + +StatusIter::StatusIter(const char* statusFile, const char* suffix, StatusFilter filter) + : fSuffix(suffix) + , fFilter(filter) { + if (!this->parseFromFile(statusFile)) { + return; + } +} + +static const char* block_names[] = { + "Completed", + "InProgress", +}; + +string StatusIter::baseDir() { + SkASSERT(fStack.back().fObject.isArray()); + SkASSERT(fStack.size() > 2); + string dir; + for (unsigned index = 2; index < fStack.size(); ++index) { + dir += fStack[index].fName; + if (index < fStack.size() - 1) { + dir += SkOSPath::SEPARATOR; + } + } + return dir; +} + +// FIXME: need to compare fBlockName against fFilter +// need to compare fSuffix against next value returned +bool StatusIter::next(string* str) { + JsonStatus* status; + do { + do { + if (fStack.empty()) { + return false; + } + status = &fStack.back(); + if (status->fIter != status->fObject.end()) { + break; + } + fStack.pop_back(); + } while (true); + if (1 == fStack.size()) { + do { + StatusFilter blockType = StatusFilter::kUnknown; + for (unsigned index = 0; index < SK_ARRAY_COUNT(block_names); ++index) { + if (status->fIter.key().asString() == block_names[index]) { + blockType = (StatusFilter) index; + break; + } + } + if (blockType <= fFilter) { + break; + } + status->fIter++; + } while (status->fIter != status->fObject.end()); + if (status->fIter == status->fObject.end()) { + continue; + } + } + if (!status->fObject.isArray()) { + SkASSERT(status->fIter != status->fObject.end()); + JsonStatus block = { + *status->fIter, + status->fIter->begin(), + status->fIter.key().asString() + }; + fStack.emplace_back(block); + status = &(&fStack.back())[-1]; + status->fIter++; + status = &fStack.back(); + continue; + } + *str = status->fIter->asString(); + status->fIter++; + if (str->length() - strlen(fSuffix) == str->find(fSuffix)) { + return true; + } + } while (true); + return true; +} + +bool StatusIter::parseFromFile(const char* path) { + sk_sp<SkData> json(SkData::MakeFromFileName(path)); + if (!json) { + SkDebugf("file %s:\n", path); + return this->reportError<bool>("file not readable"); + } + Json::Reader reader; + const char* data = (const char*)json->data(); + if (!reader.parse(data, data+json->size(), fRoot)) { + SkDebugf("file %s:\n", path); + return this->reportError<bool>("file not parsable"); + } + JsonStatus block = { fRoot, fRoot.begin(), "" }; + fStack.emplace_back(block); + return true; +} + +void StatusIter::reset() { + fStack.clear(); +} |