Skip to content

Commit 02d0cab

Browse files
committed
wscript: the i18n class names doesn't define the i18n waf command names
Try to make it a bit more clear what is going on with class and def for i18n commands. It was confusing that we first defined i18n classes in the beginning of the wscript file, and then replaced them with "plain" functions with the same name at the end. pyflakes also didn't like it. It seemed magic. The i18n functionality easily broke if trying to touch that. It deserves an explanation to make it maintainable ... and some cleanup. Simple functions in the top level wscript file are generally exposed as custom waf commands. The command will have the same name as the function and will get a plain Context. But that simple method doesn't work for these i18n commands. They have to be declared in a different way with a custom BuildContext, as seen and described in the comment. The name of the BuildContext classes doesn't matter, so we change the name to avoid the name collision and to give a hint how they actually just are contexts for the commands - they are not the command itself. We also place the classes next to the corresponding functions so it is more obvious that they are related.
1 parent bcc656e commit 02d0cab

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

Diff for: wscript

+20-16
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,6 @@ from waflib.Tools.compiler_cxx import cxx_compiler
1616
c_compiler['darwin'] = ['gcc', 'clang' ]
1717
cxx_compiler['darwin'] = ['g++', 'clang++' ]
1818

19-
class i18n(BuildContext):
20-
cmd = 'i18n'
21-
fun = 'i18n'
22-
23-
class i18n_pot(BuildContext):
24-
cmd = 'i18n_pot'
25-
fun = 'i18n_pot'
26-
27-
class i18n_po(BuildContext):
28-
cmd = 'i18n_po'
29-
fun = 'i18n_po'
30-
31-
class i18n_mo(BuildContext):
32-
cmd = 'i18n_mo'
33-
fun = 'i18n_mo'
34-
3519
compiler_flags_dictionaries= {
3620
'gcc' : {
3721
# Flags required when building a debug build
@@ -1687,16 +1671,36 @@ def build(bld):
16871671
if bld.env['RUN_TESTS']:
16881672
bld.add_post_fun(test)
16891673

1674+
# The following i18n command implementations need a BuildContext (with .env),
1675+
# and we thus create BuildContext subclasses that define the `cmd` command to
1676+
# execute the `fun` function (which often will recurse).
1677+
1678+
class _i18n_build_context(BuildContext):
1679+
cmd = 'i18n'
1680+
fun = 'i18n'
1681+
16901682
def i18n(bld):
16911683
print(bld.env)
16921684
bld.recurse (i18n_children)
16931685

1686+
class _i18n_pot_build_context(BuildContext):
1687+
cmd = 'i18n_pot'
1688+
fun = 'i18n_pot'
1689+
16941690
def i18n_pot(bld):
16951691
bld.recurse (i18n_children)
16961692

1693+
class _i18n_po_build_context(BuildContext):
1694+
cmd = 'i18n_po'
1695+
fun = 'i18n_po'
1696+
16971697
def i18n_po(bld):
16981698
bld.recurse (i18n_children)
16991699

1700+
class _i18n_mo_build_context(BuildContext):
1701+
cmd = 'i18n_mo'
1702+
fun = 'i18n_mo'
1703+
17001704
def i18n_mo(bld):
17011705
bld.recurse (i18n_children)
17021706

0 commit comments

Comments
 (0)