microsoft/openvmm
Publicmirrored fromhttps://github.com/microsoft/openvmmAvailable
flowey/flowey_lib_hvlite/src/_jobs/cfg_common.rs
163lines · modecode
| 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 | |
| 8 | use flowey::node::prelude::*; |
| 9 | |
| 10 | #[derive(Clone, Serialize, Deserialize)] |
| 11 | pub 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 | |
| 22 | flowey_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 | } |
| 30 | } |
| 31 | |
| 32 | new_simple_flow_node!(struct Node); |
| 33 | |
| 34 | impl SimpleFlowNode for Node { |
| 35 | type Request = Params; |
| 36 | |
| 37 | fn imports(ctx: &mut ImportCtx<'_>) { |
| 38 | ctx.import::<crate::resolve_openhcl_kernel_package::Node>(); |
| 39 | ctx.import::<crate::resolve_openvmm_deps::Node>(); |
| 40 | ctx.import::<crate::download_uefi_mu_msvm::Node>(); |
| 41 | ctx.import::<crate::git_checkout_openvmm_repo::Node>(); |
| 42 | ctx.import::<crate::init_openvmm_cargo_config_deny_warnings::Node>(); |
| 43 | ctx.import::<crate::install_git_credential_manager::Node>(); |
| 44 | ctx.import::<crate::install_openvmm_rust_build_essential::Node>(); |
| 45 | ctx.import::<flowey_lib_common::cfg_cargo_common_flags::Node>(); |
| 46 | ctx.import::<flowey_lib_common::download_azcopy::Node>(); |
| 47 | ctx.import::<flowey_lib_common::download_cargo_nextest::Node>(); |
| 48 | ctx.import::<flowey_lib_common::resolve_protoc::Node>(); |
| 49 | ctx.import::<flowey_lib_common::git_checkout::Node>(); |
| 50 | ctx.import::<flowey_lib_common::install_dist_pkg::Node>(); |
| 51 | ctx.import::<flowey_lib_common::install_dotnet_cli::Node>(); |
| 52 | ctx.import::<flowey_lib_common::install_azure_cli::Node>(); |
| 53 | ctx.import::<flowey_lib_common::install_git::Node>(); |
| 54 | ctx.import::<flowey_lib_common::install_nodejs::Node>(); |
| 55 | ctx.import::<flowey_lib_common::install_rust::Node>(); |
| 56 | ctx.import::<flowey_lib_common::nuget_install_package::Node>(); |
| 57 | ctx.import::<flowey_lib_common::run_cargo_nextest_run::Node>(); |
| 58 | ctx.import::<flowey_lib_common::use_gh_cli::Node>(); |
| 59 | } |
| 60 | |
| 61 | fn process_request(request: Self::Request, ctx: &mut NodeCtx<'_>) -> anyhow::Result<()> { |
| 62 | let Params { |
| 63 | local_only, |
| 64 | verbose, |
| 65 | locked, |
| 66 | deny_warnings, |
| 67 | } = request; |
| 68 | |
| 69 | if matches!(ctx.backend(), FlowBackend::Github) { |
| 70 | if local_only.is_some() { |
| 71 | anyhow::bail!("can only set `local_only` params when using Local backend"); |
| 72 | } |
| 73 | |
| 74 | ctx.req(flowey_lib_common::install_azure_cli::Request::AutoInstall( |
| 75 | true, |
| 76 | )); |
| 77 | ctx.req(flowey_lib_common::install_rust::Request::AutoInstall(true)); |
| 78 | ctx.req(flowey_lib_common::install_rust::Request::IgnoreVersion( |
| 79 | false, |
| 80 | )); |
| 81 | let token = ctx.get_gh_context_var().global().token(); |
| 82 | ctx.req(flowey_lib_common::use_gh_cli::Request::WithAuth( |
| 83 | flowey_lib_common::use_gh_cli::GhCliAuth::AuthToken(token), |
| 84 | )); |
| 85 | } else if matches!(ctx.backend(), FlowBackend::Ado) { |
| 86 | if local_only.is_some() { |
| 87 | anyhow::bail!("can only set `local_only` params when using Local backend"); |
| 88 | } |
| 89 | |
| 90 | ctx.req(flowey_lib_common::install_azure_cli::Request::AutoInstall( |
| 91 | true, |
| 92 | )); |
| 93 | ctx.req(flowey_lib_common::install_rust::Request::AutoInstall(true)); |
| 94 | ctx.req(flowey_lib_common::install_rust::Request::IgnoreVersion( |
| 95 | false, |
| 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.req( |
| 110 | flowey_lib_common::install_dist_pkg::Request::LocalOnlyInteractive(interactive), |
| 111 | ); |
| 112 | ctx.req(flowey_lib_common::use_gh_cli::Request::WithAuth( |
| 113 | flowey_lib_common::use_gh_cli::GhCliAuth::LocalOnlyInteractive, |
| 114 | )); |
| 115 | ctx.req(flowey_lib_common::install_rust::Request::IgnoreVersion( |
| 116 | ignore_rust_version, |
| 117 | )); |
| 118 | } |
| 119 | |
| 120 | // wire up auto_install |
| 121 | { |
| 122 | ctx.req(flowey_lib_common::install_rust::Request::AutoInstall( |
| 123 | auto_install, |
| 124 | )); |
| 125 | ctx.req( |
| 126 | flowey_lib_common::install_dist_pkg::Request::LocalOnlySkipUpdate( |
| 127 | !auto_install, |
| 128 | ), |
| 129 | ); |
| 130 | ctx.req(flowey_lib_common::install_nodejs::Request::AutoInstall( |
| 131 | auto_install, |
| 132 | )); |
| 133 | ctx.req(flowey_lib_common::install_azure_cli::Request::AutoInstall( |
| 134 | auto_install, |
| 135 | )); |
| 136 | ctx.req( |
| 137 | flowey_lib_common::install_git::Request::LocalOnlyAutoInstall(auto_install), |
| 138 | ); |
| 139 | ctx.req(flowey_lib_common::install_dotnet_cli::Request::AutoInstall( |
| 140 | auto_install, |
| 141 | )); |
| 142 | } |
| 143 | |
| 144 | // FUTURE: if we ever spin up a openvmm setup utility - it might be |
| 145 | // interesting to distribute a flowey-based tool that also clones |
| 146 | // the repo. |
| 147 | ctx.req(flowey_lib_common::git_checkout::Request::LocalOnlyRequireExistingClones(true)); |
| 148 | } else { |
| 149 | anyhow::bail!("unsupported backend") |
| 150 | } |
| 151 | |
| 152 | ctx.requests::<flowey_lib_common::cfg_cargo_common_flags::Node>([ |
| 153 | flowey_lib_common::cfg_cargo_common_flags::Request::SetVerbose(verbose), |
| 154 | flowey_lib_common::cfg_cargo_common_flags::Request::SetLocked(locked), |
| 155 | ]); |
| 156 | |
| 157 | ctx.req( |
| 158 | crate::init_openvmm_cargo_config_deny_warnings::Request::DenyWarnings(deny_warnings), |
| 159 | ); |
| 160 | |
| 161 | Ok(()) |
| 162 | } |
| 163 | } |
| 164 | |