diff options
author | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2017-10-01 13:23:10 +0200 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2017-10-01 13:23:10 +0200 |
commit | 0414abd565dbdf12ea741930bef5268bc7fe6da3 (patch) | |
tree | aa7e983f81ffe2090fa31869b6670bf18bcc28a0 /engine/SCons/Platform/win32.py | |
parent | 3765e33b76c51c81dd7bbbfacab0c4e76a1713cb (diff) | |
parent | 3bab2962eecc24c19366692e52ebca5eb835d117 (diff) |
Merge branch 'feature/upstream' into develop
Diffstat (limited to 'engine/SCons/Platform/win32.py')
-rw-r--r-- | engine/SCons/Platform/win32.py | 113 |
1 files changed, 85 insertions, 28 deletions
diff --git a/engine/SCons/Platform/win32.py b/engine/SCons/Platform/win32.py index dacb27d..79955e7 100644 --- a/engine/SCons/Platform/win32.py +++ b/engine/SCons/Platform/win32.py @@ -8,7 +8,7 @@ selection method. """ # -# Copyright (c) 2001 - 2016 The SCons Foundation +# Copyright (c) 2001 - 2017 The SCons Foundation # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the @@ -30,7 +30,7 @@ selection method. # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # -__revision__ = "src/engine/SCons/Platform/win32.py rel_2.5.1:3735:9dc6cee5c168 2016/11/03 14:02:02 bdbaddog" +__revision__ = "src/engine/SCons/Platform/win32.py rel_3.0.0:4395:8972f6a2f699 2017/09/18 12:59:24 bdbaddog" import os import os.path @@ -60,15 +60,8 @@ except AttributeError: else: parallel_msg = None - _builtin_file = file _builtin_open = open - class _scons_file(_builtin_file): - def __init__(self, *args, **kw): - _builtin_file.__init__(self, *args, **kw) - win32api.SetHandleInformation(msvcrt.get_osfhandle(self.fileno()), - win32con.HANDLE_FLAG_INHERIT, 0) - def _scons_open(*args, **kw): fp = _builtin_open(*args, **kw) win32api.SetHandleInformation(msvcrt.get_osfhandle(fp.fileno()), @@ -76,13 +69,64 @@ else: 0) return fp - file = _scons_file open = _scons_open + if sys.version_info.major == 2: + _builtin_file = file + class _scons_file(_builtin_file): + def __init__(self, *args, **kw): + _builtin_file.__init__(self, *args, **kw) + win32api.SetHandleInformation(msvcrt.get_osfhandle(self.fileno()), + win32con.HANDLE_FLAG_INHERIT, 0) + file = _scons_file + else: + import io + for io_class in ['BufferedReader', 'BufferedWriter', 'BufferedRWPair', + 'BufferedRandom', 'TextIOWrapper']: + _builtin_file = getattr(io, io_class) + class _scons_file(_builtin_file): + def __init__(self, *args, **kw): + _builtin_file.__init__(self, *args, **kw) + win32api.SetHandleInformation(msvcrt.get_osfhandle(self.fileno()), + win32con.HANDLE_FLAG_INHERIT, 0) + setattr(io, io_class, _scons_file) + + + +if False: + # Now swap out shutil.filecopy and filecopy2 for win32 api native CopyFile + try: + from ctypes import windll + import shutil + + CopyFile = windll.kernel32.CopyFileA + SetFileTime = windll.kernel32.SetFileTime + + _shutil_copy = shutil.copy + _shutil_copy2 = shutil.copy2 + + shutil.copy2 = CopyFile + + def win_api_copyfile(src,dst): + CopyFile(src,dst) + os.utime(dst) + + shutil.copy = win_api_copyfile + + except AttributeError: + parallel_msg = \ + "Couldn't override shutil.copy or shutil.copy2 falling back to shutil defaults" + + + + + + + try: import threading spawn_lock = threading.Lock() - + # This locked version of spawnve works around a Windows # MSVCRT bug, because its spawnve is not thread-safe. # Without this, python can randomly crash while using -jN. @@ -111,11 +155,12 @@ except ImportError: # simulating a non-existent package. def spawnve(mode, file, args, env): return os.spawnve(mode, file, args, env) - + # 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 # scons. + def piped_spawn(sh, escape, cmd, args, env, stdout, stderr): # There is no direct way to do that in python. What we do # here should work for most cases: @@ -136,8 +181,7 @@ def piped_spawn(sh, escape, cmd, args, env, stdout, stderr): stderrRedirected = 0 for arg in args: # are there more possibilities to redirect stdout ? - if (arg.find( ">", 0, 1 ) != -1 or - arg.find( "1>", 0, 2 ) != -1): + if arg.find( ">", 0, 1 ) != -1 or arg.find( "1>", 0, 2 ) != -1: stdoutRedirected = 1 # are there more possibilities to redirect stderr ? if arg.find( "2>", 0, 2 ) != -1: @@ -153,7 +197,7 @@ def piped_spawn(sh, escape, cmd, args, env, stdout, stderr): try: args = [sh, '/C', escape(' '.join(args)) ] ret = spawnve(os.P_WAIT, sh, args, env) - except OSError, e: + except OSError as e: # catch any error try: ret = exitvalmap[e[0]] @@ -178,13 +222,14 @@ def piped_spawn(sh, escape, cmd, args, env, stdout, stderr): pass return ret + def exec_spawn(l, env): try: result = spawnve(os.P_WAIT, l[0], l, env) - except OSError, e: + except (OSError, EnvironmentError) as e: try: - result = exitvalmap[e[0]] - sys.stderr.write("scons: %s: %s\n" % (l[0], e[1])) + result = exitvalmap[e.errno] + sys.stderr.write("scons: %s: %s\n" % (l[0], e.strerror)) except KeyError: result = 127 if len(l) > 2: @@ -194,9 +239,10 @@ def exec_spawn(l, env): command = l[0] else: command = l[0] - sys.stderr.write("scons: unknown OSError exception code %d - '%s': %s\n" % (e[0], command, e[1])) + sys.stderr.write("scons: unknown OSError exception code %d - '%s': %s\n" % (e.errno, command, e.strerror)) return result + def spawn(sh, escape, cmd, args, env): if not sh: sys.stderr.write("scons: Could not find command interpreter, is it in your PATH?\n") @@ -216,6 +262,7 @@ def escape(x): # Get the windows system directory name _system_root = None + def get_system_root(): global _system_root if _system_root is not None: @@ -240,11 +287,21 @@ def get_system_root(): raise except: pass + + # Ensure system root is a string and not unicode + # (This only matters for py27 were unicode in env passed to POpen fails) + val = str(val) _system_root = val return val -# Get the location of the program files directory + def get_program_files_dir(): + """ + Get the location of the program files directory + Returns + ------- + + """ # Now see if we can look in the registry... val = '' if SCons.Util.can_read_reg: @@ -261,14 +318,13 @@ def get_program_files_dir(): # A reasonable default if we can't read the registry # (Actually, it's pretty reasonable even if we can :-) val = os.path.join(os.path.dirname(get_system_root()),"Program Files") - - return val + return val -# Determine which windows CPU were running on. class ArchDefinition(object): """ + Determine which windows CPU were running on. A class for defining architecture-specific settings and logic. """ def __init__(self, arch, synonyms=[]): @@ -298,6 +354,7 @@ for a in SupportedArchitectureList: for s in a.synonyms: SupportedArchitectureMap[s] = a + def get_architecture(arch=None): """Returns the definition for the specified architecture string. @@ -311,6 +368,7 @@ def get_architecture(arch=None): arch = os.environ.get('PROCESSOR_ARCHITECTURE') return SupportedArchitectureMap.get(arch, ArchDefinition('', [''])) + def generate(env): # Attempt to find cmd.exe (for WinNT/2k/XP) or # command.com for Win9x @@ -346,7 +404,7 @@ def generate(env): os.path.join(systemroot,'System32') tmp_pathext = '.com;.exe;.bat;.cmd' if 'PATHEXT' in os.environ: - tmp_pathext = os.environ['PATHEXT'] + tmp_pathext = os.environ['PATHEXT'] cmd_interp = SCons.Util.WhereIs('cmd', tmp_path, tmp_pathext) if not cmd_interp: cmd_interp = SCons.Util.WhereIs('command', tmp_path, tmp_pathext) @@ -356,7 +414,6 @@ def generate(env): if not cmd_interp: cmd_interp = env.Detect('command') - if 'ENV' not in env: env['ENV'] = {} @@ -368,7 +425,7 @@ def generate(env): # for SystemDrive because it's related. # # Weigh the impact carefully before adding other variables to this list. - import_env = [ 'SystemDrive', 'SystemRoot', 'TEMP', 'TMP' ] + import_env = ['SystemDrive', 'SystemRoot', 'TEMP', 'TMP' ] for var in import_env: v = os.environ.get(var) if v: @@ -401,10 +458,10 @@ def generate(env): env['TEMPFILEPREFIX'] = '@' env['MAXLINELENGTH'] = 2048 env['ESCAPE'] = escape - + env['HOST_OS'] = 'win32' env['HOST_ARCH'] = get_architecture().arch - + # Local Variables: # tab-width:4 |