13
0

wscript: the i18n class names do not 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.
This commit is contained in:
Mads Kiilerich 2022-01-25 21:05:50 +01:00 committed by Paul Davis
parent c78b3289d5
commit 27acda4ccd

36
wscript
View File

@ -16,22 +16,6 @@ from waflib.Tools.compiler_cxx import cxx_compiler
c_compiler['darwin'] = ['gcc', 'clang' ] c_compiler['darwin'] = ['gcc', 'clang' ]
cxx_compiler['darwin'] = ['g++', 'clang++' ] cxx_compiler['darwin'] = ['g++', 'clang++' ]
class i18n(BuildContext):
cmd = 'i18n'
fun = 'i18n'
class i18n_pot(BuildContext):
cmd = 'i18n_pot'
fun = 'i18n_pot'
class i18n_po(BuildContext):
cmd = 'i18n_po'
fun = 'i18n_po'
class i18n_mo(BuildContext):
cmd = 'i18n_mo'
fun = 'i18n_mo'
compiler_flags_dictionaries= { compiler_flags_dictionaries= {
'gcc' : { 'gcc' : {
# Flags required when building a debug build # Flags required when building a debug build
@ -1648,16 +1632,36 @@ def build(bld):
if bld.env['RUN_TESTS']: if bld.env['RUN_TESTS']:
bld.add_post_fun(test) bld.add_post_fun(test)
# The following i18n command implementations need a BuildContext (with .env),
# and we thus create BuildContext subclasses that define the `cmd` command to
# execute the `fun` function (which often will recurse).
class _i18n_build_context(BuildContext):
cmd = 'i18n'
fun = 'i18n'
def i18n(bld): def i18n(bld):
print(bld.env) print(bld.env)
bld.recurse (i18n_children) bld.recurse (i18n_children)
class _i18n_pot_build_context(BuildContext):
cmd = 'i18n_pot'
fun = 'i18n_pot'
def i18n_pot(bld): def i18n_pot(bld):
bld.recurse (i18n_children) bld.recurse (i18n_children)
class _i18n_po_build_context(BuildContext):
cmd = 'i18n_po'
fun = 'i18n_po'
def i18n_po(bld): def i18n_po(bld):
bld.recurse (i18n_children) bld.recurse (i18n_children)
class _i18n_mo_build_context(BuildContext):
cmd = 'i18n_mo'
fun = 'i18n_mo'
def i18n_mo(bld): def i18n_mo(bld):
bld.recurse (i18n_children) bld.recurse (i18n_children)