mirror of
https://github.com/zotero/zotero.git
synced 2026-08-28 05:25:31 +00:00
Move utility functions for build to separate file
`replace_line`, etc. To make them available to both build.sh and fetch_xulrunner
This commit is contained in:
parent
9777d21001
commit
7e7ceffd77
6 changed files with 68 additions and 78 deletions
14
app/build.sh
14
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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
@ -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"
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
64
app/scripts/utils.sh
Normal file
64
app/scripts/utils.sh
Normal file
|
|
@ -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
|
||||
}
|
||||
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue