[gimp] Issue #8338: add a BOM to ISL files.



commit 4293d05dda76bc86d7bbbb2a133c2e365020677d
Author: Jehan <jehan girinstud io>
Date:   Sat Jul 30 23:28:39 2022 +0200

    Issue #8338: add a BOM to ISL files.
    
    Inno-Setup absolutely requires it to recognize UTF-8 translation files.
    This should hopefully be the final fix to #8338.
    
    Note that this fix is full of workaround for meson bugs or limitations.
    While it was a one-liner in autotools, added to the existing rule, here
    I have to add an additional (non-relevant) target rule, then uglily work
    around 2 bugs:
    https://github.com/mesonbuild/meson/issues/1564
    https://github.com/mesonbuild/meson/issues/7696
    
    I can't say I'm so happy about the resulting change, even though it
    seems to work. If anyone can propose a nicer build rule, it would be
    welcome.

 build/windows/installer/lang/meson.build | 33 ++++++++++++++++++++++++++++----
 1 file changed, 29 insertions(+), 4 deletions(-)
---
diff --git a/build/windows/installer/lang/meson.build b/build/windows/installer/lang/meson.build
index ae0b0d07e7..7e8e9415fb 100644
--- a/build/windows/installer/lang/meson.build
+++ b/build/windows/installer/lang/meson.build
@@ -51,7 +51,6 @@ languages = [
 ]
 
 # Then, we generate the .isl file for each language using some xsltproc magic
-all_isl = []
 foreach language : languages
   lang_code = language.get('code')
 
@@ -67,10 +66,10 @@ foreach language : languages
     configuration: { 'LANG_CHECK': lang_check },
   )
 
-  setup_isl = '@0  setup isl'.format(lang_code)
-  all_isl += custom_target(setup_isl,
+  nobom_setup_isl = '@0 -nobom setup isl'.format(lang_code)
+  nobom_setup_isl_tmp = custom_target(nobom_setup_isl,
     input : [ ms_installer_config_xml, gimp_ms_installer_lang_xsl  ],
-    output: setup_isl,
+    output: nobom_setup_isl,
     command: [
       xsltproc,
       '--xinclude',
@@ -80,6 +79,32 @@ foreach language : languages
     ],
     build_by_default: true,
   )
+
+  setup_isl = '@0  setup isl'.format(lang_code)
+  # Inno-Setup absolutely requires a BOM to recognize UTF-8 files.
+  # Here I am working around 3 issues in meson:
+  # 1. We can't easily combine commands in meson. So either we combine
+  # them in an external script, or we run several custom_target(), which
+  # is what I chose here, even though it's really not a clean build rule.
+  # 2. To concat a BOM to the file, I'd like to simply call this Python
+  # code:
+  # 'open("@OUTPUT@", "wb").write(b"\\xEF\\xBB\\xBF" + open("@INPUT@", "rb").read())'
+  # Unfortunately we can't pass several @INPUT@/@OUTPUT@ in a same arg.
+  # See: https://github.com/mesonbuild/meson/issues/7696
+  # 3. Antislashes are replaced with slashes in custom_target(). This is
+  # why I do this weird trick of using a string, which I encode to UTF-8
+  # instead of using the well known BOM bytes directly.
+  # See https://github.com/mesonbuild/meson/issues/1564
+  custom_target(setup_isl,
+    input : [ nobom_setup_isl_tmp ],
+    output: [ setup_isl ],
+    command: [
+      python, '-c',
+      'import sys; open(sys.argv[1], "wb").write("\ufeff".encode("utf-8") + open("@INPUT@", "rb").read())',
+      '@OUTPUT@'
+    ],
+    build_by_default: true,
+  )
 endforeach
 
 test('windows-installer-langs',


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