# 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 from os.path import isfile import sys from file_util import * from patch_util import * # cannot be loaded as a module if __name__ != "__main__": sys.stderr.write('This file cannot be loaded as a module!') sys.exit() # parse command-line options disc = """ This utility applies patch files. """ parser = OptionParser(description=disc) parser.add_option('--patch-dir', dest='patchdir', metavar='DIR', help='source directory for patch files') (options, args) = parser.parse_args() # the patchdir option is required if options.patchdir is None: parser.print_help(sys.stdout) sys.exit() # normalize the directory value patchdir = options.patchdir.replace('\\', '/') if patchdir[-1] != '/': patchdir += '/' # check if the patching should be skipped if isfile(patchdir + 'NOPATCH'): nopatch = True sys.stdout.write('NOPATCH exists -- files have not been patched.\n') else: nopatch = False # locate the patch configuration file patchcfg = patchdir + 'patch.cfg' if not isfile(patchcfg): sys.stderr.write('File '+patchcfg+' does not exist.\n') sys.exit() scope = {} execfile(patchcfg, scope) patches = scope["patches"] for name in patches.keys(): file = patchdir+'patches/'+name+'.patch' if not isfile(file): sys.stderr.write('Patch file '+file+' does not exist.\n') else: sys.stderr.write('Reading patch file '+file+'\n') dir = patches[name] patchObj = from_file(file) patchObj.apply(dir) # 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 isfile(incfile): inccur = read_file(incfile) if inccur != incnew: sys.stdout.write('Writing file '+incfile+'.\n') write_file(incfile, incnew)