10
10
import tempfile
11
11
12
12
BINDGEN_FLAGS_PREFIX = "// bindgen-flags: "
13
- BINDGEN_FEATURES_PREFIX = "// bindgen-features: "
14
13
15
14
COMMON_PRELUDE = """
16
15
#![allow(non_snake_case)]
@@ -78,34 +77,22 @@ def make_bindgen_env():
78
77
79
78
return env
80
79
81
- def get_bindgen_flags_and_features (header_path ):
80
+ def get_bindgen_flags (header_path ):
82
81
"""
83
- Return the bindgen flags and features required for this header as a tuple
84
- (flags, features).
82
+ Return the bindgen flags required for this header
85
83
"""
86
- found_flags = False
87
- found_features = False
88
-
89
- features = []
90
84
flags = ["--no-unstable-rust" ]
91
85
for line in COMMON_PRELUDE .split ("\n " ):
92
86
flags .append ("--raw-line" )
93
87
flags .append (line )
94
88
95
89
with open (header_path ) as f :
96
90
for line in f :
97
- if not found_flags and line .startswith (BINDGEN_FLAGS_PREFIX ):
91
+ if line .startswith (BINDGEN_FLAGS_PREFIX ):
98
92
flags .extend (line .strip ().split (BINDGEN_FLAGS_PREFIX )[1 ].split (" " ))
99
- found_flags = True
100
-
101
- if not found_features and line .startswith (BINDGEN_FEATURES_PREFIX ):
102
- features .extend (line .strip ().split (BINDGEN_FEATURES_PREFIX )[1 ].split (" " ))
103
- found_features = True
104
-
105
- if found_flags and found_features :
106
93
break
107
94
108
- return ( flags , features )
95
+ return flags
109
96
110
97
def get_expected_bindings (rust_bindings_path ):
111
98
"""
@@ -163,7 +150,7 @@ def check_actual_vs_expected(expected_bindings, rust_bindings_path):
163
150
164
151
def to_diffable (s ):
165
152
return map (lambda l : l + "\n " , s .split ("\n " ))
166
-
153
+
167
154
diff = difflib .unified_diff (to_diffable (expected_bindings ),
168
155
to_diffable (actual_bindings ),
169
156
fromfile = "expected_bindings.rs" ,
@@ -172,14 +159,11 @@ def to_diffable(s):
172
159
sys .stderr .write ("\n " )
173
160
174
161
sys .exit (1 )
175
-
162
+
176
163
def main ():
177
164
args = parse_args ()
178
165
179
- (test_flags , test_features ) = get_bindgen_flags_and_features (args .header )
180
- if not all (f in args .features for f in test_features ):
181
- sys .exit (0 )
182
-
166
+ test_flags = get_bindgen_flags (args .header )
183
167
expected_bindings = get_expected_bindings (args .rust_bindings )
184
168
generate_bindings (args .bindgen , test_flags , args .header , args .rust_bindings )
185
169
test_generated_bindings (args .rust_bindings )
0 commit comments