[gimp/wip/Jehan/issue-8338-fixing-installer-lang] Issue #8338: add BOM to ISL file as external script.




commit 195ed374f4adbb378ef3e573e6cce68dacd84977
Author: Jehan <jehan girinstud io>
Date:   Sun Jul 31 01:43:05 2022 +0200

    Issue #8338: add BOM to ISL file as external script.
    
    Unfortunately the weird encoding of a string to bytes to get the UTF-8
    BOM worked on my local machine, but not on the Windows CI. I'm not going
    to fight it and fallback to a shell script.
    
    I am guessing it should work fine on all platform since we use basically
    the same sed call in build/windows/gitlab-ci/installer-gimp-msys2.sh
    already.

 build/windows/installer/lang/addbom.sh   |  3 +++
 build/windows/installer/lang/meson.build | 18 +++++++++---------
 2 files changed, 12 insertions(+), 9 deletions(-)
---
diff --git a/build/windows/installer/lang/addbom.sh b/build/windows/installer/lang/addbom.sh
new file mode 100644
index 0000000000..61e2739331
--- /dev/null
+++ b/build/windows/installer/lang/addbom.sh
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+sed "1s/^/\xEF\xBB\xBF/" "$1" > "$2"
diff --git a/build/windows/installer/lang/meson.build b/build/windows/installer/lang/meson.build
index 7e8e9415fb..c2ab94b53b 100644
--- a/build/windows/installer/lang/meson.build
+++ b/build/windows/installer/lang/meson.build
@@ -84,24 +84,24 @@ foreach language : languages
   # 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.
+  # them in an external script, or we run several custom_target(). I do
+  # a mix of both because custom_target() has too many bugs.
   # 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.
+  # 3. Antislashes are replaced with slashes in custom_target(). I tried
+  # some weird trick encoding a string to UTF-8 instead of using the
+  # well known BOM bytes directly. Unfortunately result was not
+  # consistent on all platforms (at least Linux and Windows).
   # See https://github.com/mesonbuild/meson/issues/1564
   custom_target(setup_isl,
-    input : [ nobom_setup_isl_tmp ],
+    input : [ nobom_setup_isl_tmp, 'addbom.sh' ],
     output: [ setup_isl ],
     command: [
-      python, '-c',
-      'import sys; open(sys.argv[1], "wb").write("\ufeff".encode("utf-8") + open("@INPUT@", "rb").read())',
-      '@OUTPUT@'
+      find_program(meson.current_source_dir() / 'addbom.sh'),
+      '@INPUT0@', '@OUTPUT@'
     ],
     build_by_default: true,
   )


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