mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-10 03:16:17 +01:00
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
This commit is contained in:
parent
47a949d74f
commit
19106af47f
@ -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])
|
||||
|
Loading…
Reference in New Issue
Block a user