Skip to content

Commit 69621ff

Browse files
committed
Merge pull request #283 from grissiom/win32spawn
Scons: fix the Win32Spawn
2 parents adbe1ea + 66ac982 commit 69621ff

File tree

1 file changed

+32
-13
lines changed

1 file changed

+32
-13
lines changed

tools/building.py

+32-13
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,43 @@
1212

1313
class Win32Spawn:
1414
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+
1526
import subprocess
1627

1728
newargs = string.join(args[1:], ' ')
1829
cmdline = cmd + " " + newargs
1930
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()}
2035

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
2950

30-
if rv:
31-
return rv
32-
return 0
51+
return proc.wait()
3352

3453
def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = []):
3554
import SCons.cpp
@@ -59,11 +78,11 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [
5978
env['LIBDIRPREFIX'] = '--userlibpath '
6079

6180
# patch for win32 spawn
62-
if env['PLATFORM'] == 'win32' and rtconfig.PLATFORM == 'gcc':
81+
if env['PLATFORM'] == 'win32':
6382
win32_spawn = Win32Spawn()
6483
win32_spawn.env = env
6584
env['SPAWN'] = win32_spawn.spawn
66-
85+
6786
if env['PLATFORM'] == 'win32':
6887
os.environ['PATH'] = rtconfig.EXEC_PATH + ";" + os.environ['PATH']
6988
else:

0 commit comments

Comments
 (0)