fabaccess-bffh/api/build.rs

43 lines
1.1 KiB
Rust
Raw Normal View History

2022-05-05 15:50:44 +02:00
use walkdir::{DirEntry, WalkDir};
2021-08-29 10:09:41 +02:00
fn is_hidden(entry: &DirEntry) -> bool {
2022-05-05 15:50:44 +02:00
entry
.file_name()
2021-08-29 10:09:41 +02:00
.to_str()
2021-09-19 18:17:42 +02:00
.map(|s| s.starts_with('.'))
2021-08-29 10:09:41 +02:00
.unwrap_or(false)
}
fn generate_api() {
2022-03-12 01:56:05 +01:00
println!("cargo:rerun-if-changed=schema");
2021-08-29 10:09:41 +02:00
let mut compile_command = ::capnpc::CompilerCommand::new();
2021-11-26 02:25:48 +01:00
compile_command
.src_prefix("schema")
.default_parent_module(vec!["schema".to_string()]);
2021-08-29 10:09:41 +02:00
for entry in WalkDir::new("schema")
.max_depth(2)
.into_iter()
.filter_entry(|e| !is_hidden(e))
.filter_map(Result::ok) // Filter all entries that access failed on
.filter(|e| !e.file_type().is_dir()) // Filter directories
// Filter non-schema files
2022-05-05 15:50:44 +02:00
.filter(|e| {
e.file_name()
.to_str()
.map(|s| s.ends_with(".capnp"))
.unwrap_or(false)
})
2021-08-29 10:09:41 +02:00
{
println!("Collecting schema file {}", entry.path().display());
2022-05-05 15:50:44 +02:00
compile_command.file(entry.path());
2021-08-29 10:09:41 +02:00
}
println!("Compiling schemas...");
compile_command.run().expect("Failed to generate API code");
2020-02-14 12:20:17 +01:00
}
2021-12-01 17:12:57 +01:00
fn main() {
generate_api();
2022-03-12 01:56:05 +01:00
}