copy_clang_profile_rt.py 1.5 KB

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