Bump version and soname for 5.6.0.
[xz.git] / build-aux / ci_build.sh
blob73fcca3061fb94737235f3f826334f4646ea5eda
1 #!/bin/bash
2 # SPDX-License-Identifier: 0BSD
4 #############################################################################
6 # Script meant to be used for Continuous Integration automation for POSIX
7 # systems. On GitHub, this is used by Ubuntu and MacOS builds.
9 #############################################################################
11 # Author: Jia Tan
13 #############################################################################
15 set -e
17 USAGE="Usage: $0
18 -a [autogen flags]
19 -b [autotools|cmake]
20 -c [crc32|crc64|sha256]
21 -d [encoders|decoders|bcj|delta|threads|shared|nls|small|ifunc|clmul|sandbox]
22 -f [CFLAGS]
23 -l [destdir]
24 -m [compiler]
25 -n [ARTIFACTS_DIR_NAME]
26 -p [all|build|test]
27 -s [srcdir]"
29 # Absolute path of script directory
30 ABS_DIR=$(cd -- "$(dirname -- "$0")" && pwd)
32 # Default CLI option values
33 AUTOGEN_FLAGS=""
34 BUILD_SYSTEM="autotools"
35 CHECK_TYPE="crc32,crc64,sha256"
36 BCJ="y"
37 DELTA="y"
38 ENCODERS="y"
39 DECODERS="y"
40 THREADS="y"
41 SHARED="y"
42 NATIVE_LANG_SUPPORT="y"
43 SMALL="n"
44 IFUNC="y"
45 CLMUL="y"
46 SANDBOX="y"
47 SRC_DIR="$ABS_DIR/../"
48 DEST_DIR="$SRC_DIR/../xz_build"
49 PHASE="all"
50 ARTIFACTS_DIR_NAME="output"
53 ###################
54 # Parse arguments #
55 ###################
57 while getopts a:b:c:d:l:m:n:s:p:f:h opt; do
58 # b option can have either value "autotools" OR "cmake"
59 case ${opt} in
61 echo "$USAGE"
62 exit 0
65 AUTOGEN_FLAGS="$OPTARG"
68 case "$OPTARG" in
69 autotools) ;;
70 cmake) ;;
71 *) echo "Invalid build system: $OPTARG"; exit 1;;
72 esac
73 BUILD_SYSTEM="$OPTARG"
75 c) CHECK_TYPE="$OPTARG"
77 # d options can be a comma separated list of things to disable at
78 # configure time
80 for disable_arg in $(echo "$OPTARG" | sed "s/,/ /g"); do
81 case "$disable_arg" in
82 encoders) ENCODERS="n" ;;
83 decoders) DECODERS="n" ;;
84 bcj) BCJ="n" ;;
85 delta) DELTA="n" ;;
86 threads) THREADS="n" ;;
87 shared) SHARED="n";;
88 nls) NATIVE_LANG_SUPPORT="n";;
89 small) SMALL="y";;
90 ifunc) IFUNC="n";;
91 clmul) CLMUL="n";;
92 sandbox) SANDBOX="n";;
93 *) echo "Invalid disable value: $disable_arg"; exit 1 ;;
94 esac
95 done
97 l) DEST_DIR="$OPTARG"
100 CC="$OPTARG"
101 export CC
103 n) ARTIFACTS_DIR_NAME="$OPTARG"
105 s) SRC_DIR="$OPTARG"
107 p) PHASE="$OPTARG"
110 CFLAGS="$OPTARG"
111 export CFLAGS
113 esac
114 done
117 ####################
118 # Helper Functions #
119 ####################
121 # These two functions essentially implement the ternary "?" operator.
122 add_extra_option() {
123 # First argument is option value ("y" or "n")
124 # Second argument is option to set if "y"
125 # Third argument is option to set if "n"
126 if [ "$1" = "y" ]
127 then
128 EXTRA_OPTIONS="$EXTRA_OPTIONS $2"
129 else
130 EXTRA_OPTIONS="$EXTRA_OPTIONS $3"
135 add_to_filter_list() {
136 # First argument is option value ("y" or "n")
137 # Second argument is option to set if "y"
138 if [ "$1" = "y" ]
139 then
140 FILTER_LIST="$FILTER_LIST$2"
145 ###############
146 # Build Phase #
147 ###############
149 if [ "$PHASE" = "all" ] || [ "$PHASE" = "build" ]
150 then
151 # Checksum options should be specified differently based on the
152 # build system. It must be calculated here since we won't know
153 # the build system used until all args have been parsed.
154 # Autotools - comma separated
155 # CMake - semi-colon separated
156 if [ "$BUILD_SYSTEM" = "autotools" ]
157 then
158 SEP=","
159 else
160 SEP=";"
163 CHECK_TYPE_TEMP=""
164 for crc in $(echo "$CHECK_TYPE" | sed "s/,/ /g"); do
165 case "$crc" in
166 # Remove "crc32" from cmake build, if specified.
167 crc32)
168 if [ "$BUILD_SYSTEM" = "cmake" ]
169 then
170 continue
173 crc64) ;;
174 sha256) ;;
175 *) echo "Invalid check type: $crc"; exit 1 ;;
176 esac
178 CHECK_TYPE_TEMP="$CHECK_TYPE_TEMP$SEP$crc"
179 done
181 # Remove the first character from $CHECK_TYPE_TEMP since it will
182 # always be the delimiter.
183 CHECK_TYPE="${CHECK_TYPE_TEMP:1}"
185 FILTER_LIST="lzma1$SEP"lzma2
187 # Build based on arguments
188 mkdir -p "$DEST_DIR"
190 # Generate configure option values
191 EXTRA_OPTIONS=""
193 case $BUILD_SYSTEM in
194 autotools)
195 cd "$SRC_DIR"
197 # Run autogen.sh script if not already run
198 if [ ! -f configure ]
199 then
200 ./autogen.sh "$AUTOGEN_FLAGS"
203 cd "$DEST_DIR"
205 add_to_filter_list "$BCJ" ",x86,powerpc,ia64,arm,armthumb,arm64,sparc,riscv"
206 add_to_filter_list "$DELTA" ",delta"
208 add_extra_option "$ENCODERS" "--enable-encoders=$FILTER_LIST" "--disable-encoders"
209 add_extra_option "$DECODERS" "--enable-decoders=$FILTER_LIST" "--disable-decoders"
210 add_extra_option "$THREADS" "" "--disable-threads"
211 add_extra_option "$SHARED" "" "--disable-shared"
212 add_extra_option "$NATIVE_LANG_SUPPORT" "" "--disable-nls"
213 add_extra_option "$SMALL" "--enable-small" ""
214 add_extra_option "$IFUNC" "" "--disable-ifunc"
215 add_extra_option "$CLMUL" "" "--disable-clmul-crc"
216 add_extra_option "$SANDBOX" "" "--enable-sandbox=no"
218 # Run configure script
219 "$SRC_DIR"/configure --enable-werror --enable-checks="$CHECK_TYPE" $EXTRA_OPTIONS --config-cache
221 # Build the project
222 make
224 cmake)
225 cd "$DEST_DIR"
227 add_to_filter_list "$BCJ" ";x86;powerpc;ia64;arm;armthumb;arm64;sparc;riscv"
228 add_to_filter_list "$DELTA" ";delta"
230 add_extra_option "$THREADS" "-DENABLE_THREADS=ON" "-DENABLE_THREADS=OFF"
232 # Disable MicroLZMA if encoders are not configured.
233 add_extra_option "$ENCODERS" "-DENCODERS=$FILTER_LIST" "-DENCODERS= -DMICROLZMA_ENCODER=OFF"
235 # Disable MicroLZMA and lzip decoders if decoders are not configured.
236 add_extra_option "$DECODERS" "-DDECODERS=$FILTER_LIST" "-DDECODERS= -DMICROLZMA_DECODER=OFF -DLZIP_DECODER=OFF"
238 # CMake disables the shared library by default.
239 add_extra_option "$SHARED" "-DBUILD_SHARED_LIBS=ON" ""
241 add_extra_option "$SMALL" "-DHAVE_SMALL=ON" ""
243 if test -n "$CC" ; then
244 EXTRA_OPTIONS="$EXTRA_OPTIONS -DCMAKE_C_COMPILER=$CC"
247 # Remove old cache file to clear previous settings.
248 rm -f "CMakeCache.txt"
249 cmake "$SRC_DIR/CMakeLists.txt" -B "$DEST_DIR" $EXTRA_OPTIONS -DADDITIONAL_CHECK_TYPES="$CHECK_TYPE" -G "Unix Makefiles"
250 cmake --build "$DEST_DIR"
252 esac
256 ##############
257 # Test Phase #
258 ##############
260 if [ "$PHASE" = "all" ] || [ "$PHASE" = "test" ]
261 then
262 case $BUILD_SYSTEM in
263 autotools)
264 cd "$DEST_DIR"
265 # If the tests fail, copy the test logs into the artifacts folder
266 if make check
267 then
269 else
270 mkdir -p "$SRC_DIR/build-aux/artifacts/$ARTIFACTS_DIR_NAME"
271 cp ./tests/*.log "$SRC_DIR/build-aux/artifacts/$ARTIFACTS_DIR_NAME"
272 exit 1
275 cmake)
276 cd "$DEST_DIR"
277 if make test
278 then
280 else
281 mkdir -p "$SRC_DIR/build-aux/artifacts/$ARTIFACTS_DIR_NAME"
282 cp ./Testing/Temporary/*.log "$SRC_DIR/build-aux/artifacts/$ARTIFACTS_DIR_NAME"
283 exit 1
286 esac