Skip to content

Commit e0aa28e

Browse files
committed
Rename module dependencies
Remove the term declared from the dependencies in a ModuleData that refer to the full transitive list of dependencies, those in the buf.lock file. Declared dependencies are the direct dependencies, those in the buf.yaml file.
1 parent abfbd3d commit e0aa28e

File tree

7 files changed

+103
-104
lines changed

7 files changed

+103
-104
lines changed

private/bufpkg/bufmodule/added_module.go

+23-23
Original file line numberDiff line numberDiff line change
@@ -161,27 +161,27 @@ func (a *addedModule) ToModule(
161161
}
162162
return moduleData.V1Beta1OrV1BufLockObjectData()
163163
}
164-
// getDeclaredDepModuleKeysB5 gets the declared dependencies for the specific Module.
164+
// getDepModuleKeysB5 gets the dependencies for the specific Module.
165165
//
166166
// This is needed to calculate the digest for the Module. A Module constructed from this
167-
// ModuleData as the target will require all Modules referenced by its DeclaredDepModuleKeys
168-
// to be present in the ModuleSet.
167+
// ModuleData as the target will require all Modules referenced by its DepModuleKeys to
168+
// be present in the ModuleSet.
169169
//
170170
// Modules that depend on this remote Module will include this Module and its data.
171171
// However all the dependencies of the remote Module may not be present in the parents ModuleSet.
172172
// As the target Module will use its direct dependencies to resolve the dependencies required.
173173
// The digest of the remote Module is however, unchanged. It is calculated based on the contents
174-
// and its declared dependencies, not the dependencies of the parent ModuleSet.
174+
// and its dependencies, not the dependencies of the parent ModuleSet.
175175
//
176176
// In contrast, a local Module dependency can be thought of as a ModuleKey at the latest commit.
177-
// It will always use the bucket and declared dependencies, which may be resolved recursively
178-
// for dependencies on other local Modules, to calculate its digest.
177+
// It will always use the bucket and dependencies, which may be resolved recursively for
178+
// dependencies on other local Modules, to calculate its digest.
179179
// This is the difference between the ModuleData digest calculation and the Module
180-
// digest calculation. As remote Modules are required to have all their dependencies
181-
// declared as ModuleKeys they can calculate their digest directly from the contents
182-
// and declared dependencies, they do not need to recursively resolve digests.
180+
// digest calculation. As remote Modules are required to have all their dependencies as
181+
// ModuleKeys, they can calculate their digest directly from the contents and dependencies,
182+
// without needing to recursively resolve the digest as local Modules do.
183183
//
184-
// For example, consider the following modules at commits with their declared dependencies:
184+
// For example, consider the following modules at commits with their dependencies:
185185
// ```
186186
// X:C1 (X has no dependencies)
187187
// A:C1 -> X:C1 (A depends on X)
@@ -196,42 +196,42 @@ func (a *addedModule) ToModule(
196196
// The ModuleSet for B:C1 will include A:C1 and X:C1.
197197
// When calculating the digest for B:C1 in the ModuleSet of C:C1, the ModuleSet
198198
// ModuleDeps cannot be used to resolve the dependencies of B:C1. It must use
199-
// the declared dependencies of B:C1, which are A:C1 and X:C1, not A:C2.
199+
// the dependencies of B:C1, which are A:C1 and X:C1, not A:C2.
200200
//
201201
// This is used for digest calculations. It is not used otherwise.
202-
getDeclaredDepModuleKeysB5 := func() ([]ModuleKey, error) {
202+
getDepModuleKeysB5 := func() ([]ModuleKey, error) {
203203
moduleData, err := getModuleData()
204204
if err != nil {
205205
return nil, err
206206
}
207-
declaredDepModuleKeys, err := moduleData.DeclaredDepModuleKeys()
207+
depModuleKeys, err := moduleData.DepModuleKeys()
208208
if err != nil {
209209
return nil, err
210210
}
211-
if len(declaredDepModuleKeys) == 0 {
211+
if len(depModuleKeys) == 0 {
212212
return nil, nil
213213
}
214214
var digestType DigestType
215-
for i, moduleKey := range declaredDepModuleKeys {
215+
for i, moduleKey := range depModuleKeys {
216216
digest, err := moduleKey.Digest()
217217
if err != nil {
218218
return nil, err
219219
}
220220
if i == 0 {
221221
digestType = digest.Type()
222222
} else if digestType != digest.Type() {
223-
return nil, syserror.Newf("multiple digest types found in DeclaredDepModuleKeys: %v, %v", digestType, digest.Type())
223+
return nil, syserror.Newf("multiple digest types found in DepModuleKeys: %v, %v", digestType, digest.Type())
224224
}
225225
}
226226
switch digestType {
227227
case DigestTypeB4:
228-
// The declared ModuleKey dependencies for a commit may be stored in v1 buf.lock file,
228+
// The ModuleKey dependencies for a commit may be stored in v1 buf.lock file,
229229
// in which case they will use B4 digests. B4 digests aren't allowed to be used as
230230
// input to the B5 digest calculation, so we perform a call to convert all ModuleKeys
231231
// from B4 to B5 by using the commit provider.
232-
commitKeysToFetch := make([]CommitKey, len(declaredDepModuleKeys))
233-
for i, declaredDepModuleKey := range declaredDepModuleKeys {
234-
commitKey, err := NewCommitKey(declaredDepModuleKey.FullName().Registry(), declaredDepModuleKey.CommitID(), DigestTypeB5)
232+
commitKeysToFetch := make([]CommitKey, len(depModuleKeys))
233+
for i, depModuleKey := range depModuleKeys {
234+
commitKey, err := NewCommitKey(depModuleKey.FullName().Registry(), depModuleKey.CommitID(), DigestTypeB5)
235235
if err != nil {
236236
return nil, err
237237
}
@@ -248,8 +248,8 @@ func (a *addedModule) ToModule(
248248
return commit.ModuleKey()
249249
}), nil
250250
case DigestTypeB5:
251-
// No need to fetch b5 digests - we've already got them stored in the module's declared dependencies.
252-
return declaredDepModuleKeys, nil
251+
// No need to fetch b5 digests - we've already got them stored in the module's dependencies.
252+
return depModuleKeys, nil
253253
default:
254254
return nil, syserror.Newf("unsupported digest type: %v", digestType)
255255
}
@@ -265,7 +265,7 @@ func (a *addedModule) ToModule(
265265
false,
266266
getV1BufYAMLObjectData,
267267
getV1BufLockObjectData,
268-
getDeclaredDepModuleKeysB5,
268+
getDepModuleKeysB5,
269269
a.remoteTargetPaths,
270270
a.remoteTargetExcludePaths,
271271
"",

private/bufpkg/bufmodule/bufmoduleapi/module_data_provider.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ func (a *moduleDataProvider) getIndexedModuleDatasForRegistryAndIndexedModuleKey
126126
digestType bufmodule.DigestType,
127127
) ([]slicesext.Indexed[bufmodule.ModuleData], error) {
128128
// This returns the graph with pruned dependencies for the given indexedModuleKeys.
129-
// We must resolve the declared dependencies for each ModuleKey.
129+
// We must resolve the direct and transitive dependencies for each ModuleKey.
130130
graph, err := a.graphProvider.GetGraphForModuleKeys(ctx, slicesext.IndexedToValues(indexedModuleKeys))
131131
if err != nil {
132132
return nil, err

private/bufpkg/bufmodule/bufmodulestore/module_data_store.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,9 @@ func (p *moduleDataStore) getModuleDataForModuleKey(
262262
// We don't want to do this lazily (or anything else in this function) as we want to
263263
// make sure everything we have is valid before returning so we can auto-correct
264264
// the cache if necessary.
265-
declaredDepModuleKeys, err := slicesext.MapError(
265+
depModuleKeys, err := slicesext.MapError(
266266
externalModuleData.Deps,
267-
getDeclaredDepModuleKeyForExternalModuleDataDep,
267+
getDepModuleKeyForExternalModuleDataDep,
268268
)
269269
if err != nil {
270270
return nil, err
@@ -316,7 +316,7 @@ func (p *moduleDataStore) getModuleDataForModuleKey(
316316
), nil
317317
},
318318
func() ([]bufmodule.ModuleKey, error) {
319-
return declaredDepModuleKeys, nil
319+
return depModuleKeys, nil
320320
},
321321
func() (bufmodule.ObjectData, error) {
322322
return v1BufYAMLObjectData, nil
@@ -461,7 +461,7 @@ func (p *moduleDataStore) putModuleData(
461461
}
462462
}
463463
// Proceed to writing module data.
464-
depModuleKeys, err := moduleData.DeclaredDepModuleKeys()
464+
depModuleKeys, err := moduleData.DepModuleKeys()
465465
if err != nil {
466466
return err
467467
}
@@ -653,7 +653,7 @@ func getModuleDataStoreTarPath(moduleKey bufmodule.ModuleKey) (string, error) {
653653
), nil
654654
}
655655

656-
func getDeclaredDepModuleKeyForExternalModuleDataDep(dep externalModuleDataDep) (bufmodule.ModuleKey, error) {
656+
func getDepModuleKeyForExternalModuleDataDep(dep externalModuleDataDep) (bufmodule.ModuleKey, error) {
657657
if dep.Name == "" {
658658
return nil, errors.New("no module name specified")
659659
}

private/bufpkg/bufmodule/bufmoduletesting/bufmoduletesting.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ func (o *omniProvider) getModuleDataForModuleKey(
311311
if err != nil {
312312
return nil, err
313313
}
314-
declaredDepModuleKeys, err := slicesext.MapError(
314+
depModuleKeys, err := slicesext.MapError(
315315
moduleDeps,
316316
func(moduleDep bufmodule.ModuleDep) (bufmodule.ModuleKey, error) {
317317
return bufmodule.ModuleToModuleKey(moduleDep, digest.Type())
@@ -327,7 +327,7 @@ func (o *omniProvider) getModuleDataForModuleKey(
327327
return bufmodule.ModuleReadBucketToStorageReadBucket(module), nil
328328
},
329329
func() ([]bufmodule.ModuleKey, error) {
330-
return declaredDepModuleKeys, nil
330+
return depModuleKeys, nil
331331
},
332332
func() (bufmodule.ObjectData, error) {
333333
return module.V1Beta1OrV1BufYAMLObjectData()

private/bufpkg/bufmodule/module.go

+44-44
Original file line numberDiff line numberDiff line change
@@ -230,17 +230,17 @@ func ModuleDirectModuleDeps(module Module) ([]ModuleDep, error) {
230230
type module struct {
231231
ModuleReadBucket
232232

233-
ctx context.Context
234-
getBucket func() (storage.ReadBucket, error)
235-
bucketID string
236-
description string
237-
moduleFullName bufparse.FullName
238-
commitID uuid.UUID
239-
isTarget bool
240-
isLocal bool
241-
getV1BufYAMLObjectData func() (ObjectData, error)
242-
getV1BufLockObjectData func() (ObjectData, error)
243-
getDeclaredDepModuleKeysB5 func() ([]ModuleKey, error)
233+
ctx context.Context
234+
getBucket func() (storage.ReadBucket, error)
235+
bucketID string
236+
description string
237+
moduleFullName bufparse.FullName
238+
commitID uuid.UUID
239+
isTarget bool
240+
isLocal bool
241+
getV1BufYAMLObjectData func() (ObjectData, error)
242+
getV1BufLockObjectData func() (ObjectData, error)
243+
getDepModuleKeysB5 func() ([]ModuleKey, error)
244244

245245
moduleSet ModuleSet
246246

@@ -261,7 +261,7 @@ func newModule(
261261
isLocal bool,
262262
getV1BufYAMLObjectData func() (ObjectData, error),
263263
getV1BufLockObjectData func() (ObjectData, error),
264-
getDeclaredDepModuleKeysB5 func() ([]ModuleKey, error),
264+
getDepModuleKeysB5 func() ([]ModuleKey, error),
265265
targetPaths []string,
266266
targetExcludePaths []string,
267267
protoFileTargetPath string,
@@ -304,17 +304,17 @@ func newModule(
304304
}
305305

306306
module := &module{
307-
ctx: ctx,
308-
getBucket: syncOnceValuesGetBucketWithStorageMatcherApplied,
309-
bucketID: bucketID,
310-
description: description,
311-
moduleFullName: moduleFullName,
312-
commitID: commitID,
313-
isTarget: isTarget,
314-
isLocal: isLocal,
315-
getV1BufYAMLObjectData: sync.OnceValues(getV1BufYAMLObjectData),
316-
getV1BufLockObjectData: sync.OnceValues(getV1BufLockObjectData),
317-
getDeclaredDepModuleKeysB5: sync.OnceValues(getDeclaredDepModuleKeysB5),
307+
ctx: ctx,
308+
getBucket: syncOnceValuesGetBucketWithStorageMatcherApplied,
309+
bucketID: bucketID,
310+
description: description,
311+
moduleFullName: moduleFullName,
312+
commitID: commitID,
313+
isTarget: isTarget,
314+
isLocal: isLocal,
315+
getV1BufYAMLObjectData: sync.OnceValues(getV1BufYAMLObjectData),
316+
getV1BufLockObjectData: sync.OnceValues(getV1BufLockObjectData),
317+
getDepModuleKeysB5: sync.OnceValues(getDepModuleKeysB5),
318318
}
319319
moduleReadBucket, err := newModuleReadBucketForModule(
320320
ctx,
@@ -398,17 +398,17 @@ func (m *module) ModuleSet() ModuleSet {
398398
func (m *module) withIsTarget(isTarget bool) (Module, error) {
399399
// We don't just call newModule directly as we don't want to double sync.OnceValues stuff.
400400
newModule := &module{
401-
ctx: m.ctx,
402-
getBucket: m.getBucket,
403-
bucketID: m.bucketID,
404-
description: m.description,
405-
moduleFullName: m.moduleFullName,
406-
commitID: m.commitID,
407-
isTarget: isTarget,
408-
isLocal: m.isLocal,
409-
getV1BufYAMLObjectData: m.getV1BufYAMLObjectData,
410-
getV1BufLockObjectData: m.getV1BufLockObjectData,
411-
getDeclaredDepModuleKeysB5: m.getDeclaredDepModuleKeysB5,
401+
ctx: m.ctx,
402+
getBucket: m.getBucket,
403+
bucketID: m.bucketID,
404+
description: m.description,
405+
moduleFullName: m.moduleFullName,
406+
commitID: m.commitID,
407+
isTarget: isTarget,
408+
isLocal: m.isLocal,
409+
getV1BufYAMLObjectData: m.getV1BufYAMLObjectData,
410+
getV1BufLockObjectData: m.getV1BufLockObjectData,
411+
getDepModuleKeysB5: m.getDepModuleKeysB5,
412412
}
413413
moduleReadBucket, ok := m.ModuleReadBucket.(*moduleReadBucket)
414414
if !ok {
@@ -452,26 +452,26 @@ func newGetDigestFuncForModuleAndDigestType(module *module, digestType DigestTyp
452452
}
453453
return getB4Digest(module.ctx, bucket, v1BufYAMLObjectData, v1BufLockObjectData)
454454
case DigestTypeB5:
455-
// B5 digests are calculated from the Module's content and its declared dependencies.
455+
// B5 digests are calculated from the Module's content and its dependencies.
456456
//
457-
// Declared dependencies are all direct and transitive dependencies of the Module.
458-
// For local Modules, the declared dependencies are resolved to the current ModuleSet.
459-
// For remote Modules, the declared dependencies are the ModuleKeys of
457+
// Dependencies are all direct and transitive dependencies of the Module.
458+
// For local Modules, the dependencies are resolved to the current ModuleSet.
459+
// For remote Modules, the dependencies are the ModuleKeys of
460460
// the direct and transitive dependencies of the Module at the specific commit.
461461
//
462-
// This is effectively the same. The local Modules have a declared dependency at the current commit,
463-
// and the remote Modules have a declared dependency at a specific commit. Pushing up a local Module
462+
// This is effectively the same. The local Modules have a dependency at the current commit,
463+
// and the remote Modules have a dependency at a specific commit. Pushing up a local Module
464464
// as a remote Module will result in the same Digest.
465465
//
466-
// See the comment on getDeclaredDepModuleKeysB5 for more information.
466+
// See the comment on getDepModuleKeysB5 for more information.
467467
if !module.isLocal {
468-
declaredDepModuleKeys, err := module.getDeclaredDepModuleKeysB5()
468+
depModuleKeys, err := module.getDepModuleKeysB5()
469469
if err != nil {
470470
return nil, err
471471
}
472-
return getB5DigestForBucketAndDepModuleKeys(module.ctx, bucket, declaredDepModuleKeys)
472+
return getB5DigestForBucketAndDepModuleKeys(module.ctx, bucket, depModuleKeys)
473473
}
474-
// ModuleDeps returns the declared dependent Modules resolved for the target Module in the ModuleSet.
474+
// ModuleDeps returns the dependent Modules resolved for the target Module in the ModuleSet.
475475
// A local Module will recursively resolve the Digest of other dependent local Modules.
476476
// This is done by calling Module.Digest(DigestTypeB5) on each ModuleDep.
477477
moduleDeps, err := module.ModuleDeps()

0 commit comments

Comments
 (0)