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+
505525try :
506526 xrange
507527except NameError :
@@ -631,11 +651,13 @@ class _IncludeState(object):
631651 _MY_H_SECTION = 1
632652 _C_SECTION = 2
633653 _CPP_SECTION = 3
634- _OTHER_H_SECTION = 4
654+ _CUSTSYS_SECTION = 4
655+ _OTHER_H_SECTION = 5
635656
636657 _TYPE_NAMES = {
637658 _C_SYS_HEADER : 'C system header' ,
638659 _CPP_SYS_HEADER : 'C++ system header' ,
660+ _CUSTOM_SYS_HEADER : 'Custome system header' ,
639661 _LIKELY_MY_HEADER : 'header this file implements' ,
640662 _POSSIBLE_MY_HEADER : 'header this file may implement' ,
641663 _OTHER_HEADER : 'other header' ,
@@ -645,6 +667,7 @@ class _IncludeState(object):
645667 _MY_H_SECTION : 'a header this file implements' ,
646668 _C_SECTION : 'C system header' ,
647669 _CPP_SECTION : 'C++ system header' ,
670+ _CUSTSYS_SECTION : 'Custome system header' ,
648671 _OTHER_H_SECTION : 'other header' ,
649672 }
650673
@@ -756,6 +779,9 @@ def CheckNextIncludeOrder(self, header_type):
756779 else :
757780 self ._last_header = ''
758781 return error_message
782+ elif header_type == _CUSTOM_SYS_HEADER :
783+ if self ._section <= self ._CUSTSYS_SECTION :
784+ self ._section = self ._CUSTSYS_SECTION
759785 elif header_type == _LIKELY_MY_HEADER :
760786 if self ._section <= self ._MY_H_SECTION :
761787 self ._section = self ._MY_H_SECTION
@@ -4602,6 +4628,9 @@ def _ClassifyInclude(fileinfo, include, is_system):
46024628 is_cpp_h = include in _CPP_HEADERS
46034629
46044630 if is_system :
4631+ for prefix in _custom_system_headers :
4632+ if include .startswith (prefix ):
4633+ return _CUSTOM_SYS_HEADER
46054634 if is_cpp_h :
46064635 return _CPP_SYS_HEADER
46074636 else :
@@ -6131,6 +6160,10 @@ def ProcessConfigOverrides(filename):
61316160 _line_length = int (val )
61326161 except ValueError :
61336162 sys .stderr .write ('Line length must be numeric.' )
6163+ elif name == 'custom_headers' :
6164+ global _custom_system_headers
6165+ for prefix in val .split (',' ):
6166+ _custom_system_headers .append (prefix )
61346167 else :
61356168 sys .stderr .write (
61366169 'Invalid configuration option (%s) in file %s\n ' %
0 commit comments