Fix patch_updater.py to work on non-Windows platforms.

git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@1690 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
Marshall Greenblatt 2014-05-02 20:57:30 +00:00
parent 5b4ed93abf
commit 84382ecbbb
2 changed files with 15 additions and 7 deletions

View File

@ -5,14 +5,20 @@
from subprocess import Popen, PIPE from subprocess import Popen, PIPE
import sys import sys
def exec_cmd(cmd, path): def exec_cmd(cmd, path, input_file=None):
""" Execute the specified command and return the result. """ """ Execute the specified command and return the result. """
out = '' out = ''
err = '' err = ''
parts = cmd.split() parts = cmd.split()
try: try:
process = Popen(parts, cwd=path, stdout=PIPE, stderr=PIPE, if not input_file:
shell=(sys.platform == 'win32')) process = Popen(parts, cwd=path, stdout=PIPE, stderr=PIPE,
shell=(sys.platform == 'win32'))
else:
with open(input_file, 'rb') as f:
process = Popen(parts, cwd=path, stdout=PIPE, stderr=PIPE,
stdin=f,
shell=(sys.platform == 'win32'))
out, err = process.communicate() out, err = process.communicate()
except IOError, (errno, strerror): except IOError, (errno, strerror):
raise raise

View File

@ -104,7 +104,7 @@ for patch in patches:
# Apply the patch file. # Apply the patch file.
msg('Applying patch to %s' % patch_root_abs) msg('Applying patch to %s' % patch_root_abs)
result = exec_cmd('patch -p0 < %s' % patch_file, patch_root_abs) result = exec_cmd('patch -p0', patch_root_abs, patch_file)
if result['err'] != '': if result['err'] != '':
raise Exception('Failed to apply patch file: %s' % result['err']) raise Exception('Failed to apply patch file: %s' % result['err'])
sys.stdout.write(result['out']) sys.stdout.write(result['out'])
@ -117,12 +117,14 @@ for patch in patches:
msg('Saving changes to %s' % patch_file) msg('Saving changes to %s' % patch_file)
patch_paths_str = ' '.join(patch_paths) patch_paths_str = ' '.join(patch_paths)
if src_is_git: if src_is_git:
cmd = 'git diff --no-prefix --relative %s > %s' % \ cmd = 'git diff --no-prefix --relative %s' % patch_paths_str
(patch_paths_str, patch_file)
else: else:
cmd = 'svn diff %s > %s' % (patch_paths_str, patch_file) cmd = 'svn diff %s' % patch_paths_str
result = exec_cmd(cmd, patch_root_abs) result = exec_cmd(cmd, patch_root_abs)
if result['err'] != '' and result['err'].find('warning:') != 0: if result['err'] != '' and result['err'].find('warning:') != 0:
raise Exception('Failed to create patch file: %s' % result['err']) raise Exception('Failed to create patch file: %s' % result['err'])
f = open(patch_file, 'wb')
f.write(result['out'])
f.close()
else: else:
raise Exception('Patch file does not exist: %s' % patch_file) raise Exception('Patch file does not exist: %s' % patch_file)