[glib: 1/2] data-to-c.py: autodetect line endings




commit 19106af47fcae90c29d88d64e9e1fa969e4a634c
Author: Aleksandr Mezin <mezin alexander gmail com>
Date:   Sun Feb 28 04:19:09 2021 +0600

    data-to-c.py: autodetect line endings
    
    When GLib code is checked out with Windows line endings (happens on Windows),
    data-to-c.py embedded that line endings into generated string literal. And
    then they translated to double newlines in glib-compile-resources output.
    
    clang-cl failed to compile such files because of empty lines in the middle of
    multiline macros:
    
        #define G_MSVC_CTOR(_func,_sym_prefix) \
    
          static void _func(void); \
    
    To fix the issue, enable 'universal newlines' mode when reading the input in
    data-to-c.py - translate both '\n' and '\r\n' to '\n'.
    
    Fixes https://gitlab.gnome.org/GNOME/glib/-/issues/2340

 gio/data-to-c.py | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
---
diff --git a/gio/data-to-c.py b/gio/data-to-c.py
index d8854b417..8a2479eb4 100755
--- a/gio/data-to-c.py
+++ b/gio/data-to-c.py
@@ -1,12 +1,13 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 import sys
 
 if len(sys.argv) < 4:
     print("Usage: {0} <filename> <variable> <output>")
 
-with open(sys.argv[1], "rb") as f:
-    in_data = f.read().decode("utf-8", "backslashreplace")
+with open(sys.argv[1], "r", encoding="utf-8", errors="backslashreplace") as f:
+    in_data = f.read()
+
 b = [r"\x{:02x}".format(ord(c)) for c in in_data]
 
 out_data = 'const char {0}[] = "'.format(sys.argv[2])


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]