[geany/geany] d45299: Windows: Create GTK bundle for x86_64 and suppt non-native execution

Enrico Tröger git-noreply at xxxxx
Sat Oct 9 10:05:59 UTC 2021


Branch:      refs/heads/master
Author:      Enrico Tröger <enrico.troeger at uvena.de>
Committer:   Enrico Tröger <enrico.troeger at uvena.de>
Date:        Sat, 09 Oct 2021 10:05:59 UTC
Commit:      d452994a75627dc282ef3223b235fc379d090cb0
             https://github.com/geany/geany/commit/d452994a75627dc282ef3223b235fc379d090cb0

Log Message:
-----------
Windows: Create GTK bundle for x86_64 and suppt non-native execution

Changes in the bundle creation script:
- the GTK (and other dependencies) bundle is now created for the x86_64
platform
- the new parameter "-x" allows to run script on a Linux system using
Wine, therefore it is necessary to run the post-install scripts after
all packages have been extracted.
- use "-Sdd" for Pacman to ignore dependencies as we resolve them
manually
- do not use "tar -x --xz" as Pacman nowadays also downloads .zst
packages, instead just download the file and let tar choose the format
automatically based on the filename
- install grep with Pacman as the build and target platform are now
identical
- update GTK dependencies to match current packages


Modified Paths:
--------------
    scripts/gtk-bundle-from-msys2.sh

Modified: scripts/gtk-bundle-from-msys2.sh
105 lines changed, 64 insertions(+), 41 deletions(-)
===================================================================
@@ -1,21 +1,24 @@
-#!/bin/sh
+#!/bin/bash
 #
 # Fetch and extract Geany dependencies for Windows/MSYS2
 # This script will download (or use Pacman's cache) to extract
 # dependencies as defined below needed to run Geany.
 # To be run within a MSYS2 shell. The extracted files will be
 # placed into the current directory.
 
-ABI=i686
+ABI=x86_64  # do not change, i686 is not supported any longer
 use_cache="no"
 make_zip="no"
 gtkv="3"
 run_pi="y"
+cross="no"
 
 UNX_UTILS_URL="https://download.geany.org/contrib/UnxUpdates.zip"
-# path to an installation of a MSYS2 installation in the native architecture matching $ABI
-# leave empty if the script is called already from the same MSYS2 architecture as $ABI
-MSYS2_ABI_PATH="/c/msys32"
+
+# Wine commands for 32bit and 64bit binaries (we still need 32bit for UnxUtils sort.exe)
+# Used only when "-x" is set
+EXE_WRAPPER_32="mingw-w64-i686-wine"
+EXE_WRAPPER_64="mingw-w64-x86_64-wine"
 
 package_urls=""
 gtk3_dependency_pkgs="
@@ -26,18 +29,25 @@ adwaita-icon-theme
 
 packages="
 gcc-libs
+grep
 pcre
+xz
 zlib
+zstd
 expat
 libffi
 libiconv
 brotli
 bzip2
+freeglut
 libffi
 libpng
 gettext
 glib2
 graphite2
+jasper
+libjpeg-turbo
+libtiff
 libwinpthread-git
 harfbuzz
 fontconfig
@@ -67,6 +77,9 @@ handle_command_line_options() {
 		"-n")
 			run_pi=""
 			;;
+		"-x")
+			cross="yes"
+			;;
 		"-h"|"--help")
 			echo "gtk-bundle-from-msys2.sh [-c] [-h] [-n] [-z] [-3] [CACHEDIR]"
 			echo "      -c Use pacman cache. Otherwise pacman will download"
@@ -75,6 +88,7 @@ handle_command_line_options() {
 			echo "      -n Do not run post install scripts of the packages"
 			echo "      -z Create a zip afterwards"
 			echo "      -3 Prefer gtk3"
+			echo "      -x Set when the script is executed in a cross-compilation context (e.g. to use wine)"
 			echo "CACHEDIR Directory where to look for cached packages (default: /var/cache/pacman/pkg)"
 			exit 1
 			;;
@@ -85,6 +99,8 @@ handle_command_line_options() {
 	done
 }
 
+set -e  # stop on errors
+
 initialize() {
 	if [ -z "$cachedir" ]; then
 		cachedir="/var/cache/pacman/pkg"
@@ -95,6 +111,12 @@ initialize() {
 		exit 1
 	fi
 
+	if [ "$cross" != "yes" ]; then
+		# if running natively, we do not need wine or any other wrappers
+		EXE_WRAPPER_32=""
+		EXE_WRAPPER_64=""
+	fi
+
 	gtk="gtk$gtkv"
 	eval "gtk_dependency_pkgs=\${${gtk}_dependency_pkgs}"
 
@@ -107,17 +129,18 @@ ${gtk}
 
 _getpkg() {
 	if [ "$use_cache" = "yes" ]; then
-		package_info=`pacman -Qi mingw-w64-$ABI-$1`
-		package_version=`echo "$package_info" | grep "^Version " | cut -d':' -f 2 | tr -d '[[:space:]]'`
+		package_info=$(pacman -Qi mingw-w64-$ABI-$1)
+		package_version=$(echo "$package_info" | grep "^Version " | cut -d':' -f 2 | tr -d '[[:space:]]')
 		ls $cachedir/mingw-w64-${ABI}-${1}-${package_version}-* | sort -V | tail -n 1
 	else
-		pacman -Sp mingw-w64-${ABI}-${1}
+		# -dd to ignore dependencies as we listed them already above in $packages
+		pacman -Sddp mingw-w64-${ABI}-${1}
 	fi
 }
 
 _remember_package_source() {
 	if [ "$use_cache" = "yes" ]; then
-		package_url=`pacman -Sp mingw-w64-${ABI}-${2}`
+		package_url=$(pacman -Sddp mingw-w64-${ABI}-${2})
 	else
 		package_url="${1}"
 	fi
@@ -138,11 +161,10 @@ extract_packages() {
 			fi
 		else
 			echo "Download $pkg using curl"
-			curl -L "$pkg" | tar -x --xz
-		fi
-		if [ -n "$run_pi" ] && [ -f .INSTALL ]; then
-			echo "Running post_install script for \"$i\""
-			/bin/bash -c ". .INSTALL; post_install"
+			filename=$(basename "$pkg")
+			curl -s -o "$filename" -l "$pkg"
+			tar xf "$filename"
+			rm "$filename"
 		fi
 		if [ "$make_zip" = "yes" -a "$i" = "$gtk" ]; then
 			VERSION=$(grep ^pkgver .PKGINFO | sed -e 's,^pkgver = ,,' -e 's,-.*$,,')
@@ -153,16 +175,27 @@ extract_packages() {
 
 move_extracted_files() {
 	echo "Move extracted data to destination directory"
-	if [ -d mingw32 ]; then
+	if [ -d mingw64 ]; then
 		for d in bin etc home include lib locale share var; do
-			if [ -d "mingw32/$d" ]; then
+			if [ -d "mingw64/$d" ]; then
 				rm -rf $d
 				# prevent sporadic 'permission denied' errors on my system, not sure why they happen
 				sleep 0.5
-				mv mingw32/$d .
+				mv mingw64/$d .
 			fi
 		done
-		rmdir mingw32
+		rmdir mingw64
+	fi
+}
+
+delayed_post_install() {
+	if [ "$run_pi" ]; then
+		echo "Execute delayed post install tasks"
+		# Commands have been collected manually from the various .INSTALL scripts
+		${EXE_WRAPPER_64} bin/fc-cache.exe -f
+		${EXE_WRAPPER_64} bin/gdk-pixbuf-query-loaders.exe --update-cache
+		${EXE_WRAPPER_64} bin/gtk-update-icon-cache-3.0.exe -q -t -f share/icons/hicolor
+		${EXE_WRAPPER_64} bin/gtk-update-icon-cache-3.0.exe -q -t -f share/icons/Adwaita
 	fi
 }
 
@@ -190,40 +223,27 @@ cleanup_unnecessary_files() {
 	rm -rf share/doc
 	rm -rf share/gdb
 	rm -rf share/gettext
+	rm -rf share/gettext-*
 	rm -rf share/gir-1.0
 	rm -rf share/glib-2.0/codegen
 	rm -rf share/glib-2.0/gdb
 	rm -rf share/glib-2.0/gettext
+	rm -rf share/glib-2.0/schemas
 	rm -rf share/graphite2
 	rm -rf share/gtk-3.0
 	rm -rf share/gtk-doc
+	rm -rf share/icons/Adwaita/cursors
 	rm -rf share/info
 	rm -rf share/man
+	rm -rf share/thumbnailers
 	rm -rf share/xml
+	rm -rf usr/share/libalpm
 	# cleanup binaries and libs (delete anything except *.dll and GSpawn helper binaries)
-	find bin ! -name '*.dll' ! -name 'gspawn-win32-helper*.exe' -type f -delete
+	find bin ! -name '*.dll' ! -name 'grep.exe' ! -name 'gspawn-win32-helper*.exe' -type f -delete
 	# cleanup empty directories
 	find . -type d -empty -delete
 }
 
-copy_grep_and_dependencies() {
-	own_arch=$(arch)
-	if [ "${own_arch}" == "${ABI}" -o -z "${MSYS2_ABI_PATH}" ]; then
-		bin_dir="/usr/bin"
-	else
-		# TODO extract grep and dependencies from Pacman packages according to the target ABI
-		bin_dir="${MSYS2_ABI_PATH}/usr/bin"
-	fi
-	echo "Copy 'grep' from ${bin_dir}"
-	cp "${bin_dir}/grep.exe" "bin/"
-	# dependencies for grep.exe
-	cp "${bin_dir}/msys-2.0.dll" "bin/"
-	cp "${bin_dir}/msys-gcc_s-1.dll" "bin/"
-	cp "${bin_dir}/msys-iconv-2.dll" "bin/"
-	cp "${bin_dir}/msys-intl-8.dll" "bin/"
-	cp "${bin_dir}/msys-pcre-1.dll" "bin/"
-}
-
 download_and_extract_sort() {
 	echo "Download and unpack 'sort'"
 	# add sort to the bin directory
@@ -234,8 +254,11 @@ download_and_extract_sort() {
 }
 
 create_bundle_dependency_info_file() {
-	grep_version="$(bin/grep --version | head -n1)"
-	sort_version="$(bin/sort --version | head -n1)"
+	# sort.exe from UnxUtils is a 32bit binary, so use $EXE_WRAPPER_32
+	sort_version="$(${EXE_WRAPPER_32} bin/sort.exe --version | sed -n 1p)"
+	# use "sed -n 1p" instead of "head -n1" as grep will otherwise prints a weird error,
+	# probably because the output pipe is closed prematurely
+	grep_version="$(${EXE_WRAPPER_64} bin/grep.exe --version | sed -n 1p)"
 	filename="ReadMe.Dependencies.Geany.txt"
 	cat << EOF > "${filename}"
 This installation contains dependencies for Geany which are distributed
@@ -248,7 +271,7 @@ sort.exe is extracted from the ZIP archive at
 ${UNX_UTILS_URL}.
 Sort version: ${sort_version}
 
-grep.exe is taken from a 32bit MSYS2 installation and
+grep.exe is taken from a 64bit MSYS2 installation and
 is bundled together with its dependencies.
 Grep version: ${grep_version}
 
@@ -275,8 +298,8 @@ handle_command_line_options $@
 initialize
 extract_packages
 move_extracted_files
+delayed_post_install
 cleanup_unnecessary_files
-copy_grep_and_dependencies
 download_and_extract_sort
 create_bundle_dependency_info_file
 create_zip_archive



--------------
This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).


More information about the Commits mailing list