mirror of https://gitlab.com/ita1024/waf.git
Reduce the amount of paths added to unit test environment variable PATH
This commit is contained in:
parent
16aeb5756a
commit
764645a014
|
@ -348,7 +348,7 @@ def process_use(self):
|
|||
del use_prec[x]
|
||||
|
||||
# topological sort
|
||||
out = []
|
||||
out = self.tmp_use_sorted = []
|
||||
tmp = []
|
||||
for x in self.tmp_use_seen:
|
||||
for k in use_prec.values():
|
||||
|
|
|
@ -36,26 +36,54 @@ the predefined callback::
|
|||
import os
|
||||
from waflib.TaskGen import feature, after_method, taskgen_method
|
||||
from waflib import Utils, Task, Logs, Options
|
||||
from waflib.Tools import ccroot
|
||||
testlock = Utils.threading.Lock()
|
||||
|
||||
@feature('test')
|
||||
@after_method('apply_link')
|
||||
@after_method('apply_link', 'process_use')
|
||||
def make_test(self):
|
||||
"""Create the unit test task. There can be only one unit test task by task generator."""
|
||||
if getattr(self, 'link_task', None):
|
||||
tsk = self.create_task('utest', self.link_task.outputs)
|
||||
if getattr(self, 'ut_str', None):
|
||||
tsk.ut_run, lst = Task.compile_fun(self.ut_str, shell=getattr(self, 'ut_shell', False))
|
||||
tsk.vars = lst + tsk.vars
|
||||
if not getattr(self, 'link_task', None):
|
||||
return
|
||||
|
||||
if getattr(self, 'ut_cwd', None):
|
||||
if isinstance(self.ut_cwd, str):
|
||||
if os.path.isabs(self.ut_cwd):
|
||||
self.ut_cwd = self.bld.root.make_node(self.ut_cwd)
|
||||
else:
|
||||
self.ut_cwd = self.path.make_node(self.ut_cwd)
|
||||
tsk = self.create_task('utest', self.link_task.outputs)
|
||||
if getattr(self, 'ut_str', None):
|
||||
self.ut_run, lst = Task.compile_fun(self.ut_str, shell=getattr(self, 'ut_shell', False))
|
||||
tsk.vars = lst + tsk.vars
|
||||
|
||||
if getattr(self, 'ut_cwd', None):
|
||||
if isinstance(self.ut_cwd, str):
|
||||
# we want a Node instance
|
||||
if os.path.isabs(self.ut_cwd):
|
||||
self.ut_cwd = self.bld.root.make_node(self.ut_cwd)
|
||||
else:
|
||||
self.ut_cwd = self.path.make_node(self.ut_cwd)
|
||||
else:
|
||||
self.ut_cwd = tsk.inputs[0].parent
|
||||
|
||||
if not hasattr(self, 'ut_paths'):
|
||||
paths = []
|
||||
for x in self.tmp_use_sorted:
|
||||
try:
|
||||
y = self.bld.get_tgen_by_name(x).link_task
|
||||
except AttributeError:
|
||||
pass
|
||||
else:
|
||||
if not isinstance(y, ccroot.stlink_task):
|
||||
paths.append(y.outputs[0].parent.abspath())
|
||||
self.ut_paths = os.pathsep.join(paths) + os.pathsep
|
||||
|
||||
if not hasattr(self, 'ut_env'):
|
||||
self.ut_env = dct = dict(os.environ)
|
||||
def add_path(var):
|
||||
dct[var] = self.ut_paths + dct[var]
|
||||
if Utils.is_win32:
|
||||
add_path('PATH')
|
||||
elif Utils.unversioned_sys_platform() == 'darwin':
|
||||
add_path('DYLD_LIBRARY_PATH')
|
||||
add_path('LD_LIBRARY_PATH')
|
||||
else:
|
||||
self.ut_cwd = tsk.inputs[0].parent
|
||||
add_path('LD_LIBRARY_PATH')
|
||||
|
||||
@taskgen_method
|
||||
def add_test_results(self, tup):
|
||||
|
@ -89,37 +117,12 @@ class utest(Task.Task):
|
|||
return Task.RUN_ME
|
||||
return ret
|
||||
|
||||
def add_path(self, dct, path, var):
|
||||
dct[var] = os.pathsep.join(Utils.to_list(path) + [os.environ.get(var, '')])
|
||||
|
||||
def get_test_env(self):
|
||||
"""
|
||||
In general, tests may require any library built anywhere in the project.
|
||||
Override this method if fewer paths are needed
|
||||
"""
|
||||
try:
|
||||
fu = getattr(self.generator.bld, 'all_test_paths')
|
||||
except AttributeError:
|
||||
# this operation may be performed by at most #maxjobs
|
||||
fu = os.environ.copy()
|
||||
|
||||
lst = []
|
||||
for g in self.generator.bld.groups:
|
||||
for tg in g:
|
||||
if getattr(tg, 'link_task', None):
|
||||
s = tg.link_task.outputs[0].parent.abspath()
|
||||
if s not in lst:
|
||||
lst.append(s)
|
||||
|
||||
if Utils.is_win32:
|
||||
self.add_path(fu, lst, 'PATH')
|
||||
elif Utils.unversioned_sys_platform() == 'darwin':
|
||||
self.add_path(fu, lst, 'DYLD_LIBRARY_PATH')
|
||||
self.add_path(fu, lst, 'LD_LIBRARY_PATH')
|
||||
else:
|
||||
self.add_path(fu, lst, 'LD_LIBRARY_PATH')
|
||||
self.generator.bld.all_test_paths = fu
|
||||
return fu
|
||||
return self.generator.ut_env
|
||||
|
||||
def post_run(self):
|
||||
super(utest, self).post_run()
|
||||
|
@ -133,13 +136,13 @@ class utest(Task.Task):
|
|||
|
||||
Override ``add_test_results`` to interrupt the build
|
||||
"""
|
||||
if hasattr(self, 'ut_run'):
|
||||
return self.ut_run(self)
|
||||
if hasattr(self.generator, 'ut_run'):
|
||||
return self.generator.ut_run(self)
|
||||
|
||||
# TODO ut_exec, ut_fun, ut_cmd should be considered obsolete
|
||||
self.ut_exec = getattr(self.generator, 'ut_exec', [self.inputs[0].abspath()])
|
||||
if getattr(self.generator, 'ut_fun', None):
|
||||
self.generator.ut_fun(self)
|
||||
|
||||
testcmd = getattr(self.generator, 'ut_cmd', False) or getattr(Options.options, 'testcmd', False)
|
||||
if testcmd:
|
||||
self.ut_exec = (testcmd % ' '.join(self.ut_exec)).split(' ')
|
||||
|
|
Loading…
Reference in New Issue