Files
qt6-migration-pipeline/app/patches/apply_grantlee_fix.sh
T

55 lines
2.1 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
# Apply lightweight fix to Grantlee sources in externals to avoid duplicate
# QT_TESTCASE_BUILDDIR definition which causes compiler errors on Qt6.
GRANTLEE_SRC_DIR="${1:-./external/grantlee-src}"
if [ ! -d "$GRANTLEE_SRC_DIR" ]; then
echo "Grantlee source dir not found: $GRANTLEE_SRC_DIR" >&2
exit 2
fi
TARGET_FILE="$GRANTLEE_SRC_DIR/textdocument/tests/CMakeLists.txt"
if [ ! -f "$TARGET_FILE" ]; then
echo "Target CMake file not found: $TARGET_FILE" >&2
exit 3
fi
# Replace the unconditional target_compile_definitions block with a commented
# explanation to avoid duplicate -D flags.
# export TARGET_FILE for the python subprocess
TARGET_FILE="$TARGET_FILE"
export TARGET_FILE
python3 - <<'PY'
import io,sys
import os
TARGET_FILE = os.environ.get('TARGET_FILE')
if not TARGET_FILE:
print('TARGET_FILE not set', file=sys.stderr)
sys.exit(2)
with open(TARGET_FILE, 'r', encoding='utf-8') as f:
s = f.read()
old = 'target_compile_definitions(plainmarkupbuildertest_exec PRIVATE QT_TESTCASE_BUILDDIR'
if old in s:
# remove the line and any surrounding if/endif that only wrap it
import re
# replace the specific line plus optional surrounding if/endif block with a comment
s2 = re.sub(r"if \(NOT GRANTLEE_BUILD_WITH_QT6\)\s*target_compile_definitions\(plainmarkupbuildertest_exec PRIVATE QT_TESTCASE_BUILDDIR[\s\S]*?endif\(\)\n?", \
'# QT_TESTCASE_BUILDDIR was previously defined here which could conflict with the\n# the definition injected by Qt\'s test configuration. Defining the macro in\n# multiple places leads to compiler redefinition errors. The test framework\n# already provides this define when needed, so omit the explicit definition\n# to avoid duplicate -D flags.\n', s)
if s2==s:
# fallback: remove only the line
s2 = s.replace('target_compile_definitions(plainmarkupbuildertest_exec PRIVATE QT_TESTCASE_BUILDDIR="${CMAKE_BINARY_DIR}")\n','')
s = s2
with open(TARGET_FILE, 'w', encoding='utf-8') as f:
f.write(s)
print('Applied grantlee fix to', TARGET_FILE)
PY