Main method for the code generator. This method reads the specfile and emits Javascript to sys.stdout. Args: specfile: Path to validator.protoascii, the specfile to generate Javascript from. validator_pb2: The proto2 Python module generated from validator.proto. generate_pr
(specfile, validator_pb2, generate_proto_only,
generate_spec_only, text_format, html_format,
descriptor, out)
| 688 | |
| 689 | |
| 690 | def GenerateValidatorGeneratedJs(specfile, validator_pb2, generate_proto_only, |
| 691 | generate_spec_only, text_format, html_format, |
| 692 | descriptor, out): |
| 693 | """Main method for the code generator. |
| 694 | |
| 695 | This method reads the specfile and emits Javascript to sys.stdout. |
| 696 | |
| 697 | Args: |
| 698 | specfile: Path to validator.protoascii, the specfile to generate |
| 699 | Javascript from. |
| 700 | validator_pb2: The proto2 Python module generated from validator.proto. |
| 701 | generate_proto_only: If true, then only generate proto definition. |
| 702 | generate_spec_only: If true, then only generate spec. |
| 703 | text_format: The text_format module from the protobuf package, e.g. |
| 704 | google.protobuf.text_format. |
| 705 | html_format: Either a TagSpec.HtmlFormat enum value indicating which |
| 706 | HTML format the generated validator code should support, |
| 707 | or None indicating that all formats should be supported. |
| 708 | descriptor: The descriptor module from the protobuf package, e.g. |
| 709 | google.protobuf.descriptor. |
| 710 | out: a list of lines to output (without the newline characters), to |
| 711 | which this function will append. |
| 712 | """ |
| 713 | |
| 714 | # Only one of these flags should be true. |
| 715 | assert generate_proto_only is not generate_spec_only |
| 716 | |
| 717 | if generate_spec_only: |
| 718 | assert specfile is not None |
| 719 | |
| 720 | # First, find the descriptors and enums and generate Javascript |
| 721 | # classes and enums. |
| 722 | msg_desc_by_name = {} |
| 723 | enum_desc_by_name = {} |
| 724 | FindDescriptors(validator_pb2, msg_desc_by_name, enum_desc_by_name) |
| 725 | |
| 726 | rules_obj = '%s.RULES' % validator_pb2.DESCRIPTOR.package |
| 727 | all_names = [rules_obj] + list(msg_desc_by_name.keys()) + list(enum_desc_by_name.keys()) |
| 728 | all_names.sort() |
| 729 | |
| 730 | out = OutputFormatter(out) |
| 731 | out.Line('//') |
| 732 | out.Line('// Generated by %s - do not edit.' % os.path.basename(__file__)) |
| 733 | out.Line('//') |
| 734 | out.Line('') |
| 735 | if generate_proto_only: |
| 736 | out.Line("goog.module('amp.validator.protogenerated');") |
| 737 | if generate_spec_only: |
| 738 | out.Line("goog.module('amp.validator.createRules');") |
| 739 | out.Line( |
| 740 | "const protoGenerated = goog.require('amp.validator.protogenerated');") |
| 741 | out.Line('') |
| 742 | |
| 743 | if generate_proto_only: |
| 744 | # We share the empty arrays between all specification object instances; this |
| 745 | # works because these arrays are never mutated. To make the Closure compiler |
| 746 | # happy, we use one empty array per element type. |
| 747 | # PS: It may also help execution performance in V8 to keep the element types |
nothing calls this directly
no test coverage detected