|
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 calling:\n%s' % cmdline |
| 47 | + print 'Exception: %s: %s' % (e, os.strerror(e.errno)) |
| 48 | + return e.errno |
| 49 | + finally: |
| 50 | + os.environ['PATH'] = old_path |
29 | 51 |
|
30 | | - if rv: |
31 | | - return rv |
32 | | - return 0 |
| 52 | + return proc.wait() |
33 | 53 |
|
34 | 54 | def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = []): |
35 | 55 | import SCons.cpp |
@@ -59,11 +79,11 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [ |
59 | 79 | env['LIBDIRPREFIX'] = '--userlibpath ' |
60 | 80 |
|
61 | 81 | # patch for win32 spawn |
62 | | - if env['PLATFORM'] == 'win32' and rtconfig.PLATFORM == 'gcc': |
| 82 | + if env['PLATFORM'] == 'win32': |
63 | 83 | win32_spawn = Win32Spawn() |
64 | 84 | win32_spawn.env = env |
65 | 85 | env['SPAWN'] = win32_spawn.spawn |
66 | | - |
| 86 | + |
67 | 87 | if env['PLATFORM'] == 'win32': |
68 | 88 | os.environ['PATH'] = rtconfig.EXEC_PATH + ";" + os.environ['PATH'] |
69 | 89 | else: |
|
0 commit comments