| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # | 2 # |
| 3 # Copyright (c) 2009 Google Inc. All rights reserved. | 3 # Copyright (c) 2009 Google Inc. All rights reserved. |
| 4 # | 4 # |
| 5 # Redistribution and use in source and binary forms, with or without | 5 # Redistribution and use in source and binary forms, with or without |
| 6 # modification, are permitted provided that the following conditions are | 6 # modification, are permitted provided that the following conditions are |
| 7 # met: | 7 # met: |
| 8 # | 8 # |
| 9 # * Redistributions of source code must retain the above copyright | 9 # * Redistributions of source code must retain the above copyright |
| 10 # notice, this list of conditions and the following disclaimer. | 10 # notice, this list of conditions and the following disclaimer. |
| (...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 517 _regexp_compile_cache = {} | 517 _regexp_compile_cache = {} |
| 518 | 518 |
| 519 # {str, set(int)}: a map from error categories to sets of linenumbers | 519 # {str, set(int)}: a map from error categories to sets of linenumbers |
| 520 # on which those errors are expected and should be suppressed. | 520 # on which those errors are expected and should be suppressed. |
| 521 _error_suppressions = {} | 521 _error_suppressions = {} |
| 522 | 522 |
| 523 # The root directory used for deriving header guard CPP variable. | 523 # The root directory used for deriving header guard CPP variable. |
| 524 # This is set by --root flag. | 524 # This is set by --root flag. |
| 525 _root = None | 525 _root = None |
| 526 | 526 |
| 527 # The project root directory. Used for deriving header guard CPP variable. |
| 528 # This is set by --project_root flag. Must be an absolute path. |
| 529 _project_root = None |
| 530 |
| 527 # The allowed line length of files. | 531 # The allowed line length of files. |
| 528 # This is set by --linelength flag. | 532 # This is set by --linelength flag. |
| 529 _line_length = 80 | 533 _line_length = 80 |
| 530 | 534 |
| 531 # The allowed extensions for file names | 535 # The allowed extensions for file names |
| 532 # This is set by --extensions flag. | 536 # This is set by --extensions flag. |
| 533 _valid_extensions = set(['cc', 'h', 'cpp', 'cu', 'cuh']) | 537 _valid_extensions = set(['cc', 'h', 'cpp', 'cu', 'cuh']) |
| 534 | 538 |
| 535 # {str, bool}: a map from error categories to booleans which indicate if the | 539 # {str, bool}: a map from error categories to booleans which indicate if the |
| 536 # category should be suppressed for every line. | 540 # category should be suppressed for every line. |
| (...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1058 the name so that we get header guards that don't include things like | 1062 the name so that we get header guards that don't include things like |
| 1059 "C:\Documents and Settings\..." or "/home/username/..." in them and thus | 1063 "C:\Documents and Settings\..." or "/home/username/..." in them and thus |
| 1060 people on different computers who have checked the source out to different | 1064 people on different computers who have checked the source out to different |
| 1061 locations won't see bogus errors. | 1065 locations won't see bogus errors. |
| 1062 """ | 1066 """ |
| 1063 fullname = self.FullName() | 1067 fullname = self.FullName() |
| 1064 | 1068 |
| 1065 if os.path.exists(fullname): | 1069 if os.path.exists(fullname): |
| 1066 project_dir = os.path.dirname(fullname) | 1070 project_dir = os.path.dirname(fullname) |
| 1067 | 1071 |
| 1072 if _project_root: |
| 1073 prefix = os.path.commonprefix([_project_root, project_dir]) |
| 1074 return fullname[len(prefix) + 1:] |
| 1075 |
| 1068 if os.path.exists(os.path.join(project_dir, ".svn")): | 1076 if os.path.exists(os.path.join(project_dir, ".svn")): |
| 1069 # If there's a .svn file in the current directory, we recursively look | 1077 # If there's a .svn file in the current directory, we recursively look |
| 1070 # up the directory tree for the top of the SVN checkout | 1078 # up the directory tree for the top of the SVN checkout |
| 1071 root_dir = project_dir | 1079 root_dir = project_dir |
| 1072 one_up_dir = os.path.dirname(root_dir) | 1080 one_up_dir = os.path.dirname(root_dir) |
| 1073 while os.path.exists(os.path.join(one_up_dir, ".svn")): | 1081 while os.path.exists(os.path.join(one_up_dir, ".svn")): |
| 1074 root_dir = os.path.dirname(root_dir) | 1082 root_dir = os.path.dirname(root_dir) |
| 1075 one_up_dir = os.path.dirname(one_up_dir) | 1083 one_up_dir = os.path.dirname(one_up_dir) |
| 1076 | 1084 |
| 1077 prefix = os.path.commonprefix([root_dir, project_dir]) | 1085 prefix = os.path.commonprefix([root_dir, project_dir]) |
| (...skipping 4932 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6010 | 6018 |
| 6011 Returns: | 6019 Returns: |
| 6012 The list of filenames to lint. | 6020 The list of filenames to lint. |
| 6013 """ | 6021 """ |
| 6014 try: | 6022 try: |
| 6015 (opts, filenames) = getopt.getopt(args, '', ['help', 'output=', 'verbose=', | 6023 (opts, filenames) = getopt.getopt(args, '', ['help', 'output=', 'verbose=', |
| 6016 'counting=', | 6024 'counting=', |
| 6017 'filter=', | 6025 'filter=', |
| 6018 'root=', | 6026 'root=', |
| 6019 'linelength=', | 6027 'linelength=', |
| 6020 'extensions=']) | 6028 'extensions=', |
| 6029 'project_root=']) |
| 6021 except getopt.GetoptError: | 6030 except getopt.GetoptError: |
| 6022 PrintUsage('Invalid arguments.') | 6031 PrintUsage('Invalid arguments.') |
| 6023 | 6032 |
| 6024 verbosity = _VerboseLevel() | 6033 verbosity = _VerboseLevel() |
| 6025 output_format = _OutputFormat() | 6034 output_format = _OutputFormat() |
| 6026 filters = '' | 6035 filters = '' |
| 6027 counting_style = '' | 6036 counting_style = '' |
| 6028 | 6037 |
| 6029 for (opt, val) in opts: | 6038 for (opt, val) in opts: |
| 6030 if opt == '--help': | 6039 if opt == '--help': |
| 6031 PrintUsage(None) | 6040 PrintUsage(None) |
| 6032 elif opt == '--output': | 6041 elif opt == '--output': |
| 6033 if val not in ('emacs', 'vs7', 'eclipse'): | 6042 if val not in ('emacs', 'vs7', 'eclipse'): |
| 6034 PrintUsage('The only allowed output formats are emacs, vs7 and eclipse.'
) | 6043 PrintUsage('The only allowed output formats are emacs, vs7 and eclipse.'
) |
| 6035 output_format = val | 6044 output_format = val |
| 6036 elif opt == '--verbose': | 6045 elif opt == '--verbose': |
| 6037 verbosity = int(val) | 6046 verbosity = int(val) |
| 6038 elif opt == '--filter': | 6047 elif opt == '--filter': |
| 6039 filters = val | 6048 filters = val |
| 6040 if not filters: | 6049 if not filters: |
| 6041 PrintCategories() | 6050 PrintCategories() |
| 6042 elif opt == '--counting': | 6051 elif opt == '--counting': |
| 6043 if val not in ('total', 'toplevel', 'detailed'): | 6052 if val not in ('total', 'toplevel', 'detailed'): |
| 6044 PrintUsage('Valid counting options are total, toplevel, and detailed') | 6053 PrintUsage('Valid counting options are total, toplevel, and detailed') |
| 6045 counting_style = val | 6054 counting_style = val |
| 6046 elif opt == '--root': | 6055 elif opt == '--root': |
| 6047 global _root | 6056 global _root |
| 6048 _root = val | 6057 _root = val |
| 6058 elif opt == '--project_root': |
| 6059 global _project_root |
| 6060 _project_root = val |
| 6061 if not os.path.isabs(_project_root): |
| 6062 PrintUsage('Project root must be an absolute path.') |
| 6049 elif opt == '--linelength': | 6063 elif opt == '--linelength': |
| 6050 global _line_length | 6064 global _line_length |
| 6051 try: | 6065 try: |
| 6052 _line_length = int(val) | 6066 _line_length = int(val) |
| 6053 except ValueError: | 6067 except ValueError: |
| 6054 PrintUsage('Line length must be digits.') | 6068 PrintUsage('Line length must be digits.') |
| 6055 elif opt == '--extensions': | 6069 elif opt == '--extensions': |
| 6056 global _valid_extensions | 6070 global _valid_extensions |
| 6057 try: | 6071 try: |
| 6058 _valid_extensions = set(val.split(',')) | 6072 _valid_extensions = set(val.split(',')) |
| (...skipping 24 matching lines...) Expand all Loading... |
| 6083 _cpplint_state.ResetErrorCounts() | 6097 _cpplint_state.ResetErrorCounts() |
| 6084 for filename in filenames: | 6098 for filename in filenames: |
| 6085 ProcessFile(filename, _cpplint_state.verbose_level) | 6099 ProcessFile(filename, _cpplint_state.verbose_level) |
| 6086 _cpplint_state.PrintErrorCounts() | 6100 _cpplint_state.PrintErrorCounts() |
| 6087 | 6101 |
| 6088 sys.exit(_cpplint_state.error_count > 0) | 6102 sys.exit(_cpplint_state.error_count > 0) |
| 6089 | 6103 |
| 6090 | 6104 |
| 6091 if __name__ == '__main__': | 6105 if __name__ == '__main__': |
| 6092 main() | 6106 main() |
| OLD | NEW |