From fc33a8e0ce58f1fa5a5d9454874b3e220e0129d4 Mon Sep 17 00:00:00 2001 From: Bart Thomee <11445373+bthomee@users.noreply.github.com> Date: Thu, 23 Oct 2025 10:59:35 -0400 Subject: [PATCH] Use gnu-sed on MacOS --- .github/scripts/rename/definitions.sh | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/.github/scripts/rename/definitions.sh b/.github/scripts/rename/definitions.sh index d9f04b91e6..53fcffe860 100755 --- a/.github/scripts/rename/definitions.sh +++ b/.github/scripts/rename/definitions.sh @@ -1,5 +1,18 @@ #!/bin/bash +# Exit the script as soon as an error occurs. +set -e + +# On MacOS, ensure that GNU sed is installed and available as `gsed`. +SED_COMMAND=sed +if [[ "$OSTYPE" == "darwin"* ]]; then + if ! command -v gsed &> /dev/null; then + echo "Error: gsed is not installed. Please install it using 'brew install gnu-sed'." + exit 1 + fi + SED_COMMAND=gsed +fi + # This script renames definitions, such as include guards, in this project. # Specifically, it renames "RIPPLED_XXX" and "RIPPLE_XXX" to "XRPL_XXX" by # scanning all cmake, header, and source files in the specified directory and @@ -20,12 +33,10 @@ fi find "${DIRECTORY}" -type f \( -name "*.h" -o -name "*.hpp" -o -name "*.ipp" -o -name "*.cpp" \) | while read -r FILE; do echo "Processing file: ${FILE}" - sed -i'.bak' -E 's@#(define|endif|if|ifdef|ifndef)(.*)(RIPPLED_|RIPPLE_)([A-Z0-9_]+)@#\1\2XRPL_\4@g' "${FILE}" - rm "${FILE}.bak" + ${SED_COMMAND} -i -E 's@#(define|endif|if|ifdef|ifndef)(.*)(RIPPLED_|RIPPLE_)([A-Z0-9_]+)@#\1\2XRPL_\4@g' "${FILE}" done find "${DIRECTORY}" -type f \( -name "*.cmake" -o -name "*.txt" \) | while read -r FILE; do echo "Processing file: ${FILE}" - sed -i'.bak' -E 's@(RIPPLED_|RIPPLE_)([A-Z0-9_]+)@XRPL_\2@g' "${FILE}" - rm "${FILE}.bak" + ${SED_COMMAND} -i -E 's@(RIPPLED_|RIPPLE_)([A-Z0-9_]+)@XRPL_\2@g' "${FILE}" done echo "Renaming complete."