From adc1ce1375dc3dde955e5fb08f8c6f5e06f6d85c Mon Sep 17 00:00:00 2001 From: Thomas Nagy Date: Mon, 11 Jan 2016 05:25:46 +0100 Subject: [PATCH] Simplification: added Task.get_cwd() --- ChangeLog | 2 +- TODO | 1 - waflib/Task.py | 16 +++++++++++----- waflib/Tools/cs.py | 9 ++------- waflib/Tools/fc.py | 2 +- waflib/Tools/glib2.py | 17 +++++------------ waflib/Tools/msvc.py | 8 ++------ waflib/Tools/tex.py | 10 ++-------- waflib/extras/midl.py | 11 +---------- waflib/extras/print_commands.py | 4 ++++ waflib/extras/stracedeps.py | 9 +++------ 11 files changed, 32 insertions(+), 57 deletions(-) diff --git a/ChangeLog b/ChangeLog index f28d35e9..ba6d9517 100644 --- a/ChangeLog +++ b/ChangeLog @@ -12,4 +12,4 @@ NEW IN WAF 1.9 * Reduced the key size in bld.task_sigs by adding bld.node_sigs and bld.imp_sigs * Made lazy visual studio detection the default * Flags given in the form ${FOO}${BAR} will be merged in commands executed without a shell - +* Added Task.get_cwd() diff --git a/TODO b/TODO index 918ac9a1..9ed12787 100644 --- a/TODO +++ b/TODO @@ -9,6 +9,5 @@ Waf 1.9 * Use relative paths in apply_incpaths (and absolute ones when paths cross drives) * Provide a more efficient ConfigSet implementation * Ensure _cache.py are valid python files -* Accessor for task.cwd * Other issues listed on https://github.com/waf-project/waf/issues diff --git a/waflib/Task.py b/waflib/Task.py index 32ea3680..10774d88 100644 --- a/waflib/Task.py +++ b/waflib/Task.py @@ -44,7 +44,7 @@ def f(tsk): env = tsk.env gen = tsk.generator bld = gen.bld - cwdx = getattr(tsk, 'cwd', None) or getattr(bld, 'cwd', bld.bldnode) + cwdx = tsk.get_cwd() p = env.get_flat tsk.last_cmd = cmd = \'\'\' %s \'\'\' % s return tsk.exec_command(cmd, cwd=cwdx, env=env.env or None) @@ -55,7 +55,7 @@ def f(tsk): env = tsk.env gen = tsk.generator bld = gen.bld - cwdx = getattr(tsk, 'cwd', None) or getattr(bld, 'cwd', bld.bldnode) + cwdx = tsk.get_cwd() def to_list(xx): if isinstance(xx, str): return [xx] return xx @@ -168,6 +168,13 @@ class TaskBase(evil): return 'Function' return 'Processing' + def get_cwd(self): + bld = self.generator.bld + ret = getattr(self, 'cwd', None) or getattr(self.generator.bld, 'cwd', bld.bldnode) + if isinstance(ret, str): + self.generator.bld.fatal('Working folders given to tasks must be Node objects') + return ret + def exec_command(self, cmd, **kw): """ Wrapper for :py:meth:`waflib.Context.Context.exec_command` which sets a current working directory to ``build.variant_dir`` @@ -175,10 +182,9 @@ class TaskBase(evil): :return: the return code :rtype: int """ - bld = self.generator.bld if not 'cwd' in kw: - kw['cwd'] = getattr(self, 'cwd', None) or getattr(bld, 'cwd', bld.bldnode) - return bld.exec_command(cmd, **kw) + kw['cwd'] = self.get_cwd() + return self.generator.bld.exec_command(cmd, **kw) def runnable_status(self): """ diff --git a/waflib/Tools/cs.py b/waflib/Tools/cs.py index 7d118d1d..77201acf 100644 --- a/waflib/Tools/cs.py +++ b/waflib/Tools/cs.py @@ -126,13 +126,8 @@ class mcs(Task.Task): run_str = '${MCS} ${CSTYPE} ${CSFLAGS} ${ASS_ST:ASSEMBLIES} ${RES_ST:RESOURCES} ${OUT} ${SRC}' def exec_command(self, cmd, **kw): - bld = self.generator.bld - - try: - if not kw.get('cwd', None): - kw['cwd'] = bld.cwd - except AttributeError: - kw['cwd'] = bld.bldnode + if not 'cwd' in kw: + kw['cwd'] = self.get_cwd() try: tmp = None diff --git a/waflib/Tools/fc.py b/waflib/Tools/fc.py index b480eb3c..31a06f95 100644 --- a/waflib/Tools/fc.py +++ b/waflib/Tools/fc.py @@ -167,7 +167,7 @@ class fcprogram_test(fcprogram): kw['shell'] = isinstance(cmd, str) kw['stdout'] = kw['stderr'] = Utils.subprocess.PIPE - kw['cwd'] = bld.bldnode + kw['cwd'] = self.get_cwd() bld.out = bld.err = '' bld.to_log('command: %s\n' % cmd) diff --git a/waflib/Tools/glib2.py b/waflib/Tools/glib2.py index 1eb2911d..7522febc 100644 --- a/waflib/Tools/glib2.py +++ b/waflib/Tools/glib2.py @@ -54,10 +54,11 @@ def process_marshal(self): self.source.append(c_node) class glib_genmarshal(Task.Task): - + vars = ['GLIB_GENMARSHAL_PREFIX', 'GLIB_GENMARSHAL'] + color = 'BLUE' + ext_out = ['.h'] def run(self): - - bld = self.inputs[0].__class__.ctx + bld = self.generator.bld get = self.env.get_flat cmd1 = "%s %s --prefix=%s --header > %s" % ( @@ -82,10 +83,6 @@ class glib_genmarshal(Task.Task): ) return bld.exec_command(cmd2) - vars = ['GLIB_GENMARSHAL_PREFIX', 'GLIB_GENMARSHAL'] - color = 'BLUE' - ext_out = ['.h'] - ########################## glib-mkenums @taskgen_method @@ -383,11 +380,7 @@ class glib_gresource_base(Task.Task): """ bld = self.generator.bld kw = {} - try: - if not kw.get('cwd', None): - kw['cwd'] = bld.cwd - except AttributeError: - kw['cwd'] = bld.bldnode + kw['cwd'] = self.get_cwd() kw['quiet'] = Context.BOTH cmd = Utils.subst_vars('${GLIB_COMPILE_RESOURCES} --sourcedir=%s --sourcedir=%s --generate-dependencies %s' % ( diff --git a/waflib/Tools/msvc.py b/waflib/Tools/msvc.py index 9ec2c199..c3af2ad8 100644 --- a/waflib/Tools/msvc.py +++ b/waflib/Tools/msvc.py @@ -1099,13 +1099,9 @@ def exec_command_msvc(self, *k, **kw): env.update(PATH = ';'.join(self.env['PATH'])) kw['env'] = env - bld = self.generator.bld - try: - if not kw.get('cwd', None): - kw['cwd'] = bld.cwd - except AttributeError: - kw['cwd'] = bld.bldnode + if not 'cwd' in kw: + kw['cwd'] = self.get_cwd() ret = self.exec_response_command(k[0], **kw) if not ret and getattr(self, 'do_manifest', None): ret = self.exec_mf() diff --git a/waflib/Tools/tex.py b/waflib/Tools/tex.py index eeb0b2a2..d6600265 100644 --- a/waflib/Tools/tex.py +++ b/waflib/Tools/tex.py @@ -113,14 +113,8 @@ class tex(Task.Task): :return: the return code :rtype: int """ - bld = self.generator.bld - Logs.info('runner: %r' % cmd) - try: - if not kw.get('cwd', None): - kw['cwd'] = bld.cwd.abspath() - except AttributeError: - kw['cwd'] = bld.bldnode.abspath() - return Utils.subprocess.Popen(cmd, **kw).wait() + kw['stdout'] = kw['stderr'] = None + return super(tex, self).exec_command(cmd, **kw) def scan_aux(self, node): """ diff --git a/waflib/extras/midl.py b/waflib/extras/midl.py index a2a94abb..d9100001 100644 --- a/waflib/extras/midl.py +++ b/waflib/extras/midl.py @@ -72,14 +72,5 @@ class midl(Task.Task): env = self.env.env or dict(os.environ) env.update(PATH = ';'.join(self.env['PATH'])) kw['env'] = env - - bld = self.generator.bld - - try: - if not kw.get('cwd', None): - kw['cwd'] = bld.cwd - except AttributeError: - bld.cwd = kw['cwd'] = bld.variant_dir - - return bld.exec_command(k[0], **kw) + return super(midl, self).exec_command(*k, **kw) diff --git a/waflib/extras/print_commands.py b/waflib/extras/print_commands.py index 8ce86907..a9975557 100644 --- a/waflib/extras/print_commands.py +++ b/waflib/extras/print_commands.py @@ -45,6 +45,10 @@ def exec_command(self, cmd, **kw): kw['stdin'] = Utils.subprocess.PIPE del kw['input'] + if 'cwd' in kw: + if not isinstance(kw['cwd'], str): + kw['cwd'] = kw['cwd'].abspath() + try: if kw['stdout'] or kw['stderr']: p = subprocess.Popen(cmd, **kw) diff --git a/waflib/extras/stracedeps.py b/waflib/extras/stracedeps.py index 128701d2..a8858c90 100644 --- a/waflib/extras/stracedeps.py +++ b/waflib/extras/stracedeps.py @@ -65,12 +65,9 @@ def get_strace_args(self): @task_method def exec_command(self, cmd, **kw): - bld = self.generator.bld - try: - if not kw.get('cwd', None): - kw['cwd'] = bld.cwd - except AttributeError: - kw['cwd'] = bld.bldnode + bld = self.generator.bldA + if not 'cwd' in kw: + kw['cwd'] = self.get_cwd() args = self.get_strace_args() fname = self.get_strace_file()