Repository: SerenityOS/serenity
File: Meta/CMake/get_cxx_includes.py (Python)

Code before:
        if include_dir.endswith(b"/bits"):
            include_dir = os.path.dirname(include_dir)

        while not os.path.isdir(include_dir):
            include_dir = os.path.dirname(include_dir)

        dirs.append(include_dir)
    
    return dirs


if __name__ == "__main__":
    compiler = None
    test_file = None
    index = 1
    while index < len(sys.argv):
        if sys.argv[index] == "--compiler":
            index += 1
            compiler = sys.argv[index]
        elif sys.argv[index] == "--test-file":
            index += 1
            test_file = sys.argv[index]
        else:
            print("Unknown argument: " + sys.argv[index])
            sys.exit(1)
        index += 1
    
    if compiler is None:
        print("No compiler specified")
        sys.exit(1)
    
    if test_file is None:
        print("No test file specified")
        sys.exit(1)
    
    includes = get_includes_from_version_output(compiler)
    system_includes = get_includes_from_preprocessor_output(compiler, test_file)
    system_includes = convert_includes_to_dirs(system_includes)

    print(";".join(entry.decode("utf-8") for entry in set(includes + system_includes)), end="")

Review comment (suggestion):
shell-pilled much? here, i pasted your code into claude and asked it to convert to argparse. I haven't tried it but it looks vaguely correct:

```
import argparse

parser = argparse.ArgumentParser(description='Process compiler and test file arguments')

parser.add_argument('--compiler', 
                   required=True,
                   help='Specify the compiler to use')

parser.add_argument('--test-file',
                   required=True,
                   help='Specify the test file to use')

args = parser.parse_args()
compiler = args.compiler
test_file = args.test_file
```

(omit help strings for brevity)

Code after:

def convert_includes_to_dirs(includes):
    dirs = []
    for include in includes:
        if not os.path.isabs(include):
            continue
        include_dir = os.path.dirname(include)
        if include_dir.endswith(b"/bits"):
            include_dir = os.path.dirname(include_dir)

        while not os.path.isdir(include_dir):
            include_dir = os.path.dirname(include_dir)

        if os.path.basename(include_dir).startswith(b"_"):
            continue

        dirs.append(include_dir)

    return dirs


def main():
    parser = argparse.ArgumentParser(
        description="Extract System Includes from C++ Compiler"
    )

    parser.add_argument("--compiler", required=True, help="Specify C++ compiler to extract includes from")
    parser.add_argument("--target", help="Specify target platform for compiler")

    parser.add_argument(
        "--test-file", required=True, help="Specify the path to the test file containing '#include' directives"
    )

    args = parser.parse_args()
    compiler = args.compiler
    test_file = args.test_file
    target = args.target

    target_args = []
    if target is not None and target != "":
        target_args = [f"--target={target}"]

    includes = get_includes_from_version_output(compiler, target_args)
    system_includes = get_includes_from_preprocessor_output(compiler, test_file, target_args)
    system_includes = convert_includes_to_dirs(system_includes)

    out = []
    seen = set()
    for p in system_includes + includes:
        if p in seen:
            continue