e089cdb624f650a6cdcfc7ee0ca25f733bbd2916
[platform/upstream/connectedhomeip.git] / third_party / pigweed / repo / pw_protobuf_compiler / py / pw_protobuf_compiler / generator_not_selected.py
1 # Copyright 2020 The Pigweed Authors
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 # use this file except in compliance with the License. You may obtain a copy of
5 # the License at
6 #
7 #     https://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 # License for the specific language governing permissions and limitations under
13 # the License.
14 """Emits an error when using a protobuf library that is not generated"""
15
16 import argparse
17 import sys
18
19
20 def parse_args():
21     parser = argparse.ArgumentParser(description=__doc__)
22     parser.add_argument('--library',
23                         required=True,
24                         help='The protobuf library being built')
25     parser.add_argument('--generator',
26                         required=True,
27                         help='The protobuf generator requested')
28     return parser.parse_args()
29
30
31 def main(library: str, generator: str):
32     print(f'ERROR: Attempting to build protobuf library {library}, but the '
33           f'{generator} protobuf generator is not in use.')
34     print(f'To use {generator} protobufs, list "{generator}" in '
35           'pw_protobuf_GENERATORS.')
36     sys.exit(1)
37
38
39 if __name__ == '__main__':
40     main(**vars(parse_args()))