-
Notifications
You must be signed in to change notification settings - Fork 12
/
build.rs
80 lines (71 loc) · 2.52 KB
/
build.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Copyright (c) 2024 Jan Holthuis <[email protected]>
//
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy
// of the MPL was not distributed with this file, You can obtain one at
// http://mozilla.org/MPL/2.0/.
//
// SPDX-License-Identifier: MPL-2.0
use glob::glob;
use std::env;
use std::fs::File;
use std::io::Write;
use std::path::Path;
macro_rules! write_test {
($output_filepath:expr, $glob_pattern:literal, $header:literal, $body_path:literal) => {
let mut output_file = File::create($output_filepath).expect("failed to write test file");
writeln!(output_file, $header,).expect("failed to write test file header");
glob($glob_pattern)
.expect("failed to read glob pattern")
.map(|entry| entry.unwrap())
.for_each(|path| {
let name = path
.iter()
.skip(2)
.map(|component| component.to_str().unwrap())
.collect::<Vec<&str>>()
.join("_")
.replace(".", "_");
eprintln!("Writing setting test: {:?}", name);
writeln!(
output_file,
include_str!($body_path),
name = name,
filepath = path.canonicalize().unwrap().to_str().unwrap(),
)
.expect("failed to write test file body");
});
};
}
fn main() {
// Make cargo rerun the build script if the data directory changes.
println!("cargo:rerun-if-changed=data");
let out_dir = env::var("OUT_DIR").unwrap();
let out_dir = Path::new(&out_dir);
eprintln!("Writing tests to: {:?}", out_dir);
write_test!(
out_dir.join("tests_pdb.rs"),
"data/complete_export/*/PIONEER/rekordbox/export.pdb",
r#"// THIS FILE IS AUTOGENERATED - DO NOT EDIT!
use binrw::{{BinRead}};
use rekordcrate::pdb::Header;
"#,
"./tests/tests_pdb.rs.in"
);
write_test!(
out_dir.join("tests_anlz.rs"),
"data/complete_export/*/PIONEER/USBANLZ/*/*/ANLZ*.*",
r#"// THIS FILE IS AUTOGENERATED - DO NOT EDIT!
use rekordcrate::anlz::ANLZ;
"#,
"./tests/tests_anlz.rs.in"
);
write_test!(
out_dir.join("tests_setting.rs"),
"data/complete_export/*/PIONEER/*.DAT",
r#"// THIS FILE IS AUTOGENERATED - DO NOT EDIT!
use binrw::{{BinWrite, io::Cursor}};
use rekordcrate::setting::Setting;
"#,
"./tests/tests_setting.rs.in"
);
}