Check rules that are applicable to #include lines. Strings on #include lines are NOT removed from elided line, to make certain tasks easier. However, to prevent false positives, checks applicable to #include lines in CheckLanguage must be put here. Args: filename: The name of
(filename, clean_lines, linenum, include_state, error)
| 5828 | |
| 5829 | |
| 5830 | def CheckIncludeLine(filename, clean_lines, linenum, include_state, error): |
| 5831 | """Check rules that are applicable to #include lines. |
| 5832 | |
| 5833 | Strings on #include lines are NOT removed from elided line, to make |
| 5834 | certain tasks easier. However, to prevent false positives, checks |
| 5835 | applicable to #include lines in CheckLanguage must be put here. |
| 5836 | |
| 5837 | Args: |
| 5838 | filename: The name of the current file. |
| 5839 | clean_lines: A CleansedLines instance containing the file. |
| 5840 | linenum: The number of the line to check. |
| 5841 | include_state: An _IncludeState instance in which the headers are inserted. |
| 5842 | error: The function to call with any errors found. |
| 5843 | """ |
| 5844 | fileinfo = FileInfo(filename) |
| 5845 | line = clean_lines.lines[linenum] |
| 5846 | |
| 5847 | # "include" should use the new style "foo/bar.h" instead of just "bar.h" |
| 5848 | # Only do this check if the included header follows google naming |
| 5849 | # conventions. If not, assume that it's a 3rd party API that |
| 5850 | # requires special include conventions. |
| 5851 | # |
| 5852 | # We also make an exception for Lua headers, which follow google |
| 5853 | # naming convention but not the include convention. |
| 5854 | match = re.match(r'#include\s*"([^/]+\.(.*))"', line) |
| 5855 | if ( |
| 5856 | match |
| 5857 | and IsHeaderExtension(match.group(2)) |
| 5858 | and not _third_party_headers_pattern.match(match.group(1)) |
| 5859 | ): |
| 5860 | error( |
| 5861 | filename, |
| 5862 | linenum, |
| 5863 | "build/include_subdir", |
| 5864 | 4, |
| 5865 | "Include the directory when naming header files", |
| 5866 | ) |
| 5867 | |
| 5868 | # we shouldn't include a file more than once. actually, there are a |
| 5869 | # handful of instances where doing so is okay, but in general it's |
| 5870 | # not. |
| 5871 | match = _RE_PATTERN_INCLUDE.search(line) |
| 5872 | if match: |
| 5873 | include = match.group(2) |
| 5874 | used_angle_brackets = match.group(1) == "<" |
| 5875 | duplicate_line = include_state.FindHeader(include) |
| 5876 | if duplicate_line >= 0: |
| 5877 | error( |
| 5878 | filename, |
| 5879 | linenum, |
| 5880 | "build/include", |
| 5881 | 4, |
| 5882 | f'"{include}" already included at {filename}:{duplicate_line}', |
| 5883 | ) |
| 5884 | return |
| 5885 | |
| 5886 | for extension in GetNonHeaderExtensions(): |
| 5887 | if include.endswith("." + extension) and os.path.dirname( |
no test coverage detected
searching dependent graphs…