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_request! {
10    pub enum_struct Request {
11        /// Get a path to the OpenVMM repo
12        GetRepoDir(pub WriteVar<PathBuf>),
13        /// (config) specify which repo-id will be passed to the `git_checkout`
14        /// node. Can be used to dynamically change the OpenVMM repo source dir
15        /// based on a runtime parameter (e.g: a pipeline parameter).
16        SetRepoId(pub ReadVar<String>),
17    }
18}
19
20new_flow_node!(struct Node);
21
22impl FlowNode for Node {
23    type Request = Request;
24
25    fn imports(ctx: &mut ImportCtx<'_>) {
26        ctx.import::<flowey_lib_common::git_checkout::Node>();
27    }
28
29    fn emit(requests: Vec<Self::Request>, ctx: &mut NodeCtx<'_>) -> anyhow::Result<()> {
30        let mut repo_id = None;
31        let mut reqs = Vec::new();
32
33        for req in requests {
34            match req {
35                Request::GetRepoDir(req::GetRepoDir(v)) => reqs.push(v),
36                Request::SetRepoId(req::SetRepoId(v)) => {
37                    same_across_all_reqs_backing_var("SetRepoId", &mut repo_id, v)?
38                }
39            }
40        }
41
42        let repo_id = repo_id.context("missing SetRepoId request")?;
43
44        if reqs.is_empty() {
45            return Ok(());
46        }
47
48        let path = ctx.reqv(|v| flowey_lib_common::git_checkout::Request::CheckoutRepo {
49            repo_id,
50            repo_path: v,
51            persist_credentials: false,
52        });
53
54        ctx.emit_minor_rust_step("resolve OpenVMM repo requests", move |ctx| {
55            let path = path.claim(ctx);
56            let vars = reqs.claim(ctx);
57            move |rt| {
58                let path = rt.read(path);
59                for var in vars {
60                    rt.write(var, &path)
61                }
62            }
63        });
64
65        Ok(())
66    }
67}