Populate ALL copies of a command line flag during parsing

Now that we're declaring flags statically per-tool, we were only
setting the value on one of them (randomly) in the linked list.

BUG=skia:

GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=3881

Change-Id: I448cb7f42ee01a16daa65986b14aee9f1a2a3588
Reviewed-on: https://skia-review.googlesource.com/3881
Reviewed-by: Mike Klein <mtklein@chromium.org>
Commit-Queue: Brian Osman <brianosman@google.com>
This commit is contained in:
Brian Osman 2016-10-24 14:53:08 -04:00 committed by Skia Commit-Bot
parent 3d3a65c488
commit 49f57123eb

View File

@ -288,11 +288,18 @@ void SkCommandLineFlags::Parse(int argc, char** argv) {
helpPrinted = true; helpPrinted = true;
} }
if (!helpPrinted) { if (!helpPrinted) {
bool flagMatched = false; SkFlagInfo* matchedFlag = nullptr;
SkFlagInfo* flag = gHead; SkFlagInfo* flag = gHead;
int startI = i;
while (flag != nullptr) { while (flag != nullptr) {
if (flag->match(argv[i])) { if (flag->match(argv[startI])) {
flagMatched = true; i = startI;
if (matchedFlag) {
// Don't redefine the same flag with different types.
SkASSERT(matchedFlag->getFlagType() == flag->getFlagType());
} else {
matchedFlag = flag;
}
switch (flag->getFlagType()) { switch (flag->getFlagType()) {
case SkFlagInfo::kBool_FlagType: case SkFlagInfo::kBool_FlagType:
// Can be handled by match, above, but can also be set by the next // Can be handled by match, above, but can also be set by the next
@ -330,11 +337,10 @@ void SkCommandLineFlags::Parse(int argc, char** argv) {
default: default:
SkDEBUGFAIL("Invalid flag type"); SkDEBUGFAIL("Invalid flag type");
} }
break;
} }
flag = flag->next(); flag = flag->next();
} }
if (!flagMatched) { if (!matchedFlag) {
#if defined(SK_BUILD_FOR_MAC) #if defined(SK_BUILD_FOR_MAC)
if (SkStrStartsWith(argv[i], "NSDocumentRevisions") if (SkStrStartsWith(argv[i], "NSDocumentRevisions")
|| SkStrStartsWith(argv[i], "-NSDocumentRevisions")) { || SkStrStartsWith(argv[i], "-NSDocumentRevisions")) {