def execute(self, src_proto_path, import_proto_path, output_dir, api_name, api_version, organization_name, toolkit_path, root_dir, excluded_proto_path=[], proto_deps=[], language='python'): desc_proto_paths = [] for dep in proto_deps: if 'proto_path' in dep and dep['proto_path']: desc_proto_paths.append( os.path.join(root_dir, dep['proto_path'])) desc_protos = list( protoc_utils.find_protos(src_proto_path + desc_proto_paths, excluded_proto_path)) header_proto_path = import_proto_path + desc_proto_paths header_proto_path.extend(src_proto_path) desc_out_file = task_utils.api_full_name(api_name, api_version, organization_name) + '.desc' logger.debug('Compiling descriptors for {0}'.format(desc_protos)) self.exec_command(['mkdir', '-p', output_dir]) proto_params = protoc_utils.PROTO_PARAMS_MAP[language] proto_compiler_command = proto_params.proto_compiler_command logger.debug( 'Using protoc command: {0}'.format(proto_compiler_command)) # DescGen doesn't use group protos by package right now because # - it doesn't have to # - and multiple invocation will overwrite the desc_out_file (common_resources_includes, common_resources_paths) = \ protoc_utils.protoc_common_resources_params(root_dir) params = proto_params.proto_compiler_command + \ common_resources_includes + \ protoc_utils.protoc_header_params(header_proto_path, toolkit_path) + \ protoc_utils.protoc_desc_params(output_dir, desc_out_file) + \ common_resources_paths + \ desc_protos self.exec_command(params) return os.path.join(output_dir, desc_out_file)
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=[]): 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) 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. # # Other languages don't mind us doing this, so we just do it for # everyone. for (dirname, protos) in protoc_utils.group_by_go_package( 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)) 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
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