提交 79280142 编写于 作者: Y Yi Huang 提交者: hydai

[Misc] Add scripts to generate witx docs.

上级 e3e7f433
# SPDX-License-Identifier: Apache-2.0
# ignore generated markdown files
/*.md
# SPDX-License-Identifier: Apache-2.0
/target
Cargo.lock
[package]
name = "witx-doc"
version = "0.0.0"
edition = "2018"
[dependencies]
witx = "^0.8.8"
#!/usr/bin/env bash
# SPDX-License-Identifier: Apache-2.0
set -x
WD="$(realpath $(dirname "${BASH_SOURCE[0]}"))"
ROOT="$(realpath $WD/../../)"
WITX_DIR="$ROOT/doc/witx"
cd $WD
cargo build --release
target/release/witx-doc "$WITX_DIR"
// SPDX-License-Identifier: Apache-2.0
use std::{
ffi::OsStr,
fs,
io::{self, Write},
path::PathBuf,
process,
};
use witx::{self, Documentation};
fn main() -> io::Result<()> {
let arg1 = std::env::args().nth(1).expect("args 1 = witx root-dir");
let dirname = PathBuf::from(arg1);
let sources = fs::read_dir(dirname.as_path())?
.filter_map(|res| {
res.map_or(None, |i| {
let p = i.path();
match p.extension().and_then(OsStr::to_str) {
Some("witx") => Some(p),
_ => {
println!("skipped {:?}", p);
None
}
}
})
})
.collect::<Vec<_>>();
println!("sources: {:?}", sources);
match witx::load(&sources) {
Ok(doc) => {
let docfile = dirname.join("docs.md");
println!("docfile: {:?}", docfile);
let mut file = fs::File::create(docfile).expect("create output file");
file.write_all(doc.to_md().as_bytes())
.expect("write output file");
}
Err(e) => {
eprintln!("{}", e.report());
process::exit(7);
}
};
Ok(())
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册