Files
RedBear-OS/local/scripts/lib/qt-sysroot.sh
T
vasilito b472bb5649 fix: build plasma-framework and knotifications on a Wayland-only target
qt-sysroot.sh: Qt installs QML modules under <prefix>/qml, KDE under
<prefix>/lib/qml, and ecm_find_qmlmodule() only searches the KDE root. A
REQUIRED Qt module was therefore reported missing even though its recipe
staged it correctly (plasma-framework aborting on
Qt5Compat.GraphicalEffects) while every org.kde.* module resolved fine.
Bridge the two roots with relative symlinks, never clobbering a real KDE
module of the same name.

plasma-framework: kf6-kwindowsystem is built KWINDOWSYSTEM_X11=OFF, so
KX11Extras and KWindowInfo do not exist, yet core translation units
reference them. Every such call already sits behind a runtime
KWindowSystem::isPlatformX11(), which is always false here, and the
package already ships some #if HAVE_X11 sites -- this finishes the job
upstream started. Done in Python, not sed: the transform needs brace
matching, and an if/else chain must keep its ELSE body (appletpopup.cpp
sets the Wayland surface role there; wrapping the whole chain would have
deleted the Wayland path). Also guards the unconditional <xcb/xcb.h>
include and drops BlurEffectWatcher's QAbstractNativeEventFilter base,
whose only override is itself X11-guarded, leaving the class abstract.
Pin WaylandScanner_EXECUTABLE to the host tool for the same reason breeze
needed it.

kf6-knotifications: the range-comment sed had an UNANCHORED start address
and an anchored end, so on re-runs it matched the '#if (NOT APPLE ...'
it had produced itself while '#endif()' no longer matched -- the range
ran to END OF FILE, commenting a little more of CMakeLists.txt on every
rebuild until install(FILES ...) lost its closing paren. Anchor the start
so it cannot match its own output, and drop the companion
'sed 127,137 s/^#*//' hack that existed only to undo the damage.
2026-08-03 09:10:40 +03:00

218 lines
7.8 KiB
Bash

