diff options
-rw-r--r-- | meta/recipes-core/glib-2.0/glib-2.0/glib-mkenums-replace-and-warn-decoding.patch | 104 | ||||
-rw-r--r-- | meta/recipes-core/glib-2.0/glib-2.0_2.54.2.bb | 1 |
2 files changed, 105 insertions, 0 deletions
diff --git a/meta/recipes-core/glib-2.0/glib-2.0/glib-mkenums-replace-and-warn-decoding.patch b/meta/recipes-core/glib-2.0/glib-2.0/glib-mkenums-replace-and-warn-decoding.patch new file mode 100644 index 0000000000..a5dae7e9f4 --- /dev/null +++ b/meta/recipes-core/glib-2.0/glib-2.0/glib-mkenums-replace-and-warn-decoding.patch | |||
@@ -0,0 +1,104 @@ | |||
1 | From ba043ef4f2c713662f89425aed70dfd78e3955ee Mon Sep 17 00:00:00 2001 | ||
2 | From: Patrick Welche <prlw1@cam.ac.uk> | ||
3 | Date: Mon, 23 Oct 2017 13:59:58 +0100 | ||
4 | Subject: [PATCH] glib-mkenums: best effort attempt on non-utf8 encoded files. | ||
5 | |||
6 | Some source files aren't valid utf-8 containing for example | ||
7 | iso8859-1 accented characters in author's names. | ||
8 | Replace invalid data with a replacement '?' character and print a | ||
9 | warning to keep things working. | ||
10 | Based on a patch from Christoph Reiter in | ||
11 | https://bugzilla.gnome.org/show_bug.cgi?id=785113#c20 | ||
12 | |||
13 | Upstream-Status: Submitted [https://bug785113.bugzilla-attachments.gnome.org/attachment.cgi?id=362098] | ||
14 | |||
15 | Author: Patrick Welche <prlw1@cam.ac.uk> | ||
16 | |||
17 | Signed-off-by: Jackie Huang <jackie.huang@windriver.com> | ||
18 | --- | ||
19 | gobject/glib-mkenums.in | 41 ++++++++++++++++++++++++++++++----------- | ||
20 | 1 file changed, 30 insertions(+), 11 deletions(-) | ||
21 | |||
22 | diff --git a/gobject/glib-mkenums.in b/gobject/glib-mkenums.in | ||
23 | index 7cc55053c..9790a65a2 100755 | ||
24 | --- a/gobject/glib-mkenums.in | ||
25 | +++ b/gobject/glib-mkenums.in | ||
26 | @@ -26,14 +26,6 @@ the GNU General Public License which can be found in the | ||
27 | GLib source package. Sources, examples and contact | ||
28 | information are available at http://www.gtk.org''' | ||
29 | |||
30 | -# Python 2 defaults to ASCII in case stdout is redirected. | ||
31 | -# This should make it match Python 3, which uses the locale encoding. | ||
32 | -if sys.stdout.encoding is None: | ||
33 | - output_stream = codecs.getwriter( | ||
34 | - locale.getpreferredencoding())(sys.stdout) | ||
35 | -else: | ||
36 | - output_stream = sys.stdout | ||
37 | - | ||
38 | # pylint: disable=too-few-public-methods | ||
39 | class Color: | ||
40 | '''ANSI Terminal colors''' | ||
41 | @@ -81,6 +73,31 @@ def write_output(output): | ||
42 | global output_stream | ||
43 | print(output, file=output_stream) | ||
44 | |||
45 | + | ||
46 | +# Python 2 defaults to ASCII in case stdout is redirected. | ||
47 | +# This should make it match Python 3, which uses the locale encoding. | ||
48 | +if sys.stdout.encoding is None: | ||
49 | + output_stream = codecs.getwriter( | ||
50 | + locale.getpreferredencoding())(sys.stdout) | ||
51 | +else: | ||
52 | + output_stream = sys.stdout | ||
53 | + | ||
54 | + | ||
55 | +# Some source files aren't utf-8 and the old perl version didn't care. | ||
56 | +# Replace invalid data with a replacement character to keep things working. | ||
57 | +# https://bugzilla.gnome.org/show_bug.cgi?id=785113#c20 | ||
58 | +decoding_errors = "replace_and_warn" | ||
59 | + | ||
60 | +def replace_and_warn(err): | ||
61 | + # 7 characters of context either side of the offending character | ||
62 | + print_warning('UnicodeWarning: {} at {} ({})'.format( | ||
63 | + err.reason, err.start, | ||
64 | + err.object[err.start - 7:err.end + 7])) | ||
65 | + return ('?', err.end) | ||
66 | + | ||
67 | +codecs.register_error('replace_and_warn', replace_and_warn) | ||
68 | + | ||
69 | + | ||
70 | # glib-mkenums.py | ||
71 | # Information about the current enumeration | ||
72 | flags = None # Is enumeration a bitmask? | ||
73 | @@ -157,7 +174,8 @@ def parse_entries(file, file_name): | ||
74 | m = re.match(r'\#include\s*<([^>]*)>', line) | ||
75 | if m: | ||
76 | newfilename = os.path.join("..", m.group(1)) | ||
77 | - newfile = io.open(newfilename, encoding="utf-8") | ||
78 | + newfile = io.open(newfilename, encoding="utf-8", | ||
79 | + errors=decoding_errors) | ||
80 | |||
81 | if not parse_entries(newfile, newfilename): | ||
82 | return False | ||
83 | @@ -253,7 +271,7 @@ def read_template_file(file): | ||
84 | } | ||
85 | in_ = 'junk' | ||
86 | |||
87 | - ifile = io.open(file, encoding="utf-8") | ||
88 | + ifile = io.open(file, encoding="utf-8", errors=decoding_errors) | ||
89 | for line in ifile: | ||
90 | m = re.match(r'\/\*\*\*\s+(BEGIN|END)\s+([\w-]+)\s+\*\*\*\/', line) | ||
91 | if m: | ||
92 | @@ -408,7 +426,8 @@ def process_file(curfilename): | ||
93 | firstenum = True | ||
94 | |||
95 | try: | ||
96 | - curfile = io.open(curfilename, encoding="utf-8") | ||
97 | + curfile = io.open(curfilename, encoding="utf-8", | ||
98 | + errors=decoding_errors) | ||
99 | except IOError as e: | ||
100 | if e.errno == errno.ENOENT: | ||
101 | print_warning('No file "{}" found.'.format(curfilename)) | ||
102 | -- | ||
103 | 2.14.2 | ||
104 | |||
diff --git a/meta/recipes-core/glib-2.0/glib-2.0_2.54.2.bb b/meta/recipes-core/glib-2.0/glib-2.0_2.54.2.bb index 60ce1b5f7f..963f6b471d 100644 --- a/meta/recipes-core/glib-2.0/glib-2.0_2.54.2.bb +++ b/meta/recipes-core/glib-2.0/glib-2.0_2.54.2.bb | |||
@@ -16,6 +16,7 @@ SRC_URI = "${GNOME_MIRROR}/glib/${SHRT_VER}/glib-${PV}.tar.xz \ | |||
16 | file://0001-Do-not-ignore-return-value-of-write.patch \ | 16 | file://0001-Do-not-ignore-return-value-of-write.patch \ |
17 | file://0001-Test-for-pthread_getname_np-before-using-it.patch \ | 17 | file://0001-Test-for-pthread_getname_np-before-using-it.patch \ |
18 | file://0010-Do-not-hardcode-python-path-into-various-tools.patch \ | 18 | file://0010-Do-not-hardcode-python-path-into-various-tools.patch \ |
19 | file://glib-mkenums-replace-and-warn-decoding.patch \ | ||
19 | " | 20 | " |
20 | 21 | ||
21 | SRC_URI_append_class-native = " file://relocate-modules.patch" | 22 | SRC_URI_append_class-native = " file://relocate-modules.patch" |