summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaurentMarchelli <devnull@localhost>2014-11-26 14:19:37 (GMT)
committerLaurentMarchelli <devnull@localhost>2014-11-26 14:19:37 (GMT)
commitb52679b157050eaed717b2f2b01a9442efdc991c (patch)
tree8cd3ebcfe9ca86fcf88295abf8f49f9bee866ab3
parente3a660f0b60e8a06cf3e8450051a0f4472272d50 (diff)
downloadSCons-b52679b157050eaed717b2f2b01a9442efdc991c.zip
SCons-b52679b157050eaed717b2f2b01a9442efdc991c.tar.gz
SCons-b52679b157050eaed717b2f2b01a9442efdc991c.tar.bz2
TempFileMunge duplicate output and duplicate temporary file generation bug fixed.
-rw-r--r--src/engine/SCons/Platform/PlatformTests.py27
-rw-r--r--src/engine/SCons/Platform/__init__.py17
2 files changed, 43 insertions, 1 deletions
diff --git a/src/engine/SCons/Platform/PlatformTests.py b/src/engine/SCons/Platform/PlatformTests.py
index ca3080e..46151e1 100644
--- a/src/engine/SCons/Platform/PlatformTests.py
+++ b/src/engine/SCons/Platform/PlatformTests.py
@@ -156,6 +156,33 @@ class TempFileMungeTestCase(unittest.TestCase):
SCons.Action.print_actions = old_actions
assert cmd != defined_cmd, cmd
+ def test_tempfilecreation_once(self):
+ # Init class with cmd, such that the fully expanded
+ # string reads "a test command line".
+ # Note, how we're using a command string here that is
+ # actually longer than the substituted one. This is to ensure
+ # that the TempFileMunge class internally really takes the
+ # length of the expanded string into account.
+ defined_cmd = "a $VERY $OVERSIMPLIFIED line"
+ t = SCons.Platform.TempFileMunge(defined_cmd)
+ env = SCons.Environment.SubstitutionEnvironment(tools=[])
+ # Setting the line length high enough...
+ env['VERY'] = 'test'
+ env['OVERSIMPLIFIED'] = 'command'
+ expanded_cmd = env.subst(defined_cmd)
+ env['MAXLINELENGTH'] = len(expanded_cmd)-1
+ # Disable printing of actions...
+ old_actions = SCons.Action.print_actions
+ SCons.Action.print_actions = 0
+ # Create an instance of object derived class to allow setattrb
+ class TSList(object): pass
+ target = TSList()
+ cmd = t(target,None,env,0)
+ # ...and restoring its setting.
+ SCons.Action.print_actions = old_actions
+ assert cmd != defined_cmd, cmd
+ assert cmd == getattr(target, 'tempfile_cmdlist', None)
+
if __name__ == "__main__":
suite = unittest.TestSuite()
diff --git a/src/engine/SCons/Platform/__init__.py b/src/engine/SCons/Platform/__init__.py
index fa6df61..6dc241e 100644
--- a/src/engine/SCons/Platform/__init__.py
+++ b/src/engine/SCons/Platform/__init__.py
@@ -177,6 +177,12 @@ class TempFileMunge(object):
if length <= maxline:
return self.cmd
+ # Check if we already created the temporary file for this Executor
+ # It should have been previously done by Action.strfunction() call
+ cmdlist = getattr(target, 'tempfile_cmdlist', None)
+ if cmdlist is not None :
+ return cmdlist
+
# We do a normpath because mktemp() has what appears to be
# a bug in Windows that will use a forward slash as a path
# delimiter. Windows's link mistakes that for a command line
@@ -226,7 +232,16 @@ class TempFileMunge(object):
if SCons.Action.print_actions:
print("Using tempfile "+native_tmp+" for command line:\n"+
str(cmd[0]) + " " + " ".join(args))
- return [ cmd[0], prefix + native_tmp + '\n' + rm, native_tmp ]
+
+ # Store the temporary file command list into the target TList hold by
+ # the Executor to avoid creating two temporary files one for print and
+ # one for execute
+ cmdlist = [ cmd[0], prefix + native_tmp + '\n' + rm, native_tmp ]
+ try :
+ setattr(target, 'tempfile_cmdlist', cmdlist)
+ except AttributeError:
+ pass
+ return cmdlist
def Platform(name = platform_default()):
"""Select a canned Platform specification.