microsoft/openvmm

Public

mirrored fromhttps://github.com/microsoft/openvmmAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
1ce32569373cda4d4b485f6e6f09f15e1e4dd569

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

flowey/flowey_lib_hvlite/src/build_guide.rs

78lines · modecode

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! Build the OpenVMM Guide.
5
6use flowey::node::prelude::*;
7
8flowey_request! {
9 pub struct Request {
10 pub built_guide: WriteVar<PathBuf>,
11 }
12}
13
14new_flow_node!(struct Node);
15
16impl FlowNode for Node {
17 type Request = Request;
18
19 fn imports(ctx: &mut ImportCtx<'_>) {
20 ctx.import::<crate::git_checkout_openvmm_repo::Node>();
21 ctx.import::<flowey_lib_common::download_mdbook_admonish::Node>();
22 ctx.import::<flowey_lib_common::download_mdbook_mermaid::Node>();
23 ctx.import::<flowey_lib_common::download_mdbook::Node>();
24 ctx.import::<flowey_lib_common::install_rust::Node>();
25 }
26
27 fn emit(requests: Vec<Self::Request>, ctx: &mut NodeCtx<'_>) -> anyhow::Result<()> {
28 let mdbook_bin = ctx.reqv(flowey_lib_common::download_mdbook::Request::GetMdbook);
29 let mdbook_admonish_bin =
30 ctx.reqv(flowey_lib_common::download_mdbook_admonish::Request::GetMdbookAdmonish);
31 let mdbook_mermaid_bin =
32 ctx.reqv(flowey_lib_common::download_mdbook_mermaid::Request::GetMdbookMermaid);
33
34 let guide_source = ctx
35 .reqv(crate::git_checkout_openvmm_repo::req::GetRepoDir)
36 .map(ctx, |p| p.join("Guide"));
37
38 let rust_is_installed = ctx.reqv(flowey_lib_common::install_rust::Request::EnsureInstalled);
39
40 for Request { built_guide } in requests {
41 ctx.emit_rust_step("build OpenVMM guide (mdbook)", |ctx| {
42 // rust must be installed to build the `mdbook-openvmm-shim`
43 rust_is_installed.clone().claim(ctx);
44 let mdbook_bin = mdbook_bin.clone().claim(ctx);
45 let mdbook_admonish_bin = mdbook_admonish_bin.clone().claim(ctx);
46 let mdbook_mermaid_bin = mdbook_mermaid_bin.clone().claim(ctx);
47 let built_guide = built_guide.claim(ctx);
48 let guide_source = guide_source.clone().claim(ctx);
49 |rt| {
50 let mdbook_bin = rt.read(mdbook_bin);
51 let mdbook_admonish_bin = rt.read(mdbook_admonish_bin);
52 let mdbook_mermaid_bin = rt.read(mdbook_mermaid_bin);
53
54 let sh = xshell::Shell::new()?;
55
56 let out_path: PathBuf = sh.current_dir().absolute()?.join("book");
57 let guide_source: PathBuf = rt.read(guide_source);
58
59 sh.change_dir(&guide_source);
60 xshell::cmd!(
61 sh,
62 "{mdbook_bin} build {guide_source} --dest-dir {out_path}"
63 )
64 // intercepted by the `mdbook-openvmm-shim`
65 .env("SHIM_MDBOOK_ADMONISH", mdbook_admonish_bin)
66 .env("SHIM_MDBOOK_MERMAID", mdbook_mermaid_bin)
67 .run()?;
68
69 rt.write(built_guide, &out_path);
70
71 Ok(())
72 }
73 });
74 }
75
76 Ok(())
77 }
78}
79