1
0
Fork 0
mirror of https://git.tukaani.org/xz.git synced 2024-04-04 12:36:23 +02:00

CI: ci_build.sh allows CMake features to be configured.

Also included various clean ups for style and helper functions for
repeated work.
This commit is contained in:
Jia Tan 2023-03-24 20:35:11 +08:00
parent cf3d1f130e
commit 4fabdb269f

View file

@ -44,7 +44,11 @@ DEST_DIR="$SRC_DIR/../xz_build"
PHASE="all" PHASE="all"
ARTIFACTS_DIR_NAME="output" ARTIFACTS_DIR_NAME="output"
# Parse arguments
###################
# Parse arguments #
###################
while getopts b:c:d:l:n:s:p:f:h opt; do while getopts b:c:d:l:n:s:p:f:h opt; do
# b option can have either value "autotools" OR "cmake" # b option can have either value "autotools" OR "cmake"
case ${opt} in case ${opt} in
@ -60,17 +64,7 @@ while getopts b:c:d:l:n:s:p:f:h opt; do
esac esac
BUILD_SYSTEM="$OPTARG" BUILD_SYSTEM="$OPTARG"
;; ;;
# c options can be a comma separated list of check types to support c) CHECK_TYPE="$OPTARG"
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 # d options can be a comma separated list of things to disable at
# configure time # configure time
@ -97,17 +91,91 @@ while getopts b:c:d:l:n:s:p:f:h opt; do
p) PHASE="$OPTARG" p) PHASE="$OPTARG"
;; ;;
f) f)
CFLAGS="$OPTARG" CFLAGS="$OPTARG"
export CFLAGS export CFLAGS
;; ;;
esac esac
done done
if [ "$PHASE" = "all" ] || [ "$PHASE" = "build" ]; then
####################
# 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
# Remove "crc32" from cmake build, if specified.
crc32)
if [ "$BUILD_SYSTEM" = "cmake" ]
then
continue
fi
;;
crc64) ;;
sha256) ;;
*) 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
# Build based on arguments # Build based on arguments
mkdir -p "$DEST_DIR" mkdir -p "$DEST_DIR"
# Generate configure option values
EXTRA_OPTIONS=""
case $BUILD_SYSTEM in case $BUILD_SYSTEM in
autotools) autotools)
cd "$SRC_DIR" cd "$SRC_DIR"
# Run autogen.sh script if not already run # Run autogen.sh script if not already run
@ -118,89 +186,74 @@ if [ "$PHASE" = "all" ] || [ "$PHASE" = "build" ]; then
cd "$DEST_DIR" cd "$DEST_DIR"
# Generate configure option values add_to_filter_list "$BCJ" ",x86,powerpc,ia64,arm,armthumb,arm64,sparc"
EXTRA_OPTIONS="" add_to_filter_list "$DELTA" ",delta"
FILTER_LIST="lzma1,lzma2"
if [ "$BCJ" = "y" ] add_extra_option "$ENCODERS" "--enable-encoders=$FILTER_LIST" "--disable-encoders"
then add_extra_option "$DECODERS" "--enable-decoders=$FILTER_LIST" "--disable-decoders"
FILTER_LIST="$FILTER_LIST,x86,powerpc,ia64,arm,armthumb,arm64,sparc" add_extra_option "$THREADS" "" "--disable-threads"
fi add_extra_option "$SHARED" "" "--disable-shared"
add_extra_option "$NATIVE_LANG_SUPPORT" "" "--disable-nls"
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
if [ "$SHARED" = "n" ]
then
EXTRA_OPTIONS="$EXTRA_OPTIONS --disable-shared"
fi
if [ "$NATIVE_LANG_SUPPORT" = "n" ]
then
EXTRA_OPTIONS="$EXTRA_OPTIONS --disable-nls"
fi
# Run configure script # Run configure script
"$SRC_DIR"/configure --enable-werror --enable-checks="$CHECK_TYPE" $EXTRA_OPTIONS --config-cache "$SRC_DIR"/configure --enable-werror --enable-checks="$CHECK_TYPE" $EXTRA_OPTIONS --config-cache
# Build the project # Build the project
make make
;; ;;
cmake) cmake)
# CMake currently does not support disabling encoders, decoders, # The CMake build currently does not support disabling
# threading, or check types. For now, just run the full build. # threading.
cd "$DEST_DIR" cd "$DEST_DIR"
cmake "$SRC_DIR/CMakeLists.txt" -B "$DEST_DIR"
add_to_filter_list "$BCJ" ";x86;powerpc;ia64;arm;armthumb;arm64;sparc"
add_to_filter_list "$DELTA" ";delta"
# Disable MicroLZMA if encoders are not configured.
add_extra_option "$ENCODERS" "-DENCODERS=$FILTER_LIST" "-DENCODERS= -DMICROLZMA_ENCODER=OFF"
# Disable MicroLZMA and lzip decoders if decoders are not configured.
add_extra_option "$DECODERS" "-DDECODERS=$FILTER_LIST" "-DDECODERS= -DMICROLZMA_DECODER=OFF -DLZIP_DECODER=OFF"
# CMake disables the shared library by default.
add_extra_option "$SHARED" "-DBUILD_SHARED_LIBS=ON" ""
cmake "$SRC_DIR/CMakeLists.txt" -B "$DEST_DIR" $EXTRA_OPTIONS -DADDITIONAL_CHECK_TYPES="$CHECK_TYPE"
make make
;; ;;
esac esac
fi fi
if [ "$PHASE" = "all" ] || [ "$PHASE" = "test" ]; then
##############
# Test Phase #
##############
if [ "$PHASE" = "all" ] || [ "$PHASE" = "test" ]
then
case $BUILD_SYSTEM in case $BUILD_SYSTEM in
autotools) autotools)
cd "$DEST_DIR" cd "$DEST_DIR"
# If the tests fail, copy the test logs into the artifacts folder # If the tests fail, copy the test logs into the artifacts folder
if make check if make check
then then
: :
else else
mkdir -p "$SRC_DIR/build-aux/artifacts/$ARTIFACTS_DIR_NAME" mkdir -p "$SRC_DIR/build-aux/artifacts/$ARTIFACTS_DIR_NAME"
cp ./tests/*.log "$SRC_DIR/build-aux/artifacts/$ARTIFACTS_DIR_NAME" cp ./tests/*.log "$SRC_DIR/build-aux/artifacts/$ARTIFACTS_DIR_NAME"
exit 1 exit 1
fi fi
;; ;;
cmake) cmake)
cd "$DEST_DIR" cd "$DEST_DIR"
if make test if make test
then then
: :
else else
mkdir -p "$SRC_DIR/build-aux/artifacts/$ARTIFACTS_DIR_NAME" mkdir -p "$SRC_DIR/build-aux/artifacts/$ARTIFACTS_DIR_NAME"
cp ./Testing/Temporary/*.log "$SRC_DIR/build-aux/artifacts/$ARTIFACTS_DIR_NAME" cp ./Testing/Temporary/*.log "$SRC_DIR/build-aux/artifacts/$ARTIFACTS_DIR_NAME"
exit 1 exit 1
fi fi
;; ;;
esac esac
fi fi