(protoImage *imagev1.Image, resolver protoencoding.Resolver, computeUnusedImports bool)
| 670 | } |
| 671 | |
| 672 | func reparseImageProto(protoImage *imagev1.Image, resolver protoencoding.Resolver, computeUnusedImports bool) error { |
| 673 | if err := protoencoding.ReparseExtensions(resolver, protoImage.ProtoReflect()); err != nil { |
| 674 | return fmt.Errorf("could not reparse image: %v", err) |
| 675 | } |
| 676 | if computeUnusedImports { |
| 677 | tracker := &importTracker{ |
| 678 | resolver: resolver, |
| 679 | used: map[string]map[string]struct{}{}, |
| 680 | } |
| 681 | tracker.findUsedImports(protoImage) |
| 682 | // Now we can populated list of unused dependencies |
| 683 | for _, file := range protoImage.GetFile() { |
| 684 | bufExt := file.GetBufExtension() |
| 685 | if bufExt == nil { |
| 686 | bufExt = &imagev1.ImageFileExtension{} |
| 687 | file.SetBufExtension(bufExt) |
| 688 | } |
| 689 | bufExt.SetUnusedDependency(nil) // reset |
| 690 | usedImports := tracker.used[file.GetName()] |
| 691 | for i, dep := range file.GetDependency() { |
| 692 | if _, ok := usedImports[dep]; !ok { |
| 693 | // it's fine if it's public |
| 694 | isPublic := false |
| 695 | for _, publicDepIndex := range file.GetPublicDependency() { |
| 696 | if i == int(publicDepIndex) { |
| 697 | isPublic = true |
| 698 | break |
| 699 | } |
| 700 | } |
| 701 | if !isPublic { |
| 702 | // This should never happen, however we do a bounds check to ensure that we are |
| 703 | // doing a safe conversion for the index. |
| 704 | if i > math.MaxInt32 || i < math.MinInt32 { |
| 705 | return fmt.Errorf("unused dependency index out-of-bounds for int32 conversion: %v", i) |
| 706 | } |
| 707 | bufExt.SetUnusedDependency(append(bufExt.GetUnusedDependency(), int32(i))) |
| 708 | } |
| 709 | } |
| 710 | } |
| 711 | } |
| 712 | } |
| 713 | return nil |
| 714 | } |
| 715 | |
| 716 | // We pass in the pathToImageFileInfo here because we also call this in |
| 717 | // ImageFileInfosWithOnlyTargetsAndTargetImports and we don't want to have to make this map twice. |
no test coverage detected
searching dependent graphs…