diff options
Diffstat (limited to 'SCons/Platform/__init__.py')
-rw-r--r-- | SCons/Platform/__init__.py | 35 |
1 files changed, 30 insertions, 5 deletions
diff --git a/SCons/Platform/__init__.py b/SCons/Platform/__init__.py index 745db095d..81f3f8bd1 100644 --- a/SCons/Platform/__init__.py +++ b/SCons/Platform/__init__.py @@ -130,7 +130,7 @@ class PlatformSpec: class TempFileMunge: """Convert long command lines to use a temporary file. - You can set an Environment variable (usually `TEMPFILE`) to this, + You can set an Environment variable (usually ``TEMPFILE``) to this, then call it with a string argument, and it will perform temporary file substitution on it. This is used to circumvent limitations on the length of command lines. Example:: @@ -140,20 +140,42 @@ class TempFileMunge: By default, the name of the temporary file used begins with a prefix of '@'. This may be configured for other tool chains by - setting the TEMPFILEPREFIX variable. Example:: + setting the ``TEMPFILEPREFIX`` variable. Example:: env["TEMPFILEPREFIX"] = '-@' # diab compiler env["TEMPFILEPREFIX"] = '-via' # arm tool chain env["TEMPFILEPREFIX"] = '' # (the empty string) PC Lint You can configure the extension of the temporary file through the - TEMPFILESUFFIX variable, which defaults to '.lnk' (see comments + ``TEMPFILESUFFIX`` variable, which defaults to '.lnk' (see comments in the code below). Example:: env["TEMPFILESUFFIX"] = '.lnt' # PC Lint Entries in the temporary file are separated by the value of the - TEMPFILEARGJOIN variable, which defaults to an OS-appropriate value. + ``TEMPFILEARGJOIN`` variable, which defaults to an OS-appropriate value. + + A default argument escape function is ``SCons.Subst.quote_spaces``. + If you need to apply extra operations on a command argument before + writing to a temporary file(fix Windows slashes, normalize paths, etc.), + please set `TEMPFILEARGESCFUNC` variable to a custom function. Example:: + + import sys + import re + from SCons.Subst import quote_spaces + + WINPATHSEP_RE = re.compile(r"\\([^\"'\\]|$)") + + + def tempfile_arg_esc_func(arg): + arg = quote_spaces(arg) + if sys.platform != "win32": + return arg + # GCC requires double Windows slashes, let's use UNIX separator + return WINPATHSEP_RE.sub(r"/\1", arg) + + + env["TEMPFILEARGESCFUNC"] = tempfile_arg_esc_func """ def __init__(self, cmd, cmdstr = None): @@ -239,7 +261,10 @@ class TempFileMunge: if not prefix: prefix = '@' - args = list(map(SCons.Subst.quote_spaces, cmd[1:])) + args = [ + env.get('TEMPFILEARGESCFUNC', SCons.Subst.quote_spaces)(arg) + for arg in cmd[1:] + ] join_char = env.get('TEMPFILEARGJOIN',' ') os.write(fd, bytearray(join_char.join(args) + "\n",'utf-8')) os.close(fd) |