Logs an error if a source file does not include its header.
(filename, include_state, error)
| 2478 | |
| 2479 | |
| 2480 | def CheckHeaderFileIncluded(filename, include_state, error): |
| 2481 | """Logs an error if a source file does not include its header.""" |
| 2482 | |
| 2483 | # Do not check test files |
| 2484 | fileinfo = FileInfo(filename) |
| 2485 | if Search(_TEST_FILE_SUFFIX, fileinfo.BaseName()): |
| 2486 | return |
| 2487 | |
| 2488 | for ext in GetHeaderExtensions(): |
| 2489 | basefilename = filename[0:len(filename) - len(fileinfo.Extension())] |
| 2490 | headerfile = basefilename + '.' + ext |
| 2491 | if not os.path.exists(headerfile): |
| 2492 | continue |
| 2493 | headername = FileInfo(headerfile).RepositoryName() |
| 2494 | first_include = None |
| 2495 | include_uses_unix_dir_aliases = False |
| 2496 | for section_list in include_state.include_list: |
| 2497 | for f in section_list: |
| 2498 | include_text = f[0] |
| 2499 | if "./" in include_text: |
| 2500 | include_uses_unix_dir_aliases = True |
| 2501 | if headername in include_text or include_text in headername: |
| 2502 | return |
| 2503 | if not first_include: |
| 2504 | first_include = f[1] |
| 2505 | |
| 2506 | message = '%s should include its header file %s' % (fileinfo.RepositoryName(), headername) |
| 2507 | if include_uses_unix_dir_aliases: |
| 2508 | message += ". Relative paths like . and .. are not allowed." |
| 2509 | |
| 2510 | error(filename, first_include, 'build/include', 5, message) |
| 2511 | |
| 2512 | |
| 2513 | def CheckForBadCharacters(filename, lines, error): |
no test coverage detected