Replies: 3 comments 13 replies
-
You're using it wrong. It expects to have the whole command line, with the first arg being the program run which can be passed for example so in your case
|
Beta Was this translation helpful? Give feedback.
-
Seems like you may want to write your own tempfile-handler, that uses some heuristic for what to put in the @file and what to leave on the line as it construct it. |
Beta Was this translation helpful? Give feedback.
-
If that helps any anyone, here is an example of how this can be archived: import SCons.Subst
import SCons.compat
import tempfile
import importlib
import os
import sys
## This class is a handler to create a TEMPFILE
class TempFileRSP:
def __init__(self, cmd, cmdstr = None):
self.cmd = cmd
self.cmdstr = cmdstr
def __call__(self, target, source, env, for_signature):
if for_signature:
# If we're being called for signature calculation, it's
# because we're being called by the string expansion in
# Subst.py, which has the logic to strip any $( $) that
# may be in the command line we squirreled away. So we
# just return the raw command line and let the upper
# string substitution layers do their thing.
return self.cmd
# Now we're actually being called because someone is actually
# going to try to execute the command, so we have to do our
# own expansion.
cmd = env.subst_list(self.cmd, SCons.Subst.SUBST_CMD, target, source)[0]
# Check if the MAXLINELENGTH is reached and if that's
# not the case, we just return the file sources
try:
maxline = int(env.subst('$MAXLINELENGTH'))
except ValueError:
maxline = 2048
length = 0
for c in cmd:
length += len(c)
length += len(cmd) - 1
if length <= maxline:
return self.cmd
# Default to the .rsp suffix. We will append an
# .rsp suffix if none is given.
if 'TEMPFILESUFFIX' in env:
suffix = env.subst('$TEMPFILESUFFIX')
else:
suffix = '.rsp'
if 'TEMPFILEDIR' in env:
tempfile_dir = env.subst('$TEMPFILEDIR')
os.makedirs(tempfile_dir, exist_ok=True)
else:
tempfile_dir = None
fd, tmp = tempfile.mkstemp(suffix, dir=tempfile_dir, text=True) # <-- tempfile is a module here
native_tmp = SCons.Util.get_native_path(tmp)
if env.get('SHELL', None) == 'sh':
# The sh shell will try to escape the backslashes in the
# path, so unescape them.
native_tmp = native_tmp.replace('\\', r'\\\\')
# In Cygwin, we want to use rm to delete the temporary
# file, because del does not exist in the sh shell.
rm = env.Detect('rm') or 'del'
else:
# Don't use 'rm' if the shell is not sh, because rm won't
# work with the Windows shells (cmd.exe or command.com) or
# Windows path names.
rm = 'del'
if 'TEMPFILEPREFIX' in env:
prefix = env.subst('$TEMPFILEPREFIX')
else:
prefix = '@'
tempfile_esc_func = env.get('TEMPFILEARGESCFUNC', SCons.Subst.quote_spaces)
args = [
tempfile_esc_func(arg)
for arg in cmd
]
join_char = env.get('TEMPFILEARGJOIN', ' ')
os.write(fd, bytearray(join_char.join(args) + "\n", 'utf-8'))
os.close(fd)
# Create the string to insert in the command based on the created rsp file
# and the prefix given
cmdlist = [prefix + native_tmp]
return cmdlist |
Beta Was this translation helpful? Give feedback.
-
I'm using the following setup for TEMPFILE :
However the
$_LIBDIRFLAGS
and$_LIBFLAGS
part is getting ignored and never make it to the actual command, causing the build to fail. Example:Maybe there is something I'm missing here?
Beta Was this translation helpful? Give feedback.
All reactions