microsoft/openvmm
Publicmirrored from https://github.com/microsoft/openvmmAvailable
flowey/flowey_lib_common/src/cfg_cargo_common_flags.rs
94lines · modecode
| 1 | // Copyright (c) Microsoft Corporation. |
| 2 | // Licensed under the MIT License. |
| 3 | |
| 4 | //! Centralized configuration for setting "global" cargo command flags, such as |
| 5 | //! `--locked`, `--verbose`, etc... |
| 6 | //! |
| 7 | //! This node can then be depended on by nodes which do fine-grained ops with |
| 8 | //! cargo (e.g: `cargo build`, `cargo doc`, `cargo test`, etc...) to avoid |
| 9 | //! duping the same flag config all over the place. |
| 10 | |
| 11 | use flowey::node::prelude::*; |
| 12 | |
| 13 | #[derive(Serialize, Deserialize)] |
| 14 | pub struct Flags { |
| 15 | pub locked: bool, |
| 16 | pub verbose: bool, |
| 17 | pub no_incremental: bool, |
| 18 | } |
| 19 | |
| 20 | flowey_config! { |
| 21 | /// Config for the cfg_cargo_common_flags node. |
| 22 | pub struct Config { |
| 23 | pub locked: Option<bool>, |
| 24 | pub verbose: Option<ConfigVar<bool>>, |
| 25 | pub no_incremental: Option<bool>, |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | flowey_request! { |
| 30 | pub enum Request { |
| 31 | GetFlags(WriteVar<Flags>), |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | new_flow_node_with_config!(struct Node); |
| 36 | |
| 37 | impl FlowNodeWithConfig for Node { |
| 38 | type Request = Request; |
| 39 | type Config = Config; |
| 40 | |
| 41 | fn imports(ctx: &mut ImportCtx<'_>) { |
| 42 | ctx.import::<crate::install_rust::Node>(); |
| 43 | } |
| 44 | |
| 45 | fn emit( |
| 46 | config: Config, |
| 47 | requests: Vec<Self::Request>, |
| 48 | ctx: &mut NodeCtx<'_>, |
| 49 | ) -> anyhow::Result<()> { |
| 50 | let mut get_flags = Vec::new(); |
| 51 | |
| 52 | for req in requests { |
| 53 | match req { |
| 54 | Request::GetFlags(v) => get_flags.push(v), |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | let set_locked = config |
| 59 | .locked |
| 60 | .ok_or(anyhow::anyhow!("missing config: locked"))?; |
| 61 | let set_verbose = config |
| 62 | .verbose |
| 63 | .ok_or(anyhow::anyhow!("missing config: verbose"))?; |
| 64 | let set_no_incremental = config.no_incremental.unwrap_or(false); |
| 65 | let get_flags = get_flags; |
| 66 | |
| 67 | // -- end of req processing -- // |
| 68 | |
| 69 | if get_flags.is_empty() { |
| 70 | return Ok(()); |
| 71 | } |
| 72 | |
| 73 | ctx.emit_minor_rust_step("report common cargo flags", |ctx| { |
| 74 | let get_flags = get_flags.claim(ctx); |
| 75 | let set_verbose = set_verbose.claim(ctx); |
| 76 | |
| 77 | move |rt| { |
| 78 | let set_verbose = rt.read(set_verbose); |
| 79 | for var in get_flags { |
| 80 | rt.write( |
| 81 | var, |
| 82 | &Flags { |
| 83 | locked: set_locked, |
| 84 | verbose: set_verbose, |
| 85 | no_incremental: set_no_incremental, |
| 86 | }, |
| 87 | ); |
| 88 | } |
| 89 | } |
| 90 | }); |
| 91 | |
| 92 | Ok(()) |
| 93 | } |
| 94 | } |
| 95 | |