2012-04-03 03:34:16 +02:00
|
|
|
# Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights
|
|
|
|
# reserved. Use of this source code is governed by a BSD-style license that
|
|
|
|
# can be found in the LICENSE file.
|
|
|
|
|
2020-01-09 15:42:00 +01:00
|
|
|
from __future__ import absolute_import
|
2012-04-03 03:34:16 +02:00
|
|
|
import pickle
|
|
|
|
from optparse import OptionParser
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
from file_util import *
|
2017-04-27 03:59:52 +02:00
|
|
|
from git_util import git_apply_patch_file
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2015-04-22 14:33:11 +02:00
|
|
|
# Cannot be loaded as a module.
|
2012-04-03 03:34:16 +02:00
|
|
|
if __name__ != "__main__":
|
2015-04-22 14:33:11 +02:00
|
|
|
sys.stdout.write('This file cannot be loaded as a module!')
|
|
|
|
sys.exit()
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2017-04-27 03:59:52 +02:00
|
|
|
# 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_patch_dir = os.path.join(cef_dir, 'patch')
|
|
|
|
src_dir = os.path.abspath(os.path.join(cef_dir, os.pardir))
|
|
|
|
|
2017-05-28 15:04:18 +02:00
|
|
|
|
2017-04-27 03:59:52 +02:00
|
|
|
def write_note(type, note):
|
|
|
|
separator = '-' * 79 + '\n'
|
|
|
|
sys.stdout.write(separator)
|
|
|
|
sys.stdout.write('!!!! %s: %s\n' % (type, note))
|
|
|
|
sys.stdout.write(separator)
|
|
|
|
|
2017-05-28 15:04:18 +02:00
|
|
|
|
2017-04-27 03:59:52 +02:00
|
|
|
def apply_patch_file(patch_file, patch_dir):
|
|
|
|
''' Apply a specific patch file in optional patch directory. '''
|
2022-07-26 19:09:01 +02:00
|
|
|
patch_name = patch_file + '.patch'
|
|
|
|
patch_path = os.path.join(cef_patch_dir, 'patches', patch_name)
|
2017-04-27 03:59:52 +02:00
|
|
|
|
|
|
|
if patch_dir is None or len(patch_dir) == 0:
|
|
|
|
patch_dir = src_dir
|
|
|
|
else:
|
|
|
|
if not os.path.isabs(patch_dir):
|
|
|
|
# Apply patch relative to the Chromium 'src' directory.
|
|
|
|
patch_dir = os.path.join(src_dir, patch_dir)
|
|
|
|
patch_dir = os.path.abspath(patch_dir)
|
2022-07-26 19:09:01 +02:00
|
|
|
if not os.path.isdir(patch_dir):
|
|
|
|
sys.stdout.write('\nApply %s in %s\n' % (patch_name, patch_dir))
|
|
|
|
sys.stdout.write('... target directory does not exist (skipping).\n')
|
|
|
|
return 'skip'
|
2017-04-27 03:59:52 +02:00
|
|
|
|
|
|
|
result = git_apply_patch_file(patch_path, patch_dir)
|
|
|
|
if result == 'fail':
|
2017-05-28 15:04:18 +02:00
|
|
|
write_note('ERROR',
|
|
|
|
'This patch failed to apply. Your build will not be correct.')
|
2017-04-27 03:59:52 +02:00
|
|
|
return result
|
|
|
|
|
2017-05-28 15:04:18 +02:00
|
|
|
|
2017-04-27 03:59:52 +02:00
|
|
|
def apply_patch_config():
|
2015-04-22 14:33:11 +02:00
|
|
|
''' Apply patch files based on a configuration file. '''
|
2017-04-27 03:59:52 +02:00
|
|
|
config_file = os.path.join(cef_patch_dir, 'patch.cfg')
|
2015-04-22 14:33:11 +02:00
|
|
|
if not os.path.isfile(config_file):
|
|
|
|
raise Exception('Patch config file %s does not exist.' % config_file)
|
|
|
|
|
|
|
|
# Parse the configuration file.
|
|
|
|
scope = {}
|
2020-01-09 15:42:00 +01:00
|
|
|
exec (compile(open(config_file, "rb").read(), config_file, 'exec'), scope)
|
2015-04-22 14:33:11 +02:00
|
|
|
patches = scope["patches"]
|
|
|
|
|
2022-03-23 00:10:36 +01:00
|
|
|
results = {'apply': [], 'skip': [], 'fail': []}
|
2017-04-27 03:59:52 +02:00
|
|
|
|
2015-04-22 14:33:11 +02:00
|
|
|
for patch in patches:
|
2017-04-27 03:59:52 +02:00
|
|
|
patch_file = patch['name']
|
2015-04-22 14:33:11 +02:00
|
|
|
dopatch = True
|
|
|
|
|
|
|
|
if 'condition' in patch:
|
|
|
|
# Check that the environment variable is set.
|
|
|
|
if patch['condition'] not in os.environ:
|
2017-04-27 03:59:52 +02:00
|
|
|
sys.stdout.write('\nSkipping patch file %s\n' % patch_file)
|
2015-04-22 14:33:11 +02:00
|
|
|
dopatch = False
|
|
|
|
|
|
|
|
if dopatch:
|
2017-05-28 15:04:18 +02:00
|
|
|
result = apply_patch_file(patch_file, patch['path']
|
|
|
|
if 'path' in patch else None)
|
2022-03-23 00:10:36 +01:00
|
|
|
results[result].append(patch_file)
|
2017-04-27 03:59:52 +02:00
|
|
|
|
2015-04-22 14:33:11 +02:00
|
|
|
if 'note' in patch:
|
2017-04-27 03:59:52 +02:00
|
|
|
write_note('NOTE', patch['note'])
|
|
|
|
else:
|
2022-03-23 00:10:36 +01:00
|
|
|
results['skip'].append(patch_file)
|
2015-04-22 14:33:11 +02:00
|
|
|
|
2017-04-27 03:59:52 +02:00
|
|
|
sys.stdout.write('\n%d patches total (%d applied, %d skipped, %d failed)\n' % \
|
2022-03-23 00:10:36 +01:00
|
|
|
(len(patches), len(results['apply']), len(results['skip']), len(results['fail'])))
|
2017-04-27 03:59:52 +02:00
|
|
|
|
2022-03-23 00:10:36 +01:00
|
|
|
if len(results['fail']) > 0:
|
2017-04-27 03:59:52 +02:00
|
|
|
sys.stdout.write('\n')
|
2017-05-28 15:04:18 +02:00
|
|
|
write_note('ERROR',
|
|
|
|
'%d patches failed to apply. Your build will not be correct.' %
|
2022-03-23 00:10:36 +01:00
|
|
|
len(results['fail']))
|
|
|
|
sys.stdout.write('\nTo manually revert failed patches run:' \
|
2022-05-20 13:22:59 +02:00
|
|
|
'\n$ %s ./tools/patch_updater.py --revert --patch %s\n' %
|
|
|
|
(os.path.basename(sys.executable), ' --patch '.join(results['fail'])))
|
2018-05-11 13:09:26 +02:00
|
|
|
sys.exit(1)
|
2017-05-28 15:04:18 +02:00
|
|
|
|
2015-04-22 14:33:11 +02:00
|
|
|
|
|
|
|
# Parse command-line options.
|
2012-04-03 03:34:16 +02:00
|
|
|
disc = """
|
|
|
|
This utility applies patch files.
|
|
|
|
"""
|
|
|
|
|
|
|
|
parser = OptionParser(description=disc)
|
2017-05-28 15:04:18 +02:00
|
|
|
parser.add_option(
|
|
|
|
'--patch-file', dest='patchfile', metavar='FILE', help='patch source file')
|
|
|
|
parser.add_option(
|
|
|
|
'--patch-dir',
|
|
|
|
dest='patchdir',
|
|
|
|
metavar='DIR',
|
|
|
|
help='patch target directory')
|
2012-04-03 03:34:16 +02:00
|
|
|
(options, args) = parser.parse_args()
|
|
|
|
|
2017-04-27 03:59:52 +02:00
|
|
|
if not options.patchfile is None:
|
|
|
|
apply_patch_file(options.patchfile, options.patchdir)
|
2012-04-03 03:34:16 +02:00
|
|
|
else:
|
2017-04-27 03:59:52 +02:00
|
|
|
apply_patch_config()
|