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

Function GetHeaderGuardCPPVariable

steps/cpplint.py:2301–2374  ·  view source on GitHub ↗

Returns the CPP variable that should be used as a header guard. Args: filename: The name of a C++ header file. Returns: The CPP variable that should be used as a header guard in the named file.

(filename)

Source from the content-addressed store, hash-verified

2299 return lst
2300
2301def GetHeaderGuardCPPVariable(filename):
2302 """Returns the CPP variable that should be used as a header guard.
2303
2304 Args:
2305 filename: The name of a C++ header file.
2306
2307 Returns:
2308 The CPP variable that should be used as a header guard in the
2309 named file.
2310
2311 """
2312
2313 # Restores original filename in case that cpplint is invoked from Emacs's
2314 # flymake.
2315 filename = re.sub(r'_flymake\.h$', '.h', filename)
2316 filename = re.sub(r'/\.flymake/([^/]*)$', r'/\1', filename)
2317 # Replace 'c++' with 'cpp'.
2318 filename = filename.replace('C++', 'cpp').replace('c++', 'cpp')
2319
2320 fileinfo = FileInfo(filename)
2321 file_path_from_root = fileinfo.RepositoryName()
2322
2323 def FixupPathFromRoot():
2324 if _root_debug:
2325 sys.stderr.write("\n_root fixup, _root = '%s', repository name = '%s'\n"
2326 % (_root, fileinfo.RepositoryName()))
2327
2328 # Process the file path with the --root flag if it was set.
2329 if not _root:
2330 if _root_debug:
2331 sys.stderr.write("_root unspecified\n")
2332 return file_path_from_root
2333
2334 def StripListPrefix(lst, prefix):
2335 # f(['x', 'y'], ['w, z']) -> None (not a valid prefix)
2336 if lst[:len(prefix)] != prefix:
2337 return None
2338 # f(['a, 'b', 'c', 'd'], ['a', 'b']) -> ['c', 'd']
2339 return lst[(len(prefix)):]
2340
2341 # root behavior:
2342 # --root=subdir , lstrips subdir from the header guard
2343 maybe_path = StripListPrefix(PathSplitToList(file_path_from_root),
2344 PathSplitToList(_root))
2345
2346 if _root_debug:
2347 sys.stderr.write(("_root lstrip (maybe_path=%s, file_path_from_root=%s," +
2348 " _root=%s)\n") % (maybe_path, file_path_from_root, _root))
2349
2350 if maybe_path:
2351 return os.path.join(*maybe_path)
2352
2353 # --root=.. , will prepend the outer directory to the header guard
2354 full_path = fileinfo.FullName()
2355 root_abspath = os.path.abspath(_root)
2356
2357 maybe_path = StripListPrefix(PathSplitToList(full_path),
2358 PathSplitToList(root_abspath))

Callers 2

CheckForHeaderGuardFunction · 0.85
CheckStyleFunction · 0.85

Calls 3

RepositoryNameMethod · 0.95
FileInfoClass · 0.85
FixupPathFromRootFunction · 0.85

Tested by

no test coverage detected