2
0
mirror of https://gitlab.com/ita1024/waf.git synced 2025-01-25 18:00:03 +01:00

Simplification: added Task.get_cwd()

This commit is contained in:
Thomas Nagy 2016-01-11 05:25:46 +01:00
parent 85157243c4
commit adc1ce1375
No known key found for this signature in database
GPG Key ID: 67A565EDFDF90E64
11 changed files with 32 additions and 57 deletions

View File

@ -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()

1
TODO
View File

@ -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

View File

@ -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):
"""

View File

@ -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

View File

@ -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)

View File

@ -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' % (

View File

@ -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()

View File

@ -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):
"""

View File

@ -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)

View File

@ -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)

View File

@ -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()