2022-12-22 11:34:48 -05:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
#############################################################################
|
|
|
|
#
|
|
|
|
# Script meant to be used for Continuous Integration automation for POSIX
|
|
|
|
# systems. On GitHub, this is used by Ubuntu and MacOS builds.
|
|
|
|
#
|
|
|
|
#############################################################################
|
|
|
|
#
|
|
|
|
# Author: Jia Tan
|
|
|
|
#
|
|
|
|
# This file has been put into the public domain.
|
|
|
|
# You can do whatever you want with this file.
|
|
|
|
#
|
|
|
|
#############################################################################
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
2023-01-12 09:44:18 -05:00
|
|
|
USAGE="Usage: $0
|
|
|
|
-b [autotools|cmake]
|
|
|
|
-c [crc32|crc64|sha256]
|
2023-01-12 10:09:03 -05:00
|
|
|
-d [encoders|decoders|bcj|delta|threads|shared|nls]
|
2023-02-01 08:36:22 -05:00
|
|
|
-f [CFLAGS]
|
2023-01-12 09:44:18 -05:00
|
|
|
-l [destdir]
|
2023-02-01 08:36:22 -05:00
|
|
|
-n [ARTIFACTS_DIR_NAME]
|
2023-01-12 09:44:18 -05:00
|
|
|
-p [all|build|test]
|
2023-02-01 08:36:22 -05:00
|
|
|
-s [srcdir]"
|
2022-12-22 11:34:48 -05:00
|
|
|
|
|
|
|
# Absolute path of script directory
|
|
|
|
ABS_DIR=$(cd -- "$(dirname -- "$0")" && pwd)
|
|
|
|
|
|
|
|
# Default CLI option values
|
|
|
|
BUILD_SYSTEM="autotools"
|
|
|
|
CHECK_TYPE="crc32,crc64,sha256"
|
|
|
|
BCJ="y"
|
|
|
|
DELTA="y"
|
|
|
|
ENCODERS="y"
|
|
|
|
DECODERS="y"
|
|
|
|
THREADS="y"
|
2023-01-12 09:58:36 -05:00
|
|
|
SHARED="y"
|
2023-01-12 10:09:03 -05:00
|
|
|
NATIVE_LANG_SUPPORT="y"
|
2022-12-22 11:34:48 -05:00
|
|
|
SRC_DIR="$ABS_DIR/../"
|
|
|
|
DEST_DIR="$SRC_DIR/../xz_build"
|
2023-01-06 21:07:20 -05:00
|
|
|
PHASE="all"
|
2023-02-01 08:36:22 -05:00
|
|
|
ARTIFACTS_DIR_NAME="output"
|
2022-12-22 11:34:48 -05:00
|
|
|
|
|
|
|
# Parse arguments
|
2023-02-01 08:36:22 -05:00
|
|
|
while getopts b:c:d:l:n:s:p:f:h opt; do
|
2022-12-22 11:34:48 -05:00
|
|
|
# b option can have either value "autotools" OR "cmake"
|
|
|
|
case ${opt} in
|
2023-01-12 09:44:18 -05:00
|
|
|
h)
|
|
|
|
echo "$USAGE"
|
|
|
|
exit 0
|
|
|
|
;;
|
2022-12-22 11:34:48 -05:00
|
|
|
b)
|
|
|
|
case "$OPTARG" in
|
|
|
|
autotools) ;;
|
|
|
|
cmake) ;;
|
|
|
|
*) echo "Invalid build system: $OPTARG"; exit 1;;
|
|
|
|
esac
|
|
|
|
BUILD_SYSTEM="$OPTARG"
|
|
|
|
;;
|
|
|
|
# c options can be a comma separated list of check types to support
|
|
|
|
c)
|
|
|
|
for crc in $(echo $OPTARG | sed "s/,/ /g"); do
|
|
|
|
case "$crc" in
|
|
|
|
crc32) ;;
|
|
|
|
crc64) ;;
|
|
|
|
sha256) ;;
|
|
|
|
*) echo "Invalid check type: $crc"; exit 1 ;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
CHECK_TYPE="$OPTARG"
|
|
|
|
;;
|
|
|
|
# d options can be a comma separated list of things to disable at
|
|
|
|
# configure time
|
|
|
|
d)
|
|
|
|
for disable_arg in $(echo $OPTARG | sed "s/,/ /g"); do
|
|
|
|
case "$disable_arg" in
|
|
|
|
encoders) ENCODERS="n" ;;
|
|
|
|
decoders) DECODERS="n" ;;
|
|
|
|
bcj) BCJ="n" ;;
|
|
|
|
delta) DELTA="n" ;;
|
|
|
|
threads) THREADS="n" ;;
|
2023-01-12 09:58:36 -05:00
|
|
|
shared) SHARED="n";;
|
2023-01-12 10:09:03 -05:00
|
|
|
nls) NATIVE_LANG_SUPPORT="n";;
|
2022-12-22 11:34:48 -05:00
|
|
|
*) echo "Invalid disable value: $disable_arg"; exit 1 ;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
;;
|
|
|
|
l) DEST_DIR="$OPTARG"
|
|
|
|
;;
|
2023-02-01 08:36:22 -05:00
|
|
|
n) ARTIFACTS_DIR_NAME="$OPTARG"
|
|
|
|
;;
|
2022-12-22 11:34:48 -05:00
|
|
|
s) SRC_DIR="$OPTARG"
|
|
|
|
;;
|
2023-01-06 21:07:20 -05:00
|
|
|
p) PHASE="$OPTARG"
|
|
|
|
;;
|
2023-01-10 11:48:35 -05:00
|
|
|
f)
|
|
|
|
CFLAGS="$OPTARG"
|
|
|
|
export CFLAGS
|
|
|
|
;;
|
2022-12-22 11:34:48 -05:00
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2023-01-06 21:07:20 -05:00
|
|
|
if [ "$PHASE" = "all" ] || [ "$PHASE" = "build" ]; then
|
|
|
|
# Build based on arguments
|
|
|
|
mkdir -p "$DEST_DIR"
|
|
|
|
case $BUILD_SYSTEM in
|
|
|
|
autotools)
|
|
|
|
cd "$SRC_DIR"
|
2023-01-12 10:02:20 -05:00
|
|
|
|
|
|
|
# Run autogen.sh script if not already run
|
|
|
|
if [ ! -f configure ]
|
|
|
|
then
|
|
|
|
"./autogen.sh"
|
|
|
|
fi
|
|
|
|
|
2023-01-06 21:07:20 -05:00
|
|
|
cd "$DEST_DIR"
|
|
|
|
|
2023-01-12 10:02:20 -05:00
|
|
|
# Generate configure option values
|
2023-01-06 21:07:20 -05:00
|
|
|
EXTRA_OPTIONS=""
|
|
|
|
FILTER_LIST="lzma1,lzma2"
|
|
|
|
|
|
|
|
if [ "$BCJ" = "y" ]
|
|
|
|
then
|
|
|
|
FILTER_LIST="$FILTER_LIST,x86,powerpc,ia64,arm,armthumb,arm64,sparc"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$DELTA" = "y" ]
|
|
|
|
then
|
|
|
|
FILTER_LIST="$FILTER_LIST,delta"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$ENCODERS" = "y" ]
|
|
|
|
then
|
|
|
|
EXTRA_OPTIONS="$EXTRA_OPTIONS --enable-encoders=$FILTER_LIST"
|
|
|
|
else
|
|
|
|
EXTRA_OPTIONS="$EXTRA_OPTIONS --disable-encoders"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$DECODERS" = "y" ]
|
|
|
|
then
|
|
|
|
EXTRA_OPTIONS="$EXTRA_OPTIONS --enable-decoders=$FILTER_LIST"
|
|
|
|
else
|
|
|
|
EXTRA_OPTIONS="$EXTRA_OPTIONS --disable-decoders"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$THREADS" = "n" ]
|
|
|
|
then
|
|
|
|
EXTRA_OPTIONS="$EXTRA_OPTIONS --disable-threads"
|
|
|
|
fi
|
|
|
|
|
2023-01-12 09:58:36 -05:00
|
|
|
if [ "$SHARED" = "n" ]
|
|
|
|
then
|
|
|
|
EXTRA_OPTIONS="$EXTRA_OPTIONS --disable-shared"
|
|
|
|
fi
|
|
|
|
|
2023-01-12 10:09:03 -05:00
|
|
|
if [ "$NATIVE_LANG_SUPPORT" = "n" ]
|
|
|
|
then
|
|
|
|
EXTRA_OPTIONS="$EXTRA_OPTIONS --disable-nls"
|
|
|
|
fi
|
|
|
|
|
2023-01-06 21:07:20 -05:00
|
|
|
# Run configure script
|
2023-01-18 08:51:43 -05:00
|
|
|
"$SRC_DIR"/configure --enable-werror --enable-checks=$CHECK_TYPE $EXTRA_OPTIONS --config-cache
|
2023-01-06 21:07:20 -05:00
|
|
|
|
|
|
|
# Build the project
|
|
|
|
make
|
|
|
|
;;
|
|
|
|
cmake)
|
|
|
|
# CMake currently does not support disabling encoders, decoders,
|
|
|
|
# threading, or check types. For now, just run the full build.
|
|
|
|
cd "$DEST_DIR"
|
|
|
|
cmake "$SRC_DIR/CMakeLists.txt" -B "$DEST_DIR"
|
|
|
|
make
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$PHASE" = "all" ] || [ "$PHASE" = "test" ]; then
|
|
|
|
case $BUILD_SYSTEM in
|
|
|
|
autotools)
|
|
|
|
cd "$DEST_DIR"
|
2023-02-01 08:36:22 -05:00
|
|
|
# If the tests fail, copy the test logs into the artifacts folder
|
|
|
|
if make check
|
|
|
|
then
|
|
|
|
:
|
|
|
|
else
|
|
|
|
mkdir -p "$SRC_DIR/build-aux/artifacts/$ARTIFACTS_DIR_NAME"
|
|
|
|
cp ./tests/*.log "$SRC_DIR/build-aux/artifacts/$ARTIFACTS_DIR_NAME"
|
|
|
|
exit 1
|
|
|
|
fi
|
2023-01-06 21:07:20 -05:00
|
|
|
;;
|
|
|
|
cmake)
|
|
|
|
cd "$DEST_DIR"
|
2023-02-01 08:36:22 -05:00
|
|
|
if make test
|
|
|
|
then
|
|
|
|
:
|
|
|
|
else
|
|
|
|
mkdir -p "$SRC_DIR/build-aux/artifacts/$ARTIFACTS_DIR_NAME"
|
|
|
|
cp ./Testing/Temporary/*.log "$SRC_DIR/build-aux/artifacts/$ARTIFACTS_DIR_NAME"
|
|
|
|
exit 1
|
|
|
|
fi
|
2023-01-06 21:07:20 -05:00
|
|
|
;;
|
|
|
|
esac
|
2023-02-01 08:36:22 -05:00
|
|
|
fi
|