#!/bin/bash # # This script replaces in TQt designer UI files # with global 's, removing duplicate includes. # # The reasons for this is that includehints are not well supported # and can cause FTBFS. # # Copyright (C) 2022 Mavridis Philippe # 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/([[:alnum:]\/.]*)/\1/g' $f # would leave duplicates behind). headers=() for h in $(grep -o "[[:alnum:]\/.]*" $f | sed -E 's/<\/?includehint>//g') do if [[ ! "${headers[*]}" =~ $h ]] # if this is a unique header then echo " - $h" sed -i "0,/$h<\/includehint>/{s//$h<\/include>/}" $f headers+=($h) fi done # Remove leftover duplicate includehints sed -Ei '/([[:alnum:]\/.]*)<\/includehint>/d' $f done