mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
Add ability to patch Chromium DEPS file (issue #1612)
This commit is contained in:
142
tools/patcher.py
142
tools/patcher.py
@ -10,13 +10,61 @@ from file_util import *
|
||||
from patch_util import *
|
||||
|
||||
|
||||
# cannot be loaded as a module
|
||||
# Cannot be loaded as a module.
|
||||
if __name__ != "__main__":
|
||||
sys.stderr.write('This file cannot be loaded as a module!')
|
||||
sys.exit()
|
||||
|
||||
sys.stdout.write('This file cannot be loaded as a module!')
|
||||
sys.exit()
|
||||
|
||||
# parse command-line options
|
||||
|
||||
def normalize_dir(dir):
|
||||
''' Normalize the directory value. '''
|
||||
dir = dir.replace('\\', '/')
|
||||
if dir[-1] != '/':
|
||||
dir += '/'
|
||||
return dir
|
||||
|
||||
def patch_file(patch_file, patch_dir):
|
||||
''' Apply a single patch file in a single directory. '''
|
||||
if not os.path.isfile(patch_file):
|
||||
raise Exception('Patch file %s does not exist.' % patch_file)
|
||||
|
||||
sys.stdout.write('Reading patch file %s\n' % patch_file)
|
||||
patchObj = from_file(patch_file)
|
||||
patchObj.apply(normalize_dir(patch_dir))
|
||||
|
||||
def patch_config(config_file):
|
||||
''' Apply patch files based on a configuration file. '''
|
||||
# Normalize the patch directory value.
|
||||
patchdir = normalize_dir(os.path.dirname(os.path.abspath(config_file)))
|
||||
|
||||
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"]
|
||||
|
||||
for patch in patches:
|
||||
file = patchdir+'patches/'+patch['name']+'.patch'
|
||||
dopatch = True
|
||||
|
||||
if 'condition' in patch:
|
||||
# Check that the environment variable is set.
|
||||
if patch['condition'] not in os.environ:
|
||||
sys.stdout.write('Skipping patch file %s\n' % file)
|
||||
dopatch = False
|
||||
|
||||
if dopatch:
|
||||
patch_file(file, patch['path'])
|
||||
if 'note' in patch:
|
||||
separator = '-' * 79 + '\n'
|
||||
sys.stdout.write(separator)
|
||||
sys.stdout.write('NOTE: %s\n' % patch['note'])
|
||||
sys.stdout.write(separator)
|
||||
|
||||
|
||||
# Parse command-line options.
|
||||
disc = """
|
||||
This utility applies patch files.
|
||||
"""
|
||||
@ -24,80 +72,16 @@ This utility applies patch files.
|
||||
parser = OptionParser(description=disc)
|
||||
parser.add_option('--patch-config', dest='patchconfig', metavar='DIR',
|
||||
help='patch configuration file')
|
||||
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')
|
||||
(options, args) = parser.parse_args()
|
||||
|
||||
# the patchconfig option is required
|
||||
if options.patchconfig is None:
|
||||
parser.print_help(sys.stdout)
|
||||
sys.exit()
|
||||
|
||||
# normalize the patch directory value
|
||||
patchdir = os.path.dirname(os.path.abspath(options.patchconfig)).replace('\\', '/')
|
||||
if patchdir[-1] != '/':
|
||||
patchdir += '/'
|
||||
|
||||
# check if the patching should be skipped
|
||||
if os.path.isfile(patchdir + 'NOPATCH'):
|
||||
nopatch = True
|
||||
sys.stdout.write('NOPATCH exists -- files have not been patched.\n')
|
||||
if not options.patchconfig is None:
|
||||
patch_config(options.patchconfig)
|
||||
elif not options.patchfile is None and not options.patchdir is None:
|
||||
patch_file(options.patchfile, options.patchdir)
|
||||
else:
|
||||
nopatch = False
|
||||
# locate the patch configuration file
|
||||
if not os.path.isfile(options.patchconfig):
|
||||
sys.stderr.write('File '+options.patchconfig+' does not exist.\n')
|
||||
sys.exit()
|
||||
|
||||
scope = {}
|
||||
execfile(options.patchconfig, scope)
|
||||
patches = scope["patches"]
|
||||
|
||||
for patch in patches:
|
||||
file = patchdir+'patches/'+patch['name']+'.patch'
|
||||
dopatch = True
|
||||
|
||||
if 'condition' in patch:
|
||||
# Check that the environment variable is set.
|
||||
if patch['condition'] not in os.environ:
|
||||
sys.stderr.write('Skipping patch file '+file+'\n')
|
||||
dopatch = False
|
||||
|
||||
if dopatch:
|
||||
if not os.path.isfile(file):
|
||||
sys.stderr.write('Patch file '+file+' does not exist.\n')
|
||||
else:
|
||||
sys.stderr.write('Reading patch file '+file+'\n')
|
||||
dir = patch['path']
|
||||
patchObj = from_file(file)
|
||||
patchObj.apply(dir)
|
||||
if 'note' in patch:
|
||||
separator = '-' * 79 + '\n'
|
||||
sys.stderr.write(separator)
|
||||
sys.stderr.write('NOTE: '+patch['note']+'\n')
|
||||
sys.stderr.write(separator)
|
||||
|
||||
# read the current include file, if any
|
||||
incfile = patchdir + 'patch_state.h'
|
||||
if nopatch:
|
||||
incnew = """// This file is generated by the patch tool and should not be edited manually.
|
||||
#ifndef _PATCH_STATE_H
|
||||
#define _PATCH_STATE_H
|
||||
// No patches have been applied to the Chromium/WebKit source base.
|
||||
#define CEF_PATCHES_APPLIED 0
|
||||
#endif // _PATCH_STATE_H
|
||||
"""
|
||||
else:
|
||||
incnew = """// This file is generated by the patch tool and should not be edited manually.
|
||||
#ifndef _PATCH_STATE_H
|
||||
#define _PATCH_STATE_H
|
||||
// Patches have been applied to the Chromium/WebKit source base.
|
||||
#define CEF_PATCHES_APPLIED 1
|
||||
#endif // _PATCH_STATE_H
|
||||
"""
|
||||
|
||||
inccur = ''
|
||||
if os.path.isfile(incfile):
|
||||
inccur = read_file(incfile)
|
||||
|
||||
if inccur != incnew:
|
||||
sys.stdout.write('Writing file '+incfile+'.\n')
|
||||
write_file(incfile, incnew)
|
||||
parser.print_help(sys.stdout)
|
||||
sys.exit()
|
||||
|
Reference in New Issue
Block a user