cosmopolitan/tool/scripts/explain-deps.py
Justine Tunney a6baba1b07
Stop using .com extension in monorepo
The WIN32 CreateProcess() function does not require an .exe or .com
suffix in order to spawn an executable. Now that we have Cosmo bash
we're no longer so dependent on the cmd.exe prompt.
2024-03-03 03:12:19 -08:00

27 lines
656 B
Python
Executable file

#!/usr/bin/env python
import os
import re
import sys
def GetDeps(path):
def Dive(path, depth, visited):
sys.stdout.write('%s%s' % ('\t' * depth, path))
if path in visited:
sys.stdout.write(' cycle\n')
return
sys.stdout.write('\n')
with open(path) as f:
code = f.read()
for dep in re.findall(r'[.#]include "([^"]+)"', code):
Dive(dep, depth + 1, visited + [path])
Dive(path, 0, [])
sys.stdout.write('\n')
for arg in sys.argv[1:]:
if os.path.isdir(arg):
for dirpath, dirs, files in os.walk(arg):
for filepath in files:
GetDeps(os.path.join(dirpath, filepath))
else:
GetDeps(arg)