mz_deploy/project/compiler/
cache.rs1use std::collections::BTreeMap;
19use std::path::{Path, PathBuf};
20use thiserror::Error;
21
22pub(crate) mod build_artifact;
23pub(crate) mod project_cache;
24pub(crate) mod schema;
25
26pub(crate) use build_artifact::BuildArtifact;
27pub(crate) use project_cache::ProjectCache;
28
29pub(crate) const DB_FILE: &str = "build_artifact.db";
30
31fn decode_column_type(json: String) -> rusqlite::Result<crate::types::DataType> {
36 crate::types::DataType::from_json(&json).map_err(|err| {
37 rusqlite::Error::FromSqlConversionFailure(2, rusqlite::types::Type::Text, Box::new(err))
38 })
39}
40
41pub(crate) fn db_path(
43 root: &Path,
44 profile: &str,
45 profile_suffix: Option<&str>,
46 variables: &BTreeMap<String, String>,
47) -> PathBuf {
48 root.join(crate::types::BUILD_DIR)
49 .join(super::COMPILER_DIR)
50 .join(super::profile_namespace(profile, profile_suffix, variables))
51 .join(DB_FILE)
52}
53
54#[derive(Debug, Error)]
55pub enum CacheError {
56 #[error("failed to create compiler cache directory: {path}")]
57 DirectoryCreationFailed {
58 path: PathBuf,
59 #[source]
60 source: std::io::Error,
61 },
62 #[error("failed to open build artifact database: {path}")]
63 DatabaseOpenFailed {
64 path: PathBuf,
65 #[source]
66 source: rusqlite::Error,
67 },
68 #[error("failed to operate on build artifact database: {path}")]
69 DatabaseOperationFailed {
70 path: PathBuf,
71 #[source]
72 source: rusqlite::Error,
73 },
74 #[error("failed to read cached source file: {path}")]
75 FileReadFailed {
76 path: PathBuf,
77 #[source]
78 source: std::io::Error,
79 },
80}