gdbus.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #!/usr/bin/env python
  2. # encoding: utf-8
  3. # Copyright Garmin International or its subsidiaries, 2018
  4. #
  5. # Heavily based on dbus.py
  6. """
  7. Compiles dbus files with **gdbus-codegen**
  8. Typical usage::
  9. def options(opt):
  10. opt.load('compiler_c gdbus')
  11. def configure(conf):
  12. conf.load('compiler_c gdbus')
  13. def build(bld):
  14. tg = bld.program(
  15. includes = '.',
  16. source = bld.path.ant_glob('*.c'),
  17. target = 'gnome-hello')
  18. tg.add_gdbus_file('test.xml', 'com.example.example.', 'Example')
  19. """
  20. from waflib import Task, Errors, Utils
  21. from waflib.TaskGen import taskgen_method, before_method
  22. @taskgen_method
  23. def add_gdbus_file(self, filename, prefix, namespace, export=False):
  24. """
  25. Adds a dbus file to the list of dbus files to process. Store them in the attribute *dbus_lst*.
  26. :param filename: xml file to compile
  27. :type filename: string
  28. :param prefix: interface prefix (--interface-prefix=prefix)
  29. :type prefix: string
  30. :param mode: C namespace (--c-namespace=namespace)
  31. :type mode: string
  32. :param export: Export Headers?
  33. :type export: boolean
  34. """
  35. if not hasattr(self, 'gdbus_lst'):
  36. self.gdbus_lst = []
  37. if not 'process_gdbus' in self.meths:
  38. self.meths.append('process_gdbus')
  39. self.gdbus_lst.append([filename, prefix, namespace, export])
  40. @before_method('process_source')
  41. def process_gdbus(self):
  42. """
  43. Processes the dbus files stored in the attribute *gdbus_lst* to create :py:class:`gdbus_binding_tool` instances.
  44. """
  45. output_node = self.path.get_bld().make_node(['gdbus', self.get_name()])
  46. sources = []
  47. for filename, prefix, namespace, export in getattr(self, 'gdbus_lst', []):
  48. node = self.path.find_resource(filename)
  49. if not node:
  50. raise Errors.WafError('file not found ' + filename)
  51. c_file = output_node.find_or_declare(node.change_ext('.c').name)
  52. h_file = output_node.find_or_declare(node.change_ext('.h').name)
  53. tsk = self.create_task('gdbus_binding_tool', node, [c_file, h_file])
  54. tsk.cwd = output_node.abspath()
  55. tsk.env.GDBUS_CODEGEN_INTERFACE_PREFIX = prefix
  56. tsk.env.GDBUS_CODEGEN_NAMESPACE = namespace
  57. tsk.env.GDBUS_CODEGEN_OUTPUT = node.change_ext('').name
  58. sources.append(c_file)
  59. if sources:
  60. output_node.mkdir()
  61. self.source = Utils.to_list(self.source) + sources
  62. self.includes = [output_node] + self.to_incnodes(getattr(self, 'includes', []))
  63. if export:
  64. self.export_includes = [output_node] + self.to_incnodes(getattr(self, 'export_includes', []))
  65. class gdbus_binding_tool(Task.Task):
  66. """
  67. Compiles a dbus file
  68. """
  69. color = 'BLUE'
  70. ext_out = ['.h', '.c']
  71. run_str = '${GDBUS_CODEGEN} --interface-prefix ${GDBUS_CODEGEN_INTERFACE_PREFIX} --generate-c-code ${GDBUS_CODEGEN_OUTPUT} --c-namespace ${GDBUS_CODEGEN_NAMESPACE} --c-generate-object-manager ${SRC[0].abspath()}'
  72. shell = True
  73. def configure(conf):
  74. """
  75. Detects the program gdbus-codegen and sets ``conf.env.GDBUS_CODEGEN``
  76. """
  77. conf.find_program('gdbus-codegen', var='GDBUS_CODEGEN')