normalize_clangtidy_path.py 1.2 KB

123456789101112131415161718192021222324252627282930313233
  1. #!/usr/bin/env python
  2. import argparse
  3. import re
  4. from os.path import dirname, exists, join, normpath, 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. if not exists(file_path):
  8. print('Skipping normalizing. This could only happen when skipping clang-tidy check '
  9. 'because of no c file modified. Please double check')
  10. return
  11. with open(output_path, 'w') as fw:
  12. for line in open(file_path):
  13. result = CLANG_TIDY_REGEX.match(line)
  14. if result:
  15. path = result.group(1)
  16. abs_path = normpath(join(dirname(file_path), path))
  17. rel_path = relpath(abs_path, base_dir)
  18. line = line.replace(path, rel_path)
  19. fw.write(line)
  20. if __name__ == '__main__':
  21. parser = argparse.ArgumentParser()
  22. parser.add_argument('file', help='clang tidy report path')
  23. parser.add_argument('output_file', help='normalized clang tidy report path')
  24. parser.add_argument('base_dir', help='relative path base dir')
  25. args = parser.parse_args()
  26. normalize_clang_tidy_path(args.file, args.output_file, args.base_dir)