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)
| 2284 | return lst |
| 2285 | |
| 2286 | def GetHeaderGuardCPPVariable(filename): |
| 2287 | """Returns the CPP variable that should be used as a header guard. |
| 2288 | |
| 2289 | Args: |
| 2290 | filename: The name of a C++ header file. |
| 2291 | |
| 2292 | Returns: |
| 2293 | The CPP variable that should be used as a header guard in the |
| 2294 | named file. |
| 2295 | |
| 2296 | """ |
| 2297 | |
| 2298 | # Restores original filename in case that cpplint is invoked from Emacs's |
| 2299 | # flymake. |
| 2300 | filename = re.sub(r'_flymake\.h$', '.h', filename) |
| 2301 | filename = re.sub(r'/\.flymake/([^/]*)$', r'/\1', filename) |
| 2302 | # Replace 'c++' with 'cpp'. |
| 2303 | filename = filename.replace('C++', 'cpp').replace('c++', 'cpp') |
| 2304 | |
| 2305 | fileinfo = FileInfo(filename) |
| 2306 | file_path_from_root = fileinfo.RepositoryName() |
| 2307 | |
| 2308 | def FixupPathFromRoot(): |
| 2309 | if _root_debug: |
| 2310 | sys.stderr.write("\n_root fixup, _root = '%s', repository name = '%s'\n" |
| 2311 | % (_root, fileinfo.RepositoryName())) |
| 2312 | |
| 2313 | # Process the file path with the --root flag if it was set. |
| 2314 | if not _root: |
| 2315 | if _root_debug: |
| 2316 | sys.stderr.write("_root unspecified\n") |
| 2317 | return file_path_from_root |
| 2318 | |
| 2319 | def StripListPrefix(lst, prefix): |
| 2320 | # f(['x', 'y'], ['w, z']) -> None (not a valid prefix) |
| 2321 | if lst[:len(prefix)] != prefix: |
| 2322 | return None |
| 2323 | # f(['a, 'b', 'c', 'd'], ['a', 'b']) -> ['c', 'd'] |
| 2324 | return lst[(len(prefix)):] |
| 2325 | |
| 2326 | # root behavior: |
| 2327 | # --root=subdir , lstrips subdir from the header guard |
| 2328 | maybe_path = StripListPrefix(PathSplitToList(file_path_from_root), |
| 2329 | PathSplitToList(_root)) |
| 2330 | |
| 2331 | if _root_debug: |
| 2332 | sys.stderr.write(("_root lstrip (maybe_path=%s, file_path_from_root=%s," + |
| 2333 | " _root=%s)\n") % (maybe_path, file_path_from_root, _root)) |
| 2334 | |
| 2335 | if maybe_path: |
| 2336 | return os.path.join(*maybe_path) |
| 2337 | |
| 2338 | # --root=.. , will prepend the outer directory to the header guard |
| 2339 | full_path = fileinfo.FullName() |
| 2340 | # adapt slashes for windows |
| 2341 | root_abspath = os.path.abspath(_root).replace('\\', '/') |
| 2342 | |
| 2343 | maybe_path = StripListPrefix(PathSplitToList(full_path), |
no test coverage detected