[BACK]Return to patch-gobject_glib-mkenums.in CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / pkgsrc / devel / glib2 / patches

File: [cvs.NetBSD.org] / pkgsrc / devel / glib2 / patches / patch-gobject_glib-mkenums.in (download)

Revision 1.2, Sat Oct 21 08:57:33 2017 UTC (2 years, 9 months ago) by prlw1
Branch: MAIN
CVS Tags: pkgsrc-2017Q4-base, pkgsrc-2017Q4
Changes since 1.1: +47 -4 lines

glib2-tools: Handle source files which are not utf-8

python 3 is strict about file encodings. After glib-mkenums was
translated from perl to python, build failures occur due to e.g.,
ISO-8859-1 characters in authors' names as reported by martin@ in
PR pkg/52631 for xfce4-gtk2-engines, but also causing build failures
for at least libgnome and libgnomeui.

Chritoph Reiter produced an elegant workaround, making use of the
open() function's error decoding "replace" option:

  'replace' causes a replacement marker (such as '?') to be inserted
  where there is malformed data.

which is applied here.

https://bugzilla.gnome.org/show_bug.cgi?id=785113#c27

$NetBSD: patch-gobject_glib-mkenums.in,v 1.2 2017/10/21 08:57:33 prlw1 Exp $

- Revert 4395a897 Use env to run the Python-based tools
  https://bugzilla.gnome.org/show_bug.cgi?id=788527
- Don't insist that authors' names in comments be encoded in utf-8
  https://bugzilla.gnome.org/show_bug.cgi?id=785113

--- gobject/glib-mkenums.in.orig	2017-10-21 08:20:09.664007702 +0000
+++ gobject/glib-mkenums.in
@@ -1,4 +1,4 @@
-#!/usr/bin/env @PYTHON@
+#!@PYTHON@
 
 # If the code below looks horrible and unpythonic, do not panic.
 #
@@ -34,6 +34,11 @@ if sys.stdout.encoding is None:
 else:
     output_stream = sys.stdout
 
+# Some source files aren't utf-8 and the old perl version didn't care.
+# Replace invalid data with a replacement character to keep things working.
+# https://bugzilla.gnome.org/show_bug.cgi?id=785113#c20
+decoding_errors = "replace"
+
 # pylint: disable=too-few-public-methods
 class Color:
     '''ANSI Terminal colors'''
@@ -157,7 +162,8 @@ def parse_entries(file, file_name):
         m = re.match(r'\#include\s*<([^>]*)>', line)
         if m:
             newfilename = os.path.join("..", m.group(1))
-            newfile = io.open(newfilename, encoding="utf-8")
+            newfile = io.open(newfilename, encoding="utf-8",
+                              errors=decoding_errors)
 
             if not parse_entries(newfile, newfilename):
                 return False
@@ -253,7 +259,7 @@ def read_template_file(file):
            }
     in_ = 'junk'
 
-    ifile = io.open(file, encoding="utf-8")
+    ifile = io.open(file, encoding="utf-8", errors=decoding_errors)
     for line in ifile:
         m = re.match(r'\/\*\*\*\s+(BEGIN|END)\s+([\w-]+)\s+\*\*\*\/', line)
         if m:
@@ -409,7 +415,8 @@ def process_file(curfilename):
     firstenum = True
 
     try:
-        curfile = io.open(curfilename, encoding="utf-8")
+        curfile = io.open(curfilename, encoding="utf-8",
+                          errors=decoding_errors)
     except IOError as e:
         if e.errno == errno.ENOENT:
             print_warning('No file "{}" found.'.format(curfilename))