2020-07-10 03:24:33 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
import argparse
|
|
|
|
import re
|
2021-02-09 04:52:16 +00:00
|
|
|
from os.path import dirname, exists, join, normpath, relpath
|
2020-07-10 03:24:33 +00:00
|
|
|
|
|
|
|
CLANG_TIDY_REGEX = re.compile(r'(.+|[a-zA-Z]:\\\\.+):([0-9]+):([0-9]+): ([^:]+): (.+)')
|
|
|
|
|
|
|
|
|
|
|
|
def normalize_clang_tidy_path(file_path, output_path, base_dir):
|
2020-11-30 09:40:24 +00:00
|
|
|
if not exists(file_path):
|
|
|
|
print('Skipping normalizing. This could only happen when skipping clang-tidy check '
|
|
|
|
'because of no c file modified. Please double check')
|
|
|
|
return
|
|
|
|
|
2020-07-10 03:24:33 +00:00
|
|
|
with open(output_path, 'w') as fw:
|
|
|
|
for line in open(file_path):
|
|
|
|
result = CLANG_TIDY_REGEX.match(line)
|
|
|
|
if result:
|
|
|
|
path = result.group(1)
|
|
|
|
abs_path = normpath(join(dirname(file_path), path))
|
|
|
|
rel_path = relpath(abs_path, base_dir)
|
|
|
|
line = line.replace(path, rel_path)
|
|
|
|
fw.write(line)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
parser.add_argument('file', help='clang tidy report path')
|
|
|
|
parser.add_argument('output_file', help='normalized clang tidy report path')
|
|
|
|
parser.add_argument('base_dir', help='relative path base dir')
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
normalize_clang_tidy_path(args.file, args.output_file, args.base_dir)
|