(
image Image,
parameter string,
compilerVersion *pluginpb.Version,
includeImports bool,
includeWellKnownTypes bool,
alreadyUsedPaths map[string]struct{},
nonImportPaths map[string]struct{},
)
| 414 | } |
| 415 | |
| 416 | func 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 | |
| 458 | func isFileToGenerate( |
| 459 | imageFile ImageFile, |
no test coverage detected
searching dependent graphs…