|
@@ -8,67 +8,19 @@ use std::{fs, io, io::Write};
|
|
|
use indoc::indoc;
|
|
|
|
|
|
pub fn docs() -> Result<(), anyhow::Error> {
|
|
|
- let mut working_dir = PathBuf::from(".");
|
|
|
-
|
|
|
- let replace = Command::new("sed")
|
|
|
- .current_dir(&working_dir)
|
|
|
- .args(vec![
|
|
|
- "-i.bak",
|
|
|
- "s/crabby.svg/crabby_dev.svg/",
|
|
|
- "aya/src/lib.rs",
|
|
|
- ])
|
|
|
- .status()
|
|
|
- .expect("failed to replace logo");
|
|
|
- assert!(replace.success());
|
|
|
-
|
|
|
- let mut header_path = PathBuf::from(".");
|
|
|
- header_path.push("header.html");
|
|
|
+ let current_dir = PathBuf::from(".");
|
|
|
+ let header_path = current_dir.join("header.html");
|
|
|
let mut header = fs::File::create(&header_path).expect("can't create header.html");
|
|
|
header
|
|
|
.write_all(r#"<meta name="robots" content="noindex">"#.as_bytes())
|
|
|
.expect("can't write header.html contents");
|
|
|
header.flush().expect("couldn't flush contents");
|
|
|
-
|
|
|
let abs_header_path = fs::canonicalize(&header_path).unwrap();
|
|
|
- let args = vec!["+nightly", "doc", "--no-deps", "--all-features"];
|
|
|
-
|
|
|
- let status = Command::new("cargo")
|
|
|
- .current_dir(&working_dir)
|
|
|
- .env(
|
|
|
- "RUSTDOCFLAGS",
|
|
|
- format!("--html-in-header {}", abs_header_path.to_str().unwrap()),
|
|
|
- )
|
|
|
- .args(&args)
|
|
|
- .status()
|
|
|
- .expect("failed to build aya docs");
|
|
|
- assert!(status.success());
|
|
|
-
|
|
|
- working_dir.push("bpf");
|
|
|
-
|
|
|
- let replace = Command::new("sed")
|
|
|
- .current_dir(&working_dir)
|
|
|
- .args(vec![
|
|
|
- "-i.bak",
|
|
|
- "s/crabby.svg/crabby_dev.svg/",
|
|
|
- "aya-bpf/src/lib.rs",
|
|
|
- ])
|
|
|
- .status()
|
|
|
- .expect("failed to replace logo");
|
|
|
- assert!(replace.success());
|
|
|
-
|
|
|
- let status = Command::new("cargo")
|
|
|
- .current_dir(&working_dir)
|
|
|
- .env(
|
|
|
- "RUSTDOCFLAGS",
|
|
|
- format!("--html-in-header {}", abs_header_path.to_str().unwrap()),
|
|
|
- )
|
|
|
- .args(&args)
|
|
|
- .status()
|
|
|
- .expect("failed to build aya-bpf docs");
|
|
|
- assert!(status.success());
|
|
|
|
|
|
- copy_dir_all("./target/doc", "site/user")?;
|
|
|
- copy_dir_all("./bpf/target/doc", "site/bpf")?;
|
|
|
+ build_docs(¤t_dir.join("aya"), &abs_header_path)?;
|
|
|
+ build_docs(¤t_dir.join("bpf/aya-bpf"), &abs_header_path)?;
|
|
|
+ copy_dir_all("./target/doc", "./site/user")?;
|
|
|
+ copy_dir_all("./target/bpfel-unknown-none/doc", "./site/bpf")?;
|
|
|
|
|
|
let mut robots = fs::File::create("site/robots.txt").expect("can't create robots.txt");
|
|
|
robots
|
|
@@ -98,14 +50,38 @@ pub fn docs() -> Result<(), anyhow::Error> {
|
|
|
.as_bytes(),
|
|
|
)
|
|
|
.expect("can't write index.html");
|
|
|
+ Ok(())
|
|
|
+}
|
|
|
+
|
|
|
+fn build_docs(working_dir: &PathBuf, abs_header_path: &Path) -> Result<(), anyhow::Error> {
|
|
|
+ let replace = Command::new("sed")
|
|
|
+ .current_dir(&working_dir)
|
|
|
+ .args(vec!["-i.bak", "s/crabby.svg/crabby_dev.svg/", "src/lib.rs"])
|
|
|
+ .status()
|
|
|
+ .expect("failed to replace logo");
|
|
|
+ assert!(replace.success());
|
|
|
|
|
|
- fs::rename("aya/src/lib.rs.bak", "aya/src/lib.rs").unwrap();
|
|
|
- fs::rename("bpf/aya-bpf/src/lib.rs.bak", "bpf/aya-bpf/src/lib.rs").unwrap();
|
|
|
+ let args = vec!["+nightly", "doc", "--no-deps", "--all-features"];
|
|
|
|
|
|
+ let status = Command::new("cargo")
|
|
|
+ .current_dir(&working_dir)
|
|
|
+ .env(
|
|
|
+ "RUSTDOCFLAGS",
|
|
|
+ format!("--html-in-header {}", abs_header_path.to_str().unwrap()),
|
|
|
+ )
|
|
|
+ .args(&args)
|
|
|
+ .status()
|
|
|
+ .expect("failed to build aya docs");
|
|
|
+ assert!(status.success());
|
|
|
+ fs::rename(
|
|
|
+ working_dir.join("src/lib.rs.bak"),
|
|
|
+ working_dir.join("src/lib.rs"),
|
|
|
+ )
|
|
|
+ .unwrap();
|
|
|
Ok(())
|
|
|
}
|
|
|
|
|
|
-fn copy_dir_all<P: AsRef<Path>>(src: P, dst: P) -> io::Result<()> {
|
|
|
+fn copy_dir_all<P1: AsRef<Path>, P2: AsRef<Path>>(src: P1, dst: P2) -> io::Result<()> {
|
|
|
fs::create_dir_all(&dst)?;
|
|
|
for entry in fs::read_dir(src)? {
|
|
|
let entry = entry?;
|