summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Fitzgerald <fitzgen@gmail.com>2016-10-18 15:50:58 -0700
committerNick Fitzgerald <fitzgen@gmail.com>2016-10-18 15:57:10 -0700
commit294ca4d468fed0a613387c2dbba70d97373da505 (patch)
treefc7d990adf4ddb59bd754bc6ec9e21b93d6e204b
parentffd8f27613438477dcc1a46030ad3d32bf765dd0 (diff)
Allow test headers to supply required bindgen features
This adds the ability for tests to supply required features, and if the bindgen we're testing was not built with those features, then the test will be skipped. The syntax used to require features is like this: // bindgen-features: llvm_stable some_experiment another
-rw-r--r--tests/headers/class_with_typedef.hpp1
-rw-r--r--tests/tests.rs16
-rwxr-xr-xtests/tools/run-bindgen.py46
3 files changed, 49 insertions, 14 deletions
diff --git a/tests/headers/class_with_typedef.hpp b/tests/headers/class_with_typedef.hpp
index f36c7b5d..41a3cfd7 100644
--- a/tests/headers/class_with_typedef.hpp
+++ b/tests/headers/class_with_typedef.hpp
@@ -1,4 +1,5 @@
// bindgen-flags: --no-type-renaming
+// bindgen-features: llvm_stable
typedef int AnotherInt;
diff --git a/tests/tests.rs b/tests/tests.rs
index aaa7628e..b3d0e735 100644
--- a/tests/tests.rs
+++ b/tests/tests.rs
@@ -28,13 +28,19 @@ fn spawn_run_bindgen<P, Q, R>(run_bindgen: P, bindgen: Q, header: R) -> process:
expected.push(file_name);
expected.set_extension("rs");
- process::Command::new(run_bindgen)
+ let mut cmd = process::Command::new(run_bindgen);
+ cmd.stdout(process::Stdio::piped())
+ .stderr(process::Stdio::piped())
.arg(bindgen)
.arg(header)
- .stdout(process::Stdio::piped())
- .stderr(process::Stdio::piped())
- .arg(expected)
- .spawn()
+ .arg(expected);
+
+ if cfg!(feature = "llvm_stable") {
+ cmd.arg("--feature")
+ .arg("llvm_stable");
+ }
+
+ cmd.spawn()
.expect("Should be able to spawn run-bindgen.py child process")
}
diff --git a/tests/tools/run-bindgen.py b/tests/tools/run-bindgen.py
index c9ddc4f2..ddd5d11b 100755
--- a/tests/tools/run-bindgen.py
+++ b/tests/tools/run-bindgen.py
@@ -9,7 +9,8 @@ import sys
import subprocess
import tempfile
-BINDGEN_FLAGS_PREFIX = "// bindgen-flags: ";
+BINDGEN_FLAGS_PREFIX = "// bindgen-flags: "
+BINDGEN_FEATURES_PREFIX = "// bindgen-features: "
COMMON_PRELUDE = """
#![allow(non_snake_case)]
@@ -35,6 +36,12 @@ def make_parser():
at this path already exists, the newly generated \
bindings will be checked against those extant \
expected bindings.")
+ parser.add_argument("--feature",
+ dest="features",
+ action="append",
+ nargs=1,
+ help="Run tests that depend on bindgen being built with \
+ the given feature.")
return parser
def usage_and_exit(*args):
@@ -49,6 +56,9 @@ def parse_args():
parser = make_parser()
args = parser.parse_args()
+ if args.features is None:
+ args.features = []
+
if not os.path.isfile(args.bindgen):
usage_and_exit("error: bindgen is not a file:", args.bindgen)
@@ -68,21 +78,34 @@ def make_bindgen_env():
return env
-def get_bindgen_flags_for_header(header_path):
- """Get the flags to pass to bindgen for this header."""
- flags = ["--no-unstable-rust"]
+def get_bindgen_flags_and_features(header_path):
+ """
+ Return the bindgen flags and features required for this header as a tuple
+ (flags, features).
+ """
+ found_flags = False
+ found_features = False
+ features = []
+ flags = ["--no-unstable-rust"]
for line in COMMON_PRELUDE.split("\n"):
flags.append("--raw-line")
flags.append(line)
with open(header_path) as f:
for line in f:
- if line.startswith(BINDGEN_FLAGS_PREFIX):
+ if not found_flags and line.startswith(BINDGEN_FLAGS_PREFIX):
flags.extend(line.strip().split(BINDGEN_FLAGS_PREFIX)[1].split(" "))
+ found_flags = True
+
+ if not found_features and line.startswith(BINDGEN_FEATURES_PREFIX):
+ features.extend(line.strip().split(BINDGEN_FEATURES_PREFIX)[1].split(" "))
+ found_features = True
+
+ if found_flags and found_features:
break
- return flags
+ return (flags, features)
def get_expected_bindings(rust_bindings_path):
"""
@@ -106,10 +129,10 @@ def run_cmd(command, **kwargs):
print("run-bindgen.py: running", command)
subprocess.check_call(command, **kwargs)
-def generate_bindings(bindgen, header, output):
+def generate_bindings(bindgen, flags, header, output):
"""Generate the rust bindings."""
command = [bindgen, "-o", output]
- command.extend(get_bindgen_flags_for_header(header))
+ command.extend(flags)
command.append(header)
run_cmd(command, cwd=os.getcwd(), env=make_bindgen_env())
@@ -152,8 +175,13 @@ def check_actual_vs_expected(expected_bindings, rust_bindings_path):
def main():
args = parse_args()
+
+ (test_flags, test_features) = get_bindgen_flags_and_features(args.header)
+ if not all(f in args.features for f in test_features):
+ sys.exit(0)
+
expected_bindings = get_expected_bindings(args.rust_bindings)
- generate_bindings(args.bindgen, args.header, args.rust_bindings)
+ generate_bindings(args.bindgen, test_flags, args.header, args.rust_bindings)
test_generated_bindings(args.rust_bindings)
check_actual_vs_expected(expected_bindings, args.rust_bindings)
sys.exit(0)