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::download_lxutil::Node>();
46        ctx.import::<crate::download_openhcl_kernel_package::Node>();
47        ctx.import::<crate::download_openvmm_deps::Node>();
48        ctx.import::<crate::download_uefi_mu_msvm::Node>();
49        ctx.import::<crate::git_checkout_openvmm_repo::Node>();
50        ctx.import::<crate::init_openvmm_cargo_config_deny_warnings::Node>();
51        ctx.import::<crate::install_git_credential_manager::Node>();
52        ctx.import::<crate::install_openvmm_rust_build_essential::Node>();
53        ctx.import::<flowey_lib_common::cfg_cargo_common_flags::Node>();
54        ctx.import::<flowey_lib_common::download_azcopy::Node>();
55        ctx.import::<flowey_lib_common::download_cargo_nextest::Node>();
56        ctx.import::<flowey_lib_common::download_nuget_exe::Node>();
57        ctx.import::<flowey_lib_common::download_protoc::Node>();
58        ctx.import::<flowey_lib_common::git_checkout::Node>();
59        ctx.import::<flowey_lib_common::install_dist_pkg::Node>();
60        ctx.import::<flowey_lib_common::install_azure_cli::Node>();
61        ctx.import::<flowey_lib_common::install_git::Node>();
62        ctx.import::<flowey_lib_common::install_nodejs::Node>();
63        ctx.import::<flowey_lib_common::install_nuget_azure_credential_provider::Node>();
64        ctx.import::<flowey_lib_common::install_rust::Node>();
65        ctx.import::<flowey_lib_common::nuget_install_package::Node>();
66        ctx.import::<flowey_lib_common::run_cargo_nextest_run::Node>();
67        ctx.import::<flowey_lib_common::use_gh_cli::Node>();
68    }
69
70    fn process_request(request: Self::Request, ctx: &mut NodeCtx<'_>) -> anyhow::Result<()> {
71        let Params {
72            local_only,
73            verbose,
74            locked,
75            deny_warnings,
76        } = request;
77
78        if matches!(ctx.backend(), FlowBackend::Github) {
79            if local_only.is_some() {
80                anyhow::bail!("can only set `local_only` params when using Local backend");
81            }
82
83            ctx.req(flowey_lib_common::install_azure_cli::Request::AutoInstall(
84                true,
85            ));
86            ctx.req(flowey_lib_common::install_rust::Request::AutoInstall(true));
87            ctx.req(flowey_lib_common::install_rust::Request::IgnoreVersion(
88                false,
89            ));
90        } else if matches!(ctx.backend(), FlowBackend::Ado) {
91            if local_only.is_some() {
92                anyhow::bail!("can only set `local_only` params when using Local backend");
93            }
94
95            ctx.req(flowey_lib_common::install_azure_cli::Request::AutoInstall(
96                true,
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                force_nuget_mono,
106                external_nuget_auth,
107                ignore_rust_version,
108            } = local_only;
109
110            // wire up `interactive`
111            {
112                ctx.req(
113                    flowey_lib_common::install_dist_pkg::Request::LocalOnlyInteractive(interactive),
114                );
115                ctx.req(
116                    flowey_lib_common::nuget_install_package::Request::LocalOnlyInteractive(
117                        interactive,
118                    ),
119                );
120                ctx.req(
121                    flowey_lib_common::nuget_install_package::Request::LocalOnlyInteractive(
122                        interactive,
123                    ),
124                );
125                ctx.req(flowey_lib_common::use_gh_cli::Request::WithAuth(
126                    flowey_lib_common::use_gh_cli::GhCliAuth::LocalOnlyInteractive,
127                ));
128                ctx.req(flowey_lib_common::install_rust::Request::IgnoreVersion(
129                    ignore_rust_version,
130                ));
131            }
132
133            // wire up auto_install
134            {
135                ctx.req(flowey_lib_common::install_rust::Request::AutoInstall(
136                    auto_install,
137                ));
138                ctx.req(
139                    flowey_lib_common::install_nuget_azure_credential_provider::Request::LocalOnlyAutoInstall(
140                        auto_install,
141                    ),
142                );
143                ctx.req(
144                    flowey_lib_common::install_dist_pkg::Request::LocalOnlySkipUpdate(
145                        !auto_install,
146                    ),
147                );
148                ctx.req(flowey_lib_common::install_nodejs::Request::AutoInstall(
149                    auto_install,
150                ));
151                ctx.req(flowey_lib_common::install_azure_cli::Request::AutoInstall(
152                    auto_install,
153                ));
154                ctx.req(
155                    flowey_lib_common::install_git::Request::LocalOnlyAutoInstall(auto_install),
156                );
157            }
158
159            //
160            // wire up misc.
161            //
162            ctx.req(
163                flowey_lib_common::install_nuget_azure_credential_provider::Request::LocalOnlySkipAuthCheck(
164                    external_nuget_auth,
165                ),
166            );
167
168            ctx.req(
169                flowey_lib_common::download_nuget_exe::Request::LocalOnlyForceWsl2MonoNugetExe(
170                    force_nuget_mono,
171                ),
172            );
173
174            // FUTURE: if we ever spin up a openvmm setup utility - it might be
175            // interesting to distribute a flowey-based tool that also clones
176            // the repo.
177            ctx.req(flowey_lib_common::git_checkout::Request::LocalOnlyRequireExistingClones(true));
178        } else {
179            anyhow::bail!("unsupported backend")
180        }
181
182        ctx.requests::<flowey_lib_common::cfg_cargo_common_flags::Node>([
183            flowey_lib_common::cfg_cargo_common_flags::Request::SetVerbose(verbose),
184            flowey_lib_common::cfg_cargo_common_flags::Request::SetLocked(locked),
185        ]);
186
187        ctx.req(
188            crate::init_openvmm_cargo_config_deny_warnings::Request::DenyWarnings(deny_warnings),
189        );
190
191        Ok(())
192    }
193}