From 6d756149a3e2da4b523c23049a34fbdd99079d80 Mon Sep 17 00:00:00 2001 From: Felix Krull Date: Thu, 18 Oct 2018 01:19:26 +0200 Subject: [PATCH] libostree: include API docs at build time using a feature flag --- rust-bindings/rust/libostree/Cargo.toml | 10 +++- rust-bindings/rust/libostree/build.rs | 68 +++++++++++++++++++++++++ 2 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 rust-bindings/rust/libostree/build.rs diff --git a/rust-bindings/rust/libostree/Cargo.toml b/rust-bindings/rust/libostree/Cargo.toml index 0b34ad4a..6a74d130 100644 --- a/rust-bindings/rust/libostree/Cargo.toml +++ b/rust-bindings/rust/libostree/Cargo.toml @@ -2,9 +2,9 @@ name = "libostree" version = "0.1.0" authors = ["Felix Krull"] +build = "build.rs" license = "MIT" -license-file = "LICENSE" description = "Rust bindings for libostree" keywords = ["ostree", "libostree"] @@ -30,3 +30,11 @@ libostree-sys = { version = "0.1", path = "../libostree-sys" } [dev-dependencies] tempfile = "3" + +[build-dependencies] +gir = { git = "https://github.com/gtk-rs/gir", optional = true } +rustdoc-stripper = { version = "0.1", optional = true } + +[features] +dox = ["libostree-sys/dox"] +lgpl-docs = ["gir", "rustdoc-stripper"] diff --git a/rust-bindings/rust/libostree/build.rs b/rust-bindings/rust/libostree/build.rs new file mode 100644 index 00000000..c611c826 --- /dev/null +++ b/rust-bindings/rust/libostree/build.rs @@ -0,0 +1,68 @@ +#![allow(dead_code)] + +#[cfg(feature = "lgpl-docs")] +extern crate libgir; + +#[cfg(feature = "lgpl-docs")] +extern crate stripper_lib; + +fn main() { + #[cfg(feature = "lgpl-docs")] { + extract_api_docs().expect("failed to extract API docs"); + merge_api_docs(); + } +} + +fn out_dir() -> String { + std::env::var("OUT_DIR").expect("missing var OUT_DIR") +} + +fn docs_file() -> String { + format!("{}/vendor.md", out_dir()) +} + +#[cfg(feature = "lgpl-docs")] +fn extract_api_docs() -> Result<(), String> { + let mut config = libgir::Config::new( + Some("../conf/libostree.toml"), + libgir::WorkMode::Doc, + None, + None, + None, + None, + Some(&docs_file()), + false, + false, + )?; + + let mut library = libgir::Library::new(&config.library_name); + library.read_file(&config.girs_dir, &config.library_full_name())?; + library.preprocessing(config.work_mode); + libgir::update_version::apply_config(&mut library, &config); + library.postprocessing(); + config.resolve_type_ids(&library); + libgir::update_version::check_function_real_version(&mut library); + + let namespaces = libgir::namespaces_run(&library); + let symbols = libgir::symbols_run(&library, &namespaces); + let class_hierarchy = libgir::class_hierarchy_run(&library); + + let mut env = libgir::Env { + library, + config, + namespaces, + symbols: std::cell::RefCell::new(symbols), + class_hierarchy, + analysis: Default::default(), + }; + + libgir::analysis_run(&mut env); + libgir::codegen_generate(&env); + + Ok(()) +} + +#[cfg(feature = "lgpl-docs")] +fn merge_api_docs() { + stripper_lib::regenerate_doc_comments(".", false, &docs_file(), false, false); +}