mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-23 05:42:29 +00:00
Introduce Cosmopolitan Templates Library (CTL)
This commit is contained in:
parent
b003888696
commit
4937843f70
16 changed files with 7054 additions and 12 deletions
|
@ -5,23 +5,41 @@ import re
|
|||
import sys
|
||||
|
||||
def GetDeps(path):
|
||||
def Dive(path, depth, visited):
|
||||
visited = set()
|
||||
def Dive(path, inside, depth, that_isnt=None):
|
||||
sys.stdout.write('%s%s' % ('\t' * depth, path))
|
||||
if path in visited:
|
||||
sys.stdout.write(' cycle\n')
|
||||
return
|
||||
sys.stdout.write('\n')
|
||||
if path in visited:
|
||||
return
|
||||
visited.add(path)
|
||||
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
|
||||
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 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)
|
||||
|
||||
once = False
|
||||
for arg in sys.argv[1:]:
|
||||
if os.path.isdir(arg):
|
||||
for dirpath, dirs, files in os.walk(arg):
|
||||
for filepath in files:
|
||||
if not once:
|
||||
sys.stdout.write('\n')
|
||||
once = True
|
||||
GetDeps(os.path.join(dirpath, filepath))
|
||||
else:
|
||||
GetDeps(arg)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue