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)
| 4386 | |
| 4387 | |
| 4388 | def _ClassifyInclude(fileinfo, include, is_system): |
| 4389 | """Figures out what kind of header 'include' is. |
| 4390 | |
| 4391 | Args: |
| 4392 | fileinfo: The current file cpplint is running over. A FileInfo instance. |
| 4393 | include: The path to a #included file. |
| 4394 | is_system: True if the #include used <> rather than "". |
| 4395 | |
| 4396 | Returns: |
| 4397 | One of the _XXX_HEADER constants. |
| 4398 | |
| 4399 | For example: |
| 4400 | >>> _ClassifyInclude(FileInfo('foo/foo.cc'), 'stdio.h', True) |
| 4401 | _C_SYS_HEADER |
| 4402 | >>> _ClassifyInclude(FileInfo('foo/foo.cc'), 'string', True) |
| 4403 | _CPP_SYS_HEADER |
| 4404 | >>> _ClassifyInclude(FileInfo('foo/foo.cc'), 'foo/foo.h', False) |
| 4405 | _LIKELY_MY_HEADER |
| 4406 | >>> _ClassifyInclude(FileInfo('foo/foo_unknown_extension.cc'), |
| 4407 | ... 'bar/foo_other_ext.h', False) |
| 4408 | _POSSIBLE_MY_HEADER |
| 4409 | >>> _ClassifyInclude(FileInfo('foo/foo.cc'), 'foo/bar.h', False) |
| 4410 | _OTHER_HEADER |
| 4411 | """ |
| 4412 | # This is a list of all standard c++ header files, except |
| 4413 | # those already checked for above. |
| 4414 | is_cpp_h = include in _CPP_HEADERS |
| 4415 | |
| 4416 | if is_system: |
| 4417 | if is_cpp_h: |
| 4418 | return _CPP_SYS_HEADER |
| 4419 | else: |
| 4420 | return _C_SYS_HEADER |
| 4421 | |
| 4422 | # If the target file and the include we're checking share a |
| 4423 | # basename when we drop common extensions, and the include |
| 4424 | # lives in . , then it's likely to be owned by the target file. |
| 4425 | target_dir, target_base = ( |
| 4426 | os.path.split(_DropCommonSuffixes(fileinfo.RepositoryName()))) |
| 4427 | include_dir, include_base = os.path.split(_DropCommonSuffixes(include)) |
| 4428 | if target_base == include_base and ( |
| 4429 | include_dir == target_dir or |
| 4430 | include_dir == os.path.normpath(target_dir + '/../public')): |
| 4431 | return _LIKELY_MY_HEADER |
| 4432 | |
| 4433 | # If the target and include share some initial basename |
| 4434 | # component, it's possible the target is implementing the |
| 4435 | # include, so it's allowed to be first, but we'll never |
| 4436 | # complain if it's not there. |
| 4437 | target_first_component = _RE_FIRST_COMPONENT.match(target_base) |
| 4438 | include_first_component = _RE_FIRST_COMPONENT.match(include_base) |
| 4439 | if (target_first_component and include_first_component and |
| 4440 | target_first_component.group(0) == |
| 4441 | include_first_component.group(0)): |
| 4442 | return _POSSIBLE_MY_HEADER |
| 4443 | |
| 4444 | return _OTHER_HEADER |
| 4445 |
no test coverage detected