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