diff options
author | Steven Knight <knight@baldmt.com> | 2002-11-25 23:33:49 (GMT) |
---|---|---|
committer | Steven Knight <knight@baldmt.com> | 2002-11-25 23:33:49 (GMT) |
commit | dd30a312b7c59abd25d41c3d332df57801abf66b (patch) | |
tree | 850fbde140c46672ee388dea2fe3fc0dd4ed525f /src/engine/SCons/Platform/posix.py | |
parent | 22c249b07f1831b86aca87ba1728a0cf19884b80 (diff) | |
download | SCons-dd30a312b7c59abd25d41c3d332df57801abf66b.zip SCons-dd30a312b7c59abd25d41c3d332df57801abf66b.tar.gz SCons-dd30a312b7c59abd25d41c3d332df57801abf66b.tar.bz2 |
Make the shell pickable via a construction variable. (Anthony Roach)
Diffstat (limited to 'src/engine/SCons/Platform/posix.py')
-rw-r--r-- | src/engine/SCons/Platform/posix.py | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/src/engine/SCons/Platform/posix.py b/src/engine/SCons/Platform/posix.py index 551265c..c7ec9d1 100644 --- a/src/engine/SCons/Platform/posix.py +++ b/src/engine/SCons/Platform/posix.py @@ -33,8 +33,63 @@ selection method. __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" import SCons.Util +import string +import os +import sys +import os.path +def escape(arg): + "escape shell special characters" + slash = '\\' + special = '"$' + + arg = string.replace(arg, slash, slash+slash) + for c in special: + arg = string.replace(arg, c, slash+c) + + return '"' + arg + '"' + +def env_spawn(sh, escape, cmd, args, env): + if env: + s = 'env -i ' + for key in env.keys(): + s = s + '%s=%s '%(key, escape(env[key])) + s = s + sh + ' -c ' + s = s + escape(string.join(args)) + else: + s = string.join(args) + + return os.system(s) >> 8 + +def fork_spawn(sh, escape, cmd, args, env): + pid = os.fork() + if not pid: + # Child process. + exitval = 127 + args = [sh, '-c', string.join(args)] + try: + os.execvpe(sh, args, env) + except OSError, e: + exitval = exitvalmap[e[0]] + sys.stderr.write("scons: %s: %s\n" % (cmd, e[1])) + os._exit(exitval) + else: + # Parent process. + pid, stat = os.waitpid(pid, 0) + ret = stat >> 8 + return ret + def generate(env): + + # If the env command exists, then we can use os.system() + # to spawn commands, otherwise we fall back on os.fork()/os.exec(). + # os.system() is prefered because it seems to work better with + # threads (i.e. -j) and is more efficient than forking Python. + if env.Detect('env'): + spawn = env_spawn + else: + spawn = fork_spawn + if not env.has_key('ENV'): env['ENV'] = {} env['ENV']['PATH'] = '/usr/local/bin:/bin:/usr/bin' @@ -50,3 +105,6 @@ def generate(env): env['SHLIBSUFFIX'] = '.so' env['LIBPREFIXES'] = '$LIBPREFIX' env['LIBSUFFIXES'] = [ '$LIBSUFFIX', '$SHLIBSUFFIX' ] + env['SPAWN'] = spawn + env['SHELL'] = 'sh' + env['ESCAPE'] = escape |