xz: Simplify the error-label in Capsicum sandbox code.
[xz.git] / build-aux / ci_build.sh
blob3b462e635fb0aac1f67f509a8751491448763ecf
1 #!/bin/sh
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 -b [autotools|cmake]
21 -c [crc32|crc64|sha256]
22 -d [encoders|decoders|bcj|delta|threads|shared|nls]
23 -f [CFLAGS]
24 -l [destdir]
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 BUILD_SYSTEM="autotools"
34 CHECK_TYPE="crc32,crc64,sha256"
35 BCJ="y"
36 DELTA="y"
37 ENCODERS="y"
38 DECODERS="y"
39 THREADS="y"
40 SHARED="y"
41 NATIVE_LANG_SUPPORT="y"
42 SRC_DIR="$ABS_DIR/../"
43 DEST_DIR="$SRC_DIR/../xz_build"
44 PHASE="all"
45 ARTIFACTS_DIR_NAME="output"
47 # Parse arguments
48 while getopts b:c:d:l:n:s:p:f:h opt; do
49 # b option can have either value "autotools" OR "cmake"
50 case ${opt} in
52 echo "$USAGE"
53 exit 0
56 case "$OPTARG" in
57 autotools) ;;
58 cmake) ;;
59 *) echo "Invalid build system: $OPTARG"; exit 1;;
60 esac
61 BUILD_SYSTEM="$OPTARG"
63 # c options can be a comma separated list of check types to support
65 for crc in $(echo "$OPTARG" | sed "s/,/ /g"); do
66 case "$crc" in
67 crc32) ;;
68 crc64) ;;
69 sha256) ;;
70 *) echo "Invalid check type: $crc"; exit 1 ;;
71 esac
72 done
73 CHECK_TYPE="$OPTARG"
75 # d options can be a comma separated list of things to disable at
76 # configure time
78 for disable_arg in $(echo "$OPTARG" | sed "s/,/ /g"); do
79 case "$disable_arg" in
80 encoders) ENCODERS="n" ;;
81 decoders) DECODERS="n" ;;
82 bcj) BCJ="n" ;;
83 delta) DELTA="n" ;;
84 threads) THREADS="n" ;;
85 shared) SHARED="n";;
86 nls) NATIVE_LANG_SUPPORT="n";;
87 *) echo "Invalid disable value: $disable_arg"; exit 1 ;;
88 esac
89 done
91 l) DEST_DIR="$OPTARG"
93 n) ARTIFACTS_DIR_NAME="$OPTARG"
95 s) SRC_DIR="$OPTARG"
97 p) PHASE="$OPTARG"
99 f)
100 CFLAGS="$OPTARG"
101 export CFLAGS
103 esac
104 done
106 if [ "$PHASE" = "all" ] || [ "$PHASE" = "build" ]; then
107 # Build based on arguments
108 mkdir -p "$DEST_DIR"
109 case $BUILD_SYSTEM in
110 autotools)
111 cd "$SRC_DIR"
113 # Run autogen.sh script if not already run
114 if [ ! -f configure ]
115 then
116 "./autogen.sh"
119 cd "$DEST_DIR"
121 # Generate configure option values
122 EXTRA_OPTIONS=""
123 FILTER_LIST="lzma1,lzma2"
125 if [ "$BCJ" = "y" ]
126 then
127 FILTER_LIST="$FILTER_LIST,x86,powerpc,ia64,arm,armthumb,arm64,sparc"
130 if [ "$DELTA" = "y" ]
131 then
132 FILTER_LIST="$FILTER_LIST,delta"
135 if [ "$ENCODERS" = "y" ]
136 then
137 EXTRA_OPTIONS="$EXTRA_OPTIONS --enable-encoders=$FILTER_LIST"
138 else
139 EXTRA_OPTIONS="$EXTRA_OPTIONS --disable-encoders"
142 if [ "$DECODERS" = "y" ]
143 then
144 EXTRA_OPTIONS="$EXTRA_OPTIONS --enable-decoders=$FILTER_LIST"
145 else
146 EXTRA_OPTIONS="$EXTRA_OPTIONS --disable-decoders"
149 if [ "$THREADS" = "n" ]
150 then
151 EXTRA_OPTIONS="$EXTRA_OPTIONS --disable-threads"
154 if [ "$SHARED" = "n" ]
155 then
156 EXTRA_OPTIONS="$EXTRA_OPTIONS --disable-shared"
159 if [ "$NATIVE_LANG_SUPPORT" = "n" ]
160 then
161 EXTRA_OPTIONS="$EXTRA_OPTIONS --disable-nls"
164 # Run configure script
165 "$SRC_DIR"/configure --enable-werror --enable-checks="$CHECK_TYPE" $EXTRA_OPTIONS --config-cache
167 # Build the project
168 make
170 cmake)
171 # CMake currently does not support disabling encoders, decoders,
172 # threading, or check types. For now, just run the full build.
173 cd "$DEST_DIR"
174 cmake "$SRC_DIR/CMakeLists.txt" -B "$DEST_DIR"
175 make
177 esac
180 if [ "$PHASE" = "all" ] || [ "$PHASE" = "test" ]; then
181 case $BUILD_SYSTEM in
182 autotools)
183 cd "$DEST_DIR"
184 # If the tests fail, copy the test logs into the artifacts folder
185 if make check
186 then
188 else
189 mkdir -p "$SRC_DIR/build-aux/artifacts/$ARTIFACTS_DIR_NAME"
190 cp ./tests/*.log "$SRC_DIR/build-aux/artifacts/$ARTIFACTS_DIR_NAME"
191 exit 1
194 cmake)
195 cd "$DEST_DIR"
196 if make test
197 then
199 else
200 mkdir -p "$SRC_DIR/build-aux/artifacts/$ARTIFACTS_DIR_NAME"
201 cp ./Testing/Temporary/*.log "$SRC_DIR/build-aux/artifacts/$ARTIFACTS_DIR_NAME"
202 exit 1
205 esac