flowey_lib_common/
install_cargo_nextest.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! Install `cargo-nextest`.
5
6use flowey::node::prelude::*;
7
8flowey_request! {
9    pub struct Request(pub WriteVar<SideEffect>);
10}
11
12new_flow_node!(struct Node);
13
14impl FlowNode for Node {
15    type Request = Request;
16
17    fn imports(ctx: &mut ImportCtx<'_>) {
18        ctx.import::<crate::install_rust::Node>();
19        ctx.import::<crate::download_cargo_nextest::Node>();
20    }
21
22    fn emit(requests: Vec<Self::Request>, ctx: &mut NodeCtx<'_>) -> anyhow::Result<()> {
23        let mut done = Vec::new();
24
25        for req in requests {
26            done.push(req.0);
27        }
28
29        let done = done;
30
31        // -- end of req processing -- //
32
33        if done.is_empty() {
34            return Ok(());
35        }
36
37        let cargo_nextest_bin = ctx.platform().binary("cargo-nextest");
38
39        let nextest_path = ctx.reqv(|v| {
40            crate::download_cargo_nextest::Request::Get(
41                ReadVar::from_static(target_lexicon::Triple::host()),
42                v,
43            )
44        });
45        let cargo_home = ctx.reqv(crate::install_rust::Request::GetCargoHome);
46        let rust_installed = ctx.reqv(crate::install_rust::Request::EnsureInstalled);
47
48        ctx.emit_rust_step("installing cargo-nextest", |ctx| {
49            let nextest_path = nextest_path.claim(ctx);
50            let cargo_home = cargo_home.claim(ctx);
51            rust_installed.claim(ctx);
52            done.claim(ctx);
53
54            move |rt| {
55                let nextest_path = rt.read(nextest_path);
56                let cargo_home = rt.read(cargo_home);
57
58                // copy to cargo home bin folder so that nextest
59                // is accessible via `cargo nextest``
60                fs_err::copy(
61                    &nextest_path,
62                    cargo_home.join("bin").join(&cargo_nextest_bin),
63                )?;
64
65                Ok(())
66            }
67        });
68
69        Ok(())
70    }
71}