clang_wrapper.py 1.4 KB

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