Skip to content

Commit

Permalink
wscript: the i18n class names doesn't define the i18n waf command names
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kiilerix committed Jul 24, 2024
1 parent bcc656e commit 02d0cab
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions wscript
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,6 @@ from waflib.Tools.compiler_cxx import cxx_compiler
c_compiler['darwin'] = ['gcc', '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= {
'gcc' : {
# Flags required when building a debug build
Expand Down Expand Up @@ -1687,16 +1671,36 @@ def build(bld):
if bld.env['RUN_TESTS']:
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):
print(bld.env)
bld.recurse (i18n_children)

class _i18n_pot_build_context(BuildContext):
cmd = 'i18n_pot'
fun = 'i18n_pot'

def i18n_pot(bld):
bld.recurse (i18n_children)

class _i18n_po_build_context(BuildContext):
cmd = 'i18n_po'
fun = 'i18n_po'

def i18n_po(bld):
bld.recurse (i18n_children)

class _i18n_mo_build_context(BuildContext):
cmd = 'i18n_mo'
fun = 'i18n_mo'

def i18n_mo(bld):
bld.recurse (i18n_children)

Expand Down

0 comments on commit 02d0cab

Please sign in to comment.