Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

protoc supports multiple plugins #943

Merged
merged 6 commits into from
Jun 29, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 11 additions & 13 deletions src/blade/proto_library_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,15 +311,15 @@ def _proto_descriptor_rules(self):
self.generate_build('protodescriptors', output, inputs=inputs, variables={'first': inputs[0]})

def _protoc_plugin_parameters(self, language):
"""Return a tuple of (plugin path, vars) used as parameters for ninja build."""
path, vars = '', {}
"""Return a tuple of (plugin paths, vars) used as parameters for ninja build."""
paths, vars = [], {}
for p in self.data['protoc_plugin_objects']:
if language in p.code_generation:
path = p.path
flag = p.protoc_plugin_flag(self.build_dir)
vars = {'protoc%spluginflags' % language: flag}
break
return path, vars
paths.append(p.path)
flag_key = 'protoc%spluginflags' % language
flag_value = p.protoc_plugin_flag(self.build_dir)
vars[flag_key] = vars[flag_key] + ' ' + flag_value if flag_key in vars else flag_value
return paths, vars

def _add_protoc_direct_dependencies(self, vars):
""" Add a `--direct_dependencies` optiopn to protocflags.
Expand All @@ -333,11 +333,10 @@ def _add_protoc_direct_dependencies(self, vars):
vars['protocflags'] = '--direct_dependencies %s' % ':'.join(dependencies)

def _proto_cpp_rules(self):
plugin, vars = self._protoc_plugin_parameters('cpp')
plugin_paths, vars = self._protoc_plugin_parameters('cpp')
self._add_protoc_direct_dependencies(vars)
implicit_deps = self.protoc_direct_dependencies()
if plugin:
implicit_deps.append(plugin)
implicit_deps.extend(plugin_paths)
cpp_sources = []
for src in self.srcs:
full_source, full_header = self._proto_gen_cpp_files(src)
Expand All @@ -350,10 +349,9 @@ def _proto_cpp_rules(self):
self._cc_library(objs)

def _proto_java_rules(self):
plugin, vars = self._protoc_plugin_parameters('java')
plugin_paths, vars = self._protoc_plugin_parameters('java')
implicit_deps = self.protoc_direct_dependencies()
if plugin:
implicit_deps.append(plugin)
implicit_deps.extend(plugin_paths)
java_sources = []
for src in self.srcs:
input = self._source_file_path(src)
Expand Down