MCPcopy Create free account
hub / github.com/4paradigm/OpenMLDB / CheckIncludeLine

Function CheckIncludeLine

steps/cpplint.py:5060–5147  ·  view source on GitHub ↗

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 the curre

(filename, clean_lines, linenum, include_state, error)

Source from the content-addressed store, hash-verified

5058
5059
5060def CheckIncludeLine(filename, clean_lines, linenum, include_state, error):
5061 """Check rules that are applicable to #include lines.
5062
5063 Strings on #include lines are NOT removed from elided line, to make
5064 certain tasks easier. However, to prevent false positives, checks
5065 applicable to #include lines in CheckLanguage must be put here.
5066
5067 Args:
5068 filename: The name of the current file.
5069 clean_lines: A CleansedLines instance containing the file.
5070 linenum: The number of the line to check.
5071 include_state: An _IncludeState instance in which the headers are inserted.
5072 error: The function to call with any errors found.
5073 """
5074 fileinfo = FileInfo(filename)
5075 line = clean_lines.lines[linenum]
5076
5077 # "include" should use the new style "foo/bar.h" instead of just "bar.h"
5078 # Only do this check if the included header follows google naming
5079 # conventions. If not, assume that it's a 3rd party API that
5080 # requires special include conventions.
5081 #
5082 # We also make an exception for Lua headers, which follow google
5083 # naming convention but not the include convention.
5084 match = Match(r'#include\s*"([^/]+\.h)"', line)
5085 if match and not _THIRD_PARTY_HEADERS_PATTERN.match(match.group(1)):
5086 error(filename, linenum, 'build/include_subdir', 4,
5087 'Include the directory when naming .h files')
5088
5089 # we shouldn't include a file more than once. actually, there are a
5090 # handful of instances where doing so is okay, but in general it's
5091 # not.
5092 match = _RE_PATTERN_INCLUDE.search(line)
5093 if match:
5094 include = match.group(2)
5095 used_angle_brackets = (match.group(1) == '<')
5096 duplicate_line = include_state.FindHeader(include)
5097 if duplicate_line >= 0:
5098 error(filename, linenum, 'build/include', 4,
5099 '"%s" already included at %s:%s' %
5100 (include, filename, duplicate_line))
5101 return
5102
5103 for extension in GetNonHeaderExtensions():
5104 if (include.endswith('.' + extension) and
5105 os.path.dirname(fileinfo.RepositoryName()) != os.path.dirname(include)):
5106 error(filename, linenum, 'build/include', 4,
5107 'Do not include .' + extension + ' files from other packages')
5108 return
5109
5110 # We DO want to include a 3rd party looking header if it matches the
5111 # filename. Otherwise we get an erroneous error "...should include its
5112 # header" error later.
5113 third_src_header = False
5114 for ext in GetHeaderExtensions():
5115 basefilename = filename[0:len(filename) - len(fileinfo.Extension())]
5116 headerfile = basefilename + '.' + ext
5117 headername = FileInfo(headerfile).RepositoryName()

Callers 1

CheckLanguageFunction · 0.85

Calls 14

RepositoryNameMethod · 0.95
ExtensionMethod · 0.95
BaseNameMethod · 0.95
FileInfoClass · 0.85
MatchFunction · 0.85
GetNonHeaderExtensionsFunction · 0.85
GetHeaderExtensionsFunction · 0.85
_ClassifyIncludeFunction · 0.85
FindHeaderMethod · 0.80
appendMethod · 0.80
CheckNextIncludeOrderMethod · 0.80

Tested by

no test coverage detected