Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pola-rs
GitHub Repository: pola-rs/polars
Path: blob/main/tools/cargo-fail-warning.py
8424 views
1
# A wrapper for cargo which fails on warnings.
2
# This is better than -D warnings as it will continue the build rather than fail early.
3
4
import subprocess
5
import json
6
import sys
7
8
subcommand = sys.argv[1]
9
10
proc = subprocess.Popen(
11
["cargo", subcommand, "--message-format=json-diagnostic-rendered-ansi"]
12
+ sys.argv[2:],
13
stdout=subprocess.PIPE,
14
)
15
16
found_warning = False
17
for line in iter(proc.stdout.readline, b""):
18
msg = json.loads(line)
19
if msg["reason"] in (
20
"compiler-artifact",
21
"build-script-executed",
22
"build-finished",
23
):
24
continue
25
26
if msg["reason"] == "compiler-message":
27
print(msg["message"]["rendered"], file=sys.stderr)
28
if msg["message"]["level"] == "warning":
29
found_warning = True
30
continue
31
32
raise RuntimeError("unknown message reason:\n", json.dumps(msg, indent=4))
33
34
# Respect original exit code if non-zero, otherwise emit if warning was found.
35
exit = proc.wait()
36
sys.exit(exit if exit != 0 else int(found_warning))
37
38