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. is_system: True if the #include used <> rather than "". Returns: One of the _XXX_HEADER constants. For example:
(fileinfo, include, is_system)
| 3622 | |
| 3623 | |
| 3624 | def _ClassifyInclude(fileinfo, include, is_system): |
| 3625 | """Figures out what kind of header 'include' is. |
| 3626 | |
| 3627 | Args: |
| 3628 | fileinfo: The current file cpplint is running over. A FileInfo instance. |
| 3629 | include: The path to a #included file. |
| 3630 | is_system: True if the #include used <> rather than "". |
| 3631 | |
| 3632 | Returns: |
| 3633 | One of the _XXX_HEADER constants. |
| 3634 | |
| 3635 | For example: |
| 3636 | >>> _ClassifyInclude(FileInfo('foo/foo.cc'), 'stdio.h', True) |
| 3637 | _C_SYS_HEADER |
| 3638 | >>> _ClassifyInclude(FileInfo('foo/foo.cc'), 'string', True) |
| 3639 | _CPP_SYS_HEADER |
| 3640 | >>> _ClassifyInclude(FileInfo('foo/foo.cc'), 'foo/foo.h', False) |
| 3641 | _LIKELY_MY_HEADER |
| 3642 | >>> _ClassifyInclude(FileInfo('foo/foo_unknown_extension.cc'), |
| 3643 | ... 'bar/foo_other_ext.h', False) |
| 3644 | _POSSIBLE_MY_HEADER |
| 3645 | >>> _ClassifyInclude(FileInfo('foo/foo.cc'), 'foo/bar.h', False) |
| 3646 | _OTHER_HEADER |
| 3647 | """ |
| 3648 | # This is a list of all standard c++ header files, except |
| 3649 | # those already checked for above. |
| 3650 | is_cpp_h = include in _CPP_HEADERS |
| 3651 | |
| 3652 | if is_system: |
| 3653 | if is_cpp_h: |
| 3654 | return _CPP_SYS_HEADER |
| 3655 | else: |
| 3656 | return _C_SYS_HEADER |
| 3657 | |
| 3658 | # If the target file and the include we're checking share a |
| 3659 | # basename when we drop common extensions, and the include |
| 3660 | # lives in . , then it's likely to be owned by the target file. |
| 3661 | target_dir, target_base = ( |
| 3662 | os.path.split(_DropCommonSuffixes(fileinfo.RepositoryName()))) |
| 3663 | include_dir, include_base = os.path.split(_DropCommonSuffixes(include)) |
| 3664 | if target_base == include_base and ( |
| 3665 | include_dir == target_dir or |
| 3666 | include_dir == os.path.normpath(target_dir + '/../public')): |
| 3667 | return _LIKELY_MY_HEADER |
| 3668 | |
| 3669 | # If the target and include share some initial basename |
| 3670 | # component, it's possible the target is implementing the |
| 3671 | # include, so it's allowed to be first, but we'll never |
| 3672 | # complain if it's not there. |
| 3673 | target_first_component = _RE_FIRST_COMPONENT.match(target_base) |
| 3674 | include_first_component = _RE_FIRST_COMPONENT.match(include_base) |
| 3675 | if (target_first_component and include_first_component and |
| 3676 | target_first_component.group(0) == |
| 3677 | include_first_component.group(0)): |
| 3678 | return _POSSIBLE_MY_HEADER |
| 3679 | |
| 3680 | return _OTHER_HEADER |
| 3681 |
no test coverage detected