86 lines
1.7 KiB
Bash
86 lines
1.7 KiB
Bash
#!/usr/bin/env bash
|
|
|
|
function _exit() {
|
|
if [[ "$#" -gt 1 ]]; then
|
|
# When there are multiple args, the last arg is the exit code.
|
|
echo "${@:1:($# - 1)}"
|
|
exit "${@: -1}"
|
|
fi
|
|
echo "$1"
|
|
exit 0
|
|
}
|
|
|
|
help_text="\
|
|
Package a self-contained sparkd executable in a tar.gz file
|
|
|
|
Usage: pack_sparkd.sh [OPTIONS]
|
|
|
|
Positionals:
|
|
OUT The output path for the resultant sparkd tar.gz
|
|
|
|
Options:
|
|
--out OUT The output path for the resultant sparkd tar.gz
|
|
--force Overwrite existing sparkd tar.gz
|
|
-h,--help Print this help message and exit
|
|
|
|
"
|
|
|
|
dest=""
|
|
pkg_name=""
|
|
declare -i overwrite_dest=0
|
|
|
|
while [[ $# -gt 0 ]]; do
|
|
case "$1" in
|
|
--out)
|
|
if [[ -z "$2" ]]; then
|
|
_exit "OUT (--out) must be non-empty" 1
|
|
fi
|
|
dest="$2"
|
|
shift 2
|
|
;;
|
|
--force)
|
|
overwrite_dest=1
|
|
shift 1
|
|
;;
|
|
-h)
|
|
;&
|
|
--help)
|
|
_exit "$help_text" 0
|
|
;;
|
|
*)
|
|
esac
|
|
done
|
|
|
|
tools_dir="$(dirname "$(readlink -f ${BASH_SOURCE[0]})")"
|
|
repo_dir="$tools_dir/.."
|
|
build_dir="$repo_dir/build/gcc/release"
|
|
install_dir="$repo_dir/install/Release/"
|
|
revision=$(git rev-parse --short HEAD)
|
|
timestamp=$(date +'%Y-%m%d-%H%M')
|
|
|
|
if [[ -z "$dest" ]]; then
|
|
pkg_name="sparkd_${revision}_${timestamp}.tar.gz"
|
|
dest="$repo_dir/$pkg_name"
|
|
else
|
|
pkg_name="$(basename "$dest")"
|
|
fi
|
|
|
|
if [ -e "$dest" ]; then
|
|
echo "The output file '$dest' already exists (use --force to overwrite)"
|
|
exit 1
|
|
fi
|
|
eval "\
|
|
$tools_dir/build_sparkd.sh --compiler gcc --build-type release && \
|
|
cmake --build $build_dir --target install"
|
|
if [[ $? -ne 0 ]]; then
|
|
exit $?
|
|
fi
|
|
cd "$install_dir"
|
|
echo "Creating '$pkg_name'"
|
|
tar -czf "$pkg_name" "sparkd"
|
|
if [[ $? -ne 0 ]]; then
|
|
exit $?
|
|
fi
|
|
|
|
mv "$pkg_name" "$dest"
|