Fix line endings of deps analysis script.

llvm-svn: 297035
This commit is contained in:
Zachary Turner 2017-03-06 17:40:36 +00:00
parent 615353cf38
commit e030d10b62
1 changed files with 65 additions and 65 deletions

View File

@ -1,66 +1,66 @@
import os import os
import re import re
from use_lldb_suite import lldb_root from use_lldb_suite import lldb_root
src_dir = os.path.join(lldb_root, "source") src_dir = os.path.join(lldb_root, "source")
inc_dir = os.path.join(lldb_root, "include") inc_dir = os.path.join(lldb_root, "include")
src_map = {} src_map = {}
include_regex = re.compile('#include \"(lldb(.*/)+).*\"') include_regex = re.compile('#include \"(lldb(.*/)+).*\"')
def scan_deps(this_dir, file): def scan_deps(this_dir, file):
includes = set() includes = set()
with open(file) as f: with open(file) as f:
for line in list(f): for line in list(f):
m = include_regex.match(line) m = include_regex.match(line)
if m is not None: if m is not None:
relative = m.groups()[0].rstrip("/") relative = m.groups()[0].rstrip("/")
if relative != this_dir: if relative != this_dir:
includes.add(relative) includes.add(relative)
return includes return includes
def insert_or_add_mapping(base, deps): def insert_or_add_mapping(base, deps):
global src_map global src_map
if len(deps) > 0: if len(deps) > 0:
if base in src_map: if base in src_map:
existing_deps = src_map[base] existing_deps = src_map[base]
existing_deps.update(deps) existing_deps.update(deps)
else: else:
src_map[base] = deps src_map[base] = deps
for (base, dirs, files) in os.walk(inc_dir): for (base, dirs, files) in os.walk(inc_dir):
dir = os.path.basename(base) dir = os.path.basename(base)
relative = os.path.relpath(base, inc_dir) relative = os.path.relpath(base, inc_dir)
inc_files = filter(lambda x : os.path.splitext(x)[1] in [".h"], files) inc_files = filter(lambda x : os.path.splitext(x)[1] in [".h"], files)
deps = set() deps = set()
relative = relative.replace("\\", "/") relative = relative.replace("\\", "/")
for inc in inc_files: for inc in inc_files:
inc_path = os.path.join(base, inc) inc_path = os.path.join(base, inc)
deps.update(scan_deps(relative, inc_path)) deps.update(scan_deps(relative, inc_path))
insert_or_add_mapping(relative, deps) insert_or_add_mapping(relative, deps)
for (base, dirs, files) in os.walk(src_dir): for (base, dirs, files) in os.walk(src_dir):
dir = os.path.basename(base) dir = os.path.basename(base)
relative = os.path.relpath(base, src_dir) relative = os.path.relpath(base, src_dir)
src_files = filter(lambda x : os.path.splitext(x)[1] in [".cpp", ".h", ".mm"], files) src_files = filter(lambda x : os.path.splitext(x)[1] in [".cpp", ".h", ".mm"], files)
deps = set() deps = set()
norm_base_path = os.path.normpath(os.path.join("lldb", relative)) norm_base_path = os.path.normpath(os.path.join("lldb", relative))
norm_base_path = norm_base_path.replace("\\", "/") norm_base_path = norm_base_path.replace("\\", "/")
for src in src_files: for src in src_files:
src_path = os.path.join(base, src) src_path = os.path.join(base, src)
deps.update(scan_deps(norm_base_path, src_path)) deps.update(scan_deps(norm_base_path, src_path))
insert_or_add_mapping(norm_base_path, deps) insert_or_add_mapping(norm_base_path, deps)
pass pass
items = list(src_map.iteritems()) items = list(src_map.iteritems())
items.sort(lambda A, B : cmp(A[0], B[0])) items.sort(lambda A, B : cmp(A[0], B[0]))
for (path, deps) in items: for (path, deps) in items:
print path + ":" print path + ":"
sorted_deps = list(deps) sorted_deps = list(deps)
sorted_deps.sort() sorted_deps.sort()
for dep in sorted_deps: for dep in sorted_deps:
print "\t" + dep print "\t" + dep
pass pass