[cef][wam] Make the recipe work with official chromium release tarballs
[AGL/meta-agl-demo.git] / recipes-wam / cef / files / cef / 0010-Make-patcher-work-outside-a-git-checkout.patch
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
5
6 ---
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
12
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)
20  
21 -if not git.is_checkout(src_dir):
22 -  raise Exception('Not a valid checkout: %s' % (src_dir))
23 -
24 -# retrieve information for Chromium
25 -chromium_url = git.get_url(src_dir)
26 -chromium_rev = git.get_hash(src_dir)
27 -
28 -date = get_date()
29 -
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()
35  
36 +if not git.is_checkout(src_dir):
37 +  chromium_url = git.get_url(src_dir)
38 +  chromium_rev = git.get_hash(src_dir)
39 +else:
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
43 +
44 +date = get_date()
45 +
46  # list of output directories to be archived
47  archive_dirs = []
48  
49 diff --git a/tools/patch_util.py b/tools/patch_util.py
50 new file mode 100644
51 index 000000000..2025e97e0
52 --- /dev/null
53 +++ b/tools/patch_util.py
54 @@ -0,0 +1,40 @@
55 +from __future__ import absolute_import
56 +from exec_util import exec_cmd
57 +import os
58 +import sys
59 +
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))
64 +
65 +  if not os.path.isfile(patch_path):
66 +    sys.stdout.write('... patch file does not exist.\n')
67 +    return 'fail'
68 +
69 +  # Apply the patch file. This should always succeed because the previous
70 +  # command succeeded.
71 +
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:
75 +    return 'skip'
76 +
77 +  cmd = 'patch --ignore-whitespace -p0 --input=%s --verbose' % patch_path
78 +  result = exec_cmd(cmd, patch_dir)
79 +
80 +  sys.stdout.write('Err: \t%s\n' % result['err'])
81 +  sys.stdout.write('Out: \t%s\n' % result['out'])
82 +
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))
86 +    return 'fail'
87 +
88 +  if result['err'] == '':
89 +    sys.stdout.write('... successfully applied.\n')
90 +  else:
91 +    sys.stdout.write('... successfully applied (with warnings):\n')
92 +    sys.stdout.write('\t%s\n' % result['err'])
93 +  return 'apply'
94 +
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
100  import sys
101  from file_util import *
102  from git_util import git_apply_patch_file
103 +from patch_util import patch_apply_patch_file
104  
105  # Cannot be loaded as a module.
106  if __name__ != "__main__":
107 @@ -46,6 +47,8 @@ def apply_patch_file(patch_file, patch_dir):
108        return 'skip'
109  
110    result = git_apply_patch_file(patch_path, patch_dir)
111 +  if result == 'fail':
112 +    result = patch_apply_patch_file(patch_path, patch_dir)
113    if result == 'fail':
114      write_note('ERROR',
115                 'This patch failed to apply. Your build will not be correct.')
116 -- 
117 2.42.1
118