clang_wrapper.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import subprocess
  2. import sys
  3. def fix(s):
  4. if s == '/Z7' or s == '/Od' or s == '/Ob0' or s == '/D_DEBUG':
  5. return None
  6. # disable sanitizers for generated code
  7. if s.startswith('-fsanitize') or s == '-Dmemory_sanitizer_enabled' or s.startswith('-fsanitize-blacklist'):
  8. return None
  9. # strip gcc toolchain flags (appear when crosscompiling)
  10. if s.startswith('-fabi-version'):
  11. return None
  12. # remove arguments unknown to clang-cl
  13. if s == '-fcase-insensitive-paths': # or s == '-fno-lto': # DEVTOOLSSUPPORT-3966
  14. return None
  15. # Paths under .ya/tools/v3/.../msvc/include are divided with '\'
  16. return s.replace('\\', '/')
  17. def fix_path(p):
  18. try:
  19. i = p.rfind('/bin/clang')
  20. p = p[:i] + '/bin/clang-cl'
  21. except ValueError:
  22. pass
  23. return p
  24. if __name__ == '__main__':
  25. is_on_win = sys.argv[1] == 'yes'
  26. path = sys.argv[2]
  27. args = filter(None, [fix(s) for s in sys.argv[3:]])
  28. if is_on_win:
  29. path = fix_path(path)
  30. try:
  31. i = args.index('-emit-llvm')
  32. args[i:i+1] = ['-Xclang', '-emit-llvm']
  33. except ValueError:
  34. pass
  35. args.append('-fms-compatibility-version=19')
  36. cmd = [path] + args
  37. rc = subprocess.call(cmd, shell=False, stderr=sys.stderr, stdout=sys.stdout)
  38. sys.exit(rc)