diff options
author | Ivan Kravets <me@ikravets.com> | 2021-04-06 18:20:23 +0300 |
---|---|---|
committer | Ivan Kravets <me@ikravets.com> | 2021-04-06 18:20:23 +0300 |
commit | 9ee1b2e776dd76ba8fcd63da73037823849773e3 (patch) | |
tree | 4cac0609395316ccd89a2bf71247ef545fbb90a1 | |
parent | 8f79f4c6c0ce87236f5633dcb7bc08222622b70a (diff) | |
download | scons-git-9ee1b2e776dd76ba8fcd63da73037823849773e3.tar.gz |
Provide a custom argument escape function for `TempFileMunge` using a new `TEMPFILEARGESCFUNC` variable
-rwxr-xr-x | CHANGES.txt | 12 | ||||
-rw-r--r-- | SCons/Platform/__init__.py | 35 |
2 files changed, 39 insertions, 8 deletions
diff --git a/CHANGES.txt b/CHANGES.txt index 8ebeafc62..2b84bdc62 100755 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -13,7 +13,7 @@ RELEASE VERSION/DATE TO BE FILLED IN LATER It will now allow callables with expected args, and any extra args as long as they have default arguments. Additionally functions with no defaults for extra arguments as long as they are set using functools.partial to create a new callable which set them. - - Fix Issue #3035 - mingw with SHLIBVERSION set fails with either not a dll error or + - Fix Issue #3035 - mingw with SHLIBVERSION set fails with either not a dll error or "Multiple ways to build the same target were specified for:". Now mingw will disable creating the symlinks (and adding version string to ) dlls. It sets SHLIBNOVERSIONSYMLINKS, IMPLIBNOVERSIONSYMLINKS and LDMODULENOVERSIONSYMLINKS to True. @@ -23,9 +23,15 @@ RELEASE VERSION/DATE TO BE FILLED IN LATER set to any string value (For example ['none','false','no','off']) Also previously 'All' wouldn't have the desired affect. + From Ivan Kravets: + - Provide a custom argument escape function for `TempFileMunge` using a new + `TEMPFILEARGESCFUNC` variable. Useful if you need to apply extra operations on + a command argument before writing to a temporary file (fix Windows slashes, + normalize paths, etc.) + From Henrik Maier: - - DocbookXslt tool: The XSLT stylesheet file is now initialized to an env.File() Node, - such that dependencies work correctly in hierarchical builds (eg when using + - DocbookXslt tool: The XSLT stylesheet file is now initialized to an env.File() Node, + such that dependencies work correctly in hierarchical builds (eg when using DocbookXslt in SConscript('subdir/SConscript') context. From Daniel Moody: 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) |