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            let token = ctx.get_gh_context_var().global().token();
91            ctx.req(flowey_lib_common::use_gh_cli::Request::WithAuth(
92                flowey_lib_common::use_gh_cli::GhCliAuth::AuthToken(token),
93            ));
94        } else if matches!(ctx.backend(), FlowBackend::Ado) {
95            if local_only.is_some() {
96                anyhow::bail!("can only set `local_only` params when using Local backend");
97            }
98
99            ctx.req(flowey_lib_common::install_azure_cli::Request::AutoInstall(
100                true,
101            ));
102        } else if matches!(ctx.backend(), FlowBackend::Local) {
103            let local_only =
104                local_only.ok_or(anyhow::anyhow!("missing essential request: local_only"))?;
105
106            let LocalOnlyParams {
107                interactive,
108                auto_install,
109                force_nuget_mono,
110                external_nuget_auth,
111                ignore_rust_version,
112            } = local_only;
113
114            // wire up `interactive`
115            {
116                ctx.req(
117                    flowey_lib_common::install_dist_pkg::Request::LocalOnlyInteractive(interactive),
118                );
119                ctx.req(
120                    flowey_lib_common::nuget_install_package::Request::LocalOnlyInteractive(
121                        interactive,
122                    ),
123                );
124                ctx.req(
125                    flowey_lib_common::nuget_install_package::Request::LocalOnlyInteractive(
126                        interactive,
127                    ),
128                );
129                ctx.req(flowey_lib_common::use_gh_cli::Request::WithAuth(
130                    flowey_lib_common::use_gh_cli::GhCliAuth::LocalOnlyInteractive,
131                ));
132                ctx.req(flowey_lib_common::install_rust::Request::IgnoreVersion(
133                    ignore_rust_version,
134                ));
135            }
136
137            // wire up auto_install
138            {
139                ctx.req(flowey_lib_common::install_rust::Request::AutoInstall(
140                    auto_install,
141                ));
142                ctx.req(
143                    flowey_lib_common::install_nuget_azure_credential_provider::Request::LocalOnlyAutoInstall(
144                        auto_install,
145                    ),
146                );
147                ctx.req(
148                    flowey_lib_common::install_dist_pkg::Request::LocalOnlySkipUpdate(
149                        !auto_install,
150                    ),
151                );
152                ctx.req(flowey_lib_common::install_nodejs::Request::AutoInstall(
153                    auto_install,
154                ));
155                ctx.req(flowey_lib_common::install_azure_cli::Request::AutoInstall(
156                    auto_install,
157                ));
158                ctx.req(
159                    flowey_lib_common::install_git::Request::LocalOnlyAutoInstall(auto_install),
160                );
161            }
162
163            //
164            // wire up misc.
165            //
166            ctx.req(
167                flowey_lib_common::install_nuget_azure_credential_provider::Request::LocalOnlySkipAuthCheck(
168                    external_nuget_auth,
169                ),
170            );
171
172            ctx.req(
173                flowey_lib_common::download_nuget_exe::Request::LocalOnlyForceWsl2MonoNugetExe(
174                    force_nuget_mono,
175                ),
176            );
177
178            // FUTURE: if we ever spin up a openvmm setup utility - it might be
179            // interesting to distribute a flowey-based tool that also clones
180            // the repo.
181            ctx.req(flowey_lib_common::git_checkout::Request::LocalOnlyRequireExistingClones(true));
182        } else {
183            anyhow::bail!("unsupported backend")
184        }
185
186        ctx.requests::<flowey_lib_common::cfg_cargo_common_flags::Node>([
187            flowey_lib_common::cfg_cargo_common_flags::Request::SetVerbose(verbose),
188            flowey_lib_common::cfg_cargo_common_flags::Request::SetLocked(locked),
189        ]);
190
191        ctx.req(
192            crate::init_openvmm_cargo_config_deny_warnings::Request::DenyWarnings(deny_warnings),
193        );
194
195        Ok(())
196    }
197}