MCPcopy Create free account
hub / github.com/bufbuild/buf / getModuleDepsRec

Function getModuleDepsRec

private/bufpkg/bufmodule/module_dep.go:115–254  ·  view source on GitHub ↗
(
	ctx context.Context,
	module Module,
	visitedOpaqueIDToDescription map[string]string,
	// Changes as we go down the stack.
	parentOpaqueIDs map[string]struct{},
	// Ordered (by dependency relationship) version of parentOpaqueIDs so we can print a cycle error.
	orderedParentOpaqueIDs []string,
	// Already discovered deps.
	depOpaqueIDToModuleDep map[string]ModuleDep,
	protoFileTracker *protoFileTracker,
	isDirect bool,
)

Source from the content-addressed store, hash-verified

113}
114
115func getModuleDepsRec(
116 ctx context.Context,
117 module Module,
118 visitedOpaqueIDToDescription map[string]string,
119 // Changes as we go down the stack.
120 parentOpaqueIDs map[string]struct{},
121 // Ordered (by dependency relationship) version of parentOpaqueIDs so we can print a cycle error.
122 orderedParentOpaqueIDs []string,
123 // Already discovered deps.
124 depOpaqueIDToModuleDep map[string]ModuleDep,
125 protoFileTracker *protoFileTracker,
126 isDirect bool,
127) error {
128 opaqueID := module.OpaqueID()
129 if _, ok := parentOpaqueIDs[opaqueID]; ok {
130 return &ModuleCycleError{
131 Descriptions: append(
132 xslices.Map(orderedParentOpaqueIDs, func(parentOpaqueID string) string {
133 return visitedOpaqueIDToDescription[parentOpaqueID]
134 }),
135 module.Description(),
136 ),
137 }
138 }
139 if _, ok := visitedOpaqueIDToDescription[opaqueID]; ok {
140 return nil
141 }
142 visitedOpaqueIDToDescription[opaqueID] = module.Description()
143 moduleSet := module.ModuleSet()
144 if moduleSet == nil {
145 // This should never happen.
146 return syserror.New("moduleSet never set on module")
147 }
148
149 protoFileTracker.trackModule(module)
150 // Doing this BFS so we add all the direct deps to the map first, then if we
151 // see a dep later, it will still be a direct dep in the map, but will be ignored
152 // on recursive calls.
153 var newModuleDeps []ModuleDep
154 if err := module.WalkFileInfos(
155 ctx,
156 func(fileInfo FileInfo) error {
157 if fileInfo.FileType() != FileTypeProto {
158 return nil
159 }
160 protoFileTracker.trackFileInfo(fileInfo)
161
162 fastscanResult, err := module.getFastscanResultForPath(ctx, fileInfo.Path())
163 if err != nil {
164 var fileAnnotationSet bufanalysis.FileAnnotationSet
165 if errors.As(err, &fileAnnotationSet) {
166 // If a FileAnnotationSet, the error already contains path information, just return directly.
167 //
168 // We also specially handle FileAnnotationSets for exit code 100.
169 return fileAnnotationSet
170 }
171 if errors.Is(err, fs.ErrNotExist) {
172 // Strip any PathError and just get to the point.

Callers 1

getModuleDepsFunction · 0.85

Calls 13

NewFunction · 0.92
ExistsFunction · 0.92
newModuleDepFunction · 0.85
trackModuleMethod · 0.80
trackFileInfoMethod · 0.80
OpaqueIDMethod · 0.65
DescriptionMethod · 0.65
ModuleSetMethod · 0.65
WalkFileInfosMethod · 0.65
FileTypeMethod · 0.65
PathMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…