2525
2626namespace vcpkg
2727{
28+ // / Unique identifier for a provider
29+ using ProviderId = size_t ;
30+
2831 struct CacheStatus
2932 {
33+ using ReaderProviders = std::vector<const IReadBinaryProvider*>;
34+
3035 bool should_attempt_precheck (const IReadBinaryProvider* sender) const noexcept ;
3136 bool should_attempt_restore (const IReadBinaryProvider* sender) const noexcept ;
37+ bool should_attempt_write_back (ProviderId provider_id) const noexcept ;
3238
3339 bool is_unavailable (const IReadBinaryProvider* sender) const noexcept ;
3440 const IReadBinaryProvider* get_available_provider () const noexcept ;
41+ ReaderProviders& get_unavailable_providers () noexcept ;
3542 bool is_restored () const noexcept ;
3643
3744 void mark_unavailable (const IReadBinaryProvider* sender);
3845 void mark_available (const IReadBinaryProvider* sender) noexcept ;
3946 void mark_restored () noexcept ;
47+ void mark_written_back (ProviderId provider_id) noexcept ;
4048
4149 private:
4250 CacheStatusState m_status = CacheStatusState::unknown;
@@ -75,10 +83,13 @@ namespace vcpkg
7583
7684 // / Called upon a successful build of `action` to store those contents in the binary cache.
7785 // / 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;
7989
8090 virtual bool needs_nuspec_data () const = 0;
8191 virtual bool needs_zip_file () const = 0;
92+ virtual std::vector<ProviderId> get_provider_ids () const = 0;
8293 };
8394
8495 struct IReadBinaryProvider
@@ -93,6 +104,10 @@ namespace vcpkg
93104 // / Prerequisites: actions[i].package_abi(), out_status.size() == actions.size()
94105 virtual void fetch (View<const InstallPlanAction*> actions, Span<RestoreResult> out_status) const = 0;
95106
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+
96111 // / Checks whether the `actions` are present in the cache, without restoring them.
97112 // /
98113 // / Used by CI to determine missing packages. For each `i`, out_status[i] should be set to
@@ -103,6 +118,11 @@ namespace vcpkg
103118
104119 virtual LocalizedString restored_message (size_t count,
105120 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;
106126 };
107127
108128 struct UrlTemplate
@@ -114,44 +134,62 @@ namespace vcpkg
114134 std::string instantiate_variables (const BinaryPackageReadInfo& info) const ;
115135 };
116136
137+ struct GithubActionsInfo
138+ {
139+ };
140+
117141 struct NuGetRepoInfo
118142 {
119143 std::string repo;
120144 std::string branch;
121145 std::string commit;
122146 };
123147
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+
124176 struct BinaryConfigParserState
125177 {
178+ ProviderId provider_count = 0 ;
126179 bool nuget_interactive = false ;
127180 std::set<StringLiteral> binary_cache_providers;
128181
129182 std::string nugettimeout = " 100" ;
130183
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;
142188 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;
155193
156194 std::vector<std::string> secrets;
157195
@@ -173,6 +211,8 @@ namespace vcpkg
173211 NuGetRepoInfo nuget_repo;
174212 };
175213
214+ [[nodiscard]] bool HasWriteOnlyProviders (const BinaryProviders& providers);
215+
176216 struct ReadOnlyBinaryCache
177217 {
178218 ReadOnlyBinaryCache () = default ;
@@ -182,7 +222,7 @@ namespace vcpkg
182222 // / executing `actions`.
183223 void fetch (View<InstallPlanAction> actions);
184224
185- bool is_restored (const InstallPlanAction& ipa) const ;
225+ Optional<CacheStatus> cache_status (const InstallPlanAction& ipa) const ;
186226
187227 // / Checks whether the `actions` are present in the cache, without restoring them. Used by CI to determine
188228 // / missing packages.
@@ -192,6 +232,10 @@ namespace vcpkg
192232 protected:
193233 BinaryProviders m_config;
194234
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+
195239 std::unordered_map<std::string, CacheStatus> m_status;
196240 };
197241
0 commit comments