2023-03-24 12:06:33 +00:00
|
|
|
#!/bin/bash
|
2024-02-12 15:09:10 +00:00
|
|
|
# SPDX-License-Identifier: 0BSD
|
|
|
|
|
2022-12-22 16:34:48 +00:00
|
|
|
#############################################################################
|
|
|
|
#
|
|
|
|
# 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
|
|
|
|
#
|
|
|
|
#############################################################################
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
2023-01-12 14:44:18 +00:00
|
|
|
USAGE="Usage: $0
|
2023-07-21 14:11:01 +00:00
|
|
|
-a [autogen flags]
|
2023-01-12 14:44:18 +00:00
|
|
|
-b [autotools|cmake]
|
|
|
|
-c [crc32|crc64|sha256]
|
2024-04-09 14:47:01 +00:00
|
|
|
-d [encoders|decoders|bcj|delta|threads|shared|nls|small|clmul|sandbox]
|
2023-02-01 13:36:22 +00:00
|
|
|
-f [CFLAGS]
|
2023-01-12 14:44:18 +00:00
|
|
|
-l [destdir]
|
2023-11-22 13:12:15 +00:00
|
|
|
-m [compiler]
|
2023-02-01 13:36:22 +00:00
|
|
|
-n [ARTIFACTS_DIR_NAME]
|
2023-01-12 14:44:18 +00:00
|
|
|
-p [all|build|test]
|
2023-02-01 13:36:22 +00:00
|
|
|
-s [srcdir]"
|
2022-12-22 16:34:48 +00:00
|
|
|
|
|
|
|
# Absolute path of script directory
|
|
|
|
ABS_DIR=$(cd -- "$(dirname -- "$0")" && pwd)
|
|
|
|
|
|
|
|
# Default CLI option values
|
2023-07-21 14:11:01 +00:00
|
|
|
AUTOGEN_FLAGS=""
|
2022-12-22 16:34:48 +00:00
|
|
|
BUILD_SYSTEM="autotools"
|
|
|
|
CHECK_TYPE="crc32,crc64,sha256"
|
|
|
|
BCJ="y"
|
|
|
|
DELTA="y"
|
|
|
|
ENCODERS="y"
|
|
|
|
DECODERS="y"
|
|
|
|
THREADS="y"
|
2023-01-12 14:58:36 +00:00
|
|
|
SHARED="y"
|
2023-01-12 15:09:03 +00:00
|
|
|
NATIVE_LANG_SUPPORT="y"
|
2023-04-25 12:05:26 +00:00
|
|
|
SMALL="n"
|
2023-06-28 13:01:22 +00:00
|
|
|
CLMUL="y"
|
2023-10-23 16:15:39 +00:00
|
|
|
SANDBOX="y"
|
2022-12-22 16:34:48 +00:00
|
|
|
SRC_DIR="$ABS_DIR/../"
|
|
|
|
DEST_DIR="$SRC_DIR/../xz_build"
|
2023-01-07 02:07:20 +00:00
|
|
|
PHASE="all"
|
2023-02-01 13:36:22 +00:00
|
|
|
ARTIFACTS_DIR_NAME="output"
|
2022-12-22 16:34:48 +00:00
|
|
|
|
2024-04-13 00:31:13 +00:00
|
|
|
[[ -z ${CPU_COUNT} ]] && { CPU_COUNT=$(nproc 2>/dev/null || sysctl -n hw.activecpu); }
|
2024-04-10 16:42:23 +00:00
|
|
|
[[ -z ${MAKEFLAGS} ]] && export MAKEFLAGS="-j${CPU_COUNT} -l${CPU_COUNT}"
|
2024-04-10 14:41:08 +00:00
|
|
|
[[ -z ${CFLAGS} ]] && export CFLAGS="-O2"
|
2023-03-24 12:35:11 +00:00
|
|
|
|
|
|
|
###################
|
|
|
|
# Parse arguments #
|
|
|
|
###################
|
|
|
|
|
2024-04-10 10:43:10 +00:00
|
|
|
while getopts a:b:c:d:l:m:n:s:p:f:w:h opt; do
|
2022-12-22 16:34:48 +00:00
|
|
|
# b option can have either value "autotools" OR "cmake"
|
|
|
|
case ${opt} in
|
2023-01-12 14:44:18 +00:00
|
|
|
h)
|
|
|
|
echo "$USAGE"
|
|
|
|
exit 0
|
|
|
|
;;
|
2023-07-21 14:11:01 +00:00
|
|
|
a)
|
|
|
|
AUTOGEN_FLAGS="$OPTARG"
|
|
|
|
;;
|
2022-12-22 16:34:48 +00:00
|
|
|
b)
|
|
|
|
case "$OPTARG" in
|
|
|
|
autotools) ;;
|
|
|
|
cmake) ;;
|
|
|
|
*) echo "Invalid build system: $OPTARG"; exit 1;;
|
|
|
|
esac
|
|
|
|
BUILD_SYSTEM="$OPTARG"
|
|
|
|
;;
|
2023-03-24 12:35:11 +00:00
|
|
|
c) CHECK_TYPE="$OPTARG"
|
2022-12-22 16:34:48 +00:00
|
|
|
;;
|
|
|
|
# d options can be a comma separated list of things to disable at
|
|
|
|
# configure time
|
|
|
|
d)
|
2023-02-01 13:36:46 +00:00
|
|
|
for disable_arg in $(echo "$OPTARG" | sed "s/,/ /g"); do
|
2022-12-22 16:34:48 +00:00
|
|
|
case "$disable_arg" in
|
|
|
|
encoders) ENCODERS="n" ;;
|
|
|
|
decoders) DECODERS="n" ;;
|
|
|
|
bcj) BCJ="n" ;;
|
|
|
|
delta) DELTA="n" ;;
|
|
|
|
threads) THREADS="n" ;;
|
2023-01-12 14:58:36 +00:00
|
|
|
shared) SHARED="n";;
|
2023-01-12 15:09:03 +00:00
|
|
|
nls) NATIVE_LANG_SUPPORT="n";;
|
2023-04-25 12:05:26 +00:00
|
|
|
small) SMALL="y";;
|
2023-06-28 13:01:22 +00:00
|
|
|
clmul) CLMUL="n";;
|
2023-10-23 16:15:39 +00:00
|
|
|
sandbox) SANDBOX="n";;
|
2022-12-22 16:34:48 +00:00
|
|
|
*) echo "Invalid disable value: $disable_arg"; exit 1 ;;
|
|
|
|
esac
|
2023-03-24 12:35:11 +00:00
|
|
|
done
|
2022-12-22 16:34:48 +00:00
|
|
|
;;
|
|
|
|
l) DEST_DIR="$OPTARG"
|
|
|
|
;;
|
2023-11-22 13:12:15 +00:00
|
|
|
m)
|
|
|
|
CC="$OPTARG"
|
|
|
|
export CC
|
|
|
|
;;
|
2023-02-01 13:36:22 +00:00
|
|
|
n) ARTIFACTS_DIR_NAME="$OPTARG"
|
|
|
|
;;
|
2022-12-22 16:34:48 +00:00
|
|
|
s) SRC_DIR="$OPTARG"
|
|
|
|
;;
|
2023-01-07 02:07:20 +00:00
|
|
|
p) PHASE="$OPTARG"
|
|
|
|
;;
|
2023-03-24 12:35:11 +00:00
|
|
|
f)
|
2024-04-10 14:41:08 +00:00
|
|
|
CFLAGS+=" $OPTARG"
|
2023-03-24 12:35:11 +00:00
|
|
|
export CFLAGS
|
2023-01-10 16:48:35 +00:00
|
|
|
;;
|
2024-04-10 10:43:10 +00:00
|
|
|
w) WRAPPER="$OPTARG"
|
|
|
|
;;
|
2022-12-22 16:34:48 +00:00
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2023-03-24 12:35:11 +00:00
|
|
|
|
|
|
|
####################
|
|
|
|
# Helper Functions #
|
|
|
|
####################
|
|
|
|
|
|
|
|
# These two functions essentially implement the ternary "?" operator.
|
|
|
|
add_extra_option() {
|
|
|
|
# First argument is option value ("y" or "n")
|
|
|
|
# Second argument is option to set if "y"
|
|
|
|
# Third argument is option to set if "n"
|
|
|
|
if [ "$1" = "y" ]
|
|
|
|
then
|
|
|
|
EXTRA_OPTIONS="$EXTRA_OPTIONS $2"
|
|
|
|
else
|
|
|
|
EXTRA_OPTIONS="$EXTRA_OPTIONS $3"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
add_to_filter_list() {
|
|
|
|
# First argument is option value ("y" or "n")
|
|
|
|
# Second argument is option to set if "y"
|
|
|
|
if [ "$1" = "y" ]
|
|
|
|
then
|
|
|
|
FILTER_LIST="$FILTER_LIST$2"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
###############
|
|
|
|
# Build Phase #
|
|
|
|
###############
|
|
|
|
|
|
|
|
if [ "$PHASE" = "all" ] || [ "$PHASE" = "build" ]
|
|
|
|
then
|
|
|
|
# Checksum options should be specified differently based on the
|
|
|
|
# build system. It must be calculated here since we won't know
|
|
|
|
# the build system used until all args have been parsed.
|
|
|
|
# Autotools - comma separated
|
|
|
|
# CMake - semi-colon separated
|
|
|
|
if [ "$BUILD_SYSTEM" = "autotools" ]
|
|
|
|
then
|
|
|
|
SEP=","
|
|
|
|
else
|
|
|
|
SEP=";"
|
|
|
|
fi
|
|
|
|
|
|
|
|
CHECK_TYPE_TEMP=""
|
|
|
|
for crc in $(echo "$CHECK_TYPE" | sed "s/,/ /g"); do
|
|
|
|
case "$crc" in
|
2024-06-24 14:18:44 +00:00
|
|
|
crc32 | crc64 | sha256) ;;
|
2023-03-24 12:35:11 +00:00
|
|
|
*) echo "Invalid check type: $crc"; exit 1 ;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
CHECK_TYPE_TEMP="$CHECK_TYPE_TEMP$SEP$crc"
|
|
|
|
done
|
|
|
|
|
|
|
|
# Remove the first character from $CHECK_TYPE_TEMP since it will
|
|
|
|
# always be the delimiter.
|
|
|
|
CHECK_TYPE="${CHECK_TYPE_TEMP:1}"
|
|
|
|
|
|
|
|
FILTER_LIST="lzma1$SEP"lzma2
|
|
|
|
|
2023-01-07 02:07:20 +00:00
|
|
|
# Build based on arguments
|
|
|
|
mkdir -p "$DEST_DIR"
|
2023-03-24 12:35:11 +00:00
|
|
|
|
|
|
|
# Generate configure option values
|
|
|
|
EXTRA_OPTIONS=""
|
|
|
|
|
2023-01-07 02:07:20 +00:00
|
|
|
case $BUILD_SYSTEM in
|
2023-03-24 12:35:11 +00:00
|
|
|
autotools)
|
2023-01-07 02:07:20 +00:00
|
|
|
cd "$SRC_DIR"
|
2023-01-12 15:02:20 +00:00
|
|
|
|
|
|
|
# Run autogen.sh script if not already run
|
|
|
|
if [ ! -f configure ]
|
2023-03-24 12:35:11 +00:00
|
|
|
then
|
2023-07-21 14:11:01 +00:00
|
|
|
./autogen.sh "$AUTOGEN_FLAGS"
|
2023-01-12 15:02:20 +00:00
|
|
|
fi
|
|
|
|
|
2023-01-07 02:07:20 +00:00
|
|
|
cd "$DEST_DIR"
|
|
|
|
|
2024-01-23 15:52:49 +00:00
|
|
|
add_to_filter_list "$BCJ" ",x86,powerpc,ia64,arm,armthumb,arm64,sparc,riscv"
|
2023-03-24 12:35:11 +00:00
|
|
|
add_to_filter_list "$DELTA" ",delta"
|
2023-01-12 14:58:36 +00:00
|
|
|
|
2023-03-24 12:35:11 +00:00
|
|
|
add_extra_option "$ENCODERS" "--enable-encoders=$FILTER_LIST" "--disable-encoders"
|
|
|
|
add_extra_option "$DECODERS" "--enable-decoders=$FILTER_LIST" "--disable-decoders"
|
|
|
|
add_extra_option "$THREADS" "" "--disable-threads"
|
|
|
|
add_extra_option "$SHARED" "" "--disable-shared"
|
|
|
|
add_extra_option "$NATIVE_LANG_SUPPORT" "" "--disable-nls"
|
2023-04-25 12:05:26 +00:00
|
|
|
add_extra_option "$SMALL" "--enable-small" ""
|
2023-06-28 13:01:22 +00:00
|
|
|
add_extra_option "$CLMUL" "" "--disable-clmul-crc"
|
2023-10-23 16:15:39 +00:00
|
|
|
add_extra_option "$SANDBOX" "" "--enable-sandbox=no"
|
2023-01-12 15:09:03 +00:00
|
|
|
|
2024-06-24 14:39:54 +00:00
|
|
|
# Workaround a bug in too old config.guess. Version with
|
|
|
|
# timestamp='2022-05-08' would be needed but the autotools-dev
|
|
|
|
# package has 2022-01-09 in Ubuntu 22.04LTS and 24.04LTS. The
|
|
|
|
# bug breaks i386 assembler usage autodetection.
|
|
|
|
if "$SRC_DIR/build-aux/config.guess" | grep -q x86_64-pc-linux-gnux32
|
|
|
|
then
|
|
|
|
EXTRA_OPTIONS="$EXTRA_OPTIONS --build=i686-pc-linux-gnu"
|
|
|
|
fi
|
|
|
|
|
2023-01-07 02:07:20 +00:00
|
|
|
# Run configure script
|
2023-02-01 13:36:46 +00:00
|
|
|
"$SRC_DIR"/configure --enable-werror --enable-checks="$CHECK_TYPE" $EXTRA_OPTIONS --config-cache
|
2023-01-07 02:07:20 +00:00
|
|
|
|
|
|
|
# Build the project
|
|
|
|
make
|
2023-03-24 12:35:11 +00:00
|
|
|
;;
|
|
|
|
cmake)
|
2023-01-07 02:07:20 +00:00
|
|
|
cd "$DEST_DIR"
|
2023-03-24 12:35:11 +00:00
|
|
|
|
2024-01-23 15:52:49 +00:00
|
|
|
add_to_filter_list "$BCJ" ";x86;powerpc;ia64;arm;armthumb;arm64;sparc;riscv"
|
2023-03-24 12:35:11 +00:00
|
|
|
add_to_filter_list "$DELTA" ";delta"
|
|
|
|
|
2024-06-20 21:46:09 +00:00
|
|
|
add_extra_option "$THREADS" "-DXZ_THREADS=yes" "-DXZ_THREADS=no"
|
2023-03-28 14:48:24 +00:00
|
|
|
|
2023-03-24 12:35:11 +00:00
|
|
|
# Disable MicroLZMA if encoders are not configured.
|
2024-06-20 21:46:09 +00:00
|
|
|
add_extra_option "$ENCODERS" "-DXZ_ENCODERS=$FILTER_LIST" "-DXZ_ENCODERS= -DXZ_MICROLZMA_ENCODER=OFF"
|
2023-03-24 12:35:11 +00:00
|
|
|
|
|
|
|
# Disable MicroLZMA and lzip decoders if decoders are not configured.
|
2024-06-20 21:46:09 +00:00
|
|
|
add_extra_option "$DECODERS" "-DXZ_DECODERS=$FILTER_LIST" "-DXZ_DECODERS= -DXZ_MICROLZMA_DECODER=OFF -DXZ_LZIP_DECODER=OFF"
|
2023-03-24 12:35:11 +00:00
|
|
|
|
|
|
|
# CMake disables the shared library by default.
|
|
|
|
add_extra_option "$SHARED" "-DBUILD_SHARED_LIBS=ON" ""
|
|
|
|
|
2024-06-20 21:46:09 +00:00
|
|
|
add_extra_option "$SMALL" "-DXZ_SMALL=ON" ""
|
2023-04-25 12:05:26 +00:00
|
|
|
|
2023-03-28 14:45:42 +00:00
|
|
|
# Remove old cache file to clear previous settings.
|
|
|
|
rm -f "CMakeCache.txt"
|
2024-06-20 21:46:09 +00:00
|
|
|
cmake "$SRC_DIR/CMakeLists.txt" -B "$DEST_DIR" $EXTRA_OPTIONS -DXZ_CHECKS="$CHECK_TYPE" -G "Unix Makefiles"
|
2023-07-28 13:54:22 +00:00
|
|
|
cmake --build "$DEST_DIR"
|
2023-03-24 12:35:11 +00:00
|
|
|
;;
|
2023-01-07 02:07:20 +00:00
|
|
|
esac
|
|
|
|
fi
|
|
|
|
|
2023-03-24 12:35:11 +00:00
|
|
|
|
|
|
|
##############
|
|
|
|
# Test Phase #
|
|
|
|
##############
|
|
|
|
|
|
|
|
if [ "$PHASE" = "all" ] || [ "$PHASE" = "test" ]
|
|
|
|
then
|
2023-01-07 02:07:20 +00:00
|
|
|
case $BUILD_SYSTEM in
|
2023-03-24 12:35:11 +00:00
|
|
|
autotools)
|
|
|
|
cd "$DEST_DIR"
|
|
|
|
# If the tests fail, copy the test logs into the artifacts folder
|
2024-04-10 14:17:47 +00:00
|
|
|
if make check VERBOSE=1 LOG_COMPILER="$WRAPPER"
|
2023-03-24 12:35:11 +00:00
|
|
|
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
|
|
|
|
;;
|
|
|
|
cmake)
|
|
|
|
cd "$DEST_DIR"
|
2024-04-10 10:43:10 +00:00
|
|
|
if ${WRAPPER} make test
|
2023-03-24 12:35:11 +00:00
|
|
|
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-07 02:07:20 +00:00
|
|
|
esac
|
2023-02-01 13:36:22 +00:00
|
|
|
fi
|