Add NEWS for 5.4.5.
[xz.git] / build-aux / ci_build.sh
blob41cc2bc53b6d01111e3194e8347de19472e719e7
1 #!/bin/bash
3 #############################################################################
5 # Script meant to be used for Continuous Integration automation for POSIX
6 # systems. On GitHub, this is used by Ubuntu and MacOS builds.
8 #############################################################################
10 # Author: Jia Tan
12 # This file has been put into the public domain.
13 # You can do whatever you want with this file.
15 #############################################################################
17 set -e
19 USAGE="Usage: $0
20 -a [autogen flags]
21 -b [autotools|cmake]
22 -c [crc32|crc64|sha256]
23 -d [encoders|decoders|bcj|delta|threads|shared|nls|small|ifunc|clmul|sandbox]
24 -f [CFLAGS]
25 -l [destdir]
26 -n [ARTIFACTS_DIR_NAME]
27 -p [all|build|test]
28 -s [srcdir]"
30 # Absolute path of script directory
31 ABS_DIR=$(cd -- "$(dirname -- "$0")" && pwd)
33 # Default CLI option values
34 AUTOGEN_FLAGS=""
35 BUILD_SYSTEM="autotools"
36 CHECK_TYPE="crc32,crc64,sha256"
37 BCJ="y"
38 DELTA="y"
39 ENCODERS="y"
40 DECODERS="y"
41 THREADS="y"
42 SHARED="y"
43 NATIVE_LANG_SUPPORT="y"
44 SMALL="n"
45 IFUNC="y"
46 CLMUL="y"
47 SANDBOX="y"
48 SRC_DIR="$ABS_DIR/../"
49 DEST_DIR="$SRC_DIR/../xz_build"
50 PHASE="all"
51 ARTIFACTS_DIR_NAME="output"
54 ###################
55 # Parse arguments #
56 ###################
58 while getopts a:b:c:d:l:n:s:p:f:h opt; do
59 # b option can have either value "autotools" OR "cmake"
60 case ${opt} in
62 echo "$USAGE"
63 exit 0
66 AUTOGEN_FLAGS="$OPTARG"
69 case "$OPTARG" in
70 autotools) ;;
71 cmake) ;;
72 *) echo "Invalid build system: $OPTARG"; exit 1;;
73 esac
74 BUILD_SYSTEM="$OPTARG"
76 c) CHECK_TYPE="$OPTARG"
78 # d options can be a comma separated list of things to disable at
79 # configure time
81 for disable_arg in $(echo "$OPTARG" | sed "s/,/ /g"); do
82 case "$disable_arg" in
83 encoders) ENCODERS="n" ;;
84 decoders) DECODERS="n" ;;
85 bcj) BCJ="n" ;;
86 delta) DELTA="n" ;;
87 threads) THREADS="n" ;;
88 shared) SHARED="n";;
89 nls) NATIVE_LANG_SUPPORT="n";;
90 small) SMALL="y";;
91 ifunc) IFUNC="n";;
92 clmul) CLMUL="n";;
93 sandbox) SANDBOX="n";;
94 *) echo "Invalid disable value: $disable_arg"; exit 1 ;;
95 esac
96 done
98 l) DEST_DIR="$OPTARG"
100 n) ARTIFACTS_DIR_NAME="$OPTARG"
102 s) SRC_DIR="$OPTARG"
104 p) PHASE="$OPTARG"
107 CFLAGS="$OPTARG"
108 export CFLAGS
110 esac
111 done
114 ####################
115 # Helper Functions #
116 ####################
118 # These two functions essentially implement the ternary "?" operator.
119 add_extra_option() {
120 # First argument is option value ("y" or "n")
121 # Second argument is option to set if "y"
122 # Third argument is option to set if "n"
123 if [ "$1" = "y" ]
124 then
125 EXTRA_OPTIONS="$EXTRA_OPTIONS $2"
126 else
127 EXTRA_OPTIONS="$EXTRA_OPTIONS $3"
132 add_to_filter_list() {
133 # First argument is option value ("y" or "n")
134 # Second argument is option to set if "y"
135 if [ "$1" = "y" ]
136 then
137 FILTER_LIST="$FILTER_LIST$2"
142 ###############
143 # Build Phase #
144 ###############
146 if [ "$PHASE" = "all" ] || [ "$PHASE" = "build" ]
147 then
148 # Checksum options should be specified differently based on the
149 # build system. It must be calculated here since we won't know
150 # the build system used until all args have been parsed.
151 # Autotools - comma separated
152 # CMake - semi-colon separated
153 if [ "$BUILD_SYSTEM" = "autotools" ]
154 then
155 SEP=","
156 else
157 SEP=";"
160 CHECK_TYPE_TEMP=""
161 for crc in $(echo "$CHECK_TYPE" | sed "s/,/ /g"); do
162 case "$crc" in
163 # Remove "crc32" from cmake build, if specified.
164 crc32)
165 if [ "$BUILD_SYSTEM" = "cmake" ]
166 then
167 continue
170 crc64) ;;
171 sha256) ;;
172 *) echo "Invalid check type: $crc"; exit 1 ;;
173 esac
175 CHECK_TYPE_TEMP="$CHECK_TYPE_TEMP$SEP$crc"
176 done
178 # Remove the first character from $CHECK_TYPE_TEMP since it will
179 # always be the delimiter.
180 CHECK_TYPE="${CHECK_TYPE_TEMP:1}"
182 FILTER_LIST="lzma1$SEP"lzma2
184 # Build based on arguments
185 mkdir -p "$DEST_DIR"
187 # Generate configure option values
188 EXTRA_OPTIONS=""
190 case $BUILD_SYSTEM in
191 autotools)
192 cd "$SRC_DIR"
194 # Run autogen.sh script if not already run
195 if [ ! -f configure ]
196 then
197 ./autogen.sh "$AUTOGEN_FLAGS"
200 cd "$DEST_DIR"
202 add_to_filter_list "$BCJ" ",x86,powerpc,ia64,arm,armthumb,arm64,sparc"
203 add_to_filter_list "$DELTA" ",delta"
205 add_extra_option "$ENCODERS" "--enable-encoders=$FILTER_LIST" "--disable-encoders"
206 add_extra_option "$DECODERS" "--enable-decoders=$FILTER_LIST" "--disable-decoders"
207 add_extra_option "$THREADS" "" "--disable-threads"
208 add_extra_option "$SHARED" "" "--disable-shared"
209 add_extra_option "$NATIVE_LANG_SUPPORT" "" "--disable-nls"
210 add_extra_option "$SMALL" "--enable-small" ""
211 add_extra_option "$IFUNC" "" "--disable-ifunc"
212 add_extra_option "$CLMUL" "" "--disable-clmul-crc"
213 add_extra_option "$SANDBOX" "" "--enable-sandbox=no"
215 # Run configure script
216 "$SRC_DIR"/configure --enable-werror --enable-checks="$CHECK_TYPE" $EXTRA_OPTIONS --config-cache
218 # Build the project
219 make
221 cmake)
222 cd "$DEST_DIR"
224 add_to_filter_list "$BCJ" ";x86;powerpc;ia64;arm;armthumb;arm64;sparc"
225 add_to_filter_list "$DELTA" ";delta"
227 add_extra_option "$THREADS" "-DENABLE_THREADS=ON" "-DENABLE_THREADS=OFF"
229 # Disable MicroLZMA if encoders are not configured.
230 add_extra_option "$ENCODERS" "-DENCODERS=$FILTER_LIST" "-DENCODERS= -DMICROLZMA_ENCODER=OFF"
232 # Disable MicroLZMA and lzip decoders if decoders are not configured.
233 add_extra_option "$DECODERS" "-DDECODERS=$FILTER_LIST" "-DDECODERS= -DMICROLZMA_DECODER=OFF -DLZIP_DECODER=OFF"
235 # CMake disables the shared library by default.
236 add_extra_option "$SHARED" "-DBUILD_SHARED_LIBS=ON" ""
238 add_extra_option "$SMALL" "-DHAVE_SMALL=ON" ""
240 # Remove old cache file to clear previous settings.
241 rm -f "CMakeCache.txt"
242 cmake "$SRC_DIR/CMakeLists.txt" -B "$DEST_DIR" $EXTRA_OPTIONS -DADDITIONAL_CHECK_TYPES="$CHECK_TYPE" -G "Unix Makefiles"
243 cmake --build "$DEST_DIR"
245 esac
249 ##############
250 # Test Phase #
251 ##############
253 if [ "$PHASE" = "all" ] || [ "$PHASE" = "test" ]
254 then
255 case $BUILD_SYSTEM in
256 autotools)
257 cd "$DEST_DIR"
258 # If the tests fail, copy the test logs into the artifacts folder
259 if make check
260 then
262 else
263 mkdir -p "$SRC_DIR/build-aux/artifacts/$ARTIFACTS_DIR_NAME"
264 cp ./tests/*.log "$SRC_DIR/build-aux/artifacts/$ARTIFACTS_DIR_NAME"
265 exit 1
268 cmake)
269 cd "$DEST_DIR"
270 if make test
271 then
273 else
274 mkdir -p "$SRC_DIR/build-aux/artifacts/$ARTIFACTS_DIR_NAME"
275 cp ./Testing/Temporary/*.log "$SRC_DIR/build-aux/artifacts/$ARTIFACTS_DIR_NAME"
276 exit 1
279 esac