Skip to main content

flowey_hvlite/pipelines/
restore_packages.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4use crate::pipelines_shared::cfg_common_params::CommonArchCli;
5use flowey::node::prelude::ReadVar;
6use flowey::pipeline::prelude::*;
7
8/// Download and restore packages needed for building the specified architectures.
9#[derive(clap::Args)]
10pub struct RestorePackagesCli {
11    /// Specify what architectures to restore packages for.
12    ///
13    /// If none are specified, defaults to just the current host architecture.
14    arch: Vec<CommonArchCli>,
15
16    /// Skip downloading released OpenHCL IGVM files used for compatibility testing.
17    ///
18    /// This avoids the need for `gh` CLI authentication.
19    #[clap(long)]
20    no_compat_igvm: bool,
21}
22
23impl IntoPipeline for RestorePackagesCli {
24    fn into_pipeline(self, backend_hint: PipelineBackendHint) -> anyhow::Result<Pipeline> {
25        let openvmm_repo = flowey_lib_common::git_checkout::RepoSource::ExistingClone(
26            ReadVar::from_static(crate::repo_root()),
27        );
28
29        let mut pipeline = Pipeline::new();
30        let pub_last_release_igvm_files = if self.no_compat_igvm {
31            None
32        } else {
33            Some(pipeline.new_artifact("last-release-igvm-files").0)
34        };
35        let mut job = pipeline
36            .new_job(
37                FlowPlatform::host(backend_hint),
38                FlowArch::host(backend_hint),
39                "restore packages",
40            )
41            .dep_on(|_| flowey_lib_hvlite::_jobs::cfg_versions::Request::Init)
42            .dep_on(
43                |_| flowey_lib_hvlite::_jobs::cfg_hvlite_reposource::Params {
44                    hvlite_repo_source: openvmm_repo,
45                },
46            )
47            .dep_on(|_| flowey_lib_hvlite::_jobs::cfg_common::Params {
48                local_only: Some(flowey_lib_hvlite::_jobs::cfg_common::LocalOnlyParams {
49                    interactive: true,
50                    auto_install: true,
51                    ignore_rust_version: true,
52                }),
53                verbose: ReadVar::from_static(true),
54                locked: false,
55                deny_warnings: false,
56                no_incremental: false,
57            });
58
59        let arches = {
60            if self.arch.is_empty() {
61                vec![FlowArch::host(backend_hint).try_into()?]
62            } else {
63                self.arch
64            }
65        };
66
67        let arches = arches.into_iter().map(|arch| arch.into()).collect();
68
69        job = job.dep_on(
70            |ctx| flowey_lib_hvlite::_jobs::local_restore_packages::Request {
71                arches,
72                done: ctx.new_done_handle(),
73                release_artifact: pub_last_release_igvm_files.map(|a| ctx.publish_artifact(a)),
74            },
75        );
76        job.finish();
77        Ok(pipeline)
78    }
79}