#!/usr/bin/env bash
redbear_qt_link_sysroot_dir() {
local sysroot="$1"
local dir_name="$2"
if [ -d "${sysroot}/usr/${dir_name}" ] && [ ! -e "${sysroot}/${dir_name}" ]; then
ln -s "usr/${dir_name}" "${sysroot}/${dir_name}"
fi
}
redbear_qt_link_sysroot_dirs() {
local sysroot="$1"
shift
local dir_name
for dir_name in "$@"; do
redbear_qt_link_sysroot_dir "$sysroot" "$dir_name"
done
}
redbear_qt_link_plugins_dir() {
local sysroot="$1"
if [ -d "${sysroot}/usr/plugins" ] && [ ! -e "${sysroot}/plugins" ]; then
ln -s "usr/plugins" "${sysroot}/plugins"
fi
}
# Qt's generated cmake plugin targets resolve each plugin .so via
# <sysroot>/plugins (the _IMPORT_PREFIX is computed from the cmake files under
# <sysroot>/lib/cmake, i.e. the sysroot root, NOT <sysroot>/usr). But
# `cmake --install --prefix .../usr` puts plugins at usr/plugins. qtbase works
# around this by staging plugins to BOTH usr/plugins and plugins; any Qt module
# that ships plugins (qtwayland decorations, qtsvg imageformats, qtdeclarative
# qmltooling, ...) must do the same or a consumer's find_package fails: imported
# target references "<sysroot>/plugins/.../foo.so" but this file does not exist.
# Call this after `cmake --install` with the stage root ($COOKBOOK_STAGE).
redbear_qt_dual_stage_plugins() {
local stage="$1"
if [ -d "${stage}/usr/plugins" ]; then
mkdir -p "${stage}/plugins"
cp -a "${stage}/usr/plugins/." "${stage}/plugins/" 2>/dev/null || true
fi
}
# Qt and KDE install QML modules under DIFFERENT roots:
# Qt -> <prefix>/qml (QT_INSTALL_QML)
# KDE -> <prefix>/lib/qml (KDE_INSTALL_QMLDIR)
# ECM's ecm_find_qmlmodule() only looks in the KDE root (plus QT_HOST_PATH/qml,
# which holds host-tool imports, not target ones). So a REQUIRED *Qt* QML module
# is reported missing even when its recipe staged it perfectly. plasma-framework
# hit this on Qt5Compat.GraphicalEffects:
# qmldir not found in /usr/lib/qml/Qt5Compat/GraphicalEffects or
# <qt-host-build>/qml/Qt5Compat/GraphicalEffects/qmldir
# -> REQUIRED package(s) are missing, aborting CMake run
# while org.kde.* modules resolved fine precisely because they live in the KDE
# root. Bridge the roots with relative symlinks so either spelling resolves.
redbear_qt_bridge_qml_roots() {
local sysroot="$1"
local qt_qml="${sysroot}/usr/qml"
local kde_qml="${sysroot}/usr/lib/qml"
[ -d "${qt_qml}" ] || return 0
mkdir -p "${kde_qml}"
local entry name
for entry in "${qt_qml}"/*; do
[ -e "${entry}" ] || continue
name="$(basename "${entry}")"
# Never clobber a real KDE module of the same name.
[ -e "${kde_qml}/${name}" ] && continue
ln -s "../../qml/${name}" "${kde_qml}/${name}"
done
}
redbear_qt_prepare_common_sysroot() {
local sysroot="$1"
redbear_qt_link_sysroot_dirs "$sysroot" plugins mkspecs metatypes modules qml
redbear_qt_link_plugins_dir "$sysroot"
redbear_qt_bridge_qml_roots "$sysroot"
}
redbear_qt_reset_cmake_cache_dir() {
rm -f CMakeCache.txt
if [ -d CMakeFiles ]; then
python3 - <<'PY'
from pathlib import Path
import os
import shutil
path = Path("CMakeFiles")
for node in path.rglob('*'):
try:
os.chmod(node, 0o700)
except OSError:
pass
shutil.rmtree(path, ignore_errors=False)
PY
fi
}
redbear_qt_rewrite_stage_build_paths() {
local stage_usr="$1"
local build_dir="$2"
find "${stage_usr}/lib/cmake" -name '*.cmake' -exec sed -i \
"s|${build_dir}|/usr|g" {} + 2>/dev/null || true
}
redbear_qt_copy_common_stage_to_sysroot() {
local stage_usr="$1"
local sysroot="$2"
mkdir -p "${sysroot}/include" "${sysroot}/lib"
cp -a "${stage_usr}/include/"* "${sysroot}/include/" 2>/dev/null || true
cp -a "${stage_usr}/lib/libQt6"* "${sysroot}/lib/" 2>/dev/null || true
}
redbear_qt_copy_stage_cmake_subdir_to_sysroot() {
local stage_usr="$1"
local sysroot="$2"
local subdir="$3"
mkdir -p "${sysroot}/lib/cmake/${subdir}"
cp -a "${stage_usr}/lib/cmake/${subdir}/"* "${sysroot}/lib/cmake/${subdir}/" 2>/dev/null || true
}
redbear_qt_rewrite_stage_include_paths() {
local stage_cmake_dir="$1"
local sysroot="$2"
find "${stage_cmake_dir}" -name '*.cmake' -exec sed -i \
"s|/usr/include|${sysroot}/include|g" {} + 2>/dev/null || true
}
redbear_qt_rewrite_stage_lib_paths() {
local stage_cmake_dir="$1"
local sysroot="$2"
find "${stage_cmake_dir}" -name '*.cmake' -exec sed -i \
"s|/usr/lib|${sysroot}/lib|g" {} + 2>/dev/null || true
}
redbear_qt_rewrite_stage_source_metatype_paths() {
local stage_cmake_dir="$1"
local sysroot="$2"
local source_root="$3"
find "${stage_cmake_dir}" -name '*.cmake' -exec sed -i \
"s|/usr/src|${source_root}/src|g" {} + 2>/dev/null || true
find "${stage_cmake_dir}" -name '*.cmake' -exec sed -i \
"s|${source_root}/src/.*/meta_types/|${sysroot}/metatypes/|g" {} + 2>/dev/null || true
}
redbear_qt_rewrite_usr_src_metatype_paths() {
local stage_cmake_dir="$1"
local sysroot="$2"
find "${stage_cmake_dir}" -name '*.cmake' -exec sed -i \
"s|/usr/src/.*/meta_types/|${sysroot}/metatypes/|g" {} + 2>/dev/null || true
}
redbear_qt_rewrite_stage_path_literal() {
local stage_cmake_dir="$1"
local from_path="$2"
local to_path="$3"
find "${stage_cmake_dir}" -name '*.cmake' -exec sed -i \
"s|${from_path}|${to_path}|g" {} + 2>/dev/null || true
}
redbear_qt_copy_stage_qt6_cmake_to_sysroot() {
local stage_usr="$1"
local sysroot="$2"
mkdir -p "${sysroot}/lib/cmake"
cp -a "${stage_usr}/lib/cmake/Qt6"* "${sysroot}/lib/cmake/" 2>/dev/null || true
}
redbear_qt_copy_optional_stage_dir_to_sysroot() {
local stage_usr="$1"
local sysroot="$2"
local dir_name="$3"
if [ -d "${stage_usr}/${dir_name}" ]; then
mkdir -p "${sysroot}/${dir_name}"
cp -a "${stage_usr}/${dir_name}/"* "${sysroot}/${dir_name}/" 2>/dev/null || true
fi
}
redbear_qt_resolve_forwarding_headers() {
local stage_usr="$1"
local build_dir="$2"
find "${stage_usr}/include" -name '*.h' -exec grep -l "${build_dir}" {} \; 2>/dev/null | while read -r fwd_header; do
local build_path
build_path=$(grep '#include "' "${fwd_header}" | head -1 | sed 's/#include "\([^"]*\)".*/\1/')
if [ -n "${build_path}" ] && [ -f "${build_path}" ]; then
cp "${build_path}" "${fwd_header}"
fi
done
}
redbear_qt_ensure_dep_sysroots() {
local cookbook_root="$1"
local sysroot="$2"
local cmake_dir="${sysroot}/usr/lib/cmake"
[ -d "${cmake_dir}" ] || cmake_dir="${sysroot}/lib/cmake"
[ -d "${cmake_dir}" ] || return 0
# Qt cmake macros record absolute sysroot paths during build. When the
# cookbook rebuilds a later recipe, the earlier recipe's sysroot may have
# been cleaned, leaving dangling references. We recreate each missing
# directory as a symlink to the dependency's own stage.
grep -roh "${cookbook_root}/local/recipes/[^ \";]*target/x86_64-unknown-redox/sysroot" "${cmake_dir}" 2>/dev/null | sort -u | while read -r dep_sysroot; do
local dep_target_dir dep_stage_usr
dep_target_dir=$(dirname "${dep_sysroot}")
dep_stage_usr="${dep_target_dir}/stage/usr"
[ -d "${dep_stage_usr}" ] || continue
for qt_dir in include lib metatypes plugins mkspecs modules qml; do
if [ -d "${dep_sysroot}/${qt_dir}" ] && [ ! -L "${dep_sysroot}/${qt_dir}" ]; then
continue
fi
if [ -L "${dep_sysroot}/${qt_dir}" ] || [ -e "${dep_sysroot}/${qt_dir}" ]; then
rm -f "${dep_sysroot}/${qt_dir}"
fi
if [ -d "${dep_stage_usr}/${qt_dir}" ]; then
mkdir -p "${dep_sysroot}"
ln -sf "${dep_stage_usr}/${qt_dir}" "${dep_sysroot}/${qt_dir}"
fi
done
done
}