Skip to main content

canic_host/release_set/paths/
artifacts.rs

1use std::path::{Path, PathBuf};
2use thiserror::Error as ThisError;
3
4use super::super::ROOT_RELEASE_SET_MANIFEST_FILE;
5
6/// Failure to locate the exact artifact root for a selected artifact environment.
7#[derive(Debug, Eq, PartialEq, ThisError)]
8pub enum ArtifactRootError {
9    #[error("missing built ICP artifacts under {artifact_root}")]
10    Missing { artifact_root: PathBuf },
11}
12
13/// Resolve the built artifact directory for the selected artifact environment.
14pub fn resolve_artifact_root(
15    icp_root: &Path,
16    artifact_environment: &str,
17) -> Result<PathBuf, ArtifactRootError> {
18    let artifact_root = artifact_root_path(icp_root, artifact_environment);
19    if artifact_root.is_dir() {
20        return Ok(artifact_root);
21    }
22
23    Err(ArtifactRootError::Missing { artifact_root })
24}
25
26/// Return the canonical artifact directory for one artifact environment.
27#[must_use]
28pub fn artifact_root_path(icp_root: &Path, artifact_environment: &str) -> PathBuf {
29    icp_root
30        .join(".icp")
31        .join(artifact_environment)
32        .join("canisters")
33}
34
35/// Return the canonical manifest path for the staged root release set.
36#[must_use]
37pub fn root_release_set_manifest_path(artifact_root: &Path) -> PathBuf {
38    artifact_root
39        .join("root")
40        .join(ROOT_RELEASE_SET_MANIFEST_FILE)
41}