configure.ac                                  |   14 ++++++++++++++
 external/harfbuzz/ExternalProject_harfbuzz.mk |    4 ++--
 external/harfbuzz/UnpackedTarball_harfbuzz.mk |    7 +++++++
 3 files changed, 23 insertions(+), 2 deletions(-)

New commits:
commit df83ad933b11e973855d66792c9aff38714f9201
Author:     Christian Lohmaier <lohmaier+libreoff...@googlemail.com>
AuthorDate: Wed Apr 16 13:02:20 2025 +0200
Commit:     Christian Lohmaier <lohmaier+libreoff...@googlemail.com>
CommitDate: Tue Apr 22 10:11:22 2025 +0200

    fix harfbuzz build with --enable-python=fully-internal on linux
    
    if executable python scripts are run as build commands, they can pick up
    system python instead of the LO-internal python and that then can cause
    incompatibilities, ranging from just being too old and failing with
    stuff like
    AttributeError: 'str' object has no attribute 'isascii'
    or attempting to load incompatible modules
    […]
        from . import _compiler, _parser
      File 
"/home/michi/development/git/libreoffice/instdir/program/python-core-3.11.12/lib/re/_compiler.py",
 line 18, in <module>
        assert _sre.MAGIC == MAGIC, "SRE module mismatch"
    AssertionError: SRE module mismatch
    
    So remove the executable bit to make sure the scripts are run with the
    python specified for the build, either internal or the system one.
    
    Also undo the workaround added in 736998ccef0bacdd2bbf038c98dacfbe654f1a4d
    (Only run meson from python when it apparently needs to be)
    While this can help running meson itself if the distro has different
    python versions but cannot be run with the default python3 / the python
    version used to run meson is likely newer and then also avoids most of
    the issues above, it still is bad to mix build-tool python and the
    commands executed by the buildtool.
    
    For the cornercase of meson not being able to be executed by the python
    used for the build, the solution is to either specify
    PYTHON=/hatever/python/system/meson/uses (for the non-fully-internal
    case) and/or using a release tarball of meson and pointing
    MESON=/path/to/meson.py in autogen.input (can be used with both system
    and internal python)
    
    Change-Id: Id8e3ea88e0caa4afa872a62207b081c072496903
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/184271
    Tested-by: Jenkins
    Reviewed-by: Christian Lohmaier <lohmaier+libreoff...@googlemail.com>

diff --git a/configure.ac b/configure.ac
index 268d5dc5f26c..a2923daa0ea8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -11487,6 +11487,20 @@ else
     if test -z "$MESON" -o -z "$NINJA"; then
         AC_MSG_ERROR([you need to have meson and ninja in order to build 
harfbuzz])
     fi
+    if test -z "$PYTHON_FOR_BUILD"; then
+        if test "$(basename $MESON)" = "$(basename -s .py $MESON)"; then
+            AC_MSG_WARN([using internal python with a meson launcher might not 
work, best to use MESON=/path/to/meson.py in autogen.input])
+            add_warning "using internal python with a meson launcher might not 
work, best to use MESON=/path/to/meson.py in autogen.input"
+        fi
+    else
+        AC_MSG_CHECKING([whether meson can be run with "$PYTHON_FOR_BUILD 
$MESON"])
+        if ($PYTHON_FOR_BUILD $MESON --version >/dev/null) ; then
+            AC_MSG_RESULT([yes])
+        else
+            AC_MSG_RESULT([no])
+            AC_MSG_ERROR([meson incompatible with the specified python. Try 
using a different python runtime or a plain release of meson by adding 
PYTHON=/other/python.version and/or MESON=/path/to/meson.py to autogen.input])
+        fi
+    fi
 fi
 
 if test "$USING_X11" = TRUE; then
diff --git a/external/harfbuzz/ExternalProject_harfbuzz.mk 
b/external/harfbuzz/ExternalProject_harfbuzz.mk
index 488086997c0e..ee02b95753ec 100644
--- a/external/harfbuzz/ExternalProject_harfbuzz.mk
+++ b/external/harfbuzz/ExternalProject_harfbuzz.mk
@@ -47,7 +47,7 @@ $(call gb_ExternalProject_get_state_target,harfbuzz,build) : 
| $(call gb_Externa
        $(call gb_ExternalProject_run,build,\
                
PKG_CONFIG_PATH="${PKG_CONFIG_PATH}$(LIBO_PATH_SEPARATOR)$(gb_UnpackedTarball_workdir)/graphite$(if
 $(SYSTEM_ICU),,$(LIBO_PATH_SEPARATOR)$(gb_UnpackedTarball_workdir)/icu)" \
                PYTHONWARNINGS= \
-               $(if $(filter %.py,$(MESON)),$(call 
gb_ExternalExecutable_get_command,python)) $(MESON) setup builddir \
+               $(call gb_ExternalExecutable_get_command,python) $(MESON) setup 
builddir \
                        -Ddefault_library=static -Dbuildtype=$(if 
$(ENABLE_DEBUG),debug,release) \
                        -Dauto_features=disabled \
                        -Dcpp_std=$(subst -std:,,$(subst -std=,,$(filter 
-std%,$(CXXFLAGS_CXX11)))) \
@@ -57,7 +57,7 @@ $(call gb_ExternalProject_get_state_target,harfbuzz,build) : 
| $(call gb_Externa
                        -Dicu_builtin=true \
                        -Dgraphite2=enabled \
                        $(if $(filter-out 
$(BUILD_PLATFORM),$(HOST_PLATFORM))$(WSL),--cross-file cross-file.txt) && \
-               $(if $(filter %.py,$(MESON)),$(call 
gb_ExternalExecutable_get_command,python)) $(MESON) compile -C builddir lib \
+               $(call gb_ExternalExecutable_get_command,python) $(MESON) 
compile -C builddir lib \
                        $(if $(verbose),--verbose) \
        )
        $(call gb_Trace_EndRange,harfbuzz,EXTERNAL)
diff --git a/external/harfbuzz/UnpackedTarball_harfbuzz.mk 
b/external/harfbuzz/UnpackedTarball_harfbuzz.mk
index 71627725fae7..aad08765852a 100644
--- a/external/harfbuzz/UnpackedTarball_harfbuzz.mk
+++ b/external/harfbuzz/UnpackedTarball_harfbuzz.mk
@@ -19,4 +19,11 @@ $(eval $(call gb_UnpackedTarball_add_patches,harfbuzz, \
     external/harfbuzz/tdf159529.patch.0 \
 ))
 
+# meson will replace python3 from shebang in build commands with the
+# interpreter it is run with (which is what we want for python=fully-internal
+# case to avoid incompatibilities with the system python version).
+# And while it does so unconditionally on windows, on other platforms that only
+# happens if the command to run doesn't have the executable bit set.
+$(eval $(call gb_UnpackedTarball_set_post_action,harfbuzz,chmod a-x 
src/gen*.py))
+
 # vim: set noet sw=4 ts=4:

Reply via email to