liblzma: Rename crc32_aarch64.h to crc32_arm64.h.
[xz.git] / build-aux / ci_build.sh
blobab056818ca87a5649ad09798b9899009c06c70ec
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 -m [compiler]
27 -n [ARTIFACTS_DIR_NAME]
28 -p [all|build|test]
29 -s [srcdir]"
31 # Absolute path of script directory
32 ABS_DIR=$(cd -- "$(dirname -- "$0")" && pwd)
34 # Default CLI option values
35 AUTOGEN_FLAGS=""
36 BUILD_SYSTEM="autotools"
37 CHECK_TYPE="crc32,crc64,sha256"
38 BCJ="y"
39 DELTA="y"
40 ENCODERS="y"
41 DECODERS="y"
42 THREADS="y"
43 SHARED="y"
44 NATIVE_LANG_SUPPORT="y"
45 SMALL="n"
46 IFUNC="y"
47 CLMUL="y"
48 SANDBOX="y"
49 SRC_DIR="$ABS_DIR/../"
50 DEST_DIR="$SRC_DIR/../xz_build"
51 PHASE="all"
52 ARTIFACTS_DIR_NAME="output"
55 ###################
56 # Parse arguments #
57 ###################
59 while getopts a:b:c:d:l:m:n:s:p:f:h opt; do
60 # b option can have either value "autotools" OR "cmake"
61 case ${opt} in
63 echo "$USAGE"
64 exit 0
67 AUTOGEN_FLAGS="$OPTARG"
70 case "$OPTARG" in
71 autotools) ;;
72 cmake) ;;
73 *) echo "Invalid build system: $OPTARG"; exit 1;;
74 esac
75 BUILD_SYSTEM="$OPTARG"
77 c) CHECK_TYPE="$OPTARG"
79 # d options can be a comma separated list of things to disable at
80 # configure time
82 for disable_arg in $(echo "$OPTARG" | sed "s/,/ /g"); do
83 case "$disable_arg" in
84 encoders) ENCODERS="n" ;;
85 decoders) DECODERS="n" ;;
86 bcj) BCJ="n" ;;
87 delta) DELTA="n" ;;
88 threads) THREADS="n" ;;
89 shared) SHARED="n";;
90 nls) NATIVE_LANG_SUPPORT="n";;
91 small) SMALL="y";;
92 ifunc) IFUNC="n";;
93 clmul) CLMUL="n";;
94 sandbox) SANDBOX="n";;
95 *) echo "Invalid disable value: $disable_arg"; exit 1 ;;
96 esac
97 done
99 l) DEST_DIR="$OPTARG"
102 CC="$OPTARG"
103 export CC
105 n) ARTIFACTS_DIR_NAME="$OPTARG"
107 s) SRC_DIR="$OPTARG"
109 p) PHASE="$OPTARG"
112 CFLAGS="$OPTARG"
113 export CFLAGS
115 esac
116 done
119 ####################
120 # Helper Functions #
121 ####################
123 # These two functions essentially implement the ternary "?" operator.
124 add_extra_option() {
125 # First argument is option value ("y" or "n")
126 # Second argument is option to set if "y"
127 # Third argument is option to set if "n"
128 if [ "$1" = "y" ]
129 then
130 EXTRA_OPTIONS="$EXTRA_OPTIONS $2"
131 else
132 EXTRA_OPTIONS="$EXTRA_OPTIONS $3"
137 add_to_filter_list() {
138 # First argument is option value ("y" or "n")
139 # Second argument is option to set if "y"
140 if [ "$1" = "y" ]
141 then
142 FILTER_LIST="$FILTER_LIST$2"
147 ###############
148 # Build Phase #
149 ###############
151 if [ "$PHASE" = "all" ] || [ "$PHASE" = "build" ]
152 then
153 # Checksum options should be specified differently based on the
154 # build system. It must be calculated here since we won't know
155 # the build system used until all args have been parsed.
156 # Autotools - comma separated
157 # CMake - semi-colon separated
158 if [ "$BUILD_SYSTEM" = "autotools" ]
159 then
160 SEP=","
161 else
162 SEP=";"
165 CHECK_TYPE_TEMP=""
166 for crc in $(echo "$CHECK_TYPE" | sed "s/,/ /g"); do
167 case "$crc" in
168 # Remove "crc32" from cmake build, if specified.
169 crc32)
170 if [ "$BUILD_SYSTEM" = "cmake" ]
171 then
172 continue
175 crc64) ;;
176 sha256) ;;
177 *) echo "Invalid check type: $crc"; exit 1 ;;
178 esac
180 CHECK_TYPE_TEMP="$CHECK_TYPE_TEMP$SEP$crc"
181 done
183 # Remove the first character from $CHECK_TYPE_TEMP since it will
184 # always be the delimiter.
185 CHECK_TYPE="${CHECK_TYPE_TEMP:1}"
187 FILTER_LIST="lzma1$SEP"lzma2
189 # Build based on arguments
190 mkdir -p "$DEST_DIR"
192 # Generate configure option values
193 EXTRA_OPTIONS=""
195 case $BUILD_SYSTEM in
196 autotools)
197 cd "$SRC_DIR"
199 # Run autogen.sh script if not already run
200 if [ ! -f configure ]
201 then
202 ./autogen.sh "$AUTOGEN_FLAGS"
205 cd "$DEST_DIR"
207 add_to_filter_list "$BCJ" ",x86,powerpc,ia64,arm,armthumb,arm64,sparc,riscv"
208 add_to_filter_list "$DELTA" ",delta"
210 add_extra_option "$ENCODERS" "--enable-encoders=$FILTER_LIST" "--disable-encoders"
211 add_extra_option "$DECODERS" "--enable-decoders=$FILTER_LIST" "--disable-decoders"
212 add_extra_option "$THREADS" "" "--disable-threads"
213 add_extra_option "$SHARED" "" "--disable-shared"
214 add_extra_option "$NATIVE_LANG_SUPPORT" "" "--disable-nls"
215 add_extra_option "$SMALL" "--enable-small" ""
216 add_extra_option "$IFUNC" "" "--disable-ifunc"
217 add_extra_option "$CLMUL" "" "--disable-clmul-crc"
218 add_extra_option "$SANDBOX" "" "--enable-sandbox=no"
220 # Run configure script
221 "$SRC_DIR"/configure --enable-werror --enable-checks="$CHECK_TYPE" $EXTRA_OPTIONS --config-cache
223 # Build the project
224 make
226 cmake)
227 cd "$DEST_DIR"
229 add_to_filter_list "$BCJ" ";x86;powerpc;ia64;arm;armthumb;arm64;sparc;riscv"
230 add_to_filter_list "$DELTA" ";delta"
232 add_extra_option "$THREADS" "-DENABLE_THREADS=ON" "-DENABLE_THREADS=OFF"
234 # Disable MicroLZMA if encoders are not configured.
235 add_extra_option "$ENCODERS" "-DENCODERS=$FILTER_LIST" "-DENCODERS= -DMICROLZMA_ENCODER=OFF"
237 # Disable MicroLZMA and lzip decoders if decoders are not configured.
238 add_extra_option "$DECODERS" "-DDECODERS=$FILTER_LIST" "-DDECODERS= -DMICROLZMA_DECODER=OFF -DLZIP_DECODER=OFF"
240 # CMake disables the shared library by default.
241 add_extra_option "$SHARED" "-DBUILD_SHARED_LIBS=ON" ""
243 add_extra_option "$SMALL" "-DHAVE_SMALL=ON" ""
245 if test -n "$CC" ; then
246 EXTRA_OPTIONS="$EXTRA_OPTIONS -DCMAKE_C_COMPILER=$CC"
249 # Remove old cache file to clear previous settings.
250 rm -f "CMakeCache.txt"
251 cmake "$SRC_DIR/CMakeLists.txt" -B "$DEST_DIR" $EXTRA_OPTIONS -DADDITIONAL_CHECK_TYPES="$CHECK_TYPE" -G "Unix Makefiles"
252 cmake --build "$DEST_DIR"
254 esac
258 ##############
259 # Test Phase #
260 ##############
262 if [ "$PHASE" = "all" ] || [ "$PHASE" = "test" ]
263 then
264 case $BUILD_SYSTEM in
265 autotools)
266 cd "$DEST_DIR"
267 # If the tests fail, copy the test logs into the artifacts folder
268 if make check
269 then
271 else
272 mkdir -p "$SRC_DIR/build-aux/artifacts/$ARTIFACTS_DIR_NAME"
273 cp ./tests/*.log "$SRC_DIR/build-aux/artifacts/$ARTIFACTS_DIR_NAME"
274 exit 1
277 cmake)
278 cd "$DEST_DIR"
279 if make test
280 then
282 else
283 mkdir -p "$SRC_DIR/build-aux/artifacts/$ARTIFACTS_DIR_NAME"
284 cp ./Testing/Temporary/*.log "$SRC_DIR/build-aux/artifacts/$ARTIFACTS_DIR_NAME"
285 exit 1
288 esac