Debian Codegraph @

.cargo/vendor/cbindgen/build.rs

raw
1 fn generate_tests() {
2 use std::env;
3 use std::ffi::OsStr;
4 use std::fs::{self, File};
5 use std::io::Write;
6 use std::path::{Path, PathBuf};
7
8 let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
9 let mut dst = File::create(Path::new(&out_dir).join("tests.rs")).unwrap();
10
11 let manifest_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());
12 let tests_dir = manifest_dir.join("tests").join("rust");
13 let tests = fs::read_dir(&tests_dir).unwrap();
14
15 let entries = tests.map(|t| t.expect("Couldn't read test file"));
16
17 println!("cargo:rerun-if-changed={}", tests_dir.display());
18
19 for entry in entries {
20 let path_segment = if entry.file_type().unwrap().is_file() {
21 match entry.path().extension().and_then(OsStr::to_str) {
22 Some("rs") => {}
23 _ => continue,
24 };
25
26 entry
27 .path()
28 .file_stem()
29 .unwrap()
30 .to_str()
31 .unwrap()
32 .to_owned()
33 } else {
34 entry.file_name().to_str().unwrap().to_owned()
35 };
36
37 let identifier = path_segment
38 .replace(|c| !char::is_alphanumeric(c), "_")
39 .replace("__", "_");
40
41 writeln!(
42 dst,
43 "test_file!(test_{}, {:?}, {:?});",
44 identifier,
45 path_segment,
46 entry.path(),
47 )
48 .unwrap();
49 }
50
51 dst.flush().unwrap();
52 }
53
54 fn generate_depfile_tests() {
55 use std::env;
56 use std::fs::{self, File};
57 use std::io::Write;
58 use std::path::{Path, PathBuf};
59
60 let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
61 let mut dst = File::create(Path::new(&out_dir).join("depfile_tests.rs")).unwrap();
62
63 let manifest_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());
64 let tests_dir = manifest_dir.join("tests").join("depfile");
65 let tests = fs::read_dir(&tests_dir).unwrap();
66
67 let entries = tests.map(|t| t.expect("Couldn't read test file"));
68
69 println!("cargo:rerun-if-changed={}", tests_dir.display());
70
71 for entry in entries {
72 if entry.file_type().unwrap().is_file() {
73 continue;
74 };
75 let path_segment = entry.file_name().to_str().unwrap().to_owned();
76
77 let identifier = path_segment
78 .replace(|c| !char::is_alphanumeric(c), "_")
79 .replace("__", "_");
80
81 writeln!(
82 dst,
83 "test_file!(test_depfile_{}, {:?}, {:?});",
84 identifier,
85 path_segment,
86 entry.path(),
87 )
88 .unwrap();
89 }
90
91 dst.flush().unwrap();
92 }
93
94 fn main() {
95 generate_tests();
96 generate_depfile_tests();
97 }