1 | // Copyright © SixtyFPS GmbH <info@slint.dev> |
2 | // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-1.1 OR LicenseRef-Slint-commercial |
3 | |
4 | use std::io::{BufWriter, Write}; |
5 | use std::path::{Path, PathBuf}; |
6 | |
7 | /// The root dir of the git repository |
8 | fn root_dir() -> PathBuf { |
9 | let mut root: PathBuf = PathBuf::from(env!("CARGO_MANIFEST_DIR" )); |
10 | // $root/tests/driver/driver/ -> $root |
11 | root.pop(); |
12 | root.pop(); |
13 | root.pop(); |
14 | root |
15 | } |
16 | |
17 | fn main() -> Result<(), Box<dyn std::error::Error>> { |
18 | // Variables that cc.rs needs. |
19 | println!("cargo:rustc-env=TARGET= {}" , std::env::var("TARGET" ).unwrap()); |
20 | println!("cargo:rustc-env=HOST= {}" , std::env::var("HOST" ).unwrap()); |
21 | println!("cargo:rustc-env=OPT_LEVEL= {}" , std::env::var("OPT_LEVEL" ).unwrap()); |
22 | |
23 | // target/{debug|release}/build/package/out/ -> target/{debug|release} |
24 | let mut target_dir = PathBuf::from(std::env::var("OUT_DIR" ).unwrap()); |
25 | target_dir.pop(); |
26 | target_dir.pop(); |
27 | target_dir.pop(); |
28 | |
29 | println!("cargo:rustc-env=CPP_LIB_PATH= {}/deps" , target_dir.display()); |
30 | |
31 | let generated_include_dir = std::env::var_os("DEP_SLINT_CPP_GENERATED_INCLUDE_DIR" ) |
32 | .expect("the slint-cpp crate needs to provide the meta-data that points to the directory with the generated includes" ); |
33 | println!( |
34 | "cargo:rustc-env=GENERATED_CPP_HEADERS_PATH= {}" , |
35 | Path::new(&generated_include_dir).display() |
36 | ); |
37 | let root_dir = root_dir(); |
38 | println!("cargo:rustc-env=CPP_API_HEADERS_PATH= {}/api/cpp/include" , root_dir.display()); |
39 | |
40 | let tests_file_path = |
41 | std::path::Path::new(&std::env::var_os("OUT_DIR" ).unwrap()).join("test_functions.rs" ); |
42 | |
43 | let mut tests_file = BufWriter::new(std::fs::File::create(&tests_file_path)?); |
44 | |
45 | for testcase in test_driver_lib::collect_test_cases("cases" )?.into_iter().filter(|testcase| { |
46 | // Style testing not supported yet |
47 | testcase.requested_style.is_none() |
48 | }) { |
49 | let test_function_name = testcase.identifier(); |
50 | let ignored = testcase.is_ignored("cpp" ); |
51 | |
52 | write!( |
53 | tests_file, |
54 | r##" |
55 | #[test] |
56 | {ignore} |
57 | fn test_cpp_ {function_name}() {{ |
58 | cppdriver::test(&test_driver_lib::TestCase {{ |
59 | absolute_path: std::path::PathBuf::from(r#" {absolute_path}"#), |
60 | relative_path: std::path::PathBuf::from(r#" {relative_path}"#), |
61 | requested_style: None, |
62 | }}).unwrap(); |
63 | }} |
64 | |
65 | "## , |
66 | ignore = if ignored { "#[ignore]" } else { "" }, |
67 | function_name = test_function_name, |
68 | absolute_path = testcase.absolute_path.to_string_lossy(), |
69 | relative_path = testcase.relative_path.to_string_lossy(), |
70 | )?; |
71 | } |
72 | |
73 | println!("cargo:rustc-env=TEST_FUNCTIONS= {}" , tests_file_path.to_string_lossy()); |
74 | |
75 | Ok(()) |
76 | } |
77 | |