From 8205bee93012d85614006799c8366e579329bd89 Mon Sep 17 00:00:00 2001 From: Dave Tucker Date: Tue, 17 May 2022 16:24:36 +0200 Subject: [PATCH] xtask: Add docs build Signed-off-by: Dave Tucker --- xtask/src/docs/mod.rs | 54 +++++++++++++++++++++++++++++++++++++++++++ xtask/src/main.rs | 3 +++ 2 files changed, 57 insertions(+) create mode 100644 xtask/src/docs/mod.rs diff --git a/xtask/src/docs/mod.rs b/xtask/src/docs/mod.rs new file mode 100644 index 00000000..cd48de24 --- /dev/null +++ b/xtask/src/docs/mod.rs @@ -0,0 +1,54 @@ +use std::{ + path::{Path, PathBuf}, + process::Command, +}; + +use std::{fs, io}; + +pub fn docs() -> Result<(), anyhow::Error> { + let mut working_dir = PathBuf::from("."); + + let args = vec![ + "+nightly", + "doc", + "--workspace", + "--no-deps", + "--all-features", + ]; + + let status = Command::new("cargo") + .current_dir(&working_dir) + .args(&args) + .status() + .expect("failed to build aya docs"); + assert!(status.success()); + + working_dir.push("bpf"); + let status = Command::new("cargo") + .current_dir(&working_dir) + .args(&args) + .status() + .expect("failed to build aya-bpf docs"); + assert!(status.success()); + + copy_dir_all("./bpf/target/doc", "./target/doc")?; + + Ok(()) +} + +fn copy_dir_all>(src: P, dst: P) -> io::Result<()> { + fs::create_dir_all(&dst)?; + for entry in fs::read_dir(src)? { + let entry = entry?; + let ty = entry.file_type()?; + if ty.is_dir() { + copy_dir_all(entry.path(), dst.as_ref().join(entry.file_name()))?; + } else { + let new_path = dst.as_ref().join(entry.file_name()); + if !new_path.exists() { + fs::copy(entry.path(), dst.as_ref().join(entry.file_name()))?; + } + } + } + Ok(()) +} diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 14a923a5..a11c16d3 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -1,4 +1,5 @@ mod codegen; +mod docs; use std::process::exit; @@ -12,6 +13,7 @@ pub struct Options { #[derive(StructOpt)] enum Command { Codegen(codegen::Options), + Docs, } fn main() { @@ -20,6 +22,7 @@ fn main() { use Command::*; let ret = match opts.command { Codegen(opts) => codegen::codegen(opts), + Docs => docs::docs(), }; if let Err(e) = ret {