()
| 2514 | file_path_from_root = fileinfo.RepositoryName() |
| 2515 | |
| 2516 | def FixupPathFromRoot(): |
| 2517 | if _root_debug: |
| 2518 | sys.stderr.write( |
| 2519 | f"\n_root fixup, _root = '{_root}'," |
| 2520 | f" repository name = '{fileinfo.RepositoryName()}'\n" |
| 2521 | ) |
| 2522 | |
| 2523 | # Process the file path with the --root flag if it was set. |
| 2524 | if not _root: |
| 2525 | if _root_debug: |
| 2526 | sys.stderr.write("_root unspecified\n") |
| 2527 | return file_path_from_root |
| 2528 | |
| 2529 | def StripListPrefix(lst, prefix): |
| 2530 | # f(['x', 'y'], ['w, z']) -> None (not a valid prefix) |
| 2531 | if lst[: len(prefix)] != prefix: |
| 2532 | return None |
| 2533 | # f(['a, 'b', 'c', 'd'], ['a', 'b']) -> ['c', 'd'] |
| 2534 | return lst[(len(prefix)) :] |
| 2535 | |
| 2536 | # root behavior: |
| 2537 | # --root=subdir , lstrips subdir from the header guard |
| 2538 | maybe_path = StripListPrefix(PathSplitToList(file_path_from_root), PathSplitToList(_root)) |
| 2539 | |
| 2540 | if _root_debug: |
| 2541 | sys.stderr.write( |
| 2542 | ("_root lstrip (maybe_path=%s, file_path_from_root=%s," + " _root=%s)\n") |
| 2543 | % (maybe_path, file_path_from_root, _root) |
| 2544 | ) |
| 2545 | |
| 2546 | if maybe_path: |
| 2547 | return os.path.join(*maybe_path) |
| 2548 | |
| 2549 | # --root=.. , will prepend the outer directory to the header guard |
| 2550 | full_path = fileinfo.FullName() |
| 2551 | # adapt slashes for windows |
| 2552 | root_abspath = os.path.abspath(_root).replace("\\", "/") |
| 2553 | |
| 2554 | maybe_path = StripListPrefix(PathSplitToList(full_path), PathSplitToList(root_abspath)) |
| 2555 | |
| 2556 | if _root_debug: |
| 2557 | sys.stderr.write( |
| 2558 | ("_root prepend (maybe_path=%s, full_path=%s, " + "root_abspath=%s)\n") |
| 2559 | % (maybe_path, full_path, root_abspath) |
| 2560 | ) |
| 2561 | |
| 2562 | if maybe_path: |
| 2563 | return os.path.join(*maybe_path) |
| 2564 | |
| 2565 | if _root_debug: |
| 2566 | sys.stderr.write(f"_root ignore, returning {file_path_from_root}\n") |
| 2567 | |
| 2568 | # --root=FAKE_DIR is ignored |
| 2569 | return file_path_from_root |
| 2570 | |
| 2571 | file_path_from_root = FixupPathFromRoot() |
| 2572 | return re.sub(r"[^a-zA-Z0-9]", "_", file_path_from_root).upper() + "_" |
no test coverage detected