Exemple #1
0
    def _execute_proto_codegen(self,
                               language,
                               src_proto_path,
                               import_proto_path,
                               pkg_dir,
                               api_name,
                               api_version,
                               organization_name,
                               toolkit_path,
                               gapic_api_yaml,
                               gen_proto=False,
                               gen_grpc=False,
                               final_src_proto_path=None,
                               final_import_proto_path=None,
                               excluded_proto_path=[]):
        gapic_api_yaml = gapic_api_yaml[0] if gapic_api_yaml else None
        src_proto_path = final_src_proto_path or src_proto_path
        import_proto_path = final_import_proto_path or import_proto_path
        proto_params = protoc_utils.PROTO_PARAMS_MAP[language]

        if gen_proto:
            protoc_proto_params = protoc_utils.protoc_proto_params(
                proto_params, pkg_dir, gapic_api_yaml, with_grpc=True)
        else:
            protoc_proto_params = []

        if gen_grpc:
            protoc_grpc_params = protoc_utils.protoc_grpc_params(
                proto_params, pkg_dir, toolkit_path)
        else:
            protoc_grpc_params = []

        # protoc-gen-go has some peculiarities:
        # It can only compile one package per invocation. So, we need to split
        # proto files by packages.
        #
        # The order of the input files affects comments and internal variables.
        # While this doesn't affect the correctness of the result, we sort
        # proto files for reproducibility.
        #
        # Other languages don't mind us doing this, so we just do it for
        # everyone.
        for (dirname, protos) in protoc_utils.group_by_dirname(
                protoc_utils.find_protos(src_proto_path,
                                         excluded_proto_path)).items():
            # It is possible to get duplicate protos. De-dupe them.
            protos = sorted(set(protos))

            # Execute protoc.
            self.exec_command(proto_params.proto_compiler_command +
                              protoc_utils.protoc_header_params(
                                  import_proto_path +
                                  src_proto_path, toolkit_path) +
                              protoc_proto_params + protoc_grpc_params +
                              protos)

        return pkg_dir
Exemple #2
0
    def _execute_proto_codegen(
            self, language, src_proto_path, import_proto_path,
            pkg_dir, api_name, api_version, organization_name,
            toolkit_path, gapic_api_yaml, gen_proto=False, gen_grpc=False,
            final_src_proto_path=None, final_import_proto_path=None,
            excluded_proto_path=[]):
        gapic_api_yaml = gapic_api_yaml[0] if gapic_api_yaml else None
        src_proto_path = final_src_proto_path or src_proto_path
        import_proto_path = final_import_proto_path or import_proto_path
        proto_params = protoc_utils.PROTO_PARAMS_MAP[language]

        if gen_proto:
            protoc_proto_params = protoc_utils.protoc_proto_params(
                proto_params, pkg_dir, gapic_api_yaml, with_grpc=True)
        else:
            protoc_proto_params = []

        if gen_grpc:
            protoc_grpc_params = protoc_utils.protoc_grpc_params(
                proto_params, pkg_dir, toolkit_path)
        else:
            protoc_grpc_params = []

        # protoc-gen-go has some peculiarities:
        # It can only compile one package per invocation. So, we need to split
        # proto files by packages.
        #
        # The order of the input files affects comments and internal variables.
        # While this doesn't affect the correctness of the result, we sort
        # proto files for reproducibility.
        #
        # Other languages don't mind us doing this, so we just do it for
        # everyone.
        for (dirname, protos) in protoc_utils.group_by_dirname(
                protoc_utils.find_protos(src_proto_path, excluded_proto_path)).items():
            # It is possible to get duplicate protos. De-dupe them.
            protos = sorted(set(protos))

            # Execute protoc.
            self.exec_command(proto_params.proto_compiler_command +
                protoc_utils.protoc_header_params(
                    import_proto_path + src_proto_path, toolkit_path) +
                protoc_proto_params +
                protoc_grpc_params +
                protos)

        return pkg_dir
    def _execute_proto_codegen(self,
                               language,
                               src_proto_path,
                               import_proto_path,
                               pkg_dir,
                               api_name,
                               api_version,
                               organization_name,
                               toolkit_path,
                               gapic_api_yaml,
                               gen_proto=False,
                               gen_grpc=False,
                               final_src_proto_path=None,
                               final_import_proto_path=None,
                               excluded_proto_path=[]):
        gapic_api_yaml = gapic_api_yaml[0] if gapic_api_yaml else None
        src_proto_path = final_src_proto_path or src_proto_path
        import_proto_path = final_import_proto_path or import_proto_path
        proto_params = protoc_utils.PROTO_PARAMS_MAP[language]

        if gen_proto:
            protoc_proto_params = protoc_utils.protoc_proto_params(
                proto_params, pkg_dir, gapic_api_yaml, with_grpc=True)
        else:
            protoc_proto_params = []

        if gen_grpc:
            protoc_grpc_params = protoc_utils.protoc_grpc_params(
                proto_params, pkg_dir, toolkit_path)
        else:
            protoc_grpc_params = []

        # protoc-gen-go must compile all protos in a package at the same
        # time, and *only* the protos in that package. This doesn't break
        # other languages, so we do it that way for all of them.
        for (dirname, protos) in protoc_utils.group_by_dirname(
                protoc_utils.find_protos(src_proto_path,
                                         excluded_proto_path)).items():
            self.exec_command(proto_params.proto_compiler_command +
                              protoc_utils.protoc_header_params(
                                  import_proto_path +
                                  src_proto_path, toolkit_path) +
                              protoc_proto_params + protoc_grpc_params +
                              protos)

        return pkg_dir
Exemple #4
0
    def _execute_proto_codegen(self,
                               language,
                               src_proto_path,
                               import_proto_path,
                               pkg_dir,
                               api_name,
                               api_version,
                               organization_name,
                               toolkit_path,
                               gapic_yaml,
                               root_dir,
                               gen_proto=False,
                               gen_grpc=False,
                               gen_common_resources=False,
                               final_src_proto_path=None,
                               final_import_proto_path=None,
                               excluded_proto_path=[],
                               language_out_override=None):
        # Adding 17th parameter is a sin that I commit here just because
        # refactoring of this code will never happen.
        src_proto_path = final_src_proto_path or src_proto_path
        import_proto_path = final_import_proto_path or import_proto_path
        proto_params = protoc_utils.PROTO_PARAMS_MAP[language]

        if gen_proto:
            protoc_proto_params = protoc_utils.protoc_proto_params(
                proto_params,
                pkg_dir,
                gapic_yaml,
                with_grpc=True,
                language_out_override=language_out_override)
        else:
            protoc_proto_params = []

        if gen_grpc:
            protoc_grpc_params = protoc_utils.protoc_grpc_params(
                proto_params, pkg_dir, toolkit_path)
        else:
            protoc_grpc_params = []

        if gen_common_resources:
            (common_resources_includes, common_resources_paths) = \
                protoc_utils.protoc_common_resources_params(root_dir)
            protoc_plugin_params = protoc_utils.protoc_plugin_params(
                proto_params, pkg_dir, gapic_yaml)
        else:
            (common_resources_includes, common_resources_paths) = ([], [])
            protoc_plugin_params = []

        if not protoc_proto_params \
                and not protoc_grpc_params \
                and not protoc_plugin_params:
            return pkg_dir

        # protoc-gen-go has some peculiarities:
        # It can only compile one package per invocation. So, we need to split
        # proto files by packages.
        #
        # The order of the input files affects comments and internal variables.
        # While this doesn't affect the correctness of the result, we sort
        # proto files for reproducibility.

        # For other languages, we'll pass all proto files into the same protoc
        # invocation (PHP especially needs that).
        all_protos = protoc_utils.find_protos(src_proto_path,
                                              excluded_proto_path)
        if language == "go":
            protos_map = protoc_utils.group_by_go_package(all_protos)
        else:
            protos_map = {"": all_protos}

        for (dirname, protos) in protos_map.items():
            # It is possible to get duplicate protos. De-dupe them.
            protos = sorted(set(protos))

            command_params = proto_params.proto_compiler_command + \
                common_resources_includes + \
                protoc_utils.protoc_header_params(
                    import_proto_path + src_proto_path, toolkit_path) + \
                protoc_proto_params + \
                protoc_grpc_params + \
                protoc_plugin_params + \
                common_resources_paths + \
                protos

            # Execute protoc.
            self.exec_command(command_params)

        return pkg_dir