cgx_core/messages/
prebuilt_binary.rs1use std::path::PathBuf;
2
3use serde::{Deserialize, Serialize};
4
5use super::Message;
6use crate::{bin_resolver::ResolvedBinary, config::BinaryProvider, crate_resolver::ResolvedCrate};
7
8#[derive(Debug, Clone, Serialize, Deserialize)]
11#[serde(rename_all = "snake_case")]
12pub enum ProviderChangeReason {
13 RequiredProviderNotEnabled(BinaryProvider),
16 SourceProviderDisabled(BinaryProvider),
19}
20
21#[derive(Debug, Clone, Serialize, Deserialize)]
23#[serde(tag = "event", rename_all = "snake_case")]
24pub enum PrebuiltBinaryMessage {
25 CacheLookup { krate: ResolvedCrate },
27 PositiveCacheHit {
29 krate: ResolvedCrate,
30 path: PathBuf,
31 provider: BinaryProvider,
32 },
33 NegativeCacheHit { krate: ResolvedCrate },
36 CacheMiss { krate: ResolvedCrate },
38 CacheInvalidatedByProviderChange {
41 krate: ResolvedCrate,
42 reason: ProviderChangeReason,
43 },
44 CacheInvalidatedByMissingBinary { krate: ResolvedCrate, path: PathBuf },
47 CheckingProvider {
49 krate: ResolvedCrate,
50 provider: BinaryProvider,
51 },
52 ProviderHasNoBinary {
54 provider: BinaryProvider,
55 reason: String,
56 },
57 ProviderFailed {
59 provider: BinaryProvider,
60 reason: String,
61 },
62 DownloadingBinary { url: String, provider: BinaryProvider },
64 VerifyingChecksum { expected: String },
66 ChecksumVerified,
68 Resolved { binary: ResolvedBinary },
70 CacheStored { path: PathBuf },
72 NoBinaryFound {
74 krate: ResolvedCrate,
75 reasons: Vec<String>,
76 },
77 ResolutionInconclusive { reason: String },
81 DisqualifiedDueToCustomization { reason: String },
83 PrebuiltBinariesDisabled,
85}
86
87impl PrebuiltBinaryMessage {
88 pub fn cache_lookup(krate: &ResolvedCrate) -> Self {
89 Self::CacheLookup { krate: krate.clone() }
90 }
91
92 pub fn positive_cache_hit(
93 krate: &ResolvedCrate,
94 path: &std::path::Path,
95 provider: BinaryProvider,
96 ) -> Self {
97 Self::PositiveCacheHit {
98 krate: krate.clone(),
99 path: path.to_path_buf(),
100 provider,
101 }
102 }
103
104 pub fn negative_cache_hit(krate: &ResolvedCrate) -> Self {
105 Self::NegativeCacheHit { krate: krate.clone() }
106 }
107
108 pub fn cache_miss(krate: &ResolvedCrate) -> Self {
109 Self::CacheMiss { krate: krate.clone() }
110 }
111
112 pub fn cache_invalidated_by_provider_change(krate: &ResolvedCrate, reason: ProviderChangeReason) -> Self {
113 Self::CacheInvalidatedByProviderChange {
114 krate: krate.clone(),
115 reason,
116 }
117 }
118
119 pub fn cache_invalidated_by_missing_binary(krate: &ResolvedCrate, path: &std::path::Path) -> Self {
120 Self::CacheInvalidatedByMissingBinary {
121 krate: krate.clone(),
122 path: path.to_path_buf(),
123 }
124 }
125
126 pub fn checking_provider(krate: &ResolvedCrate, provider: BinaryProvider) -> Self {
127 Self::CheckingProvider {
128 krate: krate.clone(),
129 provider,
130 }
131 }
132
133 pub fn provider_has_no_binary(provider: BinaryProvider, reason: impl Into<String>) -> Self {
134 Self::ProviderHasNoBinary {
135 provider,
136 reason: reason.into(),
137 }
138 }
139
140 pub fn provider_failed(provider: BinaryProvider, reason: impl Into<String>) -> Self {
141 Self::ProviderFailed {
142 provider,
143 reason: reason.into(),
144 }
145 }
146
147 pub fn downloading_binary(url: impl Into<String>, provider: BinaryProvider) -> Self {
148 Self::DownloadingBinary {
149 url: url.into(),
150 provider,
151 }
152 }
153
154 pub fn verifying_checksum(expected: impl Into<String>) -> Self {
155 Self::VerifyingChecksum {
156 expected: expected.into(),
157 }
158 }
159
160 pub fn checksum_verified() -> Self {
161 Self::ChecksumVerified
162 }
163
164 pub fn resolved(binary: &ResolvedBinary) -> Self {
165 Self::Resolved {
166 binary: binary.clone(),
167 }
168 }
169
170 pub fn cache_stored(path: &std::path::Path) -> Self {
171 Self::CacheStored {
172 path: path.to_path_buf(),
173 }
174 }
175
176 pub fn no_binary_found(krate: &ResolvedCrate, reasons: Vec<String>) -> Self {
177 Self::NoBinaryFound {
178 krate: krate.clone(),
179 reasons,
180 }
181 }
182
183 pub fn resolution_inconclusive(reason: impl Into<String>) -> Self {
184 Self::ResolutionInconclusive {
185 reason: reason.into(),
186 }
187 }
188
189 pub fn disqualified_due_to_customization(reason: impl Into<String>) -> Self {
190 Self::DisqualifiedDueToCustomization {
191 reason: reason.into(),
192 }
193 }
194
195 pub fn prebuilt_binaries_disabled() -> Self {
196 Self::PrebuiltBinariesDisabled
197 }
198}
199
200impl From<PrebuiltBinaryMessage> for Message {
201 fn from(msg: PrebuiltBinaryMessage) -> Self {
202 Message::PrebuiltBinary(msg)
203 }
204}