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

Function imageToCodeGeneratorRequest

private/bufpkg/bufimage/util.go:416–456  ·  view source on GitHub ↗
(
	image Image,
	parameter string,
	compilerVersion *pluginpb.Version,
	includeImports bool,
	includeWellKnownTypes bool,
	alreadyUsedPaths map[string]struct{},
	nonImportPaths map[string]struct{},
)

Source from the content-addressed store, hash-verified

414}
415
416func imageToCodeGeneratorRequest(
417 image Image,
418 parameter string,
419 compilerVersion *pluginpb.Version,
420 includeImports bool,
421 includeWellKnownTypes bool,
422 alreadyUsedPaths map[string]struct{},
423 nonImportPaths map[string]struct{},
424) (*pluginpb.CodeGeneratorRequest, error) {
425 imageFiles := image.Files()
426 request := &pluginpb.CodeGeneratorRequest{
427 ProtoFile: make([]*descriptorpb.FileDescriptorProto, len(imageFiles)),
428 CompilerVersion: compilerVersion,
429 }
430 if parameter != "" {
431 request.Parameter = proto.String(parameter)
432 }
433 for i, imageFile := range imageFiles {
434 fileDescriptorProto := imageFile.FileDescriptorProto()
435 // ProtoFile should include only runtime-retained options for files to generate.
436 if isFileToGenerate(
437 imageFile,
438 alreadyUsedPaths,
439 nonImportPaths,
440 includeImports,
441 includeWellKnownTypes,
442 ) {
443 request.FileToGenerate = append(request.FileToGenerate, imageFile.Path())
444 // Source-retention options for items in FileToGenerate are provided in SourceFileDescriptors.
445 request.SourceFileDescriptors = append(request.SourceFileDescriptors, fileDescriptorProto)
446 // And the corresponding descriptor in ProtoFile will have source-retention options stripped.
447 var err error
448 fileDescriptorProto, err = protopluginutil.StripSourceRetentionOptions(fileDescriptorProto)
449 if err != nil {
450 return nil, fmt.Errorf("failed to strip source-retention options for file %q when constructing a CodeGeneratorRequest: %w", imageFile.Path(), err)
451 }
452 }
453 request.ProtoFile[i] = fileDescriptorProto
454 }
455 return request, nil
456}
457
458func isFileToGenerate(
459 imageFile ImageFile,

Callers 2

Calls 5

isFileToGenerateFunction · 0.85
FilesMethod · 0.65
StringMethod · 0.65
FileDescriptorProtoMethod · 0.65
PathMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…