25
25
26
26
namespace vcpkg
27
27
{
28
+ // / Unique identifier for a provider
29
+ using ProviderId = size_t ;
30
+
28
31
struct CacheStatus
29
32
{
33
+ using ReaderProviders = std::vector<const IReadBinaryProvider*>;
34
+
30
35
bool should_attempt_precheck (const IReadBinaryProvider* sender) const noexcept ;
31
36
bool should_attempt_restore (const IReadBinaryProvider* sender) const noexcept ;
37
+ bool should_attempt_write_back (ProviderId provider_id) const noexcept ;
32
38
33
39
bool is_unavailable (const IReadBinaryProvider* sender) const noexcept ;
34
40
const IReadBinaryProvider* get_available_provider () const noexcept ;
41
+ ReaderProviders& get_unavailable_providers () noexcept ;
35
42
bool is_restored () const noexcept ;
36
43
37
44
void mark_unavailable (const IReadBinaryProvider* sender);
38
45
void mark_available (const IReadBinaryProvider* sender) noexcept ;
39
46
void mark_restored () noexcept ;
47
+ void mark_written_back (ProviderId provider_id) noexcept ;
40
48
41
49
private:
42
50
CacheStatusState m_status = CacheStatusState::unknown;
@@ -75,10 +83,13 @@ namespace vcpkg
75
83
76
84
// / Called upon a successful build of `action` to store those contents in the binary cache.
77
85
// / returns the number of successful uploads
78
- virtual size_t push_success (const BinaryPackageWriteInfo& request, MessageSink& msg_sink) = 0;
86
+ virtual size_t push_success (const BinaryPackageWriteInfo& request,
87
+ MessageSink& msg_sink,
88
+ CacheStatus& cache_status) = 0;
79
89
80
90
virtual bool needs_nuspec_data () const = 0;
81
91
virtual bool needs_zip_file () const = 0;
92
+ virtual std::vector<ProviderId> get_provider_ids () const = 0;
82
93
};
83
94
84
95
struct IReadBinaryProvider
@@ -93,6 +104,10 @@ namespace vcpkg
93
104
// / Prerequisites: actions[i].package_abi(), out_status.size() == actions.size()
94
105
virtual void fetch (View<const InstallPlanAction*> actions, Span<RestoreResult> out_status) const = 0;
95
106
107
+ // / Flag to indicate if the provider supports an efficient check to see if a certain set of packages are
108
+ // / available. If not, packages will assumed to be present & will always be fetched.
109
+ virtual bool can_precheck () const = 0;
110
+
96
111
// / Checks whether the `actions` are present in the cache, without restoring them.
97
112
// /
98
113
// / Used by CI to determine missing packages. For each `i`, out_status[i] should be set to
@@ -103,6 +118,11 @@ namespace vcpkg
103
118
104
119
virtual LocalizedString restored_message (size_t count,
105
120
std::chrono::high_resolution_clock::duration elapsed) const = 0;
121
+
122
+ // / Unique identifier for this provider.
123
+ // /
124
+ // / Used by the cache to exclude cache providers during the write-back phase.
125
+ virtual ProviderId id () const = 0;
106
126
};
107
127
108
128
struct UrlTemplate
@@ -114,44 +134,62 @@ namespace vcpkg
114
134
std::string instantiate_variables (const BinaryPackageReadInfo& info) const ;
115
135
};
116
136
137
+ struct GithubActionsInfo
138
+ {
139
+ };
140
+
117
141
struct NuGetRepoInfo
118
142
{
119
143
std::string repo;
120
144
std::string branch;
121
145
std::string commit;
122
146
};
123
147
148
+ enum class CacheType
149
+ {
150
+ Read,
151
+ Write,
152
+ ReadWrite
153
+ };
154
+
155
+ template <typename T>
156
+ struct CacheProvider
157
+ {
158
+ ProviderId id;
159
+ T source;
160
+ CacheType cache_type;
161
+
162
+ [[nodiscard]] constexpr bool is_read () const noexcept
163
+ {
164
+ return cache_type == CacheType::Read || cache_type == CacheType::ReadWrite;
165
+ }
166
+
167
+ [[nodiscard]] constexpr bool is_write () const noexcept
168
+ {
169
+ return cache_type == CacheType::Write || cache_type == CacheType::ReadWrite;
170
+ }
171
+ };
172
+
173
+ template <typename T>
174
+ using ProviderList = std::vector<CacheProvider<T>>;
175
+
124
176
struct BinaryConfigParserState
125
177
{
178
+ ProviderId provider_count = 0 ;
126
179
bool nuget_interactive = false ;
127
180
std::set<StringLiteral> binary_cache_providers;
128
181
129
182
std::string nugettimeout = " 100" ;
130
183
131
- std::vector<Path> archives_to_read;
132
- std::vector<Path> archives_to_write;
133
-
134
- std::vector<UrlTemplate> url_templates_to_get;
135
- std::vector<UrlTemplate> url_templates_to_put;
136
-
137
- std::vector<std::string> gcs_read_prefixes;
138
- std::vector<std::string> gcs_write_prefixes;
139
-
140
- std::vector<std::string> aws_read_prefixes;
141
- std::vector<std::string> aws_write_prefixes;
184
+ ProviderList<Path> archives;
185
+ ProviderList<UrlTemplate> url_templates;
186
+ ProviderList<std::string> gcs_prefixes;
187
+ ProviderList<std::string> aws_prefixes;
142
188
bool aws_no_sign_request = false ;
143
-
144
- std::vector<std::string> cos_read_prefixes;
145
- std::vector<std::string> cos_write_prefixes;
146
-
147
- bool gha_write = false ;
148
- bool gha_read = false ;
149
-
150
- std::vector<std::string> sources_to_read;
151
- std::vector<std::string> sources_to_write;
152
-
153
- std::vector<Path> configs_to_read;
154
- std::vector<Path> configs_to_write;
189
+ ProviderList<std::string> cos_prefixes;
190
+ Optional<CacheProvider<GithubActionsInfo>> gha;
191
+ ProviderList<std::string> sources;
192
+ ProviderList<Path> configs;
155
193
156
194
std::vector<std::string> secrets;
157
195
@@ -173,6 +211,8 @@ namespace vcpkg
173
211
NuGetRepoInfo nuget_repo;
174
212
};
175
213
214
+ [[nodiscard]] bool HasWriteOnlyProviders (const BinaryProviders& providers);
215
+
176
216
struct ReadOnlyBinaryCache
177
217
{
178
218
ReadOnlyBinaryCache () = default ;
@@ -182,7 +222,7 @@ namespace vcpkg
182
222
// / executing `actions`.
183
223
void fetch (View<InstallPlanAction> actions);
184
224
185
- bool is_restored (const InstallPlanAction& ipa) const ;
225
+ Optional<CacheStatus> cache_status (const InstallPlanAction& ipa) const ;
186
226
187
227
// / Checks whether the `actions` are present in the cache, without restoring them. Used by CI to determine
188
228
// / missing packages.
@@ -192,6 +232,10 @@ namespace vcpkg
192
232
protected:
193
233
BinaryProviders m_config;
194
234
235
+ // / Flag to indicate that at least one provider is write-only. This implies that the write-back phase should
236
+ // / always take place for every Cache item.
237
+ bool m_has_write_only_providers;
238
+
195
239
std::unordered_map<std::string, CacheStatus> m_status;
196
240
};
197
241
0 commit comments