1#! /usr/bin/env python
2# encoding: utf-8
3
4import os
5from waflib import Task
6from waflib.TaskGen import extension
7
8def configure(conf):
9	conf.find_program(['resgen'], var='RESGEN')
10	conf.env.RESGENFLAGS = '/useSourcePath'
11
12@extension('.resx')
13def resx_file(self, node):
14	"""
15	Bind the .resx extension to a resgen task
16	"""
17	if not getattr(self, 'cs_task', None):
18		self.bld.fatal('resx_file has no link task for use %r' % self)
19
20	# Given assembly 'Foo' and file 'Sub/Dir/File.resx', create 'Foo.Sub.Dir.File.resources'
21	assembly = getattr(self, 'namespace', os.path.splitext(self.gen)[0])
22	res = os.path.splitext(node.path_from(self.path))[0].replace('/', '.').replace('\\', '.')
23	out = self.path.find_or_declare(assembly + '.' + res + '.resources')
24
25	tsk = self.create_task('resgen', node, out)
26
27	self.cs_task.dep_nodes.extend(tsk.outputs) # dependency
28	self.env.append_value('RESOURCES', tsk.outputs[0].bldpath())
29
30class resgen(Task.Task):
31	"""
32	Compile C# resource files
33	"""
34	color   = 'YELLOW'
35	run_str = '${RESGEN} ${RESGENFLAGS} ${SRC} ${TGT}'
36