Changeset 52541 in webkit
- Timestamp:
- Dec 23, 2009 9:31:33 PM (14 years ago)
- Location:
- trunk/WebKitTools
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebKitTools/ChangeLog
r52540 r52541 1 2009-12-20 Chris Jerdonek <chris.jerdonek@gmail.com> 2 3 Reviewed by David Levin. 4 5 Moved some sections of code in preparation to refactor 6 check-webkit-style's argument parser to avoid setting 7 global variables. 8 9 https://bugs.webkit.org/show_bug.cgi?id=32592 10 11 * Scripts/check-webkit-style: 12 - Moved _USAGE string to style.py. 13 - Addressed FIXME by eliminating dependencies on cpp_style.py. 14 15 * Scripts/modules/cpp_style.py: 16 - Moved default arguments and style categories to style.py. 17 - Moved exit_with_usage(), exit_with_categories(), and 18 parse_arguments() to style.py. 19 - Removed references in _CppStyleState to the global 20 variables now in style.py. 21 22 * Scripts/modules/cpp_style_unittest.py: 23 - Moved parse_arguments() unit tests to style_unittest.py. 24 25 * Scripts/modules/style.py: 26 - Added _USAGE string from check-webkit-style. 27 - Added default arguments and style categories from cpp_style.py. 28 - Added exit_with_usage(), exit_with_categories(), and 29 parse_arguments() from cpp_sstyle.py. 30 31 * Scripts/modules/style_unittest.py: Added. 32 - Added parse_arguments() unit tests from cpp_style_unittest.py. 33 34 * Scripts/run-webkit-unittests: 35 - Added unit tests from style_unittest.py. 36 1 37 2009-12-23 Eric Seidel <eric@webkit.org> 2 38 -
trunk/WebKitTools/Scripts/check-webkit-style
r52232 r52541 47 47 import sys 48 48 49 import modules.cpp_style as cpp_style50 49 import modules.style as style 51 50 from modules.scm import detect_scm_system 52 53 54 # FIXME: Avoid cpp_style dependency.55 cpp_style._USAGE = """56 Syntax: %(program_name)s [--verbose=#] [--git-commit=<SingleCommit>] [--output=vs7]57 [--filter=-x,+y,...] [file] ...58 59 The style guidelines this tries to follow are here:60 http://webkit.org/coding/coding-style.html61 62 Every style error is given a confidence score from 1-5, with 5 meaning63 we are certain of the problem, and 1 meaning it could be a legitimate64 construct. This can miss some errors and does not substitute for65 code review.66 67 To prevent specific lines from being linted, add a '// NOLINT' comment to the68 end of the line.69 70 Linted extensions are .cpp, .c and .h. Other file types are ignored.71 72 The file parameter is optional and accepts multiple files. Leaving73 out the file parameter applies the check to all files considered changed74 by your source control management system.75 76 Flags:77 78 verbose=#79 A number 0-5 to restrict errors to certain verbosity levels.80 Defaults to %(default_verbosity)s.81 82 git-commit=<SingleCommit>83 Checks the style of everything from the given commit to the local tree.84 85 output=vs786 The output format, which may be one of87 emacs : to ease emacs parsing88 vs7 : compatible with Visual Studio89 Defaults to "%(default_output_format)s". Other formats are unsupported.90 91 filter=-x,+y,...92 A comma-separated list of boolean filter rules used to filter93 which categories of style guidelines to check. The script checks94 a category if the category passes the filter rules, as follows.95 96 Any webkit category starts out passing. All filter rules are then97 evaluated left to right, with later rules taking precedence. For98 example, the rule "+foo" passes any category that starts with "foo",99 and "-foo" fails any such category. The filter input "-whitespace,100 +whitespace/braces" fails the category "whitespace/tab" and passes101 "whitespace/braces".102 103 Examples: --filter=-whitespace,+whitespace/braces104 --filter=-whitespace,-runtime/printf,+runtime/printf_format105 --filter=-,+build/include_what_you_use106 107 Category names appear in error messages in brackets, for example108 [whitespace/indent]. To see a list of all categories available to109 %(program_name)s, along with which are enabled by default, pass110 the empty filter as follows:111 --filter=112 """ % {113 'program_name': os.path.basename(sys.argv[0]),114 'default_verbosity': cpp_style._DEFAULT_VERBOSITY,115 'default_output_format': cpp_style._DEFAULT_OUTPUT_FORMAT116 }117 51 118 52 … … 131 65 132 66 if files and "--git-commit" in flags: 133 cpp_style.exit_with_usage('It is not possible to check files and a '134 135 67 style.exit_with_usage('It is not possible to check files and a ' 68 'specific commit at the same time.', 69 display_help=True) 136 70 137 71 if files: -
trunk/WebKitTools/Scripts/modules/cpp_style.py
r52496 r52541 38 38 39 39 import codecs 40 import getopt41 40 import math # for log 42 41 import os … … 49 48 50 49 51 # This is set by check-webkit-style.52 50 _USAGE = '' 53 54 55 # Default options56 _DEFAULT_VERBOSITY = 157 _DEFAULT_OUTPUT_FORMAT = 'emacs'58 59 60 # FIXME: For style categories we will never want to have, remove them.61 # For categories for which we want to have similar functionality,62 # modify the implementation and enable them.63 # FIXME: Add a unit test to ensure the corresponding categories64 # are elements of _STYLE_CATEGORIES.65 #66 # For unambiguous terminology, we use "filter rule" rather than "filter"67 # for an individual boolean filter flag like "+foo". This allows us to68 # reserve "filter" for what one gets by collectively applying all of69 # the filter rules as specified by a --filter flag.70 _WEBKIT_FILTER_RULES = [71 '-build/endif_comment',72 '-build/include_what_you_use', # <string> for std::string73 '-build/storage_class', # const static74 '-legal/copyright',75 '-readability/multiline_comment',76 '-readability/braces', # int foo() {};77 '-readability/fn_size',78 '-readability/casting',79 '-readability/function',80 '-runtime/arrays', # variable length array81 '-runtime/casting',82 '-runtime/sizeof',83 '-runtime/explicit', # explicit84 '-runtime/virtual', # virtual dtor85 '-runtime/printf',86 '-runtime/threadsafe_fn',87 '-runtime/rtti',88 '-whitespace/blank_line',89 '-whitespace/end_of_line',90 '-whitespace/labels',91 ]92 93 94 # We categorize each style rule we print. Here are the categories.95 # We want an explicit list so we can list them all in cpp_style --filter=.96 # If you add a new error message with a new category, add it to the list97 # here! cpp_style_unittest.py should tell you if you forget to do this.98 _STYLE_CATEGORIES = [99 'build/class',100 'build/deprecated',101 'build/endif_comment',102 'build/forward_decl',103 'build/header_guard',104 'build/include',105 'build/include_order',106 'build/include_what_you_use',107 'build/namespaces',108 'build/printf_format',109 'build/storage_class',110 'build/using_std',111 'legal/copyright',112 'readability/braces',113 'readability/casting',114 'readability/check',115 'readability/comparison_to_zero',116 'readability/constructors',117 'readability/control_flow',118 'readability/fn_size',119 'readability/function',120 'readability/multiline_comment',121 'readability/multiline_string',122 'readability/naming',123 'readability/null',124 'readability/streams',125 'readability/todo',126 'readability/utf8',127 'runtime/arrays',128 'runtime/casting',129 'runtime/explicit',130 'runtime/init',131 'runtime/int',132 'runtime/invalid_increment',133 'runtime/max_min_macros',134 'runtime/memset',135 'runtime/printf',136 'runtime/printf_format',137 'runtime/references',138 'runtime/rtti',139 'runtime/sizeof',140 'runtime/string',141 'runtime/threadsafe_fn',142 'runtime/virtual',143 'whitespace/blank_line',144 'whitespace/braces',145 'whitespace/comma',146 'whitespace/comments',147 'whitespace/declaration',148 'whitespace/end_of_line',149 'whitespace/ending_newline',150 'whitespace/indent',151 'whitespace/labels',152 'whitespace/line_length',153 'whitespace/newline',154 'whitespace/operators',155 'whitespace/parens',156 'whitespace/semicolon',157 'whitespace/tab',158 'whitespace/todo',159 ]160 51 161 52 … … 361 252 362 253 def __init__(self): 363 self.verbose_level = _DEFAULT_VERBOSITY# global setting.254 self.verbose_level = 1 # global setting. 364 255 self.error_count = 0 # global count of reported errors 365 256 # filters to apply when emitting error messages … … 369 260 # "emacs" - format that emacs can parse (default) 370 261 # "vs7" - format that Microsoft Visual Studio 7 can parse 371 self.output_format = _DEFAULT_OUTPUT_FORMAT262 self.output_format = 'emacs' 372 263 373 264 def set_output_format(self, output_format): … … 3164 3055 3165 3056 3166 def exit_with_usage(error_message, display_help=False):3167 """Exit and print a usage string with an optional error message.3168 3169 Args:3170 error_message: The optional error message.3171 display_help: Whether to display help output. Suppressing help3172 output is useful for unit tests.3173 """3174 if display_help:3175 sys.stderr.write(_USAGE)3176 if error_message:3177 sys.exit('\nFATAL ERROR: ' + error_message)3178 else:3179 sys.exit(1)3180 3181 3182 def exit_with_categories(display_help=False):3183 """Exit and print all style categories, along with the default filter.3184 3185 These category names appear in error messages. They can be filtered3186 using the --filter flag.3187 3188 Args:3189 display_help: Whether to display help output. Suppressing help3190 output is useful for unit tests.3191 """3192 if display_help:3193 sys.stderr.write('\nAll categories:\n')3194 for category in sorted(_STYLE_CATEGORIES):3195 sys.stderr.write(' ' + category + '\n')3196 3197 sys.stderr.write('\nDefault filter rules**:\n')3198 for filter_rule in sorted(_WEBKIT_FILTER_RULES):3199 sys.stderr.write(' ' + filter_rule + '\n')3200 sys.stderr.write('\n**The command always evaluates the above '3201 'rules, and before any --filter flag.\n\n')3202 3203 sys.exit(0)3204 3205 3206 def parse_arguments(args, additional_flags=[], display_help=False):3207 """Parses the command line arguments.3208 3209 This may set the output format and verbosity level as side-effects.3210 3211 Args:3212 args: The command line arguments:3213 additional_flags: A list of strings which specifies flags we allow.3214 display_help: Whether to display help output. Suppressing help3215 output is useful for unit tests.3216 3217 Returns:3218 A tuple of (filenames, flags)3219 3220 filenames: The list of filenames to lint.3221 flags: The dict of the flag names and the flag values.3222 """3223 flags = ['help', 'output=', 'verbose=', 'filter='] + additional_flags3224 additional_flag_values = {}3225 try:3226 (opts, filenames) = getopt.getopt(args, '', flags)3227 except getopt.GetoptError:3228 exit_with_usage('Invalid arguments.', display_help)3229 3230 verbosity = _verbose_level()3231 output_format = _output_format()3232 filters = ''3233 3234 for (opt, val) in opts:3235 if opt == '--help':3236 exit_with_usage(None, display_help)3237 elif opt == '--output':3238 if not val in ('emacs', 'vs7'):3239 exit_with_usage('The only allowed output formats are emacs and vs7.',3240 display_help)3241 output_format = val3242 elif opt == '--verbose':3243 verbosity = int(val)3244 elif opt == '--filter':3245 filters = val3246 if not filters:3247 exit_with_categories(display_help)3248 else:3249 additional_flag_values[opt] = val3250 3251 _set_output_format(output_format)3252 _set_verbose_level(verbosity)3253 _set_filters(filters)3254 3255 return (filenames, additional_flag_values)3256 3257 3258 3057 def can_handle(filename): 3259 3058 """Checks if this module supports for the specified file type. -
trunk/WebKitTools/Scripts/modules/cpp_style_unittest.py
r52496 r52541 42 42 import unittest 43 43 import cpp_style 44 44 # FIXME: Remove the need to import something from style. 45 from style import _STYLE_CATEGORIES 45 46 46 47 # This class works as an error collector and replaces cpp_style.Error … … 48 49 # is in cpp_style._STYLE_CATEGORIES, to help keep that list up to date. 49 50 class ErrorCollector: 50 _all_style_categories = cpp_style._STYLE_CATEGORIES51 _all_style_categories = _STYLE_CATEGORIES 51 52 # This a list including all categories seen in any unit test. 52 53 _seen_style_categories = {} … … 1568 1569 'Tab found; better to use spaces [whitespace/tab] [1]') 1569 1570 1570 def test_parse_arguments(self):1571 old_usage = cpp_style._USAGE1572 old_style_categories = cpp_style._STYLE_CATEGORIES1573 old_webkit_filter_rules = cpp_style._WEBKIT_FILTER_RULES1574 old_output_format = cpp_style._cpp_style_state.output_format1575 old_verbose_level = cpp_style._cpp_style_state.verbose_level1576 old_filters = cpp_style._cpp_style_state.filters1577 try:1578 # Don't print usage during the tests, or filter categories1579 cpp_style._USAGE = ''1580 cpp_style._STYLE_CATEGORIES = []1581 cpp_style._WEBKIT_FILTER_RULES = []1582 1583 self.assertRaises(SystemExit, cpp_style.parse_arguments, ['--badopt'])1584 self.assertRaises(SystemExit, cpp_style.parse_arguments, ['--help'])1585 self.assertRaises(SystemExit, cpp_style.parse_arguments, ['--filter='])1586 # This is illegal because all filters must start with + or -1587 self.assertRaises(ValueError, cpp_style.parse_arguments, ['--filter=foo'])1588 self.assertRaises(ValueError, cpp_style.parse_arguments,1589 ['--filter=+a,b,-c'])1590 1591 self.assertEquals((['foo.cpp'], {}), cpp_style.parse_arguments(['foo.cpp']))1592 self.assertEquals(old_output_format, cpp_style._cpp_style_state.output_format)1593 self.assertEquals(old_verbose_level, cpp_style._cpp_style_state.verbose_level)1594 1595 self.assertEquals(([], {}), cpp_style.parse_arguments([]))1596 self.assertEquals(([], {}), cpp_style.parse_arguments(['--v=0']))1597 1598 self.assertEquals((['foo.cpp'], {}),1599 cpp_style.parse_arguments(['--v=1', 'foo.cpp']))1600 self.assertEquals(1, cpp_style._cpp_style_state.verbose_level)1601 self.assertEquals((['foo.h'], {}),1602 cpp_style.parse_arguments(['--v=3', 'foo.h']))1603 self.assertEquals(3, cpp_style._cpp_style_state.verbose_level)1604 self.assertEquals((['foo.cpp'], {}),1605 cpp_style.parse_arguments(['--verbose=5', 'foo.cpp']))1606 self.assertEquals(5, cpp_style._cpp_style_state.verbose_level)1607 self.assertRaises(ValueError,1608 cpp_style.parse_arguments, ['--v=f', 'foo.cpp'])1609 1610 self.assertEquals((['foo.cpp'], {}),1611 cpp_style.parse_arguments(['--output=emacs', 'foo.cpp']))1612 self.assertEquals('emacs', cpp_style._cpp_style_state.output_format)1613 self.assertEquals((['foo.h'], {}),1614 cpp_style.parse_arguments(['--output=vs7', 'foo.h']))1615 self.assertEquals('vs7', cpp_style._cpp_style_state.output_format)1616 self.assertRaises(SystemExit,1617 cpp_style.parse_arguments, ['--output=blah', 'foo.cpp'])1618 1619 filt = '-,+whitespace,-whitespace/indent'1620 self.assertEquals((['foo.h'], {}),1621 cpp_style.parse_arguments(['--filter='+filt, 'foo.h']))1622 self.assertEquals(['-', '+whitespace', '-whitespace/indent'],1623 cpp_style._cpp_style_state.filters)1624 1625 self.assertEquals((['foo.cpp', 'foo.h'], {}),1626 cpp_style.parse_arguments(['foo.cpp', 'foo.h']))1627 1628 self.assertEquals((['foo.cpp'], {'--foo': ''}),1629 cpp_style.parse_arguments(['--foo', 'foo.cpp'], ['foo']))1630 self.assertEquals((['foo.cpp'], {'--foo': 'bar'}),1631 cpp_style.parse_arguments(['--foo=bar', 'foo.cpp'], ['foo=']))1632 self.assertEquals((['foo.cpp'], {}),1633 cpp_style.parse_arguments(['foo.cpp'], ['foo=']))1634 self.assertRaises(SystemExit,1635 cpp_style.parse_arguments,1636 ['--footypo=bar', 'foo.cpp'], ['foo='])1637 finally:1638 cpp_style._USAGE = old_usage1639 cpp_style._STYLE_CATEGORIES = old_style_categories1640 cpp_style._WEBKIT_FILTER_RULES = old_webkit_filter_rules1641 cpp_style._cpp_style_state.output_format = old_output_format1642 cpp_style._cpp_style_state.verbose_level = old_verbose_level1643 cpp_style._cpp_style_state.filters = old_filters1644 1645 1571 def test_filter(self): 1646 1572 old_filters = cpp_style._cpp_style_state.filters -
trunk/WebKitTools/Scripts/modules/style.py
r52232 r52541 32 32 # check-webkit-style should not refer cpp_style directly. 33 33 34 import getopt 34 35 import os.path 35 36 import modules.cpp_style as cpp_style 37 import modules.text_style as text_style 38 from modules.diff_parser import DiffParser 36 import sys 37 38 import cpp_style 39 import text_style 40 from diff_parser import DiffParser 41 42 43 # Default options 44 _DEFAULT_VERBOSITY = 1 45 _DEFAULT_OUTPUT_FORMAT = 'emacs' 46 47 48 # FIXME: For style categories we will never want to have, remove them. 49 # For categories for which we want to have similar functionality, 50 # modify the implementation and enable them. 51 # FIXME: Add a unit test to ensure the corresponding categories 52 # are elements of _STYLE_CATEGORIES. 53 # 54 # For unambiguous terminology, we use "filter rule" rather than "filter" 55 # for an individual boolean filter flag like "+foo". This allows us to 56 # reserve "filter" for what one gets by collectively applying all of 57 # the filter rules as specified by a --filter flag. 58 _WEBKIT_FILTER_RULES = [ 59 '-build/endif_comment', 60 '-build/include_what_you_use', # <string> for std::string 61 '-build/storage_class', # const static 62 '-legal/copyright', 63 '-readability/multiline_comment', 64 '-readability/braces', # int foo() {}; 65 '-readability/fn_size', 66 '-readability/casting', 67 '-readability/function', 68 '-runtime/arrays', # variable length array 69 '-runtime/casting', 70 '-runtime/sizeof', 71 '-runtime/explicit', # explicit 72 '-runtime/virtual', # virtual dtor 73 '-runtime/printf', 74 '-runtime/threadsafe_fn', 75 '-runtime/rtti', 76 '-whitespace/blank_line', 77 '-whitespace/end_of_line', 78 '-whitespace/labels', 79 ] 80 81 82 # We categorize each style rule we print. Here are the categories. 83 # We want an explicit list so we can list them all in cpp_style --filter=. 84 # If you add a new error message with a new category, add it to the list 85 # here! cpp_style_unittest.py should tell you if you forget to do this. 86 _STYLE_CATEGORIES = [ 87 'build/class', 88 'build/deprecated', 89 'build/endif_comment', 90 'build/forward_decl', 91 'build/header_guard', 92 'build/include', 93 'build/include_order', 94 'build/include_what_you_use', 95 'build/namespaces', 96 'build/printf_format', 97 'build/storage_class', 98 'build/using_std', 99 'legal/copyright', 100 'readability/braces', 101 'readability/casting', 102 'readability/check', 103 'readability/comparison_to_zero', 104 'readability/constructors', 105 'readability/control_flow', 106 'readability/fn_size', 107 'readability/function', 108 'readability/multiline_comment', 109 'readability/multiline_string', 110 'readability/naming', 111 'readability/null', 112 'readability/streams', 113 'readability/todo', 114 'readability/utf8', 115 'runtime/arrays', 116 'runtime/casting', 117 'runtime/explicit', 118 'runtime/init', 119 'runtime/int', 120 'runtime/invalid_increment', 121 'runtime/max_min_macros', 122 'runtime/memset', 123 'runtime/printf', 124 'runtime/printf_format', 125 'runtime/references', 126 'runtime/rtti', 127 'runtime/sizeof', 128 'runtime/string', 129 'runtime/threadsafe_fn', 130 'runtime/virtual', 131 'whitespace/blank_line', 132 'whitespace/braces', 133 'whitespace/comma', 134 'whitespace/comments', 135 'whitespace/declaration', 136 'whitespace/end_of_line', 137 'whitespace/ending_newline', 138 'whitespace/indent', 139 'whitespace/labels', 140 'whitespace/line_length', 141 'whitespace/newline', 142 'whitespace/operators', 143 'whitespace/parens', 144 'whitespace/semicolon', 145 'whitespace/tab', 146 'whitespace/todo', 147 ] 148 149 150 _USAGE = """ 151 Syntax: %(program_name)s [--verbose=#] [--git-commit=<SingleCommit>] [--output=vs7] 152 [--filter=-x,+y,...] [file] ... 153 154 The style guidelines this tries to follow are here: 155 http://webkit.org/coding/coding-style.html 156 157 Every style error is given a confidence score from 1-5, with 5 meaning 158 we are certain of the problem, and 1 meaning it could be a legitimate 159 construct. This can miss some errors and does not substitute for 160 code review. 161 162 To prevent specific lines from being linted, add a '// NOLINT' comment to the 163 end of the line. 164 165 Linted extensions are .cpp, .c and .h. Other file types are ignored. 166 167 The file parameter is optional and accepts multiple files. Leaving 168 out the file parameter applies the check to all files considered changed 169 by your source control management system. 170 171 Flags: 172 173 verbose=# 174 A number 0-5 to restrict errors to certain verbosity levels. 175 Defaults to %(default_verbosity)s. 176 177 git-commit=<SingleCommit> 178 Checks the style of everything from the given commit to the local tree. 179 180 output=vs7 181 The output format, which may be one of 182 emacs : to ease emacs parsing 183 vs7 : compatible with Visual Studio 184 Defaults to "%(default_output_format)s". Other formats are unsupported. 185 186 filter=-x,+y,... 187 A comma-separated list of boolean filter rules used to filter 188 which categories of style guidelines to check. The script checks 189 a category if the category passes the filter rules, as follows. 190 191 Any webkit category starts out passing. All filter rules are then 192 evaluated left to right, with later rules taking precedence. For 193 example, the rule "+foo" passes any category that starts with "foo", 194 and "-foo" fails any such category. The filter input "-whitespace, 195 +whitespace/braces" fails the category "whitespace/tab" and passes 196 "whitespace/braces". 197 198 Examples: --filter=-whitespace,+whitespace/braces 199 --filter=-whitespace,-runtime/printf,+runtime/printf_format 200 --filter=-,+build/include_what_you_use 201 202 Category names appear in error messages in brackets, for example 203 [whitespace/indent]. To see a list of all categories available to 204 %(program_name)s, along with which are enabled by default, pass 205 the empty filter as follows: 206 --filter= 207 """ % { 208 'program_name': os.path.basename(sys.argv[0]), 209 'default_verbosity': _DEFAULT_VERBOSITY, 210 'default_output_format': _DEFAULT_OUTPUT_FORMAT 211 } 39 212 40 213 41 214 def use_webkit_styles(): 42 215 """Configures this module for WebKit style.""" 43 cpp_style._DEFAULT_FILTER_RULES = cpp_style._WEBKIT_FILTER_RULES 216 cpp_style._DEFAULT_FILTER_RULES = _WEBKIT_FILTER_RULES 217 218 219 def exit_with_usage(error_message, display_help=False): 220 """Exit and print a usage string with an optional error message. 221 222 Args: 223 error_message: The optional error message. 224 display_help: Whether to display help output. Suppressing help 225 output is useful for unit tests. 226 """ 227 if display_help: 228 sys.stderr.write(_USAGE) 229 if error_message: 230 sys.exit('\nFATAL ERROR: ' + error_message) 231 else: 232 sys.exit(1) 233 234 235 def exit_with_categories(display_help=False): 236 """Exit and print all style categories, along with the default filter. 237 238 These category names appear in error messages. They can be filtered 239 using the --filter flag. 240 241 Args: 242 display_help: Whether to display help output. Suppressing help 243 output is useful for unit tests. 244 """ 245 if display_help: 246 sys.stderr.write('\nAll categories:\n') 247 for category in sorted(_STYLE_CATEGORIES): 248 sys.stderr.write(' ' + category + '\n') 249 250 sys.stderr.write('\nDefault filter rules**:\n') 251 for filter_rule in sorted(_WEBKIT_FILTER_RULES): 252 sys.stderr.write(' ' + filter_rule + '\n') 253 sys.stderr.write('\n**The command always evaluates the above ' 254 'rules, and before any --filter flag.\n\n') 255 256 sys.exit(0) 44 257 45 258 … … 47 260 """Parses the command line arguments. 48 261 49 See cpp_style.parse_arguments() for details. 50 """ 51 return cpp_style.parse_arguments(args, additional_flags, display_help) 262 This may set the output format and verbosity level as side-effects. 263 264 Args: 265 args: The command line arguments: 266 additional_flags: A list of strings which specifies flags we allow. 267 display_help: Whether to display help output. Suppressing help 268 output is useful for unit tests. 269 270 Returns: 271 A tuple of (filenames, flags) 272 273 filenames: The list of filenames to lint. 274 flags: The dict of the flag names and the flag values. 275 """ 276 flags = ['help', 'output=', 'verbose=', 'filter='] + additional_flags 277 additional_flag_values = {} 278 try: 279 (opts, filenames) = getopt.getopt(args, '', flags) 280 except getopt.GetoptError: 281 exit_with_usage('Invalid arguments.', display_help) 282 283 verbosity = _DEFAULT_VERBOSITY 284 output_format = _DEFAULT_OUTPUT_FORMAT 285 filters = '' 286 287 for (opt, val) in opts: 288 if opt == '--help': 289 exit_with_usage(None, display_help) 290 elif opt == '--output': 291 if not val in ('emacs', 'vs7'): 292 exit_with_usage('The only allowed output formats are emacs and vs7.', 293 display_help) 294 output_format = val 295 elif opt == '--verbose': 296 verbosity = int(val) 297 elif opt == '--filter': 298 filters = val 299 if not filters: 300 exit_with_categories(display_help) 301 else: 302 additional_flag_values[opt] = val 303 304 cpp_style._set_output_format(output_format) 305 cpp_style._set_verbose_level(verbosity) 306 cpp_style._set_filters(filters) 307 308 return (filenames, additional_flag_values) 52 309 53 310 -
trunk/WebKitTools/Scripts/run-webkit-unittests
r52430 r52541 47 47 from modules.multicommandtool_unittest import * 48 48 from modules.queueengine_unittest import * 49 from modules.style_unittest import * 49 50 from modules.text_style_unittest import * 50 51 from modules.webkitport_unittest import *
Note: See TracChangeset
for help on using the changeset viewer.