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