Treat default command line argument properly.
In SkCommandLineFlags, if the client sets a default value of multiple arguments (e.g. "arg0 arg1 ..."), set the actual defaults to all of those arguments separately (i.e. an array with [0] == "arg0", [1] == "arg1", ...), rather than as one string (i.e. [0] == "arg0 arg1 ..."). Remove the hack that worked around this bug. Also move the increasingly complicated implementation of SkFlagInfo::CreateStringFlag into the cpp file. BUG=https://code.google.com/p/skia/issues/detail?id=1237 Review URL: https://codereview.chromium.org/14366034 git-svn-id: http://skia.googlecode.com/svn/trunk@8845 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
parent
484f5bcf07
commit
58104a9c25
@ -1240,18 +1240,9 @@ DEFINE_string(gpuCacheSize, "", "<bytes> <count>: Limit the gpu cache to byte si
|
||||
#endif
|
||||
DEFINE_bool(hierarchy, false, "Whether to use multilevel directory structure "
|
||||
"when reading/writing files.");
|
||||
// TODO(epoger): Maybe should make SkCommandLineFlags handle default string
|
||||
// values differently, so that the first definition of ignoreErrorTypes worked?
|
||||
#if 0
|
||||
DEFINE_string(ignoreErrorTypes, kDefaultIgnorableErrorTypes.asString(" ").c_str(),
|
||||
"Space-separated list of ErrorTypes that should be ignored. If any *other* error "
|
||||
"types are encountered, the tool will exit with a nonzero return value.");
|
||||
#else
|
||||
DEFINE_string(ignoreErrorTypes, "", SkString(SkString(
|
||||
"Space-separated list of ErrorTypes that should be ignored. If any *other* error "
|
||||
"types are encountered, the tool will exit with a nonzero return value. "
|
||||
"Defaults to: ") += kDefaultIgnorableErrorTypes.asString(" ")).c_str());
|
||||
#endif
|
||||
DEFINE_string(match, "", "Only run tests whose name includes this substring/these substrings "
|
||||
"(more than one can be supplied, separated by spaces).");
|
||||
DEFINE_string(mismatchPath, "", "Write images for tests that failed due to "
|
||||
|
@ -8,6 +8,44 @@
|
||||
#include "SkCommandLineFlags.h"
|
||||
#include "SkTDArray.h"
|
||||
|
||||
bool SkFlagInfo::CreateStringFlag(const char* name, const char* shortName,
|
||||
SkCommandLineFlags::StringArray* pStrings,
|
||||
const char* defaultValue, const char* helpString) {
|
||||
SkFlagInfo* info = SkNEW_ARGS(SkFlagInfo, (name, shortName, kString_FlagType, helpString));
|
||||
info->fDefaultString.set(defaultValue);
|
||||
|
||||
info->fStrings = pStrings;
|
||||
SetDefaultStrings(pStrings, defaultValue);
|
||||
return true;
|
||||
}
|
||||
|
||||
void SkFlagInfo::SetDefaultStrings(SkCommandLineFlags::StringArray* pStrings,
|
||||
const char* defaultValue) {
|
||||
pStrings->reset();
|
||||
// If default is "", leave the array empty.
|
||||
size_t defaultLength = strlen(defaultValue);
|
||||
if (defaultLength > 0) {
|
||||
const char* const defaultEnd = defaultValue + defaultLength;
|
||||
const char* begin = defaultValue;
|
||||
while (true) {
|
||||
while (begin < defaultEnd && ' ' == *begin) {
|
||||
begin++;
|
||||
}
|
||||
if (begin < defaultEnd) {
|
||||
const char* end = begin + 1;
|
||||
while (end < defaultEnd && ' ' != *end) {
|
||||
end++;
|
||||
}
|
||||
size_t length = end - begin;
|
||||
pStrings->append(begin, length);
|
||||
begin = end + 1;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static bool string_is_in(const char* target, const char* set[], size_t len) {
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
if (0 == strcmp(target, set[i])) {
|
||||
|
@ -132,6 +132,10 @@ public:
|
||||
fStrings.push_back().set(string);
|
||||
}
|
||||
|
||||
void append(const char* string, size_t length) {
|
||||
fStrings.push_back().set(string, length);
|
||||
}
|
||||
|
||||
SkTArray<SkString> fStrings;
|
||||
|
||||
friend class SkFlagInfo;
|
||||
@ -216,7 +220,20 @@ public:
|
||||
kDouble_FlagType,
|
||||
};
|
||||
|
||||
// Create flags of the desired type, and append to the list.
|
||||
/**
|
||||
* Each Create<Type>Flag function creates an SkFlagInfo of the specified type. The SkFlagInfo
|
||||
* object is appended to a list, which is deleted when SkCommandLineFlags::Parse is called.
|
||||
* Therefore, each call should be made before the call to ::Parse. They are not intended
|
||||
* to be called directly. Instead, use the macros described above.
|
||||
* @param name Long version (at least 2 characters) of the name of the flag. This name can
|
||||
* be referenced on the command line as "--name" to set the value of this flag.
|
||||
* @param shortName Short version (one character) of the name of the flag. This name can
|
||||
* be referenced on the command line as "-shortName" to set the value of this flag.
|
||||
* @param p<Type> Pointer to a global variable which holds the value set by SkCommandLineFlags.
|
||||
* @param defaultValue The default value of this flag. The variable pointed to by p<Type> will
|
||||
* be set to this value initially. This is also displayed as part of the help output.
|
||||
* @param helpString Explanation of what this flag changes in the program.
|
||||
*/
|
||||
static bool CreateBoolFlag(const char* name, const char* shortName, bool* pBool,
|
||||
bool defaultValue, const char* helpString) {
|
||||
SkFlagInfo* info = SkNEW_ARGS(SkFlagInfo, (name, shortName, kBool_FlagType, helpString));
|
||||
@ -225,21 +242,19 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* See comments for CreateBoolFlag.
|
||||
* @param pStrings Unlike the others, this is a pointer to an array of values.
|
||||
* @param defaultValue Thise default will be parsed so that strings separated by spaces
|
||||
* will be added to pStrings.
|
||||
*/
|
||||
static bool CreateStringFlag(const char* name, const char* shortName,
|
||||
SkCommandLineFlags::StringArray* pStrings,
|
||||
const char* defaultValue, const char* helpString) {
|
||||
SkFlagInfo* info = SkNEW_ARGS(SkFlagInfo, (name, shortName, kString_FlagType, helpString));
|
||||
info->fDefaultString.set(defaultValue);
|
||||
|
||||
info->fStrings = pStrings;
|
||||
info->fStrings->reset();
|
||||
// If default is "", leave the array empty.
|
||||
if (info->fDefaultString.size() > 0) {
|
||||
info->fStrings->append(defaultValue);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
const char* defaultValue, const char* helpString);
|
||||
|
||||
/**
|
||||
* See comments for CreateBoolFlag.
|
||||
*/
|
||||
static bool CreateIntFlag(const char* name, int32_t* pInt,
|
||||
int32_t defaultValue, const char* helpString) {
|
||||
SkFlagInfo* info = SkNEW_ARGS(SkFlagInfo, (name, NULL, kInt_FlagType, helpString));
|
||||
@ -248,6 +263,9 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* See comments for CreateBoolFlag.
|
||||
*/
|
||||
static bool CreateDoubleFlag(const char* name, double* pDouble,
|
||||
double defaultValue, const char* helpString) {
|
||||
SkFlagInfo* info = SkNEW_ARGS(SkFlagInfo, (name, NULL, kDouble_FlagType, helpString));
|
||||
@ -375,6 +393,16 @@ private:
|
||||
SkASSERT(NULL != name && strlen(name) > 1);
|
||||
SkASSERT(NULL == shortName || 1 == strlen(shortName));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a StringArray to hold the values stored in defaultStrings.
|
||||
* @param array The StringArray to modify.
|
||||
* @param defaultStrings Space separated list of strings that should be inserted into array
|
||||
* individually.
|
||||
*/
|
||||
static void SetDefaultStrings(SkCommandLineFlags::StringArray* array,
|
||||
const char* defaultStrings);
|
||||
|
||||
// Name of the flag, without initial dashes
|
||||
SkString fName;
|
||||
SkString fShortName;
|
||||
|
Loading…
Reference in New Issue
Block a user