| @@ 4607-4669 (lines=63) @@ | ||
| 4604 | return os.path.splitext(filename)[0] |
|
| 4605 | ||
| 4606 | ||
| 4607 | def _ClassifyInclude(fileinfo, include, is_system): |
|
| 4608 | """Figures out what kind of header 'include' is. |
|
| 4609 | ||
| 4610 | Args: |
|
| 4611 | fileinfo: The current file cpplint is running over. A FileInfo instance. |
|
| 4612 | include: The path to a #included file. |
|
| 4613 | is_system: True if the #include used <> rather than "". |
|
| 4614 | ||
| 4615 | Returns: |
|
| 4616 | One of the _XXX_HEADER constants. |
|
| 4617 | ||
| 4618 | For example: |
|
| 4619 | >>> _ClassifyInclude(FileInfo('foo/foo.cc'), 'stdio.h', True) |
|
| 4620 | _C_SYS_HEADER |
|
| 4621 | >>> _ClassifyInclude(FileInfo('foo/foo.cc'), 'string', True) |
|
| 4622 | _CPP_SYS_HEADER |
|
| 4623 | >>> _ClassifyInclude(FileInfo('foo/foo.cc'), 'foo/foo.h', False) |
|
| 4624 | _LIKELY_MY_HEADER |
|
| 4625 | >>> _ClassifyInclude(FileInfo('foo/foo_unknown_extension.cc'), |
|
| 4626 | ... 'bar/foo_other_ext.h', False) |
|
| 4627 | _POSSIBLE_MY_HEADER |
|
| 4628 | >>> _ClassifyInclude(FileInfo('foo/foo.cc'), 'foo/bar.h', False) |
|
| 4629 | _OTHER_HEADER |
|
| 4630 | """ |
|
| 4631 | # This is a list of all standard c++ header files, except |
|
| 4632 | # those already checked for above. |
|
| 4633 | is_cpp_h = include in _CPP_HEADERS |
|
| 4634 | ||
| 4635 | # Headers with C++ extensions shouldn't be considered C system headers |
|
| 4636 | if is_system and os.path.splitext(include)[1] in ['.hpp', '.hxx', '.h++']: |
|
| 4637 | is_system = False |
|
| 4638 | ||
| 4639 | if is_system: |
|
| 4640 | if is_cpp_h: |
|
| 4641 | return _CPP_SYS_HEADER |
|
| 4642 | else: |
|
| 4643 | return _C_SYS_HEADER |
|
| 4644 | ||
| 4645 | # If the target file and the include we're checking share a |
|
| 4646 | # basename when we drop common extensions, and the include |
|
| 4647 | # lives in . , then it's likely to be owned by the target file. |
|
| 4648 | target_dir, target_base = ( |
|
| 4649 | os.path.split(_DropCommonSuffixes(fileinfo.RepositoryName()))) |
|
| 4650 | include_dir, include_base = os.path.split(_DropCommonSuffixes(include)) |
|
| 4651 | target_dir_pub = os.path.normpath(target_dir + '/../public') |
|
| 4652 | target_dir_pub = target_dir_pub.replace('\\', '/') |
|
| 4653 | if target_base == include_base and ( |
|
| 4654 | include_dir == target_dir or |
|
| 4655 | include_dir == target_dir_pub): |
|
| 4656 | return _LIKELY_MY_HEADER |
|
| 4657 | ||
| 4658 | # If the target and include share some initial basename |
|
| 4659 | # component, it's possible the target is implementing the |
|
| 4660 | # include, so it's allowed to be first, but we'll never |
|
| 4661 | # complain if it's not there. |
|
| 4662 | target_first_component = _RE_FIRST_COMPONENT.match(target_base) |
|
| 4663 | include_first_component = _RE_FIRST_COMPONENT.match(include_base) |
|
| 4664 | if (target_first_component and include_first_component and |
|
| 4665 | target_first_component.group(0) == |
|
| 4666 | include_first_component.group(0)): |
|
| 4667 | return _POSSIBLE_MY_HEADER |
|
| 4668 | ||
| 4669 | return _OTHER_HEADER |
|
| 4670 | ||
| 4671 | ||
| 4672 | ||
| @@ 4607-4669 (lines=63) @@ | ||
| 4604 | return os.path.splitext(filename)[0] |
|
| 4605 | ||
| 4606 | ||
| 4607 | def _ClassifyInclude(fileinfo, include, is_system): |
|
| 4608 | """Figures out what kind of header 'include' is. |
|
| 4609 | ||
| 4610 | Args: |
|
| 4611 | fileinfo: The current file cpplint is running over. A FileInfo instance. |
|
| 4612 | include: The path to a #included file. |
|
| 4613 | is_system: True if the #include used <> rather than "". |
|
| 4614 | ||
| 4615 | Returns: |
|
| 4616 | One of the _XXX_HEADER constants. |
|
| 4617 | ||
| 4618 | For example: |
|
| 4619 | >>> _ClassifyInclude(FileInfo('foo/foo.cc'), 'stdio.h', True) |
|
| 4620 | _C_SYS_HEADER |
|
| 4621 | >>> _ClassifyInclude(FileInfo('foo/foo.cc'), 'string', True) |
|
| 4622 | _CPP_SYS_HEADER |
|
| 4623 | >>> _ClassifyInclude(FileInfo('foo/foo.cc'), 'foo/foo.h', False) |
|
| 4624 | _LIKELY_MY_HEADER |
|
| 4625 | >>> _ClassifyInclude(FileInfo('foo/foo_unknown_extension.cc'), |
|
| 4626 | ... 'bar/foo_other_ext.h', False) |
|
| 4627 | _POSSIBLE_MY_HEADER |
|
| 4628 | >>> _ClassifyInclude(FileInfo('foo/foo.cc'), 'foo/bar.h', False) |
|
| 4629 | _OTHER_HEADER |
|
| 4630 | """ |
|
| 4631 | # This is a list of all standard c++ header files, except |
|
| 4632 | # those already checked for above. |
|
| 4633 | is_cpp_h = include in _CPP_HEADERS |
|
| 4634 | ||
| 4635 | # Headers with C++ extensions shouldn't be considered C system headers |
|
| 4636 | if is_system and os.path.splitext(include)[1] in ['.hpp', '.hxx', '.h++']: |
|
| 4637 | is_system = False |
|
| 4638 | ||
| 4639 | if is_system: |
|
| 4640 | if is_cpp_h: |
|
| 4641 | return _CPP_SYS_HEADER |
|
| 4642 | else: |
|
| 4643 | return _C_SYS_HEADER |
|
| 4644 | ||
| 4645 | # If the target file and the include we're checking share a |
|
| 4646 | # basename when we drop common extensions, and the include |
|
| 4647 | # lives in . , then it's likely to be owned by the target file. |
|
| 4648 | target_dir, target_base = ( |
|
| 4649 | os.path.split(_DropCommonSuffixes(fileinfo.RepositoryName()))) |
|
| 4650 | include_dir, include_base = os.path.split(_DropCommonSuffixes(include)) |
|
| 4651 | target_dir_pub = os.path.normpath(target_dir + '/../public') |
|
| 4652 | target_dir_pub = target_dir_pub.replace('\\', '/') |
|
| 4653 | if target_base == include_base and ( |
|
| 4654 | include_dir == target_dir or |
|
| 4655 | include_dir == target_dir_pub): |
|
| 4656 | return _LIKELY_MY_HEADER |
|
| 4657 | ||
| 4658 | # If the target and include share some initial basename |
|
| 4659 | # component, it's possible the target is implementing the |
|
| 4660 | # include, so it's allowed to be first, but we'll never |
|
| 4661 | # complain if it's not there. |
|
| 4662 | target_first_component = _RE_FIRST_COMPONENT.match(target_base) |
|
| 4663 | include_first_component = _RE_FIRST_COMPONENT.match(include_base) |
|
| 4664 | if (target_first_component and include_first_component and |
|
| 4665 | target_first_component.group(0) == |
|
| 4666 | include_first_component.group(0)): |
|
| 4667 | return _POSSIBLE_MY_HEADER |
|
| 4668 | ||
| 4669 | return _OTHER_HEADER |
|
| 4670 | ||
| 4671 | ||
| 4672 | ||