gen_gdbus_wrapper.py 2.7 KB

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