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