139139 Examples:
140140 --extensions=hpp,cpp
141141
142+ custom_headers=header_prefix,...
143+
144+ Custom System Headers
145+ cpplint by default assumes that #include <foo/foo.h>
146+ is a "system header" due to the presence of the leading <
147+ We enable here the ability to define custom system
148+ headers, which will be classified in the correct order if they
149+ follow C/C++ system headers, but precede non-system headers.
150+
151+ ONLY USED IN CPPLINT.cfg
152+
153+ Example:
154+
155+ custom_headers = mesos,stout,process
156+
142157 cpplint.py supports per-directory configurations specified in CPPLINT.cfg
143158 files. CPPLINT.cfg file can contain a number of key=value pairs.
144159 Currently the following options are supported:
472487# _IncludeState.CheckNextIncludeOrder().
473488_C_SYS_HEADER = 1
474489_CPP_SYS_HEADER = 2
475- _LIKELY_MY_HEADER = 3
476- _POSSIBLE_MY_HEADER = 4
477- _OTHER_HEADER = 5
490+ _CUSTOM_SYS_HEADER = 3
491+ _LIKELY_MY_HEADER = 4
492+ _POSSIBLE_MY_HEADER = 5
493+ _OTHER_HEADER = 6
478494
479495# These constants define the current inline assembly state
480496_NO_ASM = 0 # Outside of inline assembly block
502518# This is set by --linelength flag.
503519_line_length = 80
504520
521+ # Custom System Headers
522+ # TODO(marco): verify that they are in the correct alpha order
523+ _custom_system_headers = []
524+
505525if sys .version_info < (3 ,):
506526 def u (x ):
507527 return codecs .unicode_escape_decode (x )[0 ]
@@ -625,11 +645,13 @@ class _IncludeState(object):
625645 _MY_H_SECTION = 1
626646 _C_SECTION = 2
627647 _CPP_SECTION = 3
628- _OTHER_H_SECTION = 4
648+ _CUSTSYS_SECTION = 4
649+ _OTHER_H_SECTION = 5
629650
630651 _TYPE_NAMES = {
631652 _C_SYS_HEADER : 'C system header' ,
632653 _CPP_SYS_HEADER : 'C++ system header' ,
654+ _CUSTOM_SYS_HEADER : 'Custome system header' ,
633655 _LIKELY_MY_HEADER : 'header this file implements' ,
634656 _POSSIBLE_MY_HEADER : 'header this file may implement' ,
635657 _OTHER_HEADER : 'other header' ,
@@ -639,6 +661,7 @@ class _IncludeState(object):
639661 _MY_H_SECTION : 'a header this file implements' ,
640662 _C_SECTION : 'C system header' ,
641663 _CPP_SECTION : 'C++ system header' ,
664+ _CUSTSYS_SECTION : 'Custome system header' ,
642665 _OTHER_H_SECTION : 'other header' ,
643666 }
644667
@@ -750,6 +773,9 @@ def CheckNextIncludeOrder(self, header_type):
750773 else :
751774 self ._last_header = ''
752775 return error_message
776+ elif header_type == _CUSTOM_SYS_HEADER :
777+ if self ._section <= self ._CUSTSYS_SECTION :
778+ self ._section = self ._CUSTSYS_SECTION
753779 elif header_type == _LIKELY_MY_HEADER :
754780 if self ._section <= self ._MY_H_SECTION :
755781 self ._section = self ._MY_H_SECTION
@@ -4596,6 +4622,9 @@ def _ClassifyInclude(fileinfo, include, is_system):
45964622 is_cpp_h = include in _CPP_HEADERS
45974623
45984624 if is_system :
4625+ for prefix in _custom_system_headers :
4626+ if include .startswith (prefix ):
4627+ return _CUSTOM_SYS_HEADER
45994628 if is_cpp_h :
46004629 return _CPP_SYS_HEADER
46014630 else :
@@ -6128,6 +6157,10 @@ def ProcessConfigOverrides(filename):
61286157 _line_length = int (val )
61296158 except ValueError :
61306159 sys .stderr .write ('Line length must be numeric.' )
6160+ elif name == 'custom_headers' :
6161+ global _custom_system_headers
6162+ for prefix in val .split (',' ):
6163+ _custom_system_headers .append (prefix )
61316164 else :
61326165 sys .stderr .write (
61336166 'Invalid configuration option (%s) in file %s\n ' %
0 commit comments