normalize_clangtidy_path.py 1.0 KB

12345678910111213141516171819202122232425262728
  1. #!/usr/bin/env python
  2. import argparse
  3. import re
  4. from os.path import join, normpath, dirname, relpath
  5. CLANG_TIDY_REGEX = re.compile(r'(.+|[a-zA-Z]:\\\\.+):([0-9]+):([0-9]+): ([^:]+): (.+)')
  6. def normalize_clang_tidy_path(file_path, output_path, base_dir):
  7. with open(output_path, 'w') as fw:
  8. for line in open(file_path):
  9. result = CLANG_TIDY_REGEX.match(line)
  10. if result:
  11. path = result.group(1)
  12. abs_path = normpath(join(dirname(file_path), path))
  13. rel_path = relpath(abs_path, base_dir)
  14. line = line.replace(path, rel_path)
  15. fw.write(line)
  16. if __name__ == '__main__':
  17. parser = argparse.ArgumentParser()
  18. parser.add_argument('file', help='clang tidy report path')
  19. parser.add_argument('output_file', help='normalized clang tidy report path')
  20. parser.add_argument('base_dir', help='relative path base dir')
  21. args = parser.parse_args()
  22. normalize_clang_tidy_path(args.file, args.output_file, args.base_dir)