1#!/usr/bin/python 2# encoding: utf-8 3# vim: tabstop=4 noexpandtab 4 5""" 6Create a satellite assembly from "*.??.txt" files. ?? stands for a language code. 7 8The projects Resources subfolder contains resources.??.txt string files for several languages. 9The build folder will hold the satellite assemblies as ./??/ExeName.resources.dll 10 11#gen becomes template (It is called gen because it also uses resx.py). 12bld(source='Resources/resources.de.txt',gen=ExeName) 13""" 14 15import os, re 16from waflib import Task 17from waflib.TaskGen import feature,before_method 18 19class al(Task.Task): 20 run_str = '${AL} ${ALFLAGS}' 21 22@feature('satellite_assembly') 23@before_method('process_source') 24def satellite_assembly(self): 25 if not getattr(self, 'gen', None): 26 self.bld.fatal('satellite_assembly needs a template assembly provided with the "gen" parameter') 27 res_lang = re.compile(r'(.*)\.(\w\w)\.(?:resx|txt)',flags=re.I) 28 29 # self.source can contain node objects, so this will break in one way or another 30 self.source = self.to_list(self.source) 31 for i, x in enumerate(self.source): 32 #x = 'resources/resources.de.resx' 33 #x = 'resources/resources.de.txt' 34 mo = res_lang.match(x) 35 if mo: 36 template = os.path.splitext(self.gen)[0] 37 templatedir, templatename = os.path.split(template) 38 res = mo.group(1) 39 lang = mo.group(2) 40 #./Resources/resources.de.resources 41 resources = self.path.find_or_declare(res+ '.' + lang + '.resources') 42 self.create_task('resgen', self.to_nodes(x), [resources]) 43 #./de/Exename.resources.dll 44 satellite = self.path.find_or_declare(os.path.join(templatedir,lang,templatename) + '.resources.dll') 45 tsk = self.create_task('al',[resources],[satellite]) 46 tsk.env.append_value('ALFLAGS','/template:'+os.path.join(self.path.relpath(),self.gen)) 47 tsk.env.append_value('ALFLAGS','/embed:'+resources.relpath()) 48 tsk.env.append_value('ALFLAGS','/culture:'+lang) 49 tsk.env.append_value('ALFLAGS','/out:'+satellite.relpath()) 50 self.source[i] = None 51 # remove the None elements that we just substituted 52 self.source = list(filter(lambda x:x, self.source)) 53 54def configure(ctx): 55 ctx.find_program('al', var='AL', mandatory=True) 56 ctx.load('resx') 57 58