aboutsummaryrefslogtreecommitdiffstats
path: root/build/scripts/clang_wrapper.py
blob: 844ae856d6bcfeb9fa744e9accdb466597023e26 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import subprocess 
import sys


def fix(s):
    # disable dbg DEVTOOLS-2744
    if s == '-g':
        return None
    if s == '/Z7' or s == '/Od' or s == '/Ob0' or s == '/D_DEBUG': 
        return None 

    # disable sanitizers for generated code 
    if s.startswith('-fsanitize') or s == '-Dmemory_sanitizer_enabled' or s.startswith('-fsanitize-blacklist'): 
        return None 
 
    # strip gcc toolchain flags (appear when crosscompiling) 
    if s.startswith('-fabi-version'): 
        return None 
 
    # remove arguments unknown to clang-cl
    if s == '-fcase-insensitive-paths':  # or s == '-fno-lto':  # DEVTOOLSSUPPORT-3966
        return None

    # Paths under .ya/tools/v3/.../msvc/include are divided with '\' 
    return s.replace('\\', '/') 


def fix_path(p): 
    try: 
        i = p.rfind('/bin/clang') 
        p = p[:i] + '/bin/clang-cl' 
    except ValueError: 
        pass 
    return p 
 
 
if __name__ == '__main__':
    is_on_win = sys.argv[1] == 'yes' 
    path = sys.argv[2] 
    args = filter(None, [fix(s) for s in sys.argv[3:]]) 
    if is_on_win: 
        path = fix_path(path) 
        try: 
            i = args.index('-emit-llvm') 
            args[i:i+1] = ['-Xclang', '-emit-llvm'] 
        except ValueError: 
            pass 
        args.append('-fms-compatibility-version=19') 

    cmd = [path] + args 
 
    rc = subprocess.call(cmd, shell=False, stderr=sys.stderr, stdout=sys.stdout) 
    sys.exit(rc)