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_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::download_cargo_nextest::Node>();
50        ctx.import::<flowey_lib_common::resolve_protoc::Node>();
51        ctx.import::<flowey_lib_common::git_checkout::Node>();
52        ctx.import::<flowey_lib_common::install_dist_pkg::Node>();
53        ctx.import::<flowey_lib_common::install_dotnet_cli::Node>();
54        ctx.import::<flowey_lib_common::install_azure_cli::Node>();
55        ctx.import::<flowey_lib_common::install_git::Node>();
56        ctx.import::<flowey_lib_common::install_nodejs::Node>();
57        ctx.import::<flowey_lib_common::install_rust::Node>();
58        ctx.import::<flowey_lib_common::nuget_install_package::Node>();
59        ctx.import::<flowey_lib_common::run_cargo_nextest_run::Node>();
60        ctx.import::<flowey_lib_common::use_gh_cli::Node>();
61    }
62
63    fn process_request(request: Self::Request, ctx: &mut NodeCtx<'_>) -> anyhow::Result<()> {
64        let Params {
65            local_only,
66            verbose,
67            locked,
68            deny_warnings,
69            no_incremental,
70        } = request;
71
72        if matches!(ctx.backend(), FlowBackend::Github) {
73            if local_only.is_some() {
74                anyhow::bail!("can only set `local_only` params when using Local backend");
75            }
76
77            ctx.config(flowey_lib_common::install_rust::Config {
78                auto_install: Some(true),
79                ignore_version: Some(false),
80                ..Default::default()
81            });
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        } else if matches!(ctx.backend(), FlowBackend::Ado) {
89            if local_only.is_some() {
90                anyhow::bail!("can only set `local_only` params when using Local backend");
91            }
92
93            ctx.config(flowey_lib_common::install_rust::Config {
94                auto_install: Some(true),
95                ignore_version: Some(false),
96                ..Default::default()
97            });
98        } else if matches!(ctx.backend(), FlowBackend::Local) {
99            let local_only =
100                local_only.ok_or(anyhow::anyhow!("missing essential request: local_only"))?;
101
102            let LocalOnlyParams {
103                interactive,
104                auto_install,
105                ignore_rust_version,
106            } = local_only;
107
108            // wire up `interactive`
109            {
110                ctx.config(flowey_lib_common::install_dist_pkg::Config {
111                    interactive: Some(interactive),
112                    ..Default::default()
113                });
114                ctx.config(flowey_lib_common::use_gh_cli::Config {
115                    auth: Some(flowey_lib_common::use_gh_cli::GhCliAuth::LocalOnlyInteractive),
116                });
117                ctx.config(flowey_lib_common::install_rust::Config {
118                    ignore_version: Some(ignore_rust_version),
119                    ..Default::default()
120                });
121            }
122
123            // wire up auto_install
124            {
125                ctx.config(flowey_lib_common::install_rust::Config {
126                    auto_install: Some(auto_install),
127                    ..Default::default()
128                });
129                ctx.config(flowey_lib_common::install_dist_pkg::Config {
130                    skip_update: Some(!auto_install),
131                    ..Default::default()
132                });
133                ctx.config(flowey_lib_common::install_nodejs::Config {
134                    auto_install: Some(auto_install),
135                    ..Default::default()
136                });
137                ctx.config(flowey_lib_common::install_azure_cli::Config {
138                    auto_install: Some(auto_install),
139                    ..Default::default()
140                });
141                ctx.config(flowey_lib_common::install_git::Config {
142                    auto_install: Some(auto_install),
143                });
144                ctx.config(flowey_lib_common::install_dotnet_cli::Config {
145                    auto_install: Some(auto_install),
146                    ..Default::default()
147                });
148                ctx.config(crate::install_vmm_tests_deps::Config {
149                    auto_install: Some(auto_install),
150                    selections: None,
151                });
152            }
153
154            // FUTURE: if we ever spin up a openvmm setup utility - it might be
155            // interesting to distribute a flowey-based tool that also clones
156            // the repo.
157            ctx.config(flowey_lib_common::git_checkout::Config {
158                require_local_clones: Some(true),
159            });
160        } else {
161            anyhow::bail!("unsupported backend")
162        }
163
164        ctx.config(flowey_lib_common::cfg_cargo_common_flags::Config {
165            locked: Some(locked),
166            verbose: Some(ConfigVar(verbose)),
167            no_incremental: Some(no_incremental),
168        });
169
170        ctx.config(crate::init_openvmm_cargo_config_deny_warnings::Config {
171            deny_warnings: Some(deny_warnings),
172        });
173
174        Ok(())
175    }
176}