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    /// (WSL2 only) Use `mono` to run `nuget.exe`, instead of using native
18    /// WSL2 interop.
19    pub force_nuget_mono: bool,
20    /// Claim that nuget is using an external auth mechanism, and Azure
21    /// Credential Provider doesn't need to be present to pull down required
22    /// packages.
23    pub external_nuget_auth: bool,
24    /// Ignore the Rust version requirement, and use whatever toolchain the user
25    /// currently has installed.
26    pub ignore_rust_version: bool,
27}
28
29flowey_request! {
30    #[derive(Clone)]
31    pub struct Params {
32        pub local_only: Option<LocalOnlyParams>,
33        pub verbose: ReadVar<bool>,
34        pub locked: bool,
35        pub deny_warnings: bool,
36    }
37}
38
39new_simple_flow_node!(struct Node);
40
41impl SimpleFlowNode for Node {
42    type Request = Params;
43
44    fn imports(ctx: &mut ImportCtx<'_>) {
45        ctx.import::<crate::resolve_openhcl_kernel_package::Node>();
46        ctx.import::<crate::resolve_openvmm_deps::Node>();
47        ctx.import::<crate::download_uefi_mu_msvm::Node>();
48        ctx.import::<crate::git_checkout_openvmm_repo::Node>();
49        ctx.import::<crate::init_openvmm_cargo_config_deny_warnings::Node>();
50        ctx.import::<crate::install_git_credential_manager::Node>();
51        ctx.import::<crate::install_openvmm_rust_build_essential::Node>();
52        ctx.import::<flowey_lib_common::cfg_cargo_common_flags::Node>();
53        ctx.import::<flowey_lib_common::download_azcopy::Node>();
54        ctx.import::<flowey_lib_common::download_cargo_nextest::Node>();
55        ctx.import::<flowey_lib_common::download_nuget_exe::Node>();
56        ctx.import::<flowey_lib_common::resolve_protoc::Node>();
57        ctx.import::<flowey_lib_common::git_checkout::Node>();
58        ctx.import::<flowey_lib_common::install_dist_pkg::Node>();
59        ctx.import::<flowey_lib_common::install_azure_cli::Node>();
60        ctx.import::<flowey_lib_common::install_git::Node>();
61        ctx.import::<flowey_lib_common::install_nodejs::Node>();
62        ctx.import::<flowey_lib_common::install_nuget_azure_credential_provider::Node>();
63        ctx.import::<flowey_lib_common::install_rust::Node>();
64        ctx.import::<flowey_lib_common::nuget_install_package::Node>();
65        ctx.import::<flowey_lib_common::run_cargo_nextest_run::Node>();
66        ctx.import::<flowey_lib_common::use_gh_cli::Node>();
67    }
68
69    fn process_request(request: Self::Request, ctx: &mut NodeCtx<'_>) -> anyhow::Result<()> {
70        let Params {
71            local_only,
72            verbose,
73            locked,
74            deny_warnings,
75        } = request;
76
77        if matches!(ctx.backend(), FlowBackend::Github) {
78            if local_only.is_some() {
79                anyhow::bail!("can only set `local_only` params when using Local backend");
80            }
81
82            ctx.req(flowey_lib_common::install_azure_cli::Request::AutoInstall(
83                true,
84            ));
85            ctx.req(flowey_lib_common::install_rust::Request::AutoInstall(true));
86            ctx.req(flowey_lib_common::install_rust::Request::IgnoreVersion(
87                false,
88            ));
89            let token = ctx.get_gh_context_var().global().token();
90            ctx.req(flowey_lib_common::use_gh_cli::Request::WithAuth(
91                flowey_lib_common::use_gh_cli::GhCliAuth::AuthToken(token),
92            ));
93        } else if matches!(ctx.backend(), FlowBackend::Ado) {
94            if local_only.is_some() {
95                anyhow::bail!("can only set `local_only` params when using Local backend");
96            }
97
98            ctx.req(flowey_lib_common::install_azure_cli::Request::AutoInstall(
99                true,
100            ));
101            ctx.req(flowey_lib_common::install_rust::Request::AutoInstall(true));
102            ctx.req(flowey_lib_common::install_rust::Request::IgnoreVersion(
103                false,
104            ));
105        } else if matches!(ctx.backend(), FlowBackend::Local) {
106            let local_only =
107                local_only.ok_or(anyhow::anyhow!("missing essential request: local_only"))?;
108
109            let LocalOnlyParams {
110                interactive,
111                auto_install,
112                force_nuget_mono,
113                external_nuget_auth,
114                ignore_rust_version,
115            } = local_only;
116
117            // wire up `interactive`
118            {
119                ctx.req(
120                    flowey_lib_common::install_dist_pkg::Request::LocalOnlyInteractive(interactive),
121                );
122                ctx.req(
123                    flowey_lib_common::nuget_install_package::Request::LocalOnlyInteractive(
124                        interactive,
125                    ),
126                );
127                ctx.req(
128                    flowey_lib_common::nuget_install_package::Request::LocalOnlyInteractive(
129                        interactive,
130                    ),
131                );
132                ctx.req(flowey_lib_common::use_gh_cli::Request::WithAuth(
133                    flowey_lib_common::use_gh_cli::GhCliAuth::LocalOnlyInteractive,
134                ));
135                ctx.req(flowey_lib_common::install_rust::Request::IgnoreVersion(
136                    ignore_rust_version,
137                ));
138            }
139
140            // wire up auto_install
141            {
142                ctx.req(flowey_lib_common::install_rust::Request::AutoInstall(
143                    auto_install,
144                ));
145                ctx.req(
146                    flowey_lib_common::install_nuget_azure_credential_provider::Request::LocalOnlyAutoInstall(
147                        auto_install,
148                    ),
149                );
150                ctx.req(
151                    flowey_lib_common::install_dist_pkg::Request::LocalOnlySkipUpdate(
152                        !auto_install,
153                    ),
154                );
155                ctx.req(flowey_lib_common::install_nodejs::Request::AutoInstall(
156                    auto_install,
157                ));
158                ctx.req(flowey_lib_common::install_azure_cli::Request::AutoInstall(
159                    auto_install,
160                ));
161                ctx.req(
162                    flowey_lib_common::install_git::Request::LocalOnlyAutoInstall(auto_install),
163                );
164            }
165
166            //
167            // wire up misc.
168            //
169            ctx.req(
170                flowey_lib_common::install_nuget_azure_credential_provider::Request::LocalOnlySkipAuthCheck(
171                    external_nuget_auth,
172                ),
173            );
174
175            ctx.req(
176                flowey_lib_common::download_nuget_exe::Request::LocalOnlyForceWsl2MonoNugetExe(
177                    force_nuget_mono,
178                ),
179            );
180
181            // FUTURE: if we ever spin up a openvmm setup utility - it might be
182            // interesting to distribute a flowey-based tool that also clones
183            // the repo.
184            ctx.req(flowey_lib_common::git_checkout::Request::LocalOnlyRequireExistingClones(true));
185        } else {
186            anyhow::bail!("unsupported backend")
187        }
188
189        ctx.requests::<flowey_lib_common::cfg_cargo_common_flags::Node>([
190            flowey_lib_common::cfg_cargo_common_flags::Request::SetVerbose(verbose),
191            flowey_lib_common::cfg_cargo_common_flags::Request::SetLocked(locked),
192        ]);
193
194        ctx.req(
195            crate::init_openvmm_cargo_config_deny_warnings::Request::DenyWarnings(deny_warnings),
196        );
197
198        Ok(())
199    }
200}