Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/ggml/blob/master/scripts/check-apiabi-compat.sh # ggml [Ported from github.com/ggml-org/ggml] docs : sync ggml_type enum in gguf.md (#1685) Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `ggml / scripts / check-apiabi-compat.sh` 292 lines · 8841 bytes Raw Blame History 1 #!/bin/sh 2 # Check for backwards-incompatible API and ABI changes between two builds 3 # 4 # Backwards-incompatible API changes, such as removing a value from an enum, 5 # are checked by abi-compliance-checker. Such changes can break compilation of 6 # existing programs. 7 # 8 # Backwards-incompatible ABI changes, such as the removal of a public function, 9 # are checked by libigail-tools. Such changes could break run-time dynamic 10 # linking of existing binaries. (We don't use a-c-c for ABI checks because it 11 # needs a debug build, whereas abigail does not.) 12 # 13 # Commands: 14 # --generate : Creates API/ABI dumps in 15 # is expected to be a CMake build result 16 # --check : Compares dumps in and 17 # Comparison exit codes 18 # 0: all good 19 # 1: backwards-incompatible changes found 20 # 21 # Options: 22 # --include-path : a-c-c calls gcc on headers; use this option to add 23 # directories to gcc's search path 24 # 25 # 26 # This script would typically be used before cutting a release: 27 # 28 # 1. Generate API/ABI dump for the old version 29 # 30 # $ check-apiabi-compat.sh --generate libfoo [ libbar ...] 31 # 32 # 2. 33 # 34 # 3. Generate API/ABI dump for the new version 35 # 36 # $ check-apiabi-compat.sh --generate libfoo [ libbar ...] 37 # 38 # 4. Compare the two dumps 39 # 40 # $ check-apiabi-compat.sh --check 41 # 42 # If the check exits 0, all is fine. Otherwise, backwards-incompatible 43 # changes were found, and the librar(ies) need a SOVER bump. 44 set -eu 45 46 # Preconditions 47 if ! command -v abi-compliance-checker >/dev/null 2>&1; then 48 echo "abi-compliance-checker is not installed." >&2 49 exit 1 50 elif ! command -v abidw >/dev/null 2>&1; then 51 echo "abigail-tools are not installed." >&2 52 exit 1 53 fi 54 55 # Some generic functions 56 usage() { 57 echo "Usage: $0 [ --include-path ] --generate libXXX [ libYYY ... ]" >&2 58 echo " $0 [ --strict ] --check " >&2 59 echo "" >&2 60 echo " --strict: fail on any API/ABI change, including backwards-compatible additions" >&2 61 } 62 63 get_cmake_project_name() { 64 sed -nr 's/^project\("(.*)".*$/\1/p' CMakeLists.txt 65 } 66 67 get_cmake_version() { 68 major="$(sed -nr 's/^set\([A-Z]+_VERSION_MAJOR ([0-9]+)\)$/\1/p' CMakeLists.txt)" 69 minor="$(sed -nr 's/^set\([A-Z]+_VERSION_MINOR ([0-9]+)\)$/\1/p' CMakeLists.txt)" 70 patch="$(sed -nr 's/^set\([A-Z]+_VERSION_PATCH ([0-9]+)\)$/\1/p' CMakeLists.txt)" 71 echo "$major.$minor.$patch" 72 } 73 74 # Option parsing and validation 75 DO_GEN=0 76 DO_CHECK=0 77 STRICT=0 78 BUILD_DIR= 79 BUILD_DIR_NEW= 80 INCLUDE_PATHS= 81 while [ "$#" -gt 0 ]; do 82 case "$1" in 83 --generate=*) 84 DO_GEN=1 85 BUILD_DIR="${1#*=}" 86 shift 87 ;; 88 --generate) 89 DO_GEN=1 90 if [ -z "${2:-}" ]; then 91 usage 92 exit 1 93 fi 94 BUILD_DIR="$2" 95 shift 2 96 ;; 97 --check) 98 DO_CHECK=1 99 if [ -z "${2:-}" ] || [ -z "${3:-}" ]; then 100 usage 101 exit 1 102 elif ! [ -d "$2" ]; then 103 echo "$2 is not a directory." >&2 104 exit 1 105 elif ! [ -d "$3" ]; then 106 echo "$3 is not a directory." >&2 107 exit 1 108 fi 109 BUILD_DIR="$2" 110 BUILD_DIR_NEW="$3" 111 shift 3 112 ;; 113 --include-path=*) 114 INCLUDE_PATHS="$INCLUDE_PATHS ${1#*=}" 115 shift 116 ;; 117 --include-path) 118 if [ -z "${2:-}" ]; then 119 usage 120 exit 1 121 fi 122 INCLUDE_PATHS="$INCLUDE_PATHS $2" 123 shift 2 124 ;; 125 --strict) 126 STRICT=1 127 shift 128 ;; 129 -h | --help) 130 usage 131 exit 1 132 ;; 133 -?*) 134 usage 135 exit 1 136 ;; 137 *) 138 break 139 ;; 140 esac 141 done 142 if [ $((DO_GEN + DO_CHECK)) -gt 1 ]; then 143 echo "Can only use one --command." >&2 144 exit 145 fi 146 PROJECT_NAME="$(get_cmake_project_name)" 147 PROJECT_VERSION="$(get_cmake_version)" 148 LIB_NAMES="" 149 while [ "$#" -gt 0 ]; do 150 if [ "${1#lib}" = "$1" ]; then 151 echo "Library to check must start with libXXX." >&2 152 exit 1 153 fi 154 LIB_NAMES="$LIB_NAMES $1" 155 shift 156 done 157 158 dump_current_api() { 159 echo "Dumping API..." 160 161 DESCRIPTOR="$BUILD_DIR/apiabi/acc-descriptor.xml" 162 mkdir -p "$BUILD_DIR/apiabi" 163 cat >"$DESCRIPTOR" <$PROJECT_VERSION 165 include 166 $INCLUDE_PATHS 167 EOF 168 169 # This addresses a bug between a-c-c and universal-ctags, manifested when 170 # a name is use both for a tag and a function name 171 mkdir -p "$BUILD_DIR/apiabi/.ctags.d" 172 echo "--fields=-t" >"$BUILD_DIR/apiabi/.ctags.d/acc.ctags" 173 174 # Change HOME so that .ctags.d gets picked up by universal-ctags, if used 175 HOME="$BUILD_DIR/apiabi" abi-compliance-checker \ 176 -headers-only \ 177 -lib "$PROJECT_NAME" \ 178 -dump "$DESCRIPTOR" \ 179 -log-path "$BUILD_DIR/apiabi/acc.log" \ 180 -dump-path "$BUILD_DIR/apiabi/api.dump" 181 # acc generates this file with an ancient timestamp, which confuses gzip 182 touch "$BUILD_DIR/apiabi/api.dump" 183 } 184 185 dump_current_abi() { 186 echo "Dumping ABIs ..." 187 mkdir -p "$BUILD_DIR/apiabi" 188 # The suppressions are needed to avoid including all the internal C++ 189 # symbols, and system types 190 cat >"$BUILD_DIR/apiabi/abidw.suppress" <&2 226 exit 1 227 fi 228 fi 229 abidw \ 230 --headers-dir include \ 231 "$abidw_undefined_syms_options" \ 232 --suppressions "$BUILD_DIR/apiabi/abidw.suppress" \ 233 --out-file "${BUILD_DIR}/apiabi/$lib_name.abi.xml" \ 234 "$lib_path" 235 done 236 } 237 238 # Run the actual commands 239 if [ "$DO_GEN" -eq 1 ]; then 240 dump_current_api 241 dump_current_abi 242 exit 0 243 elif [ "$DO_CHECK" -eq 1 ]; then 244 # From here on, we don't want to exit on first error 245 set +e 246 247 ACC_STRICT= 248 [ "$STRICT" -eq 0 ] || ACC_STRICT="-strict" 249 abi-compliance-checker \ 250 $ACC_STRICT \ 251 -source \ 252 -library "$PROJECT_NAME" \ 253 -old "$BUILD_DIR/apiabi/api.dump" \ 254 -new "$BUILD_DIR_NEW/apiabi/api.dump" \ 255 -src-report-path "$BUILD_DIR_NEW/apiabi/api_compat_report.html" 256 API_RESULT=$? 257 258 ABI_RESULT=0 259 for xml_file in "$BUILD_DIR/apiabi/"lib*.abi.xml; do 260 xml_file_new="$BUILD_DIR_NEW/apiabi/$(basename "$xml_file")" 261 262 if ! [ -f "$xml_file_new" ]; then 263 echo "Cannot compare, missing file: $xml_file_new" >&2 264 exit 1 265 fi 266 267 abidiff "$xml_file" "$xml_file_new" 268 res=$? 269 [ "$((res & 8))" -ne 0 ] && ABI_RESULT=1 270 # check bit 2 for compatible ABI changes (like new symbols) and if 271 # STRICT is set then handle this as an error. 272 [ "$STRICT" -eq 1 ] && [ "$((res & 4))" -ne 0 ] && ABI_RESULT=1 273 done 274 275 if [ "$API_RESULT" -gt 0 ]; then 276 if [ "$STRICT" -eq 1 ]; then 277 echo "ERROR: API changed — a minor version bump is required." >&2 278 else 279 echo "ERROR: API changed with backwards-incompatible problems — a major version bump is required." >&2 280 fi 281 fi 282 if [ "$ABI_RESULT" -gt 0 ]; then 283 if [ "$STRICT" -eq 1 ]; then 284 echo "ERROR: ABI changed — a minor version bump is required." >&2 285 else 286 echo "ERROR: ABI changed with backwards-incompatible problems — a major version bump is required." >&2 287 fi 288 fi 289 if [ "$((API_RESULT + ABI_RESULT))" -gt 0 ]; then 290 exit 1 291 fi 292 fi