waf_unit_test: Fix command handling under windows

The unit test tool moved from a simple split to using shlex.split for
handling the unit test command. This results in the path separators on
windows being treated as escapes.

To handle this the unit test exec command is properly escaped before
joining so that the subsequent split restores the original arguments.
The quote function is also exposed in the Utilities module so that
wscripts making use of the unit test tool can properly quote their
contributions to the command as well.
This commit is contained in:
Bootsma, James 2021-01-20 16:22:59 -07:00
parent 954adf62e7
commit c747a09a7d
2 changed files with 10 additions and 7 deletions

View File

@ -206,7 +206,7 @@ class utest(Task.Task):
self.ut_exec = getattr(self.generator, 'ut_exec', [self.inputs[0].abspath()])
ut_cmd = getattr(self.generator, 'ut_cmd', False)
if ut_cmd:
self.ut_exec = shlex.split(ut_cmd % ' '.join(self.ut_exec))
self.ut_exec = shlex.split(ut_cmd % Utils.shell_escape(self.ut_exec))
return self.exec_command(self.ut_exec)

View File

@ -11,7 +11,7 @@ through Python versions 2.5 to 3.X and across different platforms (win32, linux,
from __future__ import with_statement
import atexit, os, sys, errno, inspect, re, datetime, platform, base64, signal, functools, time
import atexit, os, sys, errno, inspect, re, datetime, platform, base64, signal, functools, time, shlex
try:
import cPickle
@ -577,10 +577,13 @@ def quote_define_name(s):
fu = fu.upper()
return fu
re_sh = re.compile('\\s|\'|"')
"""
Regexp used for shell_escape below
"""
# shlex.quote didn't exist until python 3.3. Prior to that it was a non-documented
# function in pipes.
try:
shell_quote = shlex.quote
except AttributeError:
import pipes
shell_quote = pipes.quote
def shell_escape(cmd):
"""
@ -589,7 +592,7 @@ def shell_escape(cmd):
"""
if isinstance(cmd, str):
return cmd
return ' '.join(repr(x) if re_sh.search(x) else x for x in cmd)
return ' '.join(shell_quote(x) for x in cmd)
def h_list(lst):
"""