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 a
(fileinfo, include, used_angle_brackets, include_order="default")
| 5613 | |
| 5614 | |
| 5615 | def _ClassifyInclude(fileinfo, include, used_angle_brackets, include_order="default"): |
| 5616 | """Figures out what kind of header 'include' is. |
| 5617 | |
| 5618 | Args: |
| 5619 | fileinfo: The current file cpplint is running over. A FileInfo instance. |
| 5620 | include: The path to a #included file. |
| 5621 | used_angle_brackets: True if the #include used <> rather than "". |
| 5622 | include_order: "default" or other value allowed in program arguments |
| 5623 | |
| 5624 | Returns: |
| 5625 | One of the _XXX_HEADER constants. |
| 5626 | |
| 5627 | For example: |
| 5628 | >>> _ClassifyInclude(FileInfo('foo/foo.cc'), 'stdio.h', True) |
| 5629 | _C_SYS_HEADER |
| 5630 | >>> _ClassifyInclude(FileInfo('foo/foo.cc'), 'string', True) |
| 5631 | _CPP_SYS_HEADER |
| 5632 | >>> _ClassifyInclude(FileInfo('foo/foo.cc'), 'foo/foo.h', True, "standardcfirst") |
| 5633 | _OTHER_SYS_HEADER |
| 5634 | >>> _ClassifyInclude(FileInfo('foo/foo.cc'), 'foo/foo.h', False) |
| 5635 | _LIKELY_MY_HEADER |
| 5636 | >>> _ClassifyInclude(FileInfo('foo/foo_unknown_extension.cc'), |
| 5637 | ... 'bar/foo_other_ext.h', False) |
| 5638 | _POSSIBLE_MY_HEADER |
| 5639 | >>> _ClassifyInclude(FileInfo('foo/foo.cc'), 'foo/bar.h', False) |
| 5640 | _OTHER_HEADER |
| 5641 | """ |
| 5642 | # This is a list of all standard c++ header files, except |
| 5643 | # those already checked for above. |
| 5644 | is_cpp_header = include in _CPP_HEADERS |
| 5645 | |
| 5646 | # Mark include as C header if in list or in a known folder for standard-ish C headers. |
| 5647 | is_std_c_header = (include_order == "default") or ( |
| 5648 | include in _C_HEADERS |
| 5649 | # additional linux glibc header folders |
| 5650 | or re.search(rf"(?:{'|'.join(C_STANDARD_HEADER_FOLDERS)})\/.*\.h", include) |
| 5651 | ) |
| 5652 | |
| 5653 | # Headers with C++ extensions shouldn't be considered C system headers |
| 5654 | include_ext = os.path.splitext(include)[1] |
| 5655 | is_system = used_angle_brackets and include_ext not in [".hh", ".hpp", ".hxx", ".h++"] |
| 5656 | |
| 5657 | if is_system: |
| 5658 | if is_cpp_header: |
| 5659 | return _CPP_SYS_HEADER |
| 5660 | if is_std_c_header: |
| 5661 | return _C_SYS_HEADER |
| 5662 | return _OTHER_SYS_HEADER |
| 5663 | |
| 5664 | # If the target file and the include we're checking share a |
| 5665 | # basename when we drop common extensions, and the include |
| 5666 | # lives in . , then it's likely to be owned by the target file. |
| 5667 | target_dir, target_base = os.path.split(_DropCommonSuffixes(fileinfo.RepositoryName())) |
| 5668 | include_dir, include_base = os.path.split(_DropCommonSuffixes(include)) |
| 5669 | target_dir_pub = os.path.normpath(target_dir + "/../public") |
| 5670 | target_dir_pub = target_dir_pub.replace("\\", "/") |
| 5671 | if target_base == include_base and (include_dir in (target_dir, target_dir_pub)): |
| 5672 | return _LIKELY_MY_HEADER |
no test coverage detected