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.
|
|
|
|
|
|
|
|
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. '''
|
|
|
|
patch_path = os.path.join(cef_patch_dir, 'patches', patch_file + '.patch')
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
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 = {}
|
|
|
|
execfile(config_file, scope)
|
|
|
|
patches = scope["patches"]
|
|
|
|
|
2017-04-27 03:59:52 +02:00
|
|
|
results = {'apply': 0, 'skip': 0, 'fail': 0}
|
|
|
|
|
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)
|
2017-04-27 03:59:52 +02:00
|
|
|
results[result] += 1
|
|
|
|
|
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:
|
|
|
|
results['skip'] += 1
|
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' % \
|
|
|
|
(len(patches), results['apply'], results['skip'], results['fail']))
|
|
|
|
|
|
|
|
if results['fail'] > 0:
|
|
|
|
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.' %
|
|
|
|
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()
|