Skip to main content

flowey_lib_hvlite/
git_checkout_openvmm_repo.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! Ensures that the OpenVMM repo is checked out, returning references to the
5//! repo's clone directory.
6
7use flowey::node::prelude::*;
8
9flowey_config! {
10    /// Config for the git_checkout_openvmm_repo node.
11    pub struct Config {
12        /// Specify which repo-id will be passed to the `git_checkout`
13        /// node.
14        pub repo_id: Option<ConfigVar<String>>,
15    }
16}
17
18flowey_request! {
19    pub enum_struct Request {
20        /// Get a path to the OpenVMM repo
21        GetRepoDir(pub WriteVar<PathBuf>),
22    }
23}
24
25new_flow_node_with_config!(struct Node);
26
27impl FlowNodeWithConfig for Node {
28    type Request = Request;
29    type Config = Config;
30
31    fn imports(ctx: &mut ImportCtx<'_>) {
32        ctx.import::<flowey_lib_common::git_checkout::Node>();
33        ctx.import::<flowey_lib_common::system_info::Node>();
34    }
35
36    fn emit(
37        config: Config,
38        requests: Vec<Self::Request>,
39        ctx: &mut NodeCtx<'_>,
40    ) -> anyhow::Result<()> {
41        let repo_id = config.repo_id.context("missing config: repo_id")?.0;
42        let mut reqs = Vec::new();
43
44        for req in requests {
45            match req {
46                Request::GetRepoDir(req::GetRepoDir(v)) => reqs.push(v),
47            }
48        }
49
50        if reqs.is_empty() {
51            return Ok(());
52        }
53
54        let path = ctx.reqv(|v| flowey_lib_common::git_checkout::Request::CheckoutRepo {
55            repo_id,
56            repo_path: v,
57            persist_credentials: false,
58        });
59
60        // request system info here so that it is placed early in the pipeline
61        // in case something fails.
62        // TODO: add the ability to specify that some nodes should come early in flowey
63        let printed_system_info = ctx.reqv(|v| flowey_lib_common::system_info::Request { done: v });
64
65        ctx.emit_minor_rust_step("resolve OpenVMM repo requests", move |ctx| {
66            printed_system_info.claim(ctx);
67            let path = path.claim(ctx);
68            let vars = reqs.claim(ctx);
69            move |rt| {
70                let path = rt.read(path);
71                for var in vars {
72                    rt.write(var, &path)
73                }
74            }
75        });
76
77        Ok(())
78    }
79}