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

Function FixupPathFromRoot

tools/cpplint.py:2561–2614  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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
2597 root_abspath = os.path.abspath(_root).replace("\\", "/")
2598
2599 maybe_path = StripListPrefix(PathSplitToList(full_path), PathSplitToList(root_abspath))
2600
2601 if _root_debug:
2602 sys.stderr.write(
2603 ("_root prepend (maybe_path=%s, full_path=%s, " + "root_abspath=%s)\n")
2604 % (maybe_path, full_path, root_abspath)
2605 )
2606
2607 if maybe_path:
2608 return os.path.join(*maybe_path)
2609
2610 if _root_debug:
2611 sys.stderr.write(f"_root ignore, returning {file_path_from_root}\n")
2612
2613 # --root=FAKE_DIR is ignored
2614 return file_path_from_root
2615
2616 file_path_from_root = FixupPathFromRoot()
2617 return re.sub(r"[^a-zA-Z0-9]", "_", file_path_from_root).upper() + "_"

Callers 1

Calls 6

StripListPrefixFunction · 0.85
PathSplitToListFunction · 0.85
RepositoryNameMethod · 0.80
writeMethod · 0.45
joinMethod · 0.45
FullNameMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…