From 7e7ceffd77579df925de5ebfcdef18ccccea297b Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Fri, 3 Jan 2025 01:18:17 -0500 Subject: [PATCH] Move utility functions for build to separate file `replace_line`, etc. To make them available to both build.sh and fetch_xulrunner --- app/build.sh | 14 +------- app/scripts/bootstrap.sh | 14 -------- app/scripts/check_requirements | 2 +- app/scripts/fetch_xulrunner | 51 +-------------------------- app/scripts/utils.sh | 64 ++++++++++++++++++++++++++++++++++ app/scripts/xulrunner_hash | 1 + 6 files changed, 68 insertions(+), 78 deletions(-) delete mode 100644 app/scripts/bootstrap.sh create mode 100644 app/scripts/utils.sh diff --git a/app/build.sh b/app/build.sh index 6ab6bd657d..49bd1d5ccd 100755 --- a/app/build.sh +++ b/app/build.sh @@ -20,6 +20,7 @@ CALLDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" . "$CALLDIR/config.sh" +. "$CALLDIR/scripts/utils.sh" if [ "`uname`" = "Darwin" ]; then MAC_NATIVE=1 @@ -54,19 +55,6 @@ function cleanup { } trap cleanup EXIT -function replace_line { - pattern=$1 - replacement=$2 - file=$3 - - if egrep -q "$pattern" "$file"; then - perl -pi -e "s/$pattern/$replacement/" "$file" - else - echo "$pattern" not found in "$file" -- aborting 2>&1 - exit 1 - fi -} - function abspath { echo $(cd $(dirname $1); pwd)/$(basename $1); } diff --git a/app/scripts/bootstrap.sh b/app/scripts/bootstrap.sh deleted file mode 100644 index 3e314efe21..0000000000 --- a/app/scripts/bootstrap.sh +++ /dev/null @@ -1,14 +0,0 @@ -get_current_platform() { - if [[ "$OSTYPE" == "linux-gnu"* ]]; then - echo l - elif [[ "$OSTYPE" == "darwin"* ]]; then - echo m - elif [[ "$OSTYPE" == "cygwin" ]]; then - echo w - elif [[ "$OSTYPE" == "msys" ]]; then - echo w - # Unknown, so probably Unix-y - else - echo l - fi -} diff --git a/app/scripts/check_requirements b/app/scripts/check_requirements index 570cd41cfe..ea7946a841 100755 --- a/app/scripts/check_requirements +++ b/app/scripts/check_requirements @@ -5,7 +5,7 @@ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" APP_ROOT_DIR="$(dirname "$SCRIPT_DIR")" ROOT_DIR="$(dirname "$APP_ROOT_DIR")" . "$APP_ROOT_DIR/config.sh" -. "$SCRIPT_DIR/bootstrap.sh" +. "$SCRIPT_DIR/utils.sh" cd "$ROOT_DIR" diff --git a/app/scripts/fetch_xulrunner b/app/scripts/fetch_xulrunner index ee942703a5..e2a202427b 100755 --- a/app/scripts/fetch_xulrunner +++ b/app/scripts/fetch_xulrunner @@ -22,6 +22,7 @@ set -euo pipefail SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" APP_ROOT_DIR="$(dirname "$SCRIPT_DIR")" . "$APP_ROOT_DIR/config.sh" +. "$SCRIPT_DIR/utils.sh" cd "$APP_ROOT_DIR" function usage { @@ -61,56 +62,6 @@ if [[ $BUILD_MAC == 0 ]] && [[ $BUILD_WIN == 0 ]] && [[ $BUILD_LINUX == 0 ]]; th usage fi -function check_line { - pattern=$1 - if ! egrep -q "$pattern" "$file"; then - echo "$pattern" not found in "$file" -- aborting 2>&1 - exit 1 - fi -} - -function replace_line { - pattern=$1 - replacement=$2 - file=$3 - - if egrep -q "$pattern" "$file"; then - perl -pi -e "s/$pattern/$replacement/" "$file" - else - echo "$pattern" not found in "$file" -- aborting 2>&1 - exit 1 - fi -} - -function remove_line { - pattern=$1 - file=$2 - - if egrep -q "$pattern" "$file"; then - egrep -v "$pattern" "$file" > "$file.tmp" - mv "$file.tmp" "$file" - else - echo "$pattern" not found in "$file" -- aborting 2>&1 - exit 1 - fi -} - -function remove_between { - start_pattern=$1 - end_pattern=$2 - file=$3 - - if egrep -q "$start_pattern" "$file" && egrep -q "$end_pattern" "$file"; then - perl -ni -e ' - if (/'"$start_pattern"'/) { $skip = 1; next; } - elsif ($skip && /'"$end_pattern"'/) { $skip = 0; next; } - print unless $skip;' "$file" - else - echo "$start_pattern" and "$end_pattern" not found in "$file" -- aborting 2>&1 - exit 1 - fi -} - function get_utf16_chars { str=$(echo -n "$1" | xxd -p | fold -w 2 | sed -r 's/(.+)/\\\\x{\1}\\\\x{00}/') # Add NUL padding diff --git a/app/scripts/utils.sh b/app/scripts/utils.sh new file mode 100644 index 0000000000..e46f38b7df --- /dev/null +++ b/app/scripts/utils.sh @@ -0,0 +1,64 @@ +get_current_platform() { + if [[ "$OSTYPE" == "linux-gnu"* ]]; then + echo l + elif [[ "$OSTYPE" == "darwin"* ]]; then + echo m + elif [[ "$OSTYPE" == "cygwin" ]]; then + echo w + elif [[ "$OSTYPE" == "msys" ]]; then + echo w + # Unknown, so probably Unix-y + else + echo l + fi +} + +function check_line { + pattern=$1 + if ! egrep -q "$pattern" "$file"; then + echo "$pattern" not found in "$file" -- aborting 2>&1 + exit 1 + fi +} + +function replace_line { + pattern=$1 + replacement=$2 + file=$3 + + if egrep -q "$pattern" "$file"; then + perl -pi -e "s/$pattern/$replacement/" "$file" + else + echo "$pattern" not found in "$file" -- aborting 2>&1 + exit 1 + fi +} + +function remove_line { + pattern=$1 + file=$2 + + if egrep -q "$pattern" "$file"; then + egrep -v "$pattern" "$file" > "$file.tmp" + mv "$file.tmp" "$file" + else + echo "$pattern" not found in "$file" -- aborting 2>&1 + exit 1 + fi +} + +function remove_between { + start_pattern=$1 + end_pattern=$2 + file=$3 + + if egrep -q "$start_pattern" "$file" && egrep -q "$end_pattern" "$file"; then + perl -ni -e ' + if (/'"$start_pattern"'/) { $skip = 1; next; } + elsif ($skip && /'"$end_pattern"'/) { $skip = 0; next; } + print unless $skip;' "$file" + else + echo "$start_pattern" and "$end_pattern" not found in "$file" -- aborting 2>&1 + exit 1 + fi +} diff --git a/app/scripts/xulrunner_hash b/app/scripts/xulrunner_hash index 1c19b4912a..c149d0775d 100755 --- a/app/scripts/xulrunner_hash +++ b/app/scripts/xulrunner_hash @@ -36,6 +36,7 @@ else fi xulrunner_content=$(< "$SCRIPT_DIR/fetch_xulrunner") +xulrunner_content+=$(< "$SCRIPT_DIR/utils.sh") xulrunner_content+=$(< "$APP_ROOT_DIR/assets/multilocale.txt") xulrunner_gecko_hash=$(echo -n "$GECKO_VERSION - '$xulrunner_content'" | openssl dgst -sha256)