Skip to main content

flowey_lib_hvlite/_jobs/
build_and_run_doc_tests.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! Build and run the `cargo test` based doc tests.
5//!
6//! `cargo-nextest` does not currently support running doctests, hence the need
7//! for this separate job.
8
9use crate::common::{CommonArch, CommonProfile};
10use flowey::node::prelude::*;
11
12flowey_request! {
13    pub struct Params {
14        /// Build and run doc tests for the specified target
15        pub target: target_lexicon::Triple,
16        /// Build and run doc tests with the specified cargo profile
17        pub profile: CommonProfile,
18        pub done: WriteVar<SideEffect>,
19    }
20}
21
22new_simple_flow_node!(struct Node);
23
24impl SimpleFlowNode for Node {
25    type Request = Params;
26
27    fn imports(ctx: &mut ImportCtx<'_>) {
28        ctx.import::<crate::git_checkout_openvmm_repo::Node>();
29        ctx.import::<crate::init_openvmm_magicpath_openhcl_sysroot::Node>();
30        ctx.import::<crate::install_openvmm_rust_build_essential::Node>();
31    }
32
33    fn process_request(request: Self::Request, ctx: &mut NodeCtx<'_>) -> anyhow::Result<()> {
34        let Params {
35            target,
36            profile,
37            done,
38        } = request;
39
40        let rust_installed = ctx.reqv(crate::install_openvmm_rust_build_essential::Request);
41        let openvmm_repo_path = ctx.reqv(crate::git_checkout_openvmm_repo::req::GetRepoDir);
42        let sysroot_ready = if matches!(target.environment, target_lexicon::Environment::Musl) {
43            let arch = CommonArch::from_architecture(target.architecture)?;
44            Some(
45                ctx.reqv(|v| crate::init_openvmm_magicpath_openhcl_sysroot::Request {
46                    arch,
47                    path: v,
48                })
49                .into_side_effect(),
50            )
51        } else {
52            None
53        };
54
55        ctx.emit_rust_step(format!("run doctests for {target}"), |ctx| {
56            done.claim(ctx);
57            rust_installed.claim(ctx);
58            if let Some(sysroot_ready) = sysroot_ready {
59                sysroot_ready.claim(ctx);
60            }
61            let openvmm_repo_path = openvmm_repo_path.claim(ctx);
62            move |rt| {
63                let target = target.to_string();
64                let profile = match profile {
65                    CommonProfile::Release => "release",
66                    CommonProfile::Debug => "dev",
67                };
68
69                let path = rt.read(openvmm_repo_path);
70                rt.sh.change_dir(path);
71                flowey::shell_cmd!(rt, "cargo test --locked --doc --workspace --no-fail-fast --target {target} --profile {profile}").run()?;
72
73                Ok(())
74            }
75        });
76
77        Ok(())
78    }
79}