aboutsummaryrefslogtreecommitdiff
path: root/pw_protobuf_compiler/py/pw_protobuf_compiler/python_protos.py
diff options
context:
space:
mode:
Diffstat (limited to 'pw_protobuf_compiler/py/pw_protobuf_compiler/python_protos.py')
-rw-r--r--pw_protobuf_compiler/py/pw_protobuf_compiler/python_protos.py11
1 files changed, 10 insertions, 1 deletions
diff --git a/pw_protobuf_compiler/py/pw_protobuf_compiler/python_protos.py b/pw_protobuf_compiler/py/pw_protobuf_compiler/python_protos.py
index 5d379cbb6..415611a2c 100644
--- a/pw_protobuf_compiler/py/pw_protobuf_compiler/python_protos.py
+++ b/pw_protobuf_compiler/py/pw_protobuf_compiler/python_protos.py
@@ -52,6 +52,15 @@ _LOG = logging.getLogger(__name__)
PathOrStr = Union[Path, str]
+def _find_protoc() -> str:
+ """Locates a protoc binary to use for compiling protos."""
+ if 'PROTOC' in os.environ:
+ return os.environ['PROTOC']
+
+ # Fallback is assuming `protoc` is on the system PATH.
+ return 'protoc'
+
+
def compile_protos(
output_dir: PathOrStr,
proto_files: Iterable[PathOrStr],
@@ -70,7 +79,7 @@ def compile_protos(
include_paths.add(path.parent)
cmd: Tuple[PathOrStr, ...] = (
- 'protoc',
+ _find_protoc(),
'--experimental_allow_proto3_optional',
'--python_out',
os.path.abspath(output_dir),