1
1
mirror of https://gitlab.gnome.org/GNOME/gimp.git synced 2025-10-05 21:02:42 +02:00

meson: Port meson_dist_script.sh to Python

It's not used by Windows right now, but it can be so let's port it.
This commit is contained in:
Bruno Lopes
2025-04-17 09:57:58 -03:00
parent 42049493cb
commit 160ec3d0d7
3 changed files with 40 additions and 36 deletions

View File

@@ -1905,7 +1905,7 @@ custom_target('Changelog',
build_by_default: false,
)
meson.add_dist_script('meson_dist_script.sh',
meson.add_dist_script('meson_dist_script.py',
generate_version_h ? gitversion_h.full_path() : gitversion_h,
meson.project_source_root(), meson.project_build_root())

39
meson_dist_script.py Normal file
View File

@@ -0,0 +1,39 @@
#!/usr/bin/env python3
import os
import subprocess
import sys
import shutil
GIT_VERSION_H = sys.argv[1]
MESON_SOURCE_ROOT = os.environ.get('MESON_SOURCE_ROOT', sys.argv[2])
MESON_BUILD_ROOT = os.environ.get('MESON_BUILD_ROOT', sys.argv[3])
# `meson dist` doesn't trigger a build, which is a problem because we
# need to add some configured/built files. The case where we didn't
# build at all is the less annoying (we'd get a failure, which is
# actually acceptable as it warns us). But the case where we would copy
# outdated data is much more insidious (such as wrong INSTALL
# information or wrong git information) as it would be silent.
# See: https://github.com/mesonbuild/meson/issues/10650
# And: https://gitlab.gnome.org/GNOME/gimp/-/issues/7907
# This is why we manually trigger, not only a reconfigure, but also a
# rebuild of the main project before copying data around.
try:
# INSTALL file is generated at configure time.
subprocess.run(['meson', '--reconfigure', MESON_SOURCE_ROOT], check=True)
# git-version.h is generated at build time.
subprocess.run(['meson', 'compile'], check=True)
shutil.copy2('INSTALL', os.environ['MESON_DIST_ROOT'])
install_in = os.path.join(os.environ['MESON_DIST_ROOT'], 'INSTALL.in')
if os.path.exists(install_in):
os.remove(install_in)
shutil.copy2(GIT_VERSION_H, os.environ['MESON_DIST_ROOT'])
except subprocess.CalledProcessError as e:
sys.exit(e.returncode)
except Exception:
sys.exit(1)

View File

@@ -1,35 +0,0 @@
#!/usr/bin/env bash
GIT_VERSION_H="$1"
# MESON_SOURCE_ROOT and MESON_BUILD_ROOT environment variables are
# passed since meson 0.54.0 but we depend on 0.53.0 so I also pass them
# as script arguments. When we bump out meson requirement, this test may
# go away.
if [ -z "$MESON_SOURCE_ROOT" ]; then
MESON_SOURCE_ROOT="$2"
fi
if [ -z "$MESON_BUILD_ROOT" ]; then
MESON_BUILD_ROOT="$3"
fi
# `meson dist` doesn't trigger a build, which is a problem because we
# need to add some configured/built files. The case where we didn't
# build at all is the less annoying (we'd get a failure, which is
# actually acceptable as it warns us). But the case where we would copy
# outdated data is much more insidious (such as wrong INSTALL
# information or wrong git information) as it would be silent.
# See: https://github.com/mesonbuild/meson/issues/10650
# And: https://gitlab.gnome.org/GNOME/gimp/-/issues/7907
# This is why we manually trigger, not only a reconfigure, but also a
# rebuild of the main project before copying data around.
# INSTALL file is generated at configure time.
meson --reconfigure $MESON_SOURCE_ROOT
# git-version.h is generated at build time.
meson compile
cp -f 'INSTALL' "${MESON_DIST_ROOT}"
rm -f "${MESON_DIST_ROOT}/INSTALL.in"
cp "$GIT_VERSION_H" "${MESON_DIST_ROOT}"