3 # Copyright Garmin International or its subsidiaries, 2018
5 # Heavily based on dbus.py
8 Compiles dbus files with **gdbus-codegen**
11 opt.load('compiler_c gdbus')
13 conf.load('compiler_c gdbus')
17 source = bld.path.ant_glob('*.c'),
18 target = 'gnome-hello')
19 tg.add_gdbus_file('test.xml', 'com.example.example.', 'Example')
22 from waflib
import Task
, Errors
, Utils
23 from waflib
.TaskGen
import taskgen_method
, before_method
26 def add_gdbus_file(self
, filename
, prefix
, namespace
, export
=False):
28 Adds a dbus file to the list of dbus files to process. Store them in the attribute *dbus_lst*.
29 :param filename: xml file to compile
30 :type filename: string
31 :param prefix: interface prefix (--interface-prefix=prefix)
33 :param mode: C namespace (--c-namespace=namespace)
35 :param export: Export Headers?
38 if not hasattr(self
, 'gdbus_lst'):
40 if not 'process_gdbus' in self
.meths
:
41 self
.meths
.append('process_gdbus')
42 self
.gdbus_lst
.append([filename
, prefix
, namespace
, export
])
44 @before_method('process_source')
45 def process_gdbus(self
):
47 Processes the dbus files stored in the attribute *gdbus_lst* to create :py:class:`gdbus_binding_tool` instances.
49 output_node
= self
.path
.get_bld().make_node(['gdbus', self
.get_name()])
52 for filename
, prefix
, namespace
, export
in getattr(self
, 'gdbus_lst', []):
53 node
= self
.path
.find_resource(filename
)
55 raise Errors
.WafError('file not found ' + filename
)
56 c_file
= output_node
.find_or_declare(node
.change_ext('.c').name
)
57 h_file
= output_node
.find_or_declare(node
.change_ext('.h').name
)
58 tsk
= self
.create_task('gdbus_binding_tool', node
, [c_file
, h_file
])
59 tsk
.cwd
= output_node
.abspath()
61 tsk
.env
.GDBUS_CODEGEN_INTERFACE_PREFIX
= prefix
62 tsk
.env
.GDBUS_CODEGEN_NAMESPACE
= namespace
63 tsk
.env
.GDBUS_CODEGEN_OUTPUT
= node
.change_ext('').name
64 sources
.append(c_file
)
68 self
.source
= Utils
.to_list(self
.source
) + sources
69 self
.includes
= [output_node
] + self
.to_incnodes(getattr(self
, 'includes', []))
71 self
.export_includes
= [output_node
] + self
.to_incnodes(getattr(self
, 'export_includes', []))
73 class gdbus_binding_tool(Task
.Task
):
78 ext_out
= ['.h', '.c']
79 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()}'
84 Detects the program gdbus-codegen and sets ``conf.env.GDBUS_CODEGEN``
86 conf
.find_program('gdbus-codegen', var
='GDBUS_CODEGEN')