dbus.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #!/usr/bin/env python
  2. # encoding: utf-8
  3. # Ali Sabil, 2007
  4. """
  5. Compiles dbus files with **dbus-binding-tool**
  6. Typical usage::
  7. def options(opt):
  8. opt.load('compiler_c dbus')
  9. def configure(conf):
  10. conf.load('compiler_c dbus')
  11. def build(bld):
  12. tg = bld.program(
  13. includes = '.',
  14. source = bld.path.ant_glob('*.c'),
  15. target = 'gnome-hello')
  16. tg.add_dbus_file('test.xml', 'test_prefix', 'glib-server')
  17. """
  18. from waflib import Task, Errors
  19. from waflib.TaskGen import taskgen_method, before_method
  20. @taskgen_method
  21. def add_dbus_file(self, filename, prefix, mode):
  22. """
  23. Adds a dbus file to the list of dbus files to process. Store them in the attribute *dbus_lst*.
  24. :param filename: xml file to compile
  25. :type filename: string
  26. :param prefix: dbus binding tool prefix (--prefix=prefix)
  27. :type prefix: string
  28. :param mode: dbus binding tool mode (--mode=mode)
  29. :type mode: string
  30. """
  31. if not hasattr(self, 'dbus_lst'):
  32. self.dbus_lst = []
  33. if not 'process_dbus' in self.meths:
  34. self.meths.append('process_dbus')
  35. self.dbus_lst.append([filename, prefix, mode])
  36. @before_method('process_source')
  37. def process_dbus(self):
  38. """
  39. Processes the dbus files stored in the attribute *dbus_lst* to create :py:class:`waflib.Tools.dbus.dbus_binding_tool` instances.
  40. """
  41. for filename, prefix, mode in getattr(self, 'dbus_lst', []):
  42. node = self.path.find_resource(filename)
  43. if not node:
  44. raise Errors.WafError('file not found ' + filename)
  45. tsk = self.create_task('dbus_binding_tool', node, node.change_ext('.h'))
  46. tsk.env.DBUS_BINDING_TOOL_PREFIX = prefix
  47. tsk.env.DBUS_BINDING_TOOL_MODE = mode
  48. class dbus_binding_tool(Task.Task):
  49. """
  50. Compiles a dbus file
  51. """
  52. color = 'BLUE'
  53. ext_out = ['.h']
  54. run_str = '${DBUS_BINDING_TOOL} --prefix=${DBUS_BINDING_TOOL_PREFIX} --mode=${DBUS_BINDING_TOOL_MODE} --output=${TGT} ${SRC}'
  55. shell = True # temporary workaround for #795
  56. def configure(conf):
  57. """
  58. Detects the program dbus-binding-tool and sets ``conf.env.DBUS_BINDING_TOOL``
  59. """
  60. conf.find_program('dbus-binding-tool', var='DBUS_BINDING_TOOL')