-
Notifications
You must be signed in to change notification settings - Fork 123
/
cargo_check.py
87 lines (72 loc) · 2.37 KB
/
cargo_check.py
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
"""
This script finds all of the Cargo.toml files in the script directory, finds their workspace cargo
manifest, and runs a `cargo check` on the workspace manifest. Essentially this is a check on all of
the crates we have regardless of what workspace they're in.
"""
from typing import TypeVar
import subprocess
import json
import os
def workspace_path(manifest_path: str) -> str:
process: subprocess.Popen = subprocess.Popen(
[
"cargo",
"metadata",
"--manifest-path",
manifest_path,
"--format-version",
"1",
],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
stdout: bytes
stderr: bytes
stdout, stderr = process.communicate()
try:
return json.loads(stdout)["workspace_root"]
except:
raise Exception(manifest_path, stdout.decode(), stderr.decode())
T = TypeVar("T")
def unique(l: list[T]) -> list[T]:
return list(set(l))
def main() -> None:
# Find all of the `Cargo.toml` files recursively in the script directory.
workspace_manifest_paths: list[str] = sorted(
unique(
[
os.path.join(
workspace_path(os.path.join(dirpath, filename)), "Cargo.toml"
)
for dirpath, _, filenames in os.walk(
os.path.dirname(os.path.realpath(__file__))
)
for filename in filenames
if filename == "Cargo.toml"
]
)
)
# Running cargo check on the manifest.
for workspace_manifest_file_path in workspace_manifest_paths:
if "dec_macros" in workspace_manifest_file_path:
continue
process: subprocess.Popen = subprocess.Popen(
[
"cargo",
"check",
"--all-targets",
"--manifest-path",
workspace_manifest_file_path,
],
stderr=subprocess.PIPE,
stdout=subprocess.PIPE,
)
stderr: bytes
_, stderr = process.communicate()
emoji: str = "❌" if process.returncode != 0 else "✅"
print(f"{emoji} {workspace_manifest_file_path}")
if process.returncode != 0:
print(stderr.decode())
raise Exception("Check failed on one of the workspaces")
if __name__ == "__main__":
main()