Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nanopb/nanopb.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPetteri Aimonen <jpa@git.mail.kapsi.fi>2022-11-25 15:25:45 +0300
committerPetteri Aimonen <jpa@git.mail.kapsi.fi>2022-11-25 15:25:45 +0300
commit16426666a6dffa975a359555cd8bf0c8e8562cd9 (patch)
treeb553485658302955d1317aff84d376b4ed2e4524 /generator
parentb469f3fa72743a095f3f4a1bda4b13d1935a33d9 (diff)
Add --protoc-opt to nanopb_generator.py (#628)
Allows passing flags to protoc when using it through nanopb_generator.py.
Diffstat (limited to 'generator')
-rwxr-xr-xgenerator/nanopb_generator.py7
1 files changed, 6 insertions, 1 deletions
diff --git a/generator/nanopb_generator.py b/generator/nanopb_generator.py
index 2ebf9b9..7aa26ca 100755
--- a/generator/nanopb_generator.py
+++ b/generator/nanopb_generator.py
@@ -2312,6 +2312,8 @@ optparser.add_option("-v", "--verbose", dest="verbose", action="store_true", def
help="Print more information.")
optparser.add_option("-s", dest="settings", metavar="OPTION:VALUE", action="append", default=[],
help="Set generator option (max_size, max_count etc.).")
+optparser.add_option("--protoc-opt", dest="protoc_opts", action="append", default = [], metavar="OPTION",
+ help="Pass an option to protoc when compiling .proto files")
optparser.add_option("--protoc-insertion-points", dest="protoc_insertion_points", action="store_true", default=False,
help="Include insertion point comments in output for use by custom protoc plugins")
optparser.add_option("-C", "--c-style", dest="c_style", action="store_true", default=False,
@@ -2475,7 +2477,10 @@ def main_cli():
if filename.endswith(".proto"):
with TemporaryDirectory() as tmpdir:
tmpname = os.path.join(tmpdir, os.path.basename(filename) + ".pb")
- status = invoke_protoc(["protoc"] + include_path + ['--include_imports', '--include_source_info', '-o' + tmpname, filename])
+ args = ["protoc"] + include_path
+ args += options.protoc_opts
+ args += ['--include_imports', '--include_source_info', '-o' + tmpname, filename]
+ status = invoke_protoc(args)
if status != 0: sys.exit(status)
data = open(tmpname, 'rb').read()
else: