From 73f629e321b74f68c9954728fa4f19261afccf46 Mon Sep 17 00:00:00 2001 From: Sam James Date: Wed, 10 Apr 2024 18:33:55 +0100 Subject: ci: rename ci_build.sh -> ci_build.bash We discussed the name and it's less cognitive load to just call it '.bash' so you don't have an immediate question about if bashisms are OK. --- .github/workflows/ci.yml | 52 +++---- .github/workflows/windows-ci.yml | 20 +-- build-aux/ci_build.bash | 289 +++++++++++++++++++++++++++++++++++++++ build-aux/ci_build.sh | 289 --------------------------------------- 4 files changed, 325 insertions(+), 325 deletions(-) create mode 100755 build-aux/ci_build.bash delete mode 100755 build-aux/ci_build.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ded9b68d..b661dea3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -70,11 +70,11 @@ jobs: # done first. - name: Build 32-bit if: ${{ matrix.os == 'ubuntu-latest' && matrix.build_system == 'autotools' }} - run: ./build-aux/ci_build.sh -b autotools -p build -f "-m32" + run: ./build-aux/ci_build.bash -b autotools -p build -f "-m32" - name: Test 32-bit if: ${{ matrix.os == 'ubuntu-latest' && matrix.build_system == 'autotools' }} run: | - ./build-aux/ci_build.sh -b autotools -p test -f "-m32" -n 32_bit + ./build-aux/ci_build.bash -b autotools -p test -f "-m32" -n 32_bit cd ../xz_build && make distclean # The sandbox must be disabled because it will prevent access to @@ -82,78 +82,78 @@ jobs: # instrumentation. - name: Build with -fsanitize=address,undefined if: ${{ matrix.os == 'ubuntu-latest' && matrix.build_system == 'autotools' }} - run: ./build-aux/ci_build.sh -b autotools -p build -f "-fsanitize=address,undefined" -d sandbox + run: ./build-aux/ci_build.bash -b autotools -p build -f "-fsanitize=address,undefined" -d sandbox - name: Test with -fsanitize=address,undefined if: ${{ matrix.os == 'ubuntu-latest' && matrix.build_system == 'autotools' }} run: | export UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1 - ./build-aux/ci_build.sh -b autotools -p test -f "-fsanitize=address,undefined" -d sandbox + ./build-aux/ci_build.bash -b autotools -p test -f "-fsanitize=address,undefined" -d sandbox cd ../xz_build && make distclean - name: Build with Valgrind if: ${{ matrix.os == 'ubuntu-latest' && matrix.build_system == 'autotools' }} - run: ./build-aux/ci_build.sh -b autotools -p build -d sandbox + run: ./build-aux/ci_build.bash -b autotools -p build -d sandbox - name: Test with Valgrind if: ${{ matrix.os == 'ubuntu-latest' && matrix.build_system == 'autotools' }} run: | - ./build-aux/ci_build.sh -b autotools -p test -d sandbox -w "valgrind --quiet --trace-children=yes --exit-on-first-error=yes --error-exitcode=1" + ./build-aux/ci_build.bash -b autotools -p test -d sandbox -w "valgrind --quiet --trace-children=yes --exit-on-first-error=yes --error-exitcode=1" cd ../xz_build && make distclean - name: Build with musl libc if: ${{ matrix.os == 'ubuntu-latest'}} - run: ./build-aux/ci_build.sh -b ${{ matrix.build_system }} -p build -m "/usr/bin/musl-gcc" + run: ./build-aux/ci_build.bash -b ${{ matrix.build_system }} -p build -m "/usr/bin/musl-gcc" - name: Test with musl libc if: ${{ matrix.os == 'ubuntu-latest'}} run: | - ./build-aux/ci_build.sh -b ${{ matrix.build_system }} -p test -m "/usr/bin/musl-gcc" + ./build-aux/ci_build.bash -b ${{ matrix.build_system }} -p test -m "/usr/bin/musl-gcc" - name: Clean up musl libc run if: ${{ matrix.os == 'ubuntu-latest' && matrix.build_system == 'autotools' }} run: cd ../xz_build && make distclean - name: Build with full features - run: ./build-aux/ci_build.sh -b ${{ matrix.build_system }} -p build + run: ./build-aux/ci_build.bash -b ${{ matrix.build_system }} -p build - name: Test with full features - run: ./build-aux/ci_build.sh -b ${{ matrix.build_system }} -p test -n full_features + run: ./build-aux/ci_build.bash -b ${{ matrix.build_system }} -p test -n full_features - name: Build without encoders - run: ./build-aux/ci_build.sh -b ${{ matrix.build_system }} -d encoders,shared -p build + run: ./build-aux/ci_build.bash -b ${{ matrix.build_system }} -d encoders,shared -p build - name: Test without encoders - run: ./build-aux/ci_build.sh -b ${{ matrix.build_system }} -d encoders,shared -p test -n no_encoders + run: ./build-aux/ci_build.bash -b ${{ matrix.build_system }} -d encoders,shared -p test -n no_encoders - name: Build without decoders - run: ./build-aux/ci_build.sh -b ${{ matrix.build_system }} -d decoders,shared -p build + run: ./build-aux/ci_build.bash -b ${{ matrix.build_system }} -d decoders,shared -p build - name: Test without decoders - run: ./build-aux/ci_build.sh -b ${{ matrix.build_system }} -d decoders,shared -p test -n no_decoders + run: ./build-aux/ci_build.bash -b ${{ matrix.build_system }} -d decoders,shared -p test -n no_decoders - name: Build without threads - run: ./build-aux/ci_build.sh -b ${{ matrix.build_system }} -d threads,shared -p build + run: ./build-aux/ci_build.bash -b ${{ matrix.build_system }} -d threads,shared -p build - name: Test without threads - run: ./build-aux/ci_build.sh -b ${{ matrix.build_system }} -d threads,shared -p test -n no_threads + run: ./build-aux/ci_build.bash -b ${{ matrix.build_system }} -d threads,shared -p test -n no_threads - name: Build without BCJ filters - run: ./build-aux/ci_build.sh -b ${{ matrix.build_system }} -d bcj,shared,nls -p build + run: ./build-aux/ci_build.bash -b ${{ matrix.build_system }} -d bcj,shared,nls -p build - name: Test without BCJ filters - run: ./build-aux/ci_build.sh -b ${{ matrix.build_system }} -d bcj,shared,nls -p test -n no_bcj + run: ./build-aux/ci_build.bash -b ${{ matrix.build_system }} -d bcj,shared,nls -p test -n no_bcj - name: Build without Delta filters - run: ./build-aux/ci_build.sh -b ${{ matrix.build_system }} -d delta,shared,nls -p build + run: ./build-aux/ci_build.bash -b ${{ matrix.build_system }} -d delta,shared,nls -p build - name: Test without Delta filters - run: ./build-aux/ci_build.sh -b ${{ matrix.build_system }} -d delta,shared,nls -p test -n no_delta + run: ./build-aux/ci_build.bash -b ${{ matrix.build_system }} -d delta,shared,nls -p test -n no_delta - name: Build without sha256 check - run: ./build-aux/ci_build.sh -b ${{ matrix.build_system }} -c crc32,crc64 -d shared,nls -p build + run: ./build-aux/ci_build.bash -b ${{ matrix.build_system }} -c crc32,crc64 -d shared,nls -p build - name: Test without sha256 check - run: ./build-aux/ci_build.sh -b ${{ matrix.build_system }} -c crc32,crc64 -d shared,nls -p test -n no_sha256 + run: ./build-aux/ci_build.bash -b ${{ matrix.build_system }} -c crc32,crc64 -d shared,nls -p test -n no_sha256 - name: Build without crc64 check - run: ./build-aux/ci_build.sh -b ${{ matrix.build_system }} -c crc32,sha256 -d shared,nls -p build + run: ./build-aux/ci_build.bash -b ${{ matrix.build_system }} -c crc32,sha256 -d shared,nls -p build - name: Test without crc64 check - run: ./build-aux/ci_build.sh -b ${{ matrix.build_system }} -c crc32,sha256 -d shared,nls -p test -n no_crc64 + run: ./build-aux/ci_build.bash -b ${{ matrix.build_system }} -c crc32,sha256 -d shared,nls -p test -n no_crc64 - name: Build small - run: ./build-aux/ci_build.sh -b ${{ matrix.build_system }} -d small -p build + run: ./build-aux/ci_build.bash -b ${{ matrix.build_system }} -d small -p build - name: Test small - run: ./build-aux/ci_build.sh -b ${{ matrix.build_system }} -d small -p test -n small + run: ./build-aux/ci_build.bash -b ${{ matrix.build_system }} -d small -p test -n small # Attempt to upload the test logs as artifacts if any step has failed - uses: actions/upload-artifact@c7d193f32edcb7bfad88892161225aeda64e9392 #v4.0.0 diff --git a/.github/workflows/windows-ci.yml b/.github/workflows/windows-ci.yml index 7285a78f..e02e8593 100644 --- a/.github/workflows/windows-ci.yml +++ b/.github/workflows/windows-ci.yml @@ -87,29 +87,29 @@ jobs: ################## - name: Build with full features - run: ./build-aux/ci_build.sh -a "--no-po4a" -b ${{ matrix.build_system }} -p build + run: ./build-aux/ci_build.bash -a "--no-po4a" -b ${{ matrix.build_system }} -p build - name: Test with full features - run: ./build-aux/ci_build.sh -a "--no-po4a" -b ${{ matrix.build_system }} -p test -n full_features + run: ./build-aux/ci_build.bash -a "--no-po4a" -b ${{ matrix.build_system }} -p test -n full_features - name: Build without threads - run: ./build-aux/ci_build.sh -a "--no-po4a" -b ${{ matrix.build_system }} -d threads,shared -p build + run: ./build-aux/ci_build.bash -a "--no-po4a" -b ${{ matrix.build_system }} -d threads,shared -p build - name: Test without threads - run: ./build-aux/ci_build.sh -a "--no-po4a" -b ${{ matrix.build_system }} -d threads,shared -p test -n no_threads + run: ./build-aux/ci_build.bash -a "--no-po4a" -b ${{ matrix.build_system }} -d threads,shared -p test -n no_threads - name: Build without encoders - run: ./build-aux/ci_build.sh -a "--no-po4a" -b ${{ matrix.build_system }} -d encoders,shared -p build + run: ./build-aux/ci_build.bash -a "--no-po4a" -b ${{ matrix.build_system }} -d encoders,shared -p build - name: Test without encoders - run: ./build-aux/ci_build.sh -a "--no-po4a" -b ${{ matrix.build_system }} -d encoders,shared -p test -n no_encoders + run: ./build-aux/ci_build.bash -a "--no-po4a" -b ${{ matrix.build_system }} -d encoders,shared -p test -n no_encoders - name: Build without decoders - run: ./build-aux/ci_build.sh -a "--no-po4a" -b ${{ matrix.build_system }} -d decoders,shared -p build + run: ./build-aux/ci_build.bash -a "--no-po4a" -b ${{ matrix.build_system }} -d decoders,shared -p build - name: Test without decoders - run: ./build-aux/ci_build.sh -a "--no-po4a" -b ${{ matrix.build_system }} -d decoders,shared -p test -n no_decoders + run: ./build-aux/ci_build.bash -a "--no-po4a" -b ${{ matrix.build_system }} -d decoders,shared -p test -n no_decoders - name: Build with only crc32 check - run: ./build-aux/ci_build.sh -a "--no-po4a" -b ${{ matrix.build_system }} -c crc32 -d shared,nls -p build + run: ./build-aux/ci_build.bash -a "--no-po4a" -b ${{ matrix.build_system }} -c crc32 -d shared,nls -p build - name: Test with only crc32 check - run: ./build-aux/ci_build.sh -a "--no-po4a" -b ${{ matrix.build_system }} -c crc32 -d shared,nls -p test -n crc32_only + run: ./build-aux/ci_build.bash -a "--no-po4a" -b ${{ matrix.build_system }} -c crc32 -d shared,nls -p test -n crc32_only ############### diff --git a/build-aux/ci_build.bash b/build-aux/ci_build.bash new file mode 100755 index 00000000..d40cd3ce --- /dev/null +++ b/build-aux/ci_build.bash @@ -0,0 +1,289 @@ +#!/bin/bash +# SPDX-License-Identifier: 0BSD + +############################################################################# +# +# 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 + +USAGE="Usage: $0 + -a [autogen flags] + -b [autotools|cmake] + -c [crc32|crc64|sha256] + -d [encoders|decoders|bcj|delta|threads|shared|nls|small|clmul|sandbox] + -f [CFLAGS] + -l [destdir] + -m [compiler] + -n [ARTIFACTS_DIR_NAME] + -p [all|build|test] + -s [srcdir]" + +# Absolute path of script directory +ABS_DIR=$(cd -- "$(dirname -- "$0")" && pwd) + +# Default CLI option values +AUTOGEN_FLAGS="" +BUILD_SYSTEM="autotools" +CHECK_TYPE="crc32,crc64,sha256" +BCJ="y" +DELTA="y" +ENCODERS="y" +DECODERS="y" +THREADS="y" +SHARED="y" +NATIVE_LANG_SUPPORT="y" +SMALL="n" +CLMUL="y" +SANDBOX="y" +SRC_DIR="$ABS_DIR/../" +DEST_DIR="$SRC_DIR/../xz_build" +PHASE="all" +ARTIFACTS_DIR_NAME="output" + +[[ -z ${CPU_COUNT} ]] && { CPU_COUNT=$(nproc 2>/dev/null || sysctl -n hw.ncpu); } +[[ -z ${MAKEFLAGS} ]] && export MAKEFLAGS="-j${CPU_COUNT} -l${CPU_COUNT}" +[[ -z ${CFLAGS} ]] && export CFLAGS="-O2" + +################### +# Parse arguments # +################### + +while getopts a:b:c:d:l:m:n:s:p:f:w:h opt; do + # b option can have either value "autotools" OR "cmake" + case ${opt} in + h) + echo "$USAGE" + exit 0 + ;; + a) + AUTOGEN_FLAGS="$OPTARG" + ;; + b) + case "$OPTARG" in + autotools) ;; + cmake) ;; + *) echo "Invalid build system: $OPTARG"; exit 1;; + esac + BUILD_SYSTEM="$OPTARG" + ;; + c) 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" ;; + shared) SHARED="n";; + nls) NATIVE_LANG_SUPPORT="n";; + small) SMALL="y";; + clmul) CLMUL="n";; + sandbox) SANDBOX="n";; + *) echo "Invalid disable value: $disable_arg"; exit 1 ;; + esac + done + ;; + l) DEST_DIR="$OPTARG" + ;; + m) + CC="$OPTARG" + export CC + ;; + n) ARTIFACTS_DIR_NAME="$OPTARG" + ;; + s) SRC_DIR="$OPTARG" + ;; + p) PHASE="$OPTARG" + ;; + f) + CFLAGS+=" $OPTARG" + export CFLAGS + ;; + w) WRAPPER="$OPTARG" + ;; + esac +done + + +#################### +# 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 + mkdir -p "$DEST_DIR" + + # Generate configure option values + EXTRA_OPTIONS="" + + case $BUILD_SYSTEM in + autotools) + cd "$SRC_DIR" + + # Run autogen.sh script if not already run + if [ ! -f configure ] + then + ./autogen.sh "$AUTOGEN_FLAGS" + fi + + cd "$DEST_DIR" + + add_to_filter_list "$BCJ" ",x86,powerpc,ia64,arm,armthumb,arm64,sparc,riscv" + add_to_filter_list "$DELTA" ",delta" + + 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" + add_extra_option "$SMALL" "--enable-small" "" + add_extra_option "$CLMUL" "" "--disable-clmul-crc" + add_extra_option "$SANDBOX" "" "--enable-sandbox=no" + + # Run configure script + "$SRC_DIR"/configure --enable-werror --enable-checks="$CHECK_TYPE" $EXTRA_OPTIONS --config-cache + + # Build the project + make + ;; + cmake) + cd "$DEST_DIR" + + add_to_filter_list "$BCJ" ";x86;powerpc;ia64;arm;armthumb;arm64;sparc;riscv" + add_to_filter_list "$DELTA" ";delta" + + add_extra_option "$THREADS" "-DENABLE_THREADS=ON" "-DENABLE_THREADS=OFF" + + # 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" "" + + add_extra_option "$SMALL" "-DHAVE_SMALL=ON" "" + + if test -n "$CC" ; then + EXTRA_OPTIONS="$EXTRA_OPTIONS -DCMAKE_C_COMPILER=$CC" + fi + + # Remove old cache file to clear previous settings. + rm -f "CMakeCache.txt" + cmake "$SRC_DIR/CMakeLists.txt" -B "$DEST_DIR" $EXTRA_OPTIONS -DADDITIONAL_CHECK_TYPES="$CHECK_TYPE" -G "Unix Makefiles" + cmake --build "$DEST_DIR" + ;; + esac +fi + + +############## +# Test Phase # +############## + +if [ "$PHASE" = "all" ] || [ "$PHASE" = "test" ] +then + case $BUILD_SYSTEM in + autotools) + cd "$DEST_DIR" + # If the tests fail, copy the test logs into the artifacts folder + if make check VERBOSE=1 LOG_COMPILER="$WRAPPER" + 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" + if ${WRAPPER} 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 + ;; + esac +fi diff --git a/build-aux/ci_build.sh b/build-aux/ci_build.sh deleted file mode 100755 index d40cd3ce..00000000 --- a/build-aux/ci_build.sh +++ /dev/null @@ -1,289 +0,0 @@ -#!/bin/bash -# SPDX-License-Identifier: 0BSD - -############################################################################# -# -# 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 - -USAGE="Usage: $0 - -a [autogen flags] - -b [autotools|cmake] - -c [crc32|crc64|sha256] - -d [encoders|decoders|bcj|delta|threads|shared|nls|small|clmul|sandbox] - -f [CFLAGS] - -l [destdir] - -m [compiler] - -n [ARTIFACTS_DIR_NAME] - -p [all|build|test] - -s [srcdir]" - -# Absolute path of script directory -ABS_DIR=$(cd -- "$(dirname -- "$0")" && pwd) - -# Default CLI option values -AUTOGEN_FLAGS="" -BUILD_SYSTEM="autotools" -CHECK_TYPE="crc32,crc64,sha256" -BCJ="y" -DELTA="y" -ENCODERS="y" -DECODERS="y" -THREADS="y" -SHARED="y" -NATIVE_LANG_SUPPORT="y" -SMALL="n" -CLMUL="y" -SANDBOX="y" -SRC_DIR="$ABS_DIR/../" -DEST_DIR="$SRC_DIR/../xz_build" -PHASE="all" -ARTIFACTS_DIR_NAME="output" - -[[ -z ${CPU_COUNT} ]] && { CPU_COUNT=$(nproc 2>/dev/null || sysctl -n hw.ncpu); } -[[ -z ${MAKEFLAGS} ]] && export MAKEFLAGS="-j${CPU_COUNT} -l${CPU_COUNT}" -[[ -z ${CFLAGS} ]] && export CFLAGS="-O2" - -################### -# Parse arguments # -################### - -while getopts a:b:c:d:l:m:n:s:p:f:w:h opt; do - # b option can have either value "autotools" OR "cmake" - case ${opt} in - h) - echo "$USAGE" - exit 0 - ;; - a) - AUTOGEN_FLAGS="$OPTARG" - ;; - b) - case "$OPTARG" in - autotools) ;; - cmake) ;; - *) echo "Invalid build system: $OPTARG"; exit 1;; - esac - BUILD_SYSTEM="$OPTARG" - ;; - c) 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" ;; - shared) SHARED="n";; - nls) NATIVE_LANG_SUPPORT="n";; - small) SMALL="y";; - clmul) CLMUL="n";; - sandbox) SANDBOX="n";; - *) echo "Invalid disable value: $disable_arg"; exit 1 ;; - esac - done - ;; - l) DEST_DIR="$OPTARG" - ;; - m) - CC="$OPTARG" - export CC - ;; - n) ARTIFACTS_DIR_NAME="$OPTARG" - ;; - s) SRC_DIR="$OPTARG" - ;; - p) PHASE="$OPTARG" - ;; - f) - CFLAGS+=" $OPTARG" - export CFLAGS - ;; - w) WRAPPER="$OPTARG" - ;; - esac -done - - -#################### -# 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 - mkdir -p "$DEST_DIR" - - # Generate configure option values - EXTRA_OPTIONS="" - - case $BUILD_SYSTEM in - autotools) - cd "$SRC_DIR" - - # Run autogen.sh script if not already run - if [ ! -f configure ] - then - ./autogen.sh "$AUTOGEN_FLAGS" - fi - - cd "$DEST_DIR" - - add_to_filter_list "$BCJ" ",x86,powerpc,ia64,arm,armthumb,arm64,sparc,riscv" - add_to_filter_list "$DELTA" ",delta" - - 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" - add_extra_option "$SMALL" "--enable-small" "" - add_extra_option "$CLMUL" "" "--disable-clmul-crc" - add_extra_option "$SANDBOX" "" "--enable-sandbox=no" - - # Run configure script - "$SRC_DIR"/configure --enable-werror --enable-checks="$CHECK_TYPE" $EXTRA_OPTIONS --config-cache - - # Build the project - make - ;; - cmake) - cd "$DEST_DIR" - - add_to_filter_list "$BCJ" ";x86;powerpc;ia64;arm;armthumb;arm64;sparc;riscv" - add_to_filter_list "$DELTA" ";delta" - - add_extra_option "$THREADS" "-DENABLE_THREADS=ON" "-DENABLE_THREADS=OFF" - - # 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" "" - - add_extra_option "$SMALL" "-DHAVE_SMALL=ON" "" - - if test -n "$CC" ; then - EXTRA_OPTIONS="$EXTRA_OPTIONS -DCMAKE_C_COMPILER=$CC" - fi - - # Remove old cache file to clear previous settings. - rm -f "CMakeCache.txt" - cmake "$SRC_DIR/CMakeLists.txt" -B "$DEST_DIR" $EXTRA_OPTIONS -DADDITIONAL_CHECK_TYPES="$CHECK_TYPE" -G "Unix Makefiles" - cmake --build "$DEST_DIR" - ;; - esac -fi - - -############## -# Test Phase # -############## - -if [ "$PHASE" = "all" ] || [ "$PHASE" = "test" ] -then - case $BUILD_SYSTEM in - autotools) - cd "$DEST_DIR" - # If the tests fail, copy the test logs into the artifacts folder - if make check VERBOSE=1 LOG_COMPILER="$WRAPPER" - 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" - if ${WRAPPER} 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 - ;; - esac -fi -- cgit v1.2.3