MCPcopy Index your code
hub / github.com/nodejs/node / GetHeaderGuardCPPVariable

Function GetHeaderGuardCPPVariable

tools/cpplint.py:2539–2617  ·  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

2537
2538
2539def GetHeaderGuardCPPVariable(filename):
2540 """Returns the CPP variable that should be used as a header guard.
2541
2542 Args:
2543 filename: The name of a C++ header file.
2544
2545 Returns:
2546 The CPP variable that should be used as a header guard in the
2547 named file.
2548
2549 """
2550
2551 # Restores original filename in case that cpplint is invoked from Emacs's
2552 # flymake.
2553 filename = re.sub(r"_flymake\.h$", ".h", filename)
2554 filename = re.sub(r"/\.flymake/([^/]*)$", r"/\1", filename)
2555 # Replace 'c++' with 'cpp'.
2556 filename = filename.replace("C++", "cpp").replace("c++", "cpp")
2557
2558 fileinfo = FileInfo(filename)
2559 file_path_from_root = fileinfo.RepositoryName()
2560
2561 def FixupPathFromRoot():
2562 if _root_debug:
2563 sys.stderr.write(
2564 f"\n_root fixup, _root = '{_root}',"
2565 f" repository name = '{fileinfo.RepositoryName()}'\n"
2566 )
2567
2568 # Process the file path with the --root flag if it was set.
2569 if not _root:
2570 if _root_debug:
2571 sys.stderr.write("_root unspecified\n")
2572 return file_path_from_root
2573
2574 def StripListPrefix(lst, prefix):
2575 # f(['x', 'y'], ['w, z']) -> None (not a valid prefix)
2576 if lst[: len(prefix)] != prefix:
2577 return None
2578 # f(['a, 'b', 'c', 'd'], ['a', 'b']) -> ['c', 'd']
2579 return lst[(len(prefix)) :]
2580
2581 # root behavior:
2582 # --root=subdir , lstrips subdir from the header guard
2583 maybe_path = StripListPrefix(PathSplitToList(file_path_from_root), PathSplitToList(_root))
2584
2585 if _root_debug:
2586 sys.stderr.write(
2587 ("_root lstrip (maybe_path=%s, file_path_from_root=%s," + " _root=%s)\n")
2588 % (maybe_path, file_path_from_root, _root)
2589 )
2590
2591 if maybe_path:
2592 return os.path.join(*maybe_path)
2593
2594 # --root=.. , will prepend the outer directory to the header guard
2595 full_path = fileinfo.FullName()
2596 # adapt slashes for windows

Callers 1

ProcessFileDataFunction · 0.85

Calls 3

RepositoryNameMethod · 0.95
FileInfoClass · 0.85
FixupPathFromRootFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…