copy_clang_profile_rt.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import optparse
  2. import os
  3. import shutil
  4. import process_command_files as pcf
  5. # List is a temporary thing to ensure that nothing breaks before and after switching to newer clang
  6. # Remove after DTCC-1902
  7. CLANG_RT_VERSIONS = [14, 16]
  8. def copy_clang_rt_profile(cmd, build_root, arch):
  9. profile_rt_lib = None
  10. resource_dir = None
  11. for arg in cmd:
  12. for version in CLANG_RT_VERSIONS:
  13. if arg.startswith(f'contrib/libs/clang{version}-rt/lib/profile/libclang_rt.profile'):
  14. profile_rt_lib = arg
  15. break
  16. if arg.startswith('-resource-dir='):
  17. resource_dir = arg[len('-resource-dir=') :]
  18. profile_rt_path = os.path.join(build_root, profile_rt_lib)
  19. profile_name = os.path.basename(profile_rt_path)
  20. dst_dir = os.path.join(build_root, resource_dir, 'lib/{}'.format(arch.lower()))
  21. os.makedirs(dst_dir, exist_ok=True)
  22. shutil.copy(profile_rt_path, os.path.join(dst_dir, profile_name))
  23. def parse_args():
  24. parser = optparse.OptionParser()
  25. parser.disable_interspersed_args()
  26. parser.add_option('--build-root')
  27. parser.add_option('--arch')
  28. return parser.parse_args()
  29. if __name__ == '__main__':
  30. opts, args = parse_args()
  31. args = pcf.skip_markers(args)
  32. copy_clang_rt_profile(args, opts.build_root, opts.arch)