Commits

Anonymous committed b6e8ef6

Add TempFileMunge support to AIX, Cygwin, HP-UX, Linux/UNIX and SunOS. (Leanid Nazdrynau)

Comments (0)

Files changed (7)

src/engine/SCons/Platform/__init__.py

 import os
 import string
 import sys
+import tempfile
 
 import SCons.Errors
 import SCons.Tool
 
     def __str__(self):
         return self.name
+        
+class TempFileMunge:
+    """A callable class.  You can set an Environment variable to this,
+    then call it with a string argument, then it will perform temporary
+    file substitution on it.  This is used to circumvent the long command
+    line limitation.
+
+    Example usage:
+    env["TEMPFILE"] = TempFileMunge
+    env["LINKCOM"] = "${TEMPFILE('$LINK $TARGET $SOURCES')}"
+    """
+    def __init__(self, cmd):
+        self.cmd = cmd
+
+    def __call__(self, target, source, env, for_signature):
+        if for_signature:
+            return self.cmd
+        cmd = env.subst_list(self.cmd, 0, target, source)[0]
+        try:
+            maxline = int(env.subst('$MAXLINELENGTH'))
+        except ValueError:
+            maxline = 2048
+        if (reduce(lambda x, y: x + len(y), cmd, 0) + len(cmd)) <= maxline:
+            return self.cmd
+        else:
+            # We do a normpath because mktemp() has what appears to be
+            # a bug in Win32 that will use a forward slash as a path
+            # delimiter.  Win32's link mistakes that for a command line
+            # switch and barfs.
+            #
+            # We use the .lnk suffix for the benefit of the Phar Lap
+            # linkloc linker, which likes to append an .lnk suffix if
+            # none is given.
+            tmp = os.path.normpath(tempfile.mktemp('.lnk'))
+            native_tmp = SCons.Util.get_native_path(tmp)
+
+            if env['SHELL'] and env['SHELL'] == 'sh':
+                # The sh shell will try to escape the backslashes in the
+                # path, so unescape them.
+                native_tmp = string.replace(native_tmp, '\\', 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 win32 shells (cmd.exe or command.com) or
+                # win32 path names.
+                rm = 'del'
+
+            args = map(SCons.Util.quote_spaces, cmd[1:])
+            open(tmp, 'w').write(string.join(args, " ") + "\n")
+            # XXX Using the SCons.Action.print_actions value directly
+            # like this is bogus, but expedient.  This class should
+            # really be rewritten as an Action that defines the
+            # __call__() and strfunction() methods and lets the
+            # normal action-execution logic handle whether or not to
+            # print/execute the action.  The problem, though, is all
+            # of that is decided before we execute this method as
+            # part of expanding the $TEMPFILE construction variable.
+            # Consequently, refactoring this will have to wait until
+            # we get more flexible with allowing Actions to exist
+            # independently and get strung together arbitrarily like
+            # Ant tasks.  In the meantime, it's going to be more
+            # user-friendly to not let obsession with architectural
+            # purity get in the way of just being helpful, so we'll
+            # reach into SCons.Action directly.
+            if SCons.Action.print_actions:
+                print("Using tempfile "+native_tmp+" for command line:\n"+
+                      str(cmd[0]) + " " + string.join(args," "))
+            return [ cmd[0], '@' + native_tmp + '\n' + rm, native_tmp ]
     
 def Platform(name = platform_default()):
     """Select a canned Platform specification.

src/engine/SCons/Platform/aix.py

 
 def generate(env):
     posix.generate(env)
+    #Based on AIX 5.2: ARG_MAX=24576 - 3000 for environment expansion
+    env['MAXLINELENGTH']  = 21576
+

src/engine/SCons/Platform/cygwin.py

 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
 
 import posix
-import win32
+from SCons.Platform import TempFileMunge
 
 def generate(env):
     posix.generate(env)
     env['SHLIBSUFFIX'] = '.dll'
     env['LIBPREFIXES'] = [ '$LIBPREFIX', '$SHLIBPREFIX' ]
     env['LIBSUFFIXES'] = [ '$LIBSUFFIX', '$SHLIBSUFFIX' ]
-    env['TEMPFILE']    = win32.TempFileMunge
+    env['TEMPFILE']    = TempFileMunge
+    env['MAXLINELENGTH']  = 2048

src/engine/SCons/Platform/hpux.py

 
 def generate(env):
     posix.generate(env)
+    #Based on HP-UX11i: ARG_MAX=2048000 - 3000 for environment expansion
+    env['MAXLINELENGTH']  = 2045000

src/engine/SCons/Platform/posix.py

 import select
 
 import SCons.Util
+from SCons.Platform import TempFileMunge
 
 exitvalmap = {
     2 : 127,
     env['SPAWN']          = spawn
     env['SHELL']          = 'sh'
     env['ESCAPE']         = escape
+    env['TEMPFILE']       = TempFileMunge
+    #Based on LINUX: ARG_MAX=ARG_MAX=131072 - 3000 for environment expansion
+    #Note: specific platforms might rise or lower this value
+    env['MAXLINELENGTH']  = 128072
 
     # This platform supports RPATH specifications.
     env['__RPATH'] = '$_RPATH'

src/engine/SCons/Platform/sunos.py

 
 def generate(env):
     posix.generate(env)
+    #Based on sunSparc 8:32bit   ARG_MAX=1048320 - 3000 for environment expansion
+    env['MAXLINELENGTH']  = 1045320

src/engine/SCons/Platform/win32.py

 import os.path
 import string
 import sys
-import tempfile
+
 from SCons.Platform.posix import exitvalmap
+from SCons.Platform import TempFileMunge
 
 # XXX See note below about why importing SCons.Action should be
 # eventually refactored.
 import SCons.Action
 import SCons.Util
 
-class TempFileMunge:
-    """A callable class.  You can set an Environment variable to this,
-    then call it with a string argument, then it will perform temporary
-    file substitution on it.  This is used to circumvent the win32 long command
-    line limitation.
-
-    Example usage:
-    env["TEMPFILE"] = TempFileMunge
-    env["LINKCOM"] = "${TEMPFILE('$LINK $TARGET $SOURCES')}"
-    """
-    def __init__(self, cmd):
-        self.cmd = cmd
-
-    def __call__(self, target, source, env, for_signature):
-        if for_signature:
-            return self.cmd
-        cmd = env.subst_list(self.cmd, 0, target, source)[0]
-        try:
-            maxline = int(env.subst('$MAXLINELENGTH'))
-        except ValueError:
-            maxline = 2048
-        if (reduce(lambda x, y: x + len(y), cmd, 0) + len(cmd)) <= maxline:
-            return self.cmd
-        else:
-            # We do a normpath because mktemp() has what appears to be
-            # a bug in Win32 that will use a forward slash as a path
-            # delimiter.  Win32's link mistakes that for a command line
-            # switch and barfs.
-            #
-            # We use the .lnk suffix for the benefit of the Phar Lap
-            # linkloc linker, which likes to append an .lnk suffix if
-            # none is given.
-            tmp = os.path.normpath(tempfile.mktemp('.lnk'))
-            native_tmp = SCons.Util.get_native_path(tmp)
-
-            if env['SHELL'] and env['SHELL'] == 'sh':
-                # The sh shell will try to escape the backslashes in the
-                # path, so unescape them.
-                native_tmp = string.replace(native_tmp, '\\', 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 win32 shells (cmd.exe or command.com) or
-                # win32 path names.
-                rm = 'del'
-
-            args = map(SCons.Util.quote_spaces, cmd[1:])
-            open(tmp, 'w').write(string.join(args, " ") + "\n")
-            # XXX Using the SCons.Action.print_actions value directly
-            # like this is bogus, but expedient.  This class should
-            # really be rewritten as an Action that defines the
-            # __call__() and strfunction() methods and lets the
-            # normal action-execution logic handle whether or not to
-            # print/execute the action.  The problem, though, is all
-            # of that is decided before we execute this method as
-            # part of expanding the $TEMPFILE construction variable.
-            # Consequently, refactoring this will have to wait until
-            # we get more flexible with allowing Actions to exist
-            # independently and get strung together arbitrarily like
-            # Ant tasks.  In the meantime, it's going to be more
-            # user-friendly to not let obsession with architectural
-            # purity get in the way of just being helpful, so we'll
-            # reach into SCons.Action directly.
-            if SCons.Action.print_actions:
-                print("Using tempfile "+native_tmp+" for command line:\n"+
-                      str(cmd[0]) + " " + string.join(args," "))
-            return [ cmd[0], '@' + native_tmp + '\n' + rm, native_tmp ]
 
 # The upshot of all this is that, if you are using Python 1.5.2,
 # you had better have cmd or command.com in your PATH when you run
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.