Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions scripts/debug_tools/failure_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,20 @@ def change_paths(string, path_modifier_fun):
result = []
i = 0
while i < len(string):
# Everything is a path which starts with a '/' and there is a
# whitespace after that.
# All strings that start with '/' (or './' or '../') and end with
# whitespace are recognized as paths. Additionally any string
# immediately after a '-I' option (no whitespace between option and path).
# Note, this supports only POSIX paths.
if string[i] == '/':
if string[i] == '/' or string[i:i + 2] == './' or\
string[i:i + 3] == '../' or string[i - 3:i] == ' -I':
path, path_end = find_path_end(string, i)
path = path_modifier_fun(path)
# Make sure that the prospective output folder exists.
pattern = re.compile(r'[\s\S]*-o *\Z')
if pattern.match(string[:i]):
out_dir = "./sources-root" + os.path.dirname(path)
out_dir = os.path.dirname(path)
if not os.path.isdir(out_dir):
os.makedirs(out_dir)
path = path_modifier_fun(path)
result += path
i = path_end - 1
else:
Expand All @@ -57,10 +59,17 @@ def change_paths(string, path_modifier_fun):


class IncludePathModifier:
def __init__(self, sources_root):
def __init__(self, sources_root, working_dir = '.'):
self.sources_root = sources_root
self.working_dir = working_dir

def __call__(self, path):
if not os.path.isabs(path):
return os.path.normpath(
os.path.join(
self.sources_root,
self.working_dir.lstrip(os.path.sep),
path))
return os.path.join(
self.sources_root,
os.path.normpath(
Expand Down
7 changes: 4 additions & 3 deletions scripts/debug_tools/prepare_compile_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ def prepare(compile_command_json, sources_root):
if not exists_in_source_root(entry, sources_root):
continue

working_dir = entry['directory']
entry['directory'] =\
lib.change_paths(entry['directory'],
lib.change_paths(working_dir,
lib.IncludePathModifier(sources_root_abs))

try:
Expand All @@ -62,11 +63,11 @@ def prepare(compile_command_json, sources_root):
compiler, compiler_end = lib.find_path_end(cmd.lstrip(), 0)
entry['command'] = compiler +\
lib.change_paths(cmd[compiler_end:],
lib.IncludePathModifier(sources_root_abs))
lib.IncludePathModifier(sources_root_abs, working_dir))

entry['file'] =\
lib.change_paths(entry['file'],
lib.IncludePathModifier(sources_root_abs))
lib.IncludePathModifier(sources_root_abs, working_dir))

result_json.append(entry)
return result_json
Expand Down
Loading