summaryrefslogtreecommitdiffstats
path: root/src/engine
diff options
context:
space:
mode:
authorSteven Knight <knight@baldmt.com>2005-03-10 13:30:11 (GMT)
committerSteven Knight <knight@baldmt.com>2005-03-10 13:30:11 (GMT)
commit8e8427ffb61b07b95c51a2111453789ef7ebdb17 (patch)
tree662608b2be4c0f6c14587ec68399171e60ea3c09 /src/engine
parentfa75a406512ceaea25163150c49b20081d3e1f8c (diff)
downloadSCons-8e8427ffb61b07b95c51a2111453789ef7ebdb17.zip
SCons-8e8427ffb61b07b95c51a2111453789ef7ebdb17.tar.gz
SCons-8e8427ffb61b07b95c51a2111453789ef7ebdb17.tar.bz2
Add TempFileMunge support to AIX, Cygwin, HP-UX, Linux/UNIX and SunOS. (Leanid Nazdrynau)
Diffstat (limited to 'src/engine')
-rw-r--r--src/engine/SCons/Platform/__init__.py71
-rw-r--r--src/engine/SCons/Platform/aix.py3
-rw-r--r--src/engine/SCons/Platform/cygwin.py5
-rw-r--r--src/engine/SCons/Platform/hpux.py2
-rw-r--r--src/engine/SCons/Platform/posix.py5
-rw-r--r--src/engine/SCons/Platform/sunos.py2
-rw-r--r--src/engine/SCons/Platform/win32.py72
7 files changed, 88 insertions, 72 deletions
diff --git a/src/engine/SCons/Platform/__init__.py b/src/engine/SCons/Platform/__init__.py
index 0856775..9c15a08 100644
--- a/src/engine/SCons/Platform/__init__.py
+++ b/src/engine/SCons/Platform/__init__.py
@@ -48,6 +48,7 @@ import imp
import os
import string
import sys
+import tempfile
import SCons.Errors
import SCons.Tool
@@ -116,6 +117,76 @@ class PlatformSpec:
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.
diff --git a/src/engine/SCons/Platform/aix.py b/src/engine/SCons/Platform/aix.py
index e0d2e76..cc11466 100644
--- a/src/engine/SCons/Platform/aix.py
+++ b/src/engine/SCons/Platform/aix.py
@@ -57,3 +57,6 @@ def get_xlc(env, xlc, xlc_r, packages):
def generate(env):
posix.generate(env)
+ #Based on AIX 5.2: ARG_MAX=24576 - 3000 for environment expansion
+ env['MAXLINELENGTH'] = 21576
+
diff --git a/src/engine/SCons/Platform/cygwin.py b/src/engine/SCons/Platform/cygwin.py
index fad95be..728eda3 100644
--- a/src/engine/SCons/Platform/cygwin.py
+++ b/src/engine/SCons/Platform/cygwin.py
@@ -33,7 +33,7 @@ selection method.
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
import posix
-import win32
+from SCons.Platform import TempFileMunge
def generate(env):
posix.generate(env)
@@ -44,4 +44,5 @@ def generate(env):
env['SHLIBSUFFIX'] = '.dll'
env['LIBPREFIXES'] = [ '$LIBPREFIX', '$SHLIBPREFIX' ]
env['LIBSUFFIXES'] = [ '$LIBSUFFIX', '$SHLIBSUFFIX' ]
- env['TEMPFILE'] = win32.TempFileMunge
+ env['TEMPFILE'] = TempFileMunge
+ env['MAXLINELENGTH'] = 2048
diff --git a/src/engine/SCons/Platform/hpux.py b/src/engine/SCons/Platform/hpux.py
index 9b3a6bb..ddbfafc 100644
--- a/src/engine/SCons/Platform/hpux.py
+++ b/src/engine/SCons/Platform/hpux.py
@@ -36,3 +36,5 @@ import posix
def generate(env):
posix.generate(env)
+ #Based on HP-UX11i: ARG_MAX=2048000 - 3000 for environment expansion
+ env['MAXLINELENGTH'] = 2045000
diff --git a/src/engine/SCons/Platform/posix.py b/src/engine/SCons/Platform/posix.py
index 24ce2fb..b945d1c 100644
--- a/src/engine/SCons/Platform/posix.py
+++ b/src/engine/SCons/Platform/posix.py
@@ -40,6 +40,7 @@ import sys
import select
import SCons.Util
+from SCons.Platform import TempFileMunge
exitvalmap = {
2 : 127,
@@ -240,6 +241,10 @@ def generate(env):
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'
diff --git a/src/engine/SCons/Platform/sunos.py b/src/engine/SCons/Platform/sunos.py
index 6b37dd6..b2bbb7f 100644
--- a/src/engine/SCons/Platform/sunos.py
+++ b/src/engine/SCons/Platform/sunos.py
@@ -36,3 +36,5 @@ import posix
def generate(env):
posix.generate(env)
+ #Based on sunSparc 8:32bit ARG_MAX=1048320 - 3000 for environment expansion
+ env['MAXLINELENGTH'] = 1045320
diff --git a/src/engine/SCons/Platform/win32.py b/src/engine/SCons/Platform/win32.py
index 62f2ee7..382e5b8 100644
--- a/src/engine/SCons/Platform/win32.py
+++ b/src/engine/SCons/Platform/win32.py
@@ -36,83 +36,15 @@ import os
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