From e35d3628d23590af9aa3fdb158636b135f98bba6 Mon Sep 17 00:00:00 2001 From: Thomas Nagy Date: Mon, 11 Apr 2016 23:28:33 +0200 Subject: [PATCH] Add EnvContext to simplify configuration-dependent command definition --- ChangeLog | 18 +++++++++++------- TODO | 2 -- .../examples/configuration_contexts/wscript | 18 ++++++++++++++++++ waflib/Build.py | 9 +++++++++ 4 files changed, 38 insertions(+), 9 deletions(-) create mode 100644 docs/book/examples/configuration_contexts/wscript diff --git a/ChangeLog b/ChangeLog index 023cf0aa..e1dc7ed3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -10,26 +10,30 @@ NEW IN WAF 1.9 - Merge ${FOO}${BAR} flags in commands executed without a shell (no space added) - Interpret empty command-line defines as integer values #1704 - Waf tools are not cached on "waf configure" by default anymore; pass conf.load(.., cache=True) + - Enable a consistent progress bar output #1641 - New --profile command-line option + - Add ${VAR?X} constructs in script expressions to enable simple conditional outputs + - Enable 'waf dist' to package arbitrary symlinks in tarballs #1719 * Performance highlights: - Reduce the key size in bld.task_sigs by adding bld.node_sigs and bld.imp_sigs - Remove __hash__ and __eq__ from Context, Node and Task #1629 - Make lazy visual studio detection the default - - Remove the uses of run_once that creates unfree-able memory - - Enable a consistent progress bar output #1641 - - Reduce the memory footprint of Task objects, up to 50% memory reduction on large builds - - Enabled pre-forked builds by default to achieve faster builds, up to 2x speedup on short-lived processes + - Remove the uses of run_once that can consume a lot of memory + - Enable pre-forked builds by default to achieve faster builds, up to 2x speedup on short-lived processes * API changes: - The minimum Python version required is Python 2.5 - - Remove the duplicate split functions from Utils + - Remove the duplicate split() functions from Utils - Remove the command called "update" - Add Task.get_cwd() - Remove Utils.nogc - Modify Utils.run_once so that it accepts a list of *args - - Improve the task consumer in Runner.py + - Rewrote the main task consumer in Runner.py for performance purposes - Use relative paths in apply_incpaths by default (and absolute ones when paths cross drives) - Remove Configure.err_handler - - Remove TaskBase.attr() as it was never used + - Remove TaskBase.attr() which was never used - Task.sig_vars, Task.sig_explit_deps and Task.sig_implicit_deps return None + - Better consistency between check_cfg and check_cc variables + - Subclass waflib.Build.ConfiguredContext to enable configuration-dependent user commands + diff --git a/TODO b/TODO index 9e95ba34..8f6636c0 100644 --- a/TODO +++ b/TODO @@ -1,8 +1,6 @@ Waf 1.9 ------- -* Better consistency between check_cfg and check_cc variables -* Let more context commands depend on the configuration * Rework qt5 * Regexps for extension-based processing * Other issues listed on https://github.com/waf-project/waf/issues diff --git a/docs/book/examples/configuration_contexts/wscript b/docs/book/examples/configuration_contexts/wscript new file mode 100644 index 00000000..d8cede4d --- /dev/null +++ b/docs/book/examples/configuration_contexts/wscript @@ -0,0 +1,18 @@ +#! /usr/bin/env python +# encoding: utf-8 + +""" +Call 'waf configure display' +""" + +def configure(conf): + pass + +from waflib.Build import EnvContext +class fu_class(EnvContext): + cmd = 'display' + +def display(self): + print(self.env.PREFIX) + + diff --git a/waflib/Build.py b/waflib/Build.py index 4877359f..7aac35f7 100644 --- a/waflib/Build.py +++ b/waflib/Build.py @@ -1348,3 +1348,12 @@ class StepContext(BuildContext): return pattern.match(node.abspath()) return match +class EnvContext(BuildContext): + """Subclass EnvContext to create commands that require configuration data in 'env'""" + fun = cmd = None + def execute(self): + self.restore() + if not self.all_envs: + self.load_envs() + self.recurse([self.run_dir]) +