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) {
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            let token = ctx.get_gh_context_var().global().token();
82            ctx.config(flowey_lib_common::use_gh_cli::Config {
83                auth: Some(flowey_lib_common::use_gh_cli::GhCliAuth::AuthToken(
84                    ConfigVar(token),
85                )),
86            });
87        } else if matches!(ctx.backend(), FlowBackend::Ado) {
88            if local_only.is_some() {
89                anyhow::bail!("can only set `local_only` params when using Local backend");
90            }
91
92            ctx.config(flowey_lib_common::install_rust::Config {
93                auto_install: Some(true),
94                ignore_version: Some(false),
95                ..Default::default()
96            });
97        } else if matches!(ctx.backend(), FlowBackend::Local) {
98            let local_only =
99                local_only.ok_or(anyhow::anyhow!("missing essential request: local_only"))?;
100
101            let LocalOnlyParams {
102                interactive,
103                auto_install,
104                ignore_rust_version,
105            } = local_only;
106
107            // wire up `interactive`
108            {
109                ctx.config(flowey_lib_common::install_dist_pkg::Config {
110                    interactive: Some(interactive),
111                    ..Default::default()
112                });
113                ctx.config(flowey_lib_common::use_gh_cli::Config {
114                    auth: Some(flowey_lib_common::use_gh_cli::GhCliAuth::LocalOnlyInteractive),
115                });
116                ctx.config(flowey_lib_common::install_rust::Config {
117                    ignore_version: Some(ignore_rust_version),
118                    ..Default::default()
119                });
120            }
121
122            // wire up auto_install
123            {
124                ctx.config(flowey_lib_common::install_rust::Config {
125                    auto_install: Some(auto_install),
126                    ..Default::default()
127                });
128                ctx.config(flowey_lib_common::install_dist_pkg::Config {
129                    skip_update: Some(!auto_install),
130                    ..Default::default()
131                });
132                ctx.config(flowey_lib_common::install_nodejs::Config {
133                    auto_install: Some(auto_install),
134                    ..Default::default()
135                });
136                ctx.config(flowey_lib_common::install_azure_cli::Config {
137                    auto_install: Some(auto_install),
138                    ..Default::default()
139                });
140                ctx.config(flowey_lib_common::install_git::Config {
141                    auto_install: Some(auto_install),
142                });
143                ctx.config(flowey_lib_common::install_dotnet_cli::Config {
144                    auto_install: Some(auto_install),
145                    ..Default::default()
146                });
147                ctx.config(crate::install_vmm_tests_external_deps::Config {
148                    auto_install: Some(auto_install),
149                    selections: None,
150                });
151            }
152
153            // FUTURE: if we ever spin up a openvmm setup utility - it might be
154            // interesting to distribute a flowey-based tool that also clones
155            // the repo.
156            ctx.config(flowey_lib_common::git_checkout::Config {
157                require_local_clones: Some(true),
158            });
159        } else {
160            anyhow::bail!("unsupported backend")
161        }
162
163        ctx.config(flowey_lib_common::cfg_cargo_common_flags::Config {
164            locked: Some(locked),
165            verbose: Some(ConfigVar(verbose)),
166            no_incremental: Some(no_incremental),
167        });
168
169        ctx.config(crate::init_openvmm_cargo_config_deny_warnings::Config {
170            deny_warnings: Some(deny_warnings),
171        });
172
173        Ok(())
174    }
175}