Skip to main content

flowey_lib_hvlite/_jobs/
cfg_common.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! An amalgamated configuration node that streamlines the process of resolving
5//! the most common subset of shared configuration requests required by OpenVMM
6//! pipelines.
7
8use flowey::node::prelude::*;
9
10#[derive(Clone, Serialize, Deserialize)]
11pub struct LocalOnlyParams {
12    /// Prompt the user before certain interesting operations (e.g:
13    /// installing packages from apt)
14    pub interactive: bool,
15    /// Automatically install any necessary system dependencies / tools.
16    pub auto_install: bool,
17    /// Ignore the Rust version requirement, and use whatever toolchain the user
18    /// currently has installed.
19    pub ignore_rust_version: bool,
20}
21
22flowey_request! {
23    #[derive(Clone)]
24    pub struct Params {
25        pub local_only: Option<LocalOnlyParams>,
26        pub verbose: ReadVar<bool>,
27        pub locked: bool,
28        pub deny_warnings: bool,
29        pub no_incremental: bool,
30    }
31}
32
33new_simple_flow_node!(struct Node);
34
35impl SimpleFlowNode for Node {
36    type Request = Params;
37
38    fn imports(ctx: &mut ImportCtx<'_>) {
39        ctx.import::<crate::resolve_openhcl_kernel_package::Node>();
40        ctx.import::<crate::resolve_openvmm_deps::Node>();
41        ctx.import::<crate::download_uefi_mu_msvm::Node>();
42        ctx.import::<crate::git_checkout_openvmm_repo::Node>();
43        ctx.import::<crate::init_openvmm_cargo_config_deny_warnings::Node>();
44        ctx.import::<crate::install_git_credential_manager::Node>();
45        ctx.import::<crate::install_openvmm_rust_build_essential::Node>();
46        ctx.import::<crate::install_vmm_tests_external_deps::Node>();
47        ctx.import::<flowey_lib_common::cfg_cargo_common_flags::Node>();
48        ctx.import::<flowey_lib_common::download_azcopy::Node>();
49        ctx.import::<flowey_lib_common::resolve_protoc::Node>();
50        ctx.import::<flowey_lib_common::git_checkout::Node>();
51        ctx.import::<flowey_lib_common::install_dist_pkg::Node>();
52        ctx.import::<flowey_lib_common::install_dotnet_cli::Node>();
53        ctx.import::<flowey_lib_common::install_azure_cli::Node>();
54        ctx.import::<flowey_lib_common::install_git::Node>();
55        ctx.import::<flowey_lib_common::install_nodejs::Node>();
56        ctx.import::<flowey_lib_common::install_rust::Node>();
57        ctx.import::<flowey_lib_common::nuget_install_package::Node>();
58        ctx.import::<flowey_lib_common::run_cargo_nextest_run::Node>();
59        ctx.import::<flowey_lib_common::use_gh_cli::Node>();
60    }
61
62    fn process_request(request: Self::Request, ctx: &mut NodeCtx<'_>) -> anyhow::Result<()> {
63        let Params {
64            local_only,
65            verbose,
66            locked,
67            deny_warnings,
68            no_incremental,
69        } = request;
70
71        if matches!(ctx.backend(), FlowBackend::Github | FlowBackend::Ado) {
72            if local_only.is_some() {
73                anyhow::bail!("can only set `local_only` params when using Local backend");
74            }
75
76            ctx.config(flowey_lib_common::install_rust::Config {
77                auto_install: Some(true),
78                ignore_version: Some(false),
79                ..Default::default()
80            });
81            if matches!(ctx.backend(), FlowBackend::Github) {
82                let token = ctx.get_gh_context_var().global().token();
83                ctx.config(flowey_lib_common::use_gh_cli::Config {
84                    auth: Some(flowey_lib_common::use_gh_cli::GhCliAuth::AuthToken(
85                        ConfigVar(token),
86                    )),
87                });
88            }
89        } else if matches!(ctx.backend(), FlowBackend::Local) {
90            let local_only =
91                local_only.ok_or(anyhow::anyhow!("missing essential request: local_only"))?;
92
93            let LocalOnlyParams {
94                interactive,
95                auto_install,
96                ignore_rust_version,
97            } = local_only;
98
99            // wire up `interactive`
100            {
101                ctx.config(flowey_lib_common::install_dist_pkg::Config {
102                    interactive: Some(interactive),
103                    ..Default::default()
104                });
105                ctx.config(flowey_lib_common::use_gh_cli::Config {
106                    auth: Some(flowey_lib_common::use_gh_cli::GhCliAuth::LocalOnlyInteractive),
107                });
108                ctx.config(flowey_lib_common::install_rust::Config {
109                    ignore_version: Some(ignore_rust_version),
110                    ..Default::default()
111                });
112            }
113
114            // wire up auto_install
115            {
116                ctx.config(flowey_lib_common::install_rust::Config {
117                    auto_install: Some(auto_install),
118                    ..Default::default()
119                });
120                ctx.config(flowey_lib_common::install_dist_pkg::Config {
121                    skip_update: Some(!auto_install),
122                    ..Default::default()
123                });
124                ctx.config(flowey_lib_common::install_nodejs::Config {
125                    auto_install: Some(auto_install),
126                    ..Default::default()
127                });
128                ctx.config(flowey_lib_common::install_azure_cli::Config {
129                    auto_install: Some(auto_install),
130                    ..Default::default()
131                });
132                ctx.config(flowey_lib_common::install_git::Config {
133                    auto_install: Some(auto_install),
134                });
135                ctx.config(flowey_lib_common::install_dotnet_cli::Config {
136                    auto_install: Some(auto_install),
137                    ..Default::default()
138                });
139                ctx.config(crate::install_vmm_tests_external_deps::Config {
140                    auto_install: Some(auto_install),
141                    selections: None,
142                });
143            }
144
145            // FUTURE: if we ever spin up a openvmm setup utility - it might be
146            // interesting to distribute a flowey-based tool that also clones
147            // the repo.
148            ctx.config(flowey_lib_common::git_checkout::Config {
149                require_local_clones: Some(true),
150            });
151        } else {
152            anyhow::bail!("unsupported backend")
153        }
154
155        ctx.config(flowey_lib_common::cfg_cargo_common_flags::Config {
156            locked: Some(locked),
157            verbose: Some(ConfigVar(verbose)),
158            no_incremental: Some(no_incremental),
159        });
160
161        ctx.config(crate::init_openvmm_cargo_config_deny_warnings::Config {
162            deny_warnings: Some(deny_warnings),
163        });
164
165        Ok(())
166    }
167}