~mordred/drizzle/add-drizzle-namespace

« back to all changes in this revision

Viewing changes to extra/cpplint.py

MergedĀ fromĀ me.

Show diffs side-by-side

added added

removed removed

Lines of Context:
10
10
#
11
11
# b) the "Artistic License".
12
12
 
13
 
# Modified for Drizzle by Monty Taylor
 
13
# Modified for Drizzle by Monty Taylor & Robert Collins
14
14
 
15
15
# Here are some issues that I've had people identify in my code during reviews,
16
16
# that I think are possible to flag automatically in a lint tool.  If these were
75
75
 
76
76
 
77
77
_USAGE = """
78
 
Syntax: cpplint.py [--verbose=#] [--output=vs7] [--filter=-x,+y,...]
 
78
Syntax: cpplint.py [--verbose=#] [--output=vs7] [--deps=path] [--filter=-x,+y,...]
79
79
        <file> [file] ...
80
80
 
81
81
  The style guidelines this tries to follow are those in
100
100
    verbose=#
101
101
      Specify a number 0-5 to restrict errors to certain verbosity levels.
102
102
 
 
103
    deps=path
 
104
      write out a Makefile that can be included listing the files included
 
105
      during the lint process as make style dependencies with null-build rules
 
106
      (so that deleted headers will not cause failures). This can be useful to
 
107
      perform on-demand linting. The top level target will be the name of the
 
108
      lint file itself.
 
109
 
103
110
    filter=-x,+y,...
104
111
      Specify a comma-separated list of category-filters to apply: only
105
112
      error messages whose category names pass the filters will be printed.
378
385
    # "vs7" - format that Microsoft Visual Studio 7 can parse
379
386
    self.output_format = 'emacs'
380
387
 
 
388
    # deps
 
389
    self.depfilename = None
 
390
    self.seen_fnames = set()
 
391
 
 
392
  def finished(self):
 
393
    """Complete things that wait for the end of the lint operation."""
 
394
    if self.depfilename is not None:
 
395
      if self.error_count:
 
396
          # Don't alter dependency data
 
397
          return
 
398
      depfile = file(self.depfilename, 'w+')
 
399
      # depend on what we read
 
400
      depfile.write("%s: " % self.depfilename)
 
401
      names = sorted(self.seen_fnames)
 
402
      depfile.write(' '.join(names))
 
403
      depfile.write('\n')
 
404
      # anything we read shouldn't cause an error if its missing - so claim
 
405
      # it can be made.
 
406
      for name in names:
 
407
        depfile.write('%s:\n' % name)
 
408
      depfile.close()
 
409
 
 
410
  def seen_file(self, fname):
 
411
    self.seen_fnames.add(fname)
 
412
 
381
413
  def SetOutputFormat(self, output_format):
382
414
    """Sets the output format for errors."""
383
415
    self.output_format = output_format
2582
2614
    headerfile = io.open(filename, 'r', 'utf8', 'replace')
2583
2615
  except IOError:
2584
2616
    return False
 
2617
  _cpplint_state.seen_file(filename)
2585
2618
  linenum = 0
2586
2619
  for line in headerfile:
2587
2620
    linenum += 1
2788
2821
                                        codecs.getwriter('utf8'),
2789
2822
                                        'replace').read().split('\n')
2790
2823
    else:
 
2824
      _cpplint_state.seen_file(filename)
2791
2825
      lines = codecs.open(filename, 'r', 'utf8', 'replace').read().split('\n')
2792
2826
 
2793
2827
    carriage_return_found = False
2856
2890
    The list of filenames to lint.
2857
2891
  """
2858
2892
  try:
2859
 
    (opts, filenames) = getopt.getopt(args, '', ['help', 'output=', 'verbose=',
2860
 
                                                 'filter='])
 
2893
    (opts, filenames) = getopt.getopt(args, '',
 
2894
        ['help', 'output=', 'verbose=', 'deps=', 'filter='])
2861
2895
  except getopt.GetoptError:
2862
2896
    PrintUsage('Invalid arguments.')
2863
2897
 
2878
2912
      filters = val
2879
2913
      if not filters:
2880
2914
        PrintCategories()
 
2915
    elif opt == '--deps':
 
2916
        _cpplint_state.depfilename = val
2881
2917
 
2882
2918
  if not filenames:
2883
2919
    PrintUsage('No files were specified.')
2902
2938
  _cpplint_state.ResetErrorCount()
2903
2939
  for filename in filenames:
2904
2940
    ProcessFile(filename, _cpplint_state.verbose_level)
 
2941
  _cpplint_state.finished()
2905
2942
  sys.stderr.write('Total errors found: %d\n' % _cpplint_state.error_count)
2906
2943
  sys.exit(_cpplint_state.error_count > 0)
2907
2944