|
12 | 12 |
|
13 | 13 | class Win32Spawn:
|
14 | 14 | def spawn(self, sh, escape, cmd, args, env):
|
| 15 | + # deal with the cmd build-in commands which cannot be used in |
| 16 | + # subprocess.Popen |
| 17 | + if cmd == 'del': |
| 18 | + for f in args[1:]: |
| 19 | + try: |
| 20 | + os.remove(f) |
| 21 | + except Exception as e: |
| 22 | + print 'Error removing file: %s' % e |
| 23 | + return -1 |
| 24 | + return 0 |
| 25 | + |
15 | 26 | import subprocess
|
16 | 27 |
|
17 | 28 | newargs = string.join(args[1:], ' ')
|
18 | 29 | cmdline = cmd + " " + newargs
|
19 | 30 | startupinfo = subprocess.STARTUPINFO()
|
| 31 | + startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW |
| 32 | + |
| 33 | + # Make sure the env is constructed by strings |
| 34 | + _e = {k: str(v) for k, v in env.items()} |
20 | 35 |
|
21 |
| - proc = subprocess.Popen(cmdline, stdin=subprocess.PIPE, stdout=subprocess.PIPE, |
22 |
| - stderr=subprocess.PIPE, startupinfo=startupinfo, shell = False) |
23 |
| - data, err = proc.communicate() |
24 |
| - rv = proc.wait() |
25 |
| - if data: |
26 |
| - print data |
27 |
| - if err: |
28 |
| - print err |
| 36 | + # Windows(tm) CreateProcess does not use the env passed to it to find |
| 37 | + # the executables. So we have to modify our own PATH to make Popen |
| 38 | + # work. |
| 39 | + old_path = os.environ['PATH'] |
| 40 | + os.environ['PATH'] = _e['PATH'] |
| 41 | + |
| 42 | + try: |
| 43 | + proc = subprocess.Popen(cmdline, env=_e, |
| 44 | + startupinfo=startupinfo, shell=False) |
| 45 | + except Exception as e: |
| 46 | + print 'Error in Popen: %s' % e |
| 47 | + return -1 |
| 48 | + finally: |
| 49 | + os.environ['PATH'] = old_path |
29 | 50 |
|
30 |
| - if rv: |
31 |
| - return rv |
32 |
| - return 0 |
| 51 | + return proc.wait() |
33 | 52 |
|
34 | 53 | def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = []):
|
35 | 54 | import SCons.cpp
|
@@ -59,11 +78,11 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [
|
59 | 78 | env['LIBDIRPREFIX'] = '--userlibpath '
|
60 | 79 |
|
61 | 80 | # patch for win32 spawn
|
62 |
| - if env['PLATFORM'] == 'win32' and rtconfig.PLATFORM == 'gcc': |
| 81 | + if env['PLATFORM'] == 'win32': |
63 | 82 | win32_spawn = Win32Spawn()
|
64 | 83 | win32_spawn.env = env
|
65 | 84 | env['SPAWN'] = win32_spawn.spawn
|
66 |
| - |
| 85 | + |
67 | 86 | if env['PLATFORM'] == 'win32':
|
68 | 87 | os.environ['PATH'] = rtconfig.EXEC_PATH + ";" + os.environ['PATH']
|
69 | 88 | else:
|
|
0 commit comments