flowey_lib_common/
cfg_persistent_dir_cargo_install.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

//! A node which returns a PathBuf to a single shared persistent-dir that can be
//! used by any nodes invoking `cargo install` in order to share a single cargo
//! build cache.

use flowey::node::prelude::*;

flowey_request! {
    pub struct Request(pub WriteVar<Option<PathBuf>>);
}

new_flow_node!(struct Node);

impl FlowNode for Node {
    type Request = Request;

    fn imports(_ctx: &mut ImportCtx<'_>) {}

    fn emit(requests: Vec<Self::Request>, ctx: &mut NodeCtx<'_>) -> anyhow::Result<()> {
        let persistent_dir = ctx.persistent_dir();
        ctx.emit_minor_rust_step("report cargo install persistent dir", |ctx| {
            let persistent_dir = persistent_dir.claim(ctx);
            let requests = requests
                .into_iter()
                .map(|x| x.0.claim(ctx))
                .collect::<Vec<_>>();
            |rt| {
                let persistent_dir = persistent_dir.map(|x| rt.read(x));
                for var in requests {
                    rt.write(var, &persistent_dir)
                }
            }
        });

        Ok(())
    }
}