2021-08-29 10:09:41 +02:00
|
|
|
use walkdir::{WalkDir, DirEntry};
|
|
|
|
|
|
|
|
fn is_hidden(entry: &DirEntry) -> bool {
|
|
|
|
entry.file_name()
|
|
|
|
.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)
|
|
|
|
}
|
|
|
|
|
2020-02-14 12:20:17 +01:00
|
|
|
fn main() {
|
2021-08-29 10:09:41 +02:00
|
|
|
let mut compile_command = ::capnpc::CompilerCommand::new();
|
2021-10-28 00:32:25 +02:00
|
|
|
compile_command.src_prefix("schema");
|
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
|
|
|
|
.filter(|e| e.file_name()
|
|
|
|
.to_str()
|
|
|
|
.map(|s| s.ends_with(".capnp"))
|
|
|
|
.unwrap_or(false)
|
|
|
|
)
|
|
|
|
{
|
|
|
|
println!("Collecting schema file {}", entry.path().display());
|
|
|
|
compile_command.file(entry.path());
|
|
|
|
}
|
|
|
|
|
|
|
|
println!("Compiling schemas...");
|
|
|
|
compile_command.run().expect("Failed to generate API code");
|
2020-02-14 12:20:17 +01:00
|
|
|
}
|