@@ -26,32 +26,40 @@ import (
2626 "github.com/bufbuild/buf/private/bufpkg/bufmodule/bufmoduleapi"
2727 "github.com/bufbuild/buf/private/bufpkg/bufmodule/bufmodulecache"
2828 "github.com/bufbuild/buf/private/bufpkg/bufmodule/bufmodulestore"
29+ "github.com/bufbuild/buf/private/bufpkg/bufplugin"
30+ "github.com/bufbuild/buf/private/bufpkg/bufplugin/bufpluginapi"
31+ "github.com/bufbuild/buf/private/bufpkg/bufplugin/bufplugincache"
32+ "github.com/bufbuild/buf/private/bufpkg/bufplugin/bufpluginstore"
2933 "github.com/bufbuild/buf/private/bufpkg/bufregistryapi/bufregistryapimodule"
3034 "github.com/bufbuild/buf/private/bufpkg/bufregistryapi/bufregistryapiowner"
35+ "github.com/bufbuild/buf/private/bufpkg/bufregistryapi/bufregistryapiplugin"
3136 "github.com/bufbuild/buf/private/pkg/app/appext"
3237 "github.com/bufbuild/buf/private/pkg/filelock"
3338 "github.com/bufbuild/buf/private/pkg/normalpath"
3439 "github.com/bufbuild/buf/private/pkg/storage/storageos"
3540)
3641
3742var (
38- // AllCacheModuleRelDirPaths are all directory paths for all time concerning the module cache.
43+ // AllCacheRelDirPaths are all directory paths for all time
44+ // concerning the module and plugin caches.
3945 //
4046 // These are normalized.
4147 // These are relative to container.CacheDirPath().
4248 //
4349 // This variable is used for clearing the cache.
44- AllCacheModuleRelDirPaths = []string {
45- v1beta1CacheModuleDataRelDirPath ,
46- v1beta1CacheModuleLockRelDirPath ,
50+ AllCacheRelDirPaths = []string {
4751 v1CacheModuleDataRelDirPath ,
4852 v1CacheModuleLockRelDirPath ,
4953 v1CacheModuleSumRelDirPath ,
54+ v1beta1CacheModuleDataRelDirPath ,
55+ v1beta1CacheModuleLockRelDirPath ,
5056 v2CacheModuleRelDirPath ,
51- v3CacheModuleRelDirPath ,
5257 v3CacheCommitsRelDirPath ,
53- v3CacheWKTRelDirPath ,
5458 v3CacheModuleLockRelDirPath ,
59+ v3CacheModuleRelDirPath ,
60+ v3CachePluginRelDirPath ,
61+ v3CacheWKTRelDirPath ,
62+ v3CacheWasmRuntimeRelDirPath ,
5563 }
5664
5765 // v1CacheModuleDataRelDirPath is the relative path to the cache directory where module data
@@ -103,6 +111,10 @@ var (
103111 //
104112 // Normalized.
105113 v3CacheModuleLockRelDirPath = normalpath .Join ("v3" , "modulelocks" )
114+ // v3CachePluginRelDirPath is the relative path to the files cache directory in its newest iteration.
115+ //
116+ // Normalized.
117+ v3CachePluginRelDirPath = normalpath .Join ("v3" , "plugins" )
106118 // v3CacheWasmRuntimeRelDirPath is the relative path to the Wasm runtime cache directory in its newest iteration.
107119 // This directory is used to store the Wasm runtime cache. This is an implementation specific cache and opaque outside of the runtime.
108120 //
@@ -146,6 +158,21 @@ func NewCommitProvider(container appext.Container) (bufmodule.CommitProvider, er
146158 )
147159}
148160
161+ // NewPluginDataProvider returns a new PluginDataProvider while creating the
162+ // required cache directories.
163+ func NewPluginDataProvider (container appext.Container ) (bufplugin.PluginDataProvider , error ) {
164+ clientConfig , err := NewConnectClientConfig (container )
165+ if err != nil {
166+ return nil , err
167+ }
168+ return newPluginDataProvider (
169+ container ,
170+ bufregistryapiplugin .NewClientProvider (
171+ clientConfig ,
172+ ),
173+ )
174+ }
175+
149176// CreateWasmRuntimeCacheDir creates the cache directory for the Wasm runtime.
150177//
151178// This is used by the Wasm runtime to cache compiled Wasm plugins. This is an
@@ -241,6 +268,33 @@ func newCommitProvider(
241268 ), nil
242269}
243270
271+ func newPluginDataProvider (
272+ container appext.Container ,
273+ pluginClientProvider bufregistryapiplugin.ClientProvider ,
274+ ) (bufplugin.PluginDataProvider , error ) {
275+ if err := createCacheDir (container .CacheDirPath (), v3CachePluginRelDirPath ); err != nil {
276+ return nil , err
277+ }
278+ fullCacheDirPath := normalpath .Join (container .CacheDirPath (), v3CachePluginRelDirPath )
279+ storageosProvider := storageos .NewProvider () // No symlinks.
280+ cacheBucket , err := storageosProvider .NewReadWriteBucket (fullCacheDirPath )
281+ if err != nil {
282+ return nil , err
283+ }
284+ delegateModuleDataProvider := bufpluginapi .NewPluingDataProvider (
285+ container .Logger (),
286+ pluginClientProvider ,
287+ )
288+ return bufplugincache .NewPluginDataProvider (
289+ container .Logger (),
290+ delegateModuleDataProvider ,
291+ bufpluginstore .NewPluginDataStore (
292+ container .Logger (),
293+ cacheBucket ,
294+ ),
295+ ), nil
296+ }
297+
244298func createCacheDir (baseCacheDirPath string , relDirPath string ) error {
245299 baseCacheDirPath = normalpath .Unnormalize (baseCacheDirPath )
246300 relDirPath = normalpath .Unnormalize (relDirPath )
0 commit comments