Logs an error if a source file does not include its header.
(filename, include_state, error)
| 2741 | |
| 2742 | |
| 2743 | def CheckHeaderFileIncluded(filename, include_state, error): |
| 2744 | """Logs an error if a source file does not include its header.""" |
| 2745 | |
| 2746 | # Do not check test files |
| 2747 | fileinfo = FileInfo(filename) |
| 2748 | if re.search(_TEST_FILE_SUFFIX, fileinfo.BaseName()): |
| 2749 | return |
| 2750 | |
| 2751 | first_include = message = None |
| 2752 | basefilename = filename[0 : len(filename) - len(fileinfo.Extension())] |
| 2753 | for ext in GetHeaderExtensions(): |
| 2754 | headerfile = basefilename + "." + ext |
| 2755 | if not os.path.exists(headerfile): |
| 2756 | continue |
| 2757 | headername = FileInfo(headerfile).RepositoryName() |
| 2758 | include_uses_unix_dir_aliases = False |
| 2759 | for section_list in include_state.include_list: |
| 2760 | for f in section_list: |
| 2761 | include_text = f[0] |
| 2762 | if "./" in include_text: |
| 2763 | include_uses_unix_dir_aliases = True |
| 2764 | if headername in include_text or include_text in headername: |
| 2765 | return |
| 2766 | if not first_include: |
| 2767 | first_include = f[1] |
| 2768 | |
| 2769 | message = f"{fileinfo.RepositoryName()} should include its header file {headername}" |
| 2770 | if include_uses_unix_dir_aliases: |
| 2771 | message += ". Relative paths like . and .. are not allowed." |
| 2772 | |
| 2773 | if message: |
| 2774 | error(filename, first_include, "build/include", 5, message) |
| 2775 | |
| 2776 | |
| 2777 | def CheckForBadCharacters(filename, lines, error): |
no test coverage detected
searching dependent graphs…