waf

FORK: waf with some random patches
git clone https://git.neptards.moe/neptards/waf.git
Log | Files | Refs | README

gdbus.py (2906B)


      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 """
      8 Compiles dbus files with **gdbus-codegen**
      9 Typical usage::
     10 	def options(opt):
     11 		opt.load('compiler_c gdbus')
     12 	def configure(conf):
     13 		conf.load('compiler_c gdbus')
     14 	def build(bld):
     15 		tg = bld.program(
     16 			includes = '.',
     17 			source = bld.path.ant_glob('*.c'),
     18 			target = 'gnome-hello')
     19 		tg.add_gdbus_file('test.xml', 'com.example.example.', 'Example')
     20 """
     21 
     22 from waflib import Task, Errors, Utils
     23 from waflib.TaskGen import taskgen_method, before_method
     24 
     25 @taskgen_method
     26 def add_gdbus_file(self, filename, prefix, namespace, export=False):
     27 	"""
     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)
     32 	:type prefix: string
     33 	:param mode: C namespace (--c-namespace=namespace)
     34 	:type mode: string
     35 	:param export: Export Headers?
     36 	:type export: boolean
     37 	"""
     38 	if not hasattr(self, 'gdbus_lst'):
     39 		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])
     43 
     44 @before_method('process_source')
     45 def process_gdbus(self):
     46 	"""
     47 	Processes the dbus files stored in the attribute *gdbus_lst* to create :py:class:`gdbus_binding_tool` instances.
     48 	"""
     49 	output_node = self.path.get_bld().make_node(['gdbus', self.get_name()])
     50 	sources = []
     51 
     52 	for filename, prefix, namespace, export in getattr(self, 'gdbus_lst', []):
     53 		node = self.path.find_resource(filename)
     54 		if not node:
     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()
     60 
     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)
     65 
     66 	if sources:
     67 		output_node.mkdir()
     68 		self.source = Utils.to_list(self.source) + sources
     69 		self.includes = [output_node] + self.to_incnodes(getattr(self, 'includes', []))
     70 		if export:
     71 			self.export_includes = [output_node] + self.to_incnodes(getattr(self, 'export_includes', []))
     72 
     73 class gdbus_binding_tool(Task.Task):
     74 	"""
     75 	Compiles a dbus file
     76 	"""
     77 	color   = 'BLUE'
     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()}'
     80 	shell = True
     81 
     82 def configure(conf):
     83 	"""
     84 	Detects the program gdbus-codegen and sets ``conf.env.GDBUS_CODEGEN``
     85 	"""
     86 	conf.find_program('gdbus-codegen', var='GDBUS_CODEGEN')
     87