Skip to main content

flowey_lib_hvlite/
init_openvmm_cargo_config_deny_warnings.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! Tweak `.cargo/config.toml` to deny warnings.
5
6use flowey::node::prelude::*;
7
8flowey_config! {
9    /// Config for the init_openvmm_cargo_config_deny_warnings node.
10    pub struct Config {
11        /// Whether to deny warnings in .cargo/config.toml
12        pub deny_warnings: Option<bool>,
13    }
14}
15
16flowey_request! {
17    pub enum Request {
18        Done(WriteVar<SideEffect>),
19    }
20}
21
22new_flow_node_with_config!(struct Node);
23
24impl FlowNodeWithConfig for Node {
25    type Request = Request;
26    type Config = Config;
27
28    fn imports(ctx: &mut ImportCtx<'_>) {
29        ctx.import::<crate::git_checkout_openvmm_repo::Node>();
30    }
31
32    fn emit(
33        config: Config,
34        requests: Vec<Self::Request>,
35        ctx: &mut NodeCtx<'_>,
36    ) -> anyhow::Result<()> {
37        let mut done = Vec::new();
38
39        for req in requests {
40            match req {
41                Request::Done(v) => done.push(v),
42            }
43        }
44
45        let deny_warnings = config
46            .deny_warnings
47            .ok_or(anyhow::anyhow!("missing config: deny_warnings"))?;
48
49        // -- end of req processing -- //
50
51        if done.is_empty() {
52            return Ok(());
53        }
54
55        if !deny_warnings {
56            ctx.emit_side_effect_step([], done);
57            return Ok(());
58        }
59
60        let openvmm_repo_path = ctx.reqv(crate::git_checkout_openvmm_repo::req::GetRepoDir);
61
62        ctx.emit_rust_step("set '-Dwarnings' in .cargo/config.toml", move |ctx| {
63            done.claim(ctx);
64            let openvmm_repo_path = openvmm_repo_path.claim(ctx);
65            move |rt| {
66                let path = rt.read(openvmm_repo_path).join(".cargo/config.toml");
67                let data = fs_err::read_to_string(&path)?;
68                let data = data.replace("### ENABLE_IN_CI", "");
69                fs_err::write(path, data)?;
70                Ok(())
71            }
72        });
73
74        Ok(())
75    }
76}