Figures out what kind of header 'include' is. Args: fileinfo: The current file cpplint is running over. A FileInfo instance. include: The path to a #included file. used_angle_brackets: True if the #include used <> rather than "". include_order: "default" or other value allowed in
(fileinfo, include, used_angle_brackets, include_order="default")
| 4970 | |
| 4971 | |
| 4972 | def _ClassifyInclude(fileinfo, include, used_angle_brackets, include_order="default"): |
| 4973 | """Figures out what kind of header 'include' is. |
| 4974 | |
| 4975 | Args: |
| 4976 | fileinfo: The current file cpplint is running over. A FileInfo instance. |
| 4977 | include: The path to a #included file. |
| 4978 | used_angle_brackets: True if the #include used <> rather than "". |
| 4979 | include_order: "default" or other value allowed in program arguments |
| 4980 | |
| 4981 | Returns: |
| 4982 | One of the _XXX_HEADER constants. |
| 4983 | |
| 4984 | For example: |
| 4985 | >>> _ClassifyInclude(FileInfo('foo/foo.cc'), 'stdio.h', True) |
| 4986 | _C_SYS_HEADER |
| 4987 | >>> _ClassifyInclude(FileInfo('foo/foo.cc'), 'string', True) |
| 4988 | _CPP_SYS_HEADER |
| 4989 | >>> _ClassifyInclude(FileInfo('foo/foo.cc'), 'foo/foo.h', True, "standardcfirst") |
| 4990 | _OTHER_SYS_HEADER |
| 4991 | >>> _ClassifyInclude(FileInfo('foo/foo.cc'), 'foo/foo.h', False) |
| 4992 | _LIKELY_MY_HEADER |
| 4993 | >>> _ClassifyInclude(FileInfo('foo/foo_unknown_extension.cc'), |
| 4994 | ... 'bar/foo_other_ext.h', False) |
| 4995 | _POSSIBLE_MY_HEADER |
| 4996 | >>> _ClassifyInclude(FileInfo('foo/foo.cc'), 'foo/bar.h', False) |
| 4997 | _OTHER_HEADER |
| 4998 | """ |
| 4999 | # This is a list of all standard c++ header files, except |
| 5000 | # those already checked for above. |
| 5001 | is_cpp_header = include in _CPP_HEADERS |
| 5002 | |
| 5003 | # Mark include as C header if in list or in a known folder for standard-ish C headers. |
| 5004 | is_std_c_header = (include_order == "default") or (include in _C_HEADERS |
| 5005 | # additional linux glibc header folders |
| 5006 | or Search(r'(?:%s)\/.*\.h' % "|".join(C_STANDARD_HEADER_FOLDERS), include)) |
| 5007 | |
| 5008 | # Headers with C++ extensions shouldn't be considered C system headers |
| 5009 | is_system = used_angle_brackets and not os.path.splitext(include)[1] in ['.hpp', '.hxx', '.h++'] |
| 5010 | |
| 5011 | if is_system: |
| 5012 | if is_cpp_header: |
| 5013 | return _CPP_SYS_HEADER |
| 5014 | if is_std_c_header: |
| 5015 | return _C_SYS_HEADER |
| 5016 | else: |
| 5017 | return _OTHER_SYS_HEADER |
| 5018 | |
| 5019 | # If the target file and the include we're checking share a |
| 5020 | # basename when we drop common extensions, and the include |
| 5021 | # lives in . , then it's likely to be owned by the target file. |
| 5022 | target_dir, target_base = ( |
| 5023 | os.path.split(_DropCommonSuffixes(fileinfo.RepositoryName()))) |
| 5024 | include_dir, include_base = os.path.split(_DropCommonSuffixes(include)) |
| 5025 | target_dir_pub = os.path.normpath(target_dir + '/../public') |
| 5026 | target_dir_pub = target_dir_pub.replace('\\', '/') |
| 5027 | if target_base == include_base and ( |
| 5028 | include_dir == target_dir or |
| 5029 | include_dir == target_dir_pub): |
no test coverage detected