From 5011ddcf97ac7f09eb967dfe24f7d40d3fb3eb80 Mon Sep 17 00:00:00 2001 From: Nick Fitzgerald Date: Tue, 28 Nov 2017 10:49:44 -0800 Subject: [PATCH 1/2] Don't run test expectations' layout tests with multiple libclang versions Only generating bindings depends on which libclang version we are dealing with. Running the test expectations' layout tests does not change between libclang versions, so these were redundant tests. Note that we have not been testing the expected bindings that differ across libclang versions (the nested sub-directories aren't automatically picked up by cargo) and this commit does not change that. --- .travis.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index e5d0e105d2..79e35e425b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,14 +21,10 @@ env: - LLVM_VERSION="3.8.1" BINDGEN_JOB="test" BINDGEN_PROFILE="--release" - LLVM_VERSION="3.8.1" BINDGEN_JOB="integration" BINDGEN_PROFILE= - LLVM_VERSION="3.8.1" BINDGEN_JOB="integration" BINDGEN_PROFILE="--release" - - LLVM_VERSION="3.8.1" BINDGEN_JOB="expectations" BINDGEN_PROFILE= - - LLVM_VERSION="3.8.1" BINDGEN_JOB="expectations" BINDGEN_PROFILE="--release" - LLVM_VERSION="3.9.0" BINDGEN_JOB="test" BINDGEN_PROFILE= - LLVM_VERSION="3.9.0" BINDGEN_JOB="test" BINDGEN_PROFILE="--release" - LLVM_VERSION="3.9.0" BINDGEN_JOB="integration" BINDGEN_PROFILE= - LLVM_VERSION="3.9.0" BINDGEN_JOB="integration" BINDGEN_PROFILE="--release" - - LLVM_VERSION="3.9.0" BINDGEN_JOB="expectations" BINDGEN_PROFILE= - - LLVM_VERSION="3.9.0" BINDGEN_JOB="expectations" BINDGEN_PROFILE="--release" - LLVM_VERSION="4.0.0" BINDGEN_JOB="test" BINDGEN_PROFILE= - LLVM_VERSION="4.0.0" BINDGEN_JOB="test" BINDGEN_PROFILE="--release" - LLVM_VERSION="4.0.0" BINDGEN_JOB="test" BINDGEN_PROFILE= BINDGEN_FEATURES="testing_only_extra_assertions" From 1c2172f7516ae90edfcfdc9a71849c8a37fc97fa Mon Sep 17 00:00:00 2001 From: Nick Fitzgerald Date: Tue, 28 Nov 2017 11:34:43 -0800 Subject: [PATCH 2/2] Ensure that we run layout tests from libclang version-specific expectations This adds a build.rs to generate #[path="$FILE"] mod $FILE_AS_IDENT; for each $FILE in our libclang version-specific directories. We need to do this to get those files' layout tests to run because cargo doesn't automatically pick up tests in subdirectories. --- tests/expectations/build.rs | 60 +++++++++++++++++++ ...bclang_version_specific_generated_tests.rs | 1 + 2 files changed, 61 insertions(+) create mode 100644 tests/expectations/build.rs create mode 100644 tests/expectations/tests/libclang_version_specific_generated_tests.rs diff --git a/tests/expectations/build.rs b/tests/expectations/build.rs new file mode 100644 index 0000000000..0727ce51ab --- /dev/null +++ b/tests/expectations/build.rs @@ -0,0 +1,60 @@ +//! Generate a module with a custom `#[path=...]` for each of the files in our +//! libclang version-specific test expectations so that they get their layout +//! tests run. We need to do this because cargo doesn't automatically detect +//! tests subdirectories. + +use std::env; +use std::fs; +use std::io::Write; +use std::path::Path; + +const LIBCLANG_VERSION_DIRS: &'static [&'static str] = + &["libclang-3.8", "libclang-3.9", "libclang-4"]; + +fn main() { + println!("cargo:rerun-if-changed=build.rs"); + + let mut test_string = String::new(); + + for dir in LIBCLANG_VERSION_DIRS { + let dir = Path::new(&env::var_os("CARGO_MANIFEST_DIR").unwrap()) + .join("tests") + .join(dir); + + println!("cargo:rerun-if-changed={}", dir.display()); + + for entry in fs::read_dir(dir).unwrap() { + let entry = entry.unwrap(); + let path = entry.path(); + let path = path.canonicalize().unwrap_or_else(|_| path.into()); + if path.extension().map(|e| e.to_string_lossy()) != Some("rs".into()) { + continue; + } + + println!("cargo:rerun-if-changed={}", path.display()); + + let module_name: String = path.display() + .to_string() + .chars() + .map(|c| match c { + 'a'...'z' | 'A'...'Z' | '0'...'9' => c, + _ => '_', + }) + .collect(); + + test_string.push_str(&format!( + r###" +#[path = "{}"] +mod {}; +"###, + path.display(), + module_name, + )); + } + } + + let out_path = Path::new(&env::var_os("OUT_DIR").unwrap()) + .join("libclang_version_specific_generated_tests.rs"); + let mut test_file = fs::File::create(out_path).unwrap(); + test_file.write_all(test_string.as_bytes()).unwrap(); +} diff --git a/tests/expectations/tests/libclang_version_specific_generated_tests.rs b/tests/expectations/tests/libclang_version_specific_generated_tests.rs new file mode 100644 index 0000000000..93cf0d47cc --- /dev/null +++ b/tests/expectations/tests/libclang_version_specific_generated_tests.rs @@ -0,0 +1 @@ +include!(concat!(env!("OUT_DIR"), "/libclang_version_specific_generated_tests.rs"));