提交 66ac9821 编写于 作者: G Grissiom

Scons: fix the Win32Spawn

Windows(tm) CreateProcess does not use the env passed to it to find the
executables. So we have to modify our own PATH to make Popen work. Also,
detect the cmd build-in commands and execute it directly.

Tested on MDK toolchain on RB4088 and the MSVS toolchain on simulator
BSP.
上级 adbe1ea3
...@@ -12,24 +12,43 @@ Env = None ...@@ -12,24 +12,43 @@ Env = None
class Win32Spawn: class Win32Spawn:
def spawn(self, sh, escape, cmd, args, env): def spawn(self, sh, escape, cmd, args, env):
# deal with the cmd build-in commands which cannot be used in
# subprocess.Popen
if cmd == 'del':
for f in args[1:]:
try:
os.remove(f)
except Exception as e:
print 'Error removing file: %s' % e
return -1
return 0
import subprocess import subprocess
newargs = string.join(args[1:], ' ') newargs = string.join(args[1:], ' ')
cmdline = cmd + " " + newargs cmdline = cmd + " " + newargs
startupinfo = subprocess.STARTUPINFO() startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
# Make sure the env is constructed by strings
_e = {k: str(v) for k, v in env.items()}
proc = subprocess.Popen(cmdline, stdin=subprocess.PIPE, stdout=subprocess.PIPE, # Windows(tm) CreateProcess does not use the env passed to it to find
stderr=subprocess.PIPE, startupinfo=startupinfo, shell = False) # the executables. So we have to modify our own PATH to make Popen
data, err = proc.communicate() # work.
rv = proc.wait() old_path = os.environ['PATH']
if data: os.environ['PATH'] = _e['PATH']
print data
if err: try:
print err proc = subprocess.Popen(cmdline, env=_e,
startupinfo=startupinfo, shell=False)
except Exception as e:
print 'Error in Popen: %s' % e
return -1
finally:
os.environ['PATH'] = old_path
if rv: return proc.wait()
return rv
return 0
def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = []): def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = []):
import SCons.cpp import SCons.cpp
...@@ -59,11 +78,11 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [ ...@@ -59,11 +78,11 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [
env['LIBDIRPREFIX'] = '--userlibpath ' env['LIBDIRPREFIX'] = '--userlibpath '
# patch for win32 spawn # patch for win32 spawn
if env['PLATFORM'] == 'win32' and rtconfig.PLATFORM == 'gcc': if env['PLATFORM'] == 'win32':
win32_spawn = Win32Spawn() win32_spawn = Win32Spawn()
win32_spawn.env = env win32_spawn.env = env
env['SPAWN'] = win32_spawn.spawn env['SPAWN'] = win32_spawn.spawn
if env['PLATFORM'] == 'win32': if env['PLATFORM'] == 'win32':
os.environ['PATH'] = rtconfig.EXEC_PATH + ";" + os.environ['PATH'] os.environ['PATH'] = rtconfig.EXEC_PATH + ";" + os.environ['PATH']
else: else:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册