aboutsummaryrefslogtreecommitdiffstats
path: root/build/scripts/retry_cc.py
diff options
context:
space:
mode:
authornechda <nechda@yandex-team.com>2024-11-02 11:20:12 +0300
committernechda <nechda@yandex-team.com>2024-11-02 11:34:51 +0300
commitc1e88b2643346523bc487519ca3615245fe372d2 (patch)
tree01fe58134bf0cf4c26e720c621c64685a69cc6e2 /build/scripts/retry_cc.py
parent73efac8142e4fb2b149797aadda491055f8fba02 (diff)
downloadydb-c1e88b2643346523bc487519ca3615245fe372d2.tar.gz
Add python wrapper for clang
commit_hash:0ac8fe42fec35bd7fd78602530d909a5369b4e0b
Diffstat (limited to 'build/scripts/retry_cc.py')
-rw-r--r--build/scripts/retry_cc.py45
1 files changed, 45 insertions, 0 deletions
diff --git a/build/scripts/retry_cc.py b/build/scripts/retry_cc.py
new file mode 100644
index 0000000000..88a9e6a4fc
--- /dev/null
+++ b/build/scripts/retry_cc.py
@@ -0,0 +1,45 @@
+from __future__ import print_function
+
+import os
+import sys
+import time
+import subprocess
+
+
+def need_retry(text):
+ return 'Stack dump' in text
+
+
+def retry_inf(cmd):
+ while True:
+ try:
+ yield subprocess.check_output(cmd, stderr=subprocess.STDOUT), None
+ except subprocess.CalledProcessError as e:
+ yield e.output, e
+
+
+def retry(cmd):
+ for n, (out, err) in enumerate(retry_inf(cmd)):
+ if out:
+ sys.stderr.write(out)
+
+ if n > 5:
+ raise Exception('all retries failed')
+ elif need_retry(out):
+ time.sleep(1 + n)
+ elif err:
+ raise err
+ else:
+ return
+
+
+if __name__ == '__main__':
+ cmd = sys.argv[1:]
+
+ if '-c' in cmd:
+ try:
+ retry(cmd)
+ except subprocess.CalledProcessError as e:
+ sys.exit(e.returncode)
+ else:
+ os.execv(cmd[0], cmd)