Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / build / chip / linux / gen_gdbus_wrapper.py
1 #!/usr/bin/env python
2
3 # Copyright (c) 2020 Project CHIP Authors
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 import argparse
18 import subprocess
19 import sys
20
21
22 def main(argv):
23     parser = argparse.ArgumentParser(description=("Generate dbus bindings."))
24
25     parser.add_argument("--input_file",
26                         required=True,
27                         help="The dbus service definition XML file.")
28
29     parser.add_argument(
30         "--output_c",
31         help=
32         "The source file to generate containing the GDBus proxy implementation"
33     )
34
35     parser.add_argument(
36         "--output_h",
37         help="The header file to generate containing the GDBus proxy interface"
38     )
39
40     parser.add_argument("--c-namespace",
41                         default=None,
42                         help="Prefix APIs with C namespace")
43
44     parser.add_argument("--interface-prefix",
45                         default=None,
46                         help="Add interface prefix")
47
48     parser.add_argument("--c-generate-object-manager",
49                         default=False, action='store_true',
50                         help="Generate object manager")
51
52     options = parser.parse_args(argv)
53
54     extra_args = []
55     if options.c_namespace:
56         extra_args += ["--c-namespace", options.c_namespace]
57
58     if options.interface_prefix:
59         extra_args += ["--interface-prefix", options.interface_prefix]
60
61     if options.c_generate_object_manager:
62         extra_args += ["--c-generate-object-manager"]
63
64     if options.output_c:
65         gdbus_args = ["gdbus-codegen", "--body", "--output", options.output_c
66                       ] + extra_args + [options.input_file]
67         subprocess.check_call(gdbus_args)
68         sed_args = ["sed", "-i", "s/config\.h/BuildConfig.h/g", options.output_c]
69         subprocess.check_call(sed_args)
70
71     if options.output_h:
72         gdbus_args = [
73             "gdbus-codegen", "--header", "--output", options.output_h
74         ] + extra_args + [options.input_file]
75         subprocess.check_call(gdbus_args)
76
77     return 0
78
79
80 if __name__ == '__main__':
81     sys.exit(main(sys.argv[1:]))