Add `--revert` option to patch_updater.py.

git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@1811 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
Marshall Greenblatt 2014-08-25 14:01:13 +00:00
parent c06d0cd2d8
commit cba2e8ac3a
1 changed files with 33 additions and 23 deletions

View File

@ -47,8 +47,16 @@ parser = OptionParser(description=disc)
parser.add_option('--resave', parser.add_option('--resave',
action='store_true', dest='resave', default=False, action='store_true', dest='resave', default=False,
help='re-save existing patch files to pick up manual changes') help='re-save existing patch files to pick up manual changes')
parser.add_option('--revert',
action='store_true', dest='revert', default=False,
help='revert all changes from existing patch files')
(options, args) = parser.parse_args() (options, args) = parser.parse_args()
if options.resave and options.revert:
print 'Invalid combination of options.'
parser.print_help(sys.stderr)
sys.exit()
# The CEF root directory is the parent directory of _this_ script. # The CEF root directory is the parent directory of _this_ script.
cef_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir)) cef_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir))
src_dir = os.path.join(cef_dir, os.pardir) src_dir = os.path.join(cef_dir, os.pardir)
@ -102,29 +110,31 @@ for patch in patches:
if result['out'] != '': if result['out'] != '':
sys.stdout.write(result['out']) sys.stdout.write(result['out'])
# Apply the patch file. if not options.revert:
msg('Applying patch to %s' % patch_root_abs) # Apply the patch file.
result = exec_cmd('patch -p0', patch_root_abs, patch_file) msg('Applying patch to %s' % patch_root_abs)
if result['err'] != '': result = exec_cmd('patch -p0', patch_root_abs, patch_file)
raise Exception('Failed to apply patch file: %s' % result['err']) if result['err'] != '':
sys.stdout.write(result['out']) raise Exception('Failed to apply patch file: %s' % result['err'])
if result['out'].find('FAILED') != -1: sys.stdout.write(result['out'])
warn('Failed to apply %s, fix manually and run with --resave' % \ if result['out'].find('FAILED') != -1:
patch['name']) warn('Failed to apply %s, fix manually and run with --resave' % \
continue patch['name'])
continue
# Re-create the patch file. if not options.revert:
msg('Saving changes to %s' % patch_file) # Re-create the patch file.
patch_paths_str = ' '.join(patch_paths) msg('Saving changes to %s' % patch_file)
if src_is_git: patch_paths_str = ' '.join(patch_paths)
cmd = 'git diff --no-prefix --relative %s' % patch_paths_str if src_is_git:
else: cmd = 'git diff --no-prefix --relative %s' % patch_paths_str
cmd = 'svn diff %s' % patch_paths_str else:
result = exec_cmd(cmd, patch_root_abs) cmd = 'svn diff %s' % patch_paths_str
if result['err'] != '' and result['err'].find('warning:') != 0: result = exec_cmd(cmd, patch_root_abs)
raise Exception('Failed to create patch file: %s' % result['err']) if result['err'] != '' and result['err'].find('warning:') != 0:
f = open(patch_file, 'wb') raise Exception('Failed to create patch file: %s' % result['err'])
f.write(result['out']) f = open(patch_file, 'wb')
f.close() 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)