summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMavridis Philippe <mavridisf@gmail.com>2022-02-07 16:32:54 +0200
committerMavridis Philippe <mavridisf@gmail.com>2022-02-14 19:54:57 +0200
commit1b670e287c807042997794e0344f1ae1c97b4d41 (patch)
tree0b5e8f02b5135f02d7a6de79184f321215f10427
parenteecedb7d6141478bebff53ad3e5f0f822e34595e (diff)
downloadscripts-1b670e287c807042997794e0344f1ae1c97b4d41.tar.gz
scripts-1b670e287c807042997794e0344f1ae1c97b4d41.zip
Add script to replace <includehints> with includes
Signed-off-by: Mavridis Philippe <mavridisf@gmail.com>
-rwxr-xr-xmisc/replace_includehints59
1 files changed, 59 insertions, 0 deletions
diff --git a/misc/replace_includehints b/misc/replace_includehints
new file mode 100755
index 0000000..edccc89
--- /dev/null
+++ b/misc/replace_includehints
@@ -0,0 +1,59 @@
+#!/bin/bash
+#
+# This script replaces <includehints> in TQt designer UI files
+# with global <include>'s, removing duplicate includes.
+#
+# The reasons for this is that includehints are not well supported
+# and can cause FTBFS.
+#
+# Copyright (C) 2022 Mavridis Philippe <mavridisf@gmail.com>
+# for the Trinity Desktop Project
+#
+# Licensed under GNU GPLv2 or later.
+#
+
+# Find files needing update
+TO_REPLACE=$(find * -name \*.ui -exec grep -l includehint '{}' \;)
+
+if [[ ${#TO_REPLACE} == 0 ]]
+then
+ echo "No files need to be modified."
+ exit 0
+fi
+
+echo "Files that will be modified:"
+for f in $TO_REPLACE
+do
+ echo " - $f"
+done
+
+echo
+echo "Press any key to continue to ^C to cancel."
+read
+
+# Start replacing
+declare -a headers
+for f in $TO_REPLACE
+do
+ echo "Updating file '$f'..."
+
+ # Replace containing tag
+ sed -Ei 's!<(\/?)includehints>!<\1includes>!g' $f
+
+ # Replace includes themselves while avoiding duplicates (a simple
+ # sed -Ei 's/<includehint>([[:alnum:]\/.]*)</includehint>/<include location="global" impldecl="in implementation">\1</include>/g' $f
+ # would leave duplicates behind).
+ headers=()
+ for h in $(grep -o "<includehint>[[:alnum:]\/.]*</includehint>" $f | sed -E 's/<\/?includehint>//g')
+ do
+ if [[ ! "${headers[*]}" =~ $h ]] # if this is a unique header
+ then
+ echo " - $h"
+ sed -i "0,/<includehint>$h<\/includehint>/{s//<include location=\"global\" impldecl=\"in implementation\">$h<\/include>/}" $f
+ headers+=($h)
+ fi
+ done
+
+ # Remove leftover duplicate includehints
+ sed -Ei '/<includehint>([[:alnum:]\/.]*)<\/includehint>/d' $f
+done