-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathcheck_features.py
More file actions
91 lines (80 loc) · 2.89 KB
/
check_features.py
File metadata and controls
91 lines (80 loc) · 2.89 KB
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
88
89
90
91
import toml
import subprocess
import sys
def filter_name(name):
if name == 'zig':
return False
if name.startswith("utils-"):
return False
if name.startswith("all-"):
return False
if name == "unstable":
return False
return True
def main():
# 检查cargo是否可用
try:
subprocess.run(
["cargo", "--version"],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
check=True
)
except FileNotFoundError:
print("Error: 'cargo' not found. Install Rust and ensure it's in PATH.")
sys.exit(1)
except subprocess.CalledProcessError as e:
print(f"Error checking cargo: {e}")
sys.exit(1)
# 读取Cargo.toml
try:
with open("Cargo.toml", "r") as f:
cargo_toml = toml.load(f)
except FileNotFoundError:
print("Error: Cargo.toml not found in current directory.")
sys.exit(1)
except Exception as e:
print(f"Error parsing Cargo.toml: {e}")
sys.exit(1)
features = cargo_toml.get("features", {})
feature_names = list(features.keys())
feature_names = [name for name in feature_names if filter_name(name) and f"dep:{name}" not in features[name]]
if not feature_names:
print("No features defined in Cargo.toml.")
sys.exit(0)
failed_features = []
test_failed_features = []
print(f"Testing {len(feature_names)} features...")
for idx, feature in enumerate(feature_names, 1):
print(f"\nTesting feature {idx}/{len(feature_names)}: {feature}")
cmd = ["cargo", "check", "--no-default-features", "--features", feature, '--target-dir', 'target/features_check']
try:
subprocess.run(cmd, check=True)
except subprocess.CalledProcessError:
failed_features.append(feature)
print(f"❌ Feature '{feature}' failed to compile")
else:
print(f"✅ Feature '{feature}' compiled successfully")
cmd = ["cargo", "test", "--no-default-features", "--features", feature, '--target-dir', 'target/features_check']
try:
subprocess.run(cmd, check=True)
except subprocess.CalledProcessError:
test_failed_features.append(feature)
print(f"❌ Tests for feature '{feature}' failed")
else:
print(f"✅ Tests for feature '{feature}' passed")
if failed_features or test_failed_features:
if failed_features:
print("\nFailed features:")
for f in failed_features:
print(f" - {f}")
if test_failed_features:
print("\nFailed tests for features:")
for f in test_failed_features:
print(f" - {f}")
sys.exit(1)
else:
print("\nAll features compiled successfully!")
sys.exit(0)
if __name__ == "__main__":
main()