2024-03-03 00:57:56 +00:00
|
|
|
#!/usr/bin/env python
|
2022-08-13 20:11:56 +00:00
|
|
|
|
|
|
|
import os
|
|
|
|
import re
|
|
|
|
import sys
|
|
|
|
|
|
|
|
def GetDeps(path):
|
2024-06-03 16:09:33 +00:00
|
|
|
visited = set()
|
|
|
|
def Dive(path, inside, depth, that_isnt=None):
|
2024-06-04 12:41:53 +00:00
|
|
|
included = path
|
|
|
|
|
2024-06-03 16:09:33 +00:00
|
|
|
if not os.path.exists(path):
|
|
|
|
if inside:
|
|
|
|
samedir = os.path.join(os.path.dirname(inside), path)
|
|
|
|
if inside and os.path.exists(samedir) and samedir != that_isnt:
|
|
|
|
path = samedir
|
|
|
|
elif os.path.exists('third_party/libcxx/' + path) and 'third_party/libcxx/' + path != that_isnt:
|
|
|
|
path = 'third_party/libcxx/' + path
|
|
|
|
elif os.path.exists('libc/isystem/' + path):
|
|
|
|
path = 'libc/isystem/' + path
|
|
|
|
else:
|
|
|
|
# sys.stderr.write('not found: %s\n' % (path))
|
|
|
|
return
|
2024-06-04 12:41:53 +00:00
|
|
|
|
|
|
|
sys.stdout.write('\t' * depth)
|
|
|
|
sys.stdout.write(path)
|
|
|
|
sys.stdout.write('\n')
|
|
|
|
|
|
|
|
if path in visited:
|
|
|
|
return
|
|
|
|
visited.add(path)
|
|
|
|
|
2022-08-13 20:11:56 +00:00
|
|
|
with open(path) as f:
|
|
|
|
code = f.read()
|
2024-06-03 16:09:33 +00:00
|
|
|
for dep in re.findall(r'[.#]\s*include\s+[<"]([^">]+)[">]', code):
|
|
|
|
Dive(dep, path, depth + 1)
|
|
|
|
for dep in re.findall(r'[.#]\s*include_next\s+[<"]([^">]+)[">]', code):
|
|
|
|
Dive(dep, path, depth + 1, path)
|
|
|
|
Dive(path, None, 0)
|
2022-08-13 20:11:56 +00:00
|
|
|
|
2024-06-03 16:09:33 +00:00
|
|
|
once = False
|
2022-08-13 20:11:56 +00:00
|
|
|
for arg in sys.argv[1:]:
|
|
|
|
if os.path.isdir(arg):
|
|
|
|
for dirpath, dirs, files in os.walk(arg):
|
|
|
|
for filepath in files:
|
2024-06-03 16:09:33 +00:00
|
|
|
if not once:
|
|
|
|
sys.stdout.write('\n')
|
|
|
|
once = True
|
2022-08-13 20:11:56 +00:00
|
|
|
GetDeps(os.path.join(dirpath, filepath))
|
|
|
|
else:
|
|
|
|
GetDeps(arg)
|