1 From 713ccd00a541ded20b20c84c7d985f87d3a88d00 Mon Sep 17 00:00:00 2001
2 From: Roger Zanoni <rzanoni@igalia.com>
3 Date: Wed, 18 Oct 2023 15:59:13 -0300
4 Subject: [PATCH 10/11] Make patcher work outside a git checkout
7 tools/make_distrib.py | 21 +++++++++++----------
8 tools/patch_util.py | 40 ++++++++++++++++++++++++++++++++++++++++
9 tools/patcher.py | 3 +++
10 3 files changed, 54 insertions(+), 10 deletions(-)
11 create mode 100644 tools/patch_util.py
13 diff --git a/tools/make_distrib.py b/tools/make_distrib.py
14 index 6ed748fe7..a8db7947e 100644
15 --- a/tools/make_distrib.py
16 +++ b/tools/make_distrib.py
17 @@ -621,20 +621,21 @@ cef_url = git.get_url(cef_dir)
18 cef_rev = git.get_hash(cef_dir)
19 cef_commit_number = git.get_commit_number(cef_dir)
21 -if not git.is_checkout(src_dir):
22 - raise Exception('Not a valid checkout: %s' % (src_dir))
24 -# retrieve information for Chromium
25 -chromium_url = git.get_url(src_dir)
26 -chromium_rev = git.get_hash(src_dir)
30 -# format version strings
31 formatter = VersionFormatter()
32 +# format version strings
33 cef_ver = formatter.get_version_string()
34 chromium_ver = formatter.get_chromium_version_string()
36 +if not git.is_checkout(src_dir):
37 + chromium_url = git.get_url(src_dir)
38 + chromium_rev = git.get_hash(src_dir)
40 + # retrieve information for Chromium
41 + chromium_rev = chromium_ver
42 + chromium_url = 'https://commondatastorage.googleapis.com/chromium-browser-official/chromium-%s.tar.xz' % chromium_ver
46 # list of output directories to be archived
49 diff --git a/tools/patch_util.py b/tools/patch_util.py
51 index 000000000..2025e97e0
53 +++ b/tools/patch_util.py
55 +from __future__ import absolute_import
56 +from exec_util import exec_cmd
60 +def patch_apply_patch_file(patch_path, patch_dir):
61 + """ Apply |patch_path| to files in |patch_dir|. """
62 + patch_name = os.path.basename(patch_path)
63 + sys.stdout.write('\nApply %s in %s\n' % (patch_name, patch_dir))
65 + if not os.path.isfile(patch_path):
66 + sys.stdout.write('... patch file does not exist.\n')
69 + # Apply the patch file. This should always succeed because the previous
70 + # command succeeded.
72 + cmd = 'patch -p0 -N --dry-run --ignore-whitespace --input=%s' % patch_path
73 + result = exec_cmd(cmd, patch_dir)
74 + if result['ret'] != 0:
77 + cmd = 'patch --ignore-whitespace -p0 --input=%s --verbose' % patch_path
78 + result = exec_cmd(cmd, patch_dir)
80 + sys.stdout.write('Err: \t%s\n' % result['err'])
81 + sys.stdout.write('Out: \t%s\n' % result['out'])
83 + if result['err'].find('FAILED') >= 0:
84 + sys.stdout.write('... error applying patch.\n')
85 + write_indented_output(result['err'].replace('<stdin>', patch_name))
88 + if result['err'] == '':
89 + sys.stdout.write('... successfully applied.\n')
91 + sys.stdout.write('... successfully applied (with warnings):\n')
92 + sys.stdout.write('\t%s\n' % result['err'])
95 diff --git a/tools/patcher.py b/tools/patcher.py
96 index 023e91d4b..fa6eb1946 100644
97 --- a/tools/patcher.py
98 +++ b/tools/patcher.py
99 @@ -9,6 +9,7 @@ import os
101 from file_util import *
102 from git_util import git_apply_patch_file
103 +from patch_util import patch_apply_patch_file
105 # Cannot be loaded as a module.
106 if __name__ != "__main__":
107 @@ -46,6 +47,8 @@ def apply_patch_file(patch_file, patch_dir):
110 result = git_apply_patch_file(patch_path, patch_dir)
111 + if result == 'fail':
112 + result = patch_apply_patch_file(patch_path, patch_dir)
115 'This patch failed to apply. Your build will not be correct.')