-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstab.py
executable file
·112 lines (84 loc) · 3.17 KB
/
stab.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/usr/bin/python
# Copyright 2014 The Rust Project Developers. See the COPYRIGHT
# file at the top-level directory of this distribution and at
# http://rust-lang.org/COPYRIGHT.
#
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
# option. This file may not be copied, modified, or distributed
# except according to those terms.
import os
import sys
from subprocess import call
rustc = os.getenv('RUSTC', 'rustc')
# Sanity checks
retcode = call([rustc, "--version"], )
if retcode != 0:
print "rustc isn't working. Maybe set RUSTC env var."
sys.exit(1)
# Get a list of all the source files in a crate, given the crate root
def get_deps(filename):
try:
os.remove("stab-depinfo.d")
except:
pass
# Specify a crate type so the output will have a single target (not two for rlib/dylib)
retcode = call([rustc, filename, "--crate-type=rlib", "--emit", "dep-info", "-o", "stab-depinfo"])
if retcode != 0:
return None
depstr = ""
with open("stab-depinfo.d", 'r') as depinfo:
depstr = depinfo.read()
os.remove("stab-depinfo.d")
if depstr.find(":") == -1:
raise "depinfo looks wrong"
depstr = depstr.split(":")[1].strip()
deps = depstr.split(" ")
return deps
# Some naive checks from just looking at the file,
# including examining compiletest test directives
def passes_smell_test(filename):
# Note: not using depinfo because none of the checks below need it
deps = get_deps(filename)
if deps == None:
return False
for dep in deps:
with open(dep) as f:
for line in f:
# Look for things that might be risky
# 'extern crate' might bring in experimental API's
if "extern crate" in line: return False
# No ignored test cases
if "// ignore" in line: return False
# No test cases requiring aux
if "aux-build" in line: return False
# No compile-flags
if "compile-flags" in line: return False
# No exec-env
if "exec-env" in line: return False
# Native crate in reference suite that we don't have
if "rust_test_helpers" in line: return False
return True
def uses_stable_apis(filename):
retcode1 = call([rustc, filename, "-Z", "no-trans", "-F", "deprecated", "-F", "unstable_features"]);
retcode2 = call([rustc, filename, "-Z", "no-trans", "-F", "deprecated", "-F", "unstable_features", "--test"]);
if retcode1 == 0 and retcode2 == 0: return True
else: return False
def is_stable(filename):
if not passes_smell_test(filename):
return False
if not uses_stable_apis(filename):
return False
return True
if __name__ == '__main__':
if len(sys.argv) < 2:
print "usage: stab.py filename"
sys.exit(1)
filename = sys.argv[1]
if is_stable(filename):
print "[stable] " + filename
sys.exit(0)
else:
print "[unstable] " + filename
sys.exit(1)