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")
| 5753 | |
| 5754 | |
| 5755 | def _ClassifyInclude(fileinfo, include, used_angle_brackets, include_order="default"): |
| 5756 | """Figures out what kind of header 'include' is. |
| 5757 | |
| 5758 | Args: |
| 5759 | fileinfo: The current file cpplint is running over. A FileInfo instance. |
| 5760 | include: The path to a #included file. |
| 5761 | used_angle_brackets: True if the #include used <> rather than "". |
| 5762 | include_order: "default" or other value allowed in program arguments |
| 5763 | |
| 5764 | Returns: |
| 5765 | One of the _XXX_HEADER constants. |
| 5766 | |
| 5767 | For example: |
| 5768 | >>> _ClassifyInclude(FileInfo('foo/foo.cc'), 'stdio.h', True) |
| 5769 | _C_SYS_HEADER |
| 5770 | >>> _ClassifyInclude(FileInfo('foo/foo.cc'), 'string', True) |
| 5771 | _CPP_SYS_HEADER |
| 5772 | >>> _ClassifyInclude(FileInfo('foo/foo.cc'), 'foo/foo.h', True, "standardcfirst") |
| 5773 | _OTHER_SYS_HEADER |
| 5774 | >>> _ClassifyInclude(FileInfo('foo/foo.cc'), 'foo/foo.h', False) |
| 5775 | _LIKELY_MY_HEADER |
| 5776 | >>> _ClassifyInclude(FileInfo('foo/foo_unknown_extension.cc'), |
| 5777 | ... 'bar/foo_other_ext.h', False) |
| 5778 | _POSSIBLE_MY_HEADER |
| 5779 | >>> _ClassifyInclude(FileInfo('foo/foo.cc'), 'foo/bar.h', False) |
| 5780 | _OTHER_HEADER |
| 5781 | """ |
| 5782 | # This is a list of all standard c++ header files, except |
| 5783 | # those already checked for above. |
| 5784 | is_cpp_header = include in _CPP_HEADERS |
| 5785 | |
| 5786 | # Mark include as C header if in list or in a known folder for standard-ish C headers. |
| 5787 | is_std_c_header = (include_order == "default") or ( |
| 5788 | include in _C_HEADERS |
| 5789 | # additional linux glibc header folders |
| 5790 | or re.search(rf"(?:{'|'.join(C_STANDARD_HEADER_FOLDERS)})\/.*\.h", include) |
| 5791 | ) |
| 5792 | |
| 5793 | # Headers with C++ extensions shouldn't be considered C system headers |
| 5794 | include_ext = os.path.splitext(include)[1] |
| 5795 | is_system = used_angle_brackets and include_ext not in [".hh", ".hpp", ".hxx", ".h++"] |
| 5796 | |
| 5797 | if is_system: |
| 5798 | if is_cpp_header: |
| 5799 | return _CPP_SYS_HEADER |
| 5800 | if is_std_c_header: |
| 5801 | return _C_SYS_HEADER |
| 5802 | return _OTHER_SYS_HEADER |
| 5803 | |
| 5804 | # If the target file and the include we're checking share a |
| 5805 | # basename when we drop common extensions, and the include |
| 5806 | # lives in . , then it's likely to be owned by the target file. |
| 5807 | target_dir, target_base = os.path.split(_DropCommonSuffixes(fileinfo.RepositoryName())) |
| 5808 | include_dir, include_base = os.path.split(_DropCommonSuffixes(include)) |
| 5809 | target_dir_pub = os.path.normpath(target_dir + "/../public") |
| 5810 | target_dir_pub = target_dir_pub.replace("\\", "/") |
| 5811 | if target_base == include_base and (include_dir in (target_dir, target_dir_pub)): |
| 5812 | return _LIKELY_MY_HEADER |
no test coverage detected
searching dependent graphs…