From 27acda4ccd7700d442482cd97b8b776ce5b58c15 Mon Sep 17 00:00:00 2001 From: Mads Kiilerich Date: Tue, 25 Jan 2022 21:05:50 +0100 Subject: [PATCH] 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. --- wscript | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/wscript b/wscript index c123bc191d..6cf190e344 100644 --- a/wscript +++ b/wscript @@ -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 @@ -1648,16 +1632,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)