Skip to content

Commit c1e88b2

Browse files
committed
Add python wrapper for clang
commit_hash:0ac8fe42fec35bd7fd78602530d909a5369b4e0b
1 parent 73efac8 commit c1e88b2

File tree

6 files changed

+65
-43
lines changed

6 files changed

+65
-43
lines changed

build/conf/compilers/gnu_compiler.conf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,11 +215,17 @@ _C_CPP_KV_STYLE_NEW=${hide;kv:_C_CPP_KV_STYLE_P} ${hide;kv:_C_CPP_KV_STYLE_PC}
215215
_C_CPP_KV_STYLE_P=p CC
216216
_C_CPP_KV_STYLE_PC=pc green
217217

218+
_C_CPP_WRAPPER=$YMAKE_PYTHON3 ${input:"build/scripts/wrapcc.py"} ${input:SRC}
219+
when ($CLANG_TIDY_ARGS || $RETRY_ARGS || $YNDEXER_ARGS || $OPENSOURCE == "yes") {
220+
_C_CPP_WRAPPER=
221+
}
222+
218223
_CPP_ARGS_NEW=\
219224
$CLANG_STATIC_ANALYZER_OPTIONS_NEW && \
220225
$CLANG_TIDY_ARGS \
221226
$YNDEXER_ARGS \
222227
$RETRY_ARGS \
228+
$_C_CPP_WRAPPER \
223229
$CXX_COMPILER \
224230
$C_FLAGS_PLATFORM \
225231
$GCC_COMPILE_FLAGS \
@@ -240,6 +246,7 @@ _C_ARGS_NEW=\
240246
$CLANG_TIDY_ARGS \
241247
$YNDEXER_ARGS \
242248
$RETRY_ARGS \
249+
$_C_CPP_WRAPPER \
243250
$C_COMPILER \
244251
$C_FLAGS_PLATFORM \
245252
$GCC_COMPILE_FLAGS \

build/scripts/clang_tidy.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def filter_cmd(cmd):
9696
if not skip:
9797
yield x
9898

99-
if '/wrapcc.py' in x:
99+
if '/retry_cc.py' in x:
100100
skip = False
101101

102102

@@ -116,7 +116,7 @@ def find_header(p, h):
116116

117117
def main():
118118
args, clang_cmd = parse_args()
119-
if '/wrapcc.py' in str(clang_cmd):
119+
if '/retry_cc.py' in str(clang_cmd):
120120
clang_cmd = list(filter_cmd(clang_cmd))
121121
setup_script(args)
122122
clang_tidy_bin = args.clang_tidy_bin

build/scripts/retry_cc.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
from __future__ import print_function
2+
3+
import os
4+
import sys
5+
import time
6+
import subprocess
7+
8+
9+
def need_retry(text):
10+
return 'Stack dump' in text
11+
12+
13+
def retry_inf(cmd):
14+
while True:
15+
try:
16+
yield subprocess.check_output(cmd, stderr=subprocess.STDOUT), None
17+
except subprocess.CalledProcessError as e:
18+
yield e.output, e
19+
20+
21+
def retry(cmd):
22+
for n, (out, err) in enumerate(retry_inf(cmd)):
23+
if out:
24+
sys.stderr.write(out)
25+
26+
if n > 5:
27+
raise Exception('all retries failed')
28+
elif need_retry(out):
29+
time.sleep(1 + n)
30+
elif err:
31+
raise err
32+
else:
33+
return
34+
35+
36+
if __name__ == '__main__':
37+
cmd = sys.argv[1:]
38+
39+
if '-c' in cmd:
40+
try:
41+
retry(cmd)
42+
except subprocess.CalledProcessError as e:
43+
sys.exit(e.returncode)
44+
else:
45+
os.execv(cmd[0], cmd)

build/scripts/wrapcc.py

Lines changed: 9 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,14 @@
1-
from __future__ import print_function
2-
3-
import os
4-
import sys
5-
import time
61
import subprocess
2+
import sys
73

84

9-
def need_retry(text):
10-
return 'Stack dump' in text
11-
12-
13-
def retry_inf(cmd):
14-
while True:
15-
try:
16-
yield subprocess.check_output(cmd, stderr=subprocess.STDOUT), None
17-
except subprocess.CalledProcessError as e:
18-
yield e.output, e
19-
20-
21-
def retry(cmd):
22-
for n, (out, err) in enumerate(retry_inf(cmd)):
23-
if out:
24-
sys.stderr.write(out)
25-
26-
if n > 5:
27-
raise Exception('all retries failed')
28-
elif need_retry(out):
29-
time.sleep(1 + n)
30-
elif err:
31-
raise err
32-
else:
33-
return
34-
5+
def fix(path: str):
6+
flags = []
7+
return flags
358

369
if __name__ == '__main__':
37-
cmd = sys.argv[1:]
38-
39-
if '-c' in cmd:
40-
try:
41-
retry(cmd)
42-
except subprocess.CalledProcessError as e:
43-
sys.exit(e.returncode)
44-
else:
45-
os.execv(cmd[0], cmd)
10+
path = sys.argv[1]
11+
args = sys.argv[2:]
12+
cmd = args + fix(path)
13+
rc = subprocess.call(cmd, shell=False, stderr=sys.stderr, stdout=sys.stdout)
14+
sys.exit(rc)

build/scripts/ya.make

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ ELSEIF (PY3)
117117
py_compile.py
118118
resolve_java_srcs.py
119119
retry.py
120+
retry_cc.py
120121
rodata2asm.py
121122
rodata2cpp.py
122123
run_javac.py

build/ymake.core.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ otherwise {
265265
}
266266

267267
when ($RETRY == "yes") {
268-
RETRY_ARGS=$YMAKE_PYTHON ${input:"build/scripts/wrapcc.py"}
268+
RETRY_ARGS=$YMAKE_PYTHON ${input:"build/scripts/retry_cc.py"}
269269
}
270270
otherwise {
271271
RETRY_ARGS=

0 commit comments

Comments
 (0)