From 764277dc669e0a4d384f070d2c4d95e2549ce752 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Wed, 15 May 2013 12:15:40 -0400 Subject: [PATCH] Add a mechanism for patching Chromium Any *.patch files added to the (not-yet-extant) patches/ directory will be applied before we build. If patches fail to apply, we'll revert all changes and try again. Reverting will delete our copied gyp files, so we have to make sure to copy them *after* applying patches. --- .gitmodules | 3 +++ script/apply-patches | 48 ++++++++++++++++++++++++++++++++++++++++++++ script/update | 9 +++++++++ vendor/python-patch | 1 + 4 files changed, 61 insertions(+) create mode 100755 script/apply-patches create mode 160000 vendor/python-patch diff --git a/.gitmodules b/.gitmodules index e69de29b..9fb5310e 100644 --- a/.gitmodules +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "vendor/python-patch"] + path = vendor/python-patch + url = https://github.com/svn2github/python-patch diff --git a/script/apply-patches b/script/apply-patches new file mode 100755 index 00000000..80916d47 --- /dev/null +++ b/script/apply-patches @@ -0,0 +1,48 @@ +#!/usr/bin/env python + +import glob +import os +import subprocess +import sys + + +SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) +PATCHES_DIR = os.path.join(SOURCE_ROOT, 'patches') +VENDOR_DIR = os.path.join(SOURCE_ROOT, 'vendor') +DEPOT_TOOLS_DIR = os.path.join(VENDOR_DIR, 'depot_tools') +CHROMIUM_DIR = os.path.join(VENDOR_DIR, 'chromium') +SRC_DIR = os.path.join(CHROMIUM_DIR, 'src') +PATCH_PY = os.path.join(VENDOR_DIR, 'python-patch', 'patch.py') + + +def main(): + if apply_patches(): + return + sys.stderr.write('Patches failed to apply. ' + 'Reverting changes and trying again.\n') + sys.stderr.flush() + revert_changes() + apply_patches() + + +def apply_patches(): + args = [sys.executable, PATCH_PY, '--directory', SRC_DIR, '--quiet'] + for patch in glob.glob(os.path.join(PATCHES_DIR, '*.patch')): + retcode = subprocess.call(args + [patch]) + if retcode: + return False + return True + + +def revert_changes(): + gclient = os.path.join(DEPOT_TOOLS_DIR, 'gclient.py') + cwd = os.getcwd() + os.chdir(CHROMIUM_DIR) + try: + subprocess.check_call([sys.executable, gclient, 'revert']) + finally: + os.chdir(cwd) + + +if __name__ == '__main__': + sys.exit(main()) diff --git a/script/update b/script/update index 3ef0ade3..1375c5ba 100755 --- a/script/update +++ b/script/update @@ -18,6 +18,7 @@ def main(): gclient_sync() install_win_toolchain() import_win_environment() + apply_patches() copy_gyp_files() run_gyp() @@ -85,6 +86,14 @@ def copy_gyp_files(): os.path.join(CHROMIUMCONTENT_DIR, 'chromiumcontent.gyp')) +def apply_patches(): + # Applying patches can invoke gclient, which in turn can invoke gyp, so make + # sure we have our gyp environment set. + ensure_nacl_disabled() + + subprocess.check_call([sys.executable, os.path.join(SOURCE_ROOT, 'script', 'apply-patches')]) + + def run_gyp(): ensure_nacl_disabled() os.environ['GYP_GENERATORS'] = 'ninja' diff --git a/vendor/python-patch b/vendor/python-patch new file mode 160000 index 00000000..aeb08758 --- /dev/null +++ b/vendor/python-patch @@ -0,0 +1 @@ +Subproject commit aeb08758d1a170dbb408310b53e0a43e0b2ebcc9