mirror of
https://gitlab.com/fabinfra/fabaccess/bffh.git
synced 2024-11-22 14:57:56 +01:00
Make the build script smarter
This commit is contained in:
parent
076675370a
commit
678a274544
@ -67,6 +67,8 @@ genawaiter = "0.99"
|
|||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
capnpc = "0.14"
|
capnpc = "0.14"
|
||||||
|
# Used in build.rs to iterate over all files in schema/
|
||||||
|
walkdir = "2"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
futures-test = "0.3"
|
futures-test = "0.3"
|
||||||
|
42
build.rs
42
build.rs
@ -1,5 +1,39 @@
|
|||||||
fn main() {
|
use walkdir::{WalkDir, DirEntry};
|
||||||
::capnpc::CompilerCommand::new().file("schema/connection.capnp").run().unwrap();
|
|
||||||
::capnpc::CompilerCommand::new().file("schema/api.capnp").run().unwrap();
|
fn is_hidden(entry: &DirEntry) -> bool {
|
||||||
::capnpc::CompilerCommand::new().file("schema/auth.capnp").run().unwrap();
|
entry.file_name()
|
||||||
|
.to_str()
|
||||||
|
.map(|s| s.starts_with("."))
|
||||||
|
.unwrap_or(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
// Tell cargo to only run this script if the schema files or this script have changed
|
||||||
|
println!("cargo:rerun-if-changed=schema");
|
||||||
|
|
||||||
|
let mut compile_command = ::capnpc::CompilerCommand::new();
|
||||||
|
|
||||||
|
// Set parent module of all generated schema files.
|
||||||
|
// i.e. a file "user.capnp" will result in module "schema::user"
|
||||||
|
compile_command.default_parent_module(vec!["schema".into()]);
|
||||||
|
|
||||||
|
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");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user