|
| 1 | +#!/usr/bin/env bash |
| 2 | +# Verify download_libs actually deployed binaries/headers, and that static |
| 3 | +# archives are GNU ar (the msys2 "unknown file type" / "treating as linker |
| 4 | +# script" failure mode). |
| 5 | +set -euo pipefail |
| 6 | + |
| 7 | +ROOT="$(cd "$(dirname "$0")/../.." && pwd)" |
| 8 | +cd "$ROOT" |
| 9 | + |
| 10 | +PLATFORM="" |
| 11 | +ARCH="" |
| 12 | +ALLOW_INCOMPLETE=0 |
| 13 | + |
| 14 | +usage() { |
| 15 | + cat <<EOF |
| 16 | +Usage: $0 --platform linux|msys2 --arch <arch> [--allow-incomplete] |
| 17 | +
|
| 18 | + linux arch: 64, arm64, aarch64, armv6l, armv7l |
| 19 | + msys2 arch: x86_64 (used as lib/msys2/x86_64 nested fallback) |
| 20 | +EOF |
| 21 | +} |
| 22 | + |
| 23 | +while [[ $# -gt 0 ]]; do |
| 24 | + case "$1" in |
| 25 | + --platform) |
| 26 | + PLATFORM="$2" |
| 27 | + shift 2 |
| 28 | + ;; |
| 29 | + --arch) |
| 30 | + ARCH="$2" |
| 31 | + shift 2 |
| 32 | + ;; |
| 33 | + --allow-incomplete) |
| 34 | + ALLOW_INCOMPLETE=1 |
| 35 | + shift |
| 36 | + ;; |
| 37 | + -h | --help) |
| 38 | + usage |
| 39 | + exit 0 |
| 40 | + ;; |
| 41 | + *) |
| 42 | + echo "Unknown argument: $1" |
| 43 | + usage |
| 44 | + exit 1 |
| 45 | + ;; |
| 46 | + esac |
| 47 | +done |
| 48 | + |
| 49 | +if [[ -z "$PLATFORM" || -z "$ARCH" ]]; then |
| 50 | + usage |
| 51 | + exit 1 |
| 52 | +fi |
| 53 | + |
| 54 | +pass=0 |
| 55 | +fail=0 |
| 56 | +warn=0 |
| 57 | + |
| 58 | +ok() { |
| 59 | + pass=$((pass + 1)) |
| 60 | + echo " OK $*" |
| 61 | +} |
| 62 | + |
| 63 | +bad() { |
| 64 | + fail=$((fail + 1)) |
| 65 | + echo " FAIL $*" |
| 66 | +} |
| 67 | + |
| 68 | +note() { |
| 69 | + warn=$((warn + 1)) |
| 70 | + echo " WARN $*" |
| 71 | +} |
| 72 | + |
| 73 | +is_gnu_ar() { |
| 74 | + local f="$1" |
| 75 | + if command -v python3 >/dev/null 2>&1; then |
| 76 | + python3 -c "import sys; sys.exit(0 if open(sys.argv[1],'rb').read(8)==b'!<arch>\n' else 1)" "$f" |
| 77 | + elif command -v python >/dev/null 2>&1; then |
| 78 | + python -c "import sys; sys.exit(0 if open(sys.argv[1],'rb').read(8)==b'!<arch>\n' else 1)" "$f" |
| 79 | + else |
| 80 | + # bash / dd fallback: first 7 bytes must be !<arch> |
| 81 | + local magic |
| 82 | + magic=$(dd if="$f" bs=7 count=1 2>/dev/null || true) |
| 83 | + [[ "$magic" == '!<arch>' ]] |
| 84 | + fi |
| 85 | +} |
| 86 | + |
| 87 | +archive_lists_objects() { |
| 88 | + local f="$1" |
| 89 | + local listing |
| 90 | + if ! command -v ar >/dev/null 2>&1; then |
| 91 | + return 0 |
| 92 | + fi |
| 93 | + listing=$(ar t "$f" 2>/dev/null || true) |
| 94 | + if [[ -z "$listing" ]]; then |
| 95 | + return 1 |
| 96 | + fi |
| 97 | + # GNU ar prints foo.o / foo.obj. BSD ar on GNU archives may print /0. |
| 98 | + # Ignore symbol-table members named / or //. |
| 99 | + echo "$listing" | grep -v -E '^/{1,2}$' | grep -q . |
| 100 | +} |
| 101 | + |
| 102 | +list_lib_trees() { |
| 103 | + local pattern="$1" |
| 104 | + local roots=() |
| 105 | + [[ -d libs ]] && roots+=(libs) |
| 106 | + [[ -d addons ]] && roots+=(addons) |
| 107 | + if [[ ${#roots[@]} -eq 0 ]]; then |
| 108 | + return 1 |
| 109 | + fi |
| 110 | + find "${roots[@]}" -type d -path "$pattern" 2>/dev/null | sort |
| 111 | +} |
| 112 | + |
| 113 | +echo "== deployed libraries platform=${PLATFORM} arch=${ARCH} ==" |
| 114 | + |
| 115 | +if [[ "$PLATFORM" == "linux" ]]; then |
| 116 | + SUBPATH="linux/${ARCH}" |
| 117 | + echo "--- trees under lib/${SUBPATH} ---" |
| 118 | + if list_lib_trees "*/lib/${SUBPATH}" | grep -q .; then |
| 119 | + list_lib_trees "*/lib/${SUBPATH}" |
| 120 | + ok "found lib/${SUBPATH} folders" |
| 121 | + else |
| 122 | + bad "no lib/${SUBPATH} folders under libs/ or addons/" |
| 123 | + fi |
| 124 | + |
| 125 | + require_header() { |
| 126 | + local p="$1" |
| 127 | + if [[ -f "$p" ]]; then |
| 128 | + ok "header $p" |
| 129 | + else |
| 130 | + if [[ "$ALLOW_INCOMPLETE" -eq 1 ]]; then |
| 131 | + note "header missing $p (incomplete archive allowed)" |
| 132 | + else |
| 133 | + bad "header missing $p" |
| 134 | + fi |
| 135 | + fi |
| 136 | + } |
| 137 | + |
| 138 | + require_archive() { |
| 139 | + local p="$1" |
| 140 | + if [[ ! -f "$p" ]]; then |
| 141 | + if [[ "$ALLOW_INCOMPLETE" -eq 1 ]]; then |
| 142 | + note "archive missing $p (incomplete archive allowed)" |
| 143 | + else |
| 144 | + bad "archive missing $p" |
| 145 | + fi |
| 146 | + return |
| 147 | + fi |
| 148 | + if [[ ! -s "$p" ]]; then |
| 149 | + bad "archive empty $p" |
| 150 | + return |
| 151 | + fi |
| 152 | + if is_gnu_ar "$p"; then |
| 153 | + ok "gnu ar magic $p ($(wc -c <"$p") bytes)" |
| 154 | + else |
| 155 | + bad "not a GNU ar archive $p" |
| 156 | + return |
| 157 | + fi |
| 158 | + if archive_lists_objects "$p"; then |
| 159 | + ok "ar members $p" |
| 160 | + else |
| 161 | + if command -v ar >/dev/null 2>&1; then |
| 162 | + bad "ar could not list object members in $p" |
| 163 | + ar t "$p" 2>&1 | head -20 || true |
| 164 | + else |
| 165 | + note "no ar on PATH; skipped member listing for $p" |
| 166 | + fi |
| 167 | + fi |
| 168 | + } |
| 169 | + |
| 170 | + require_header "libs/glm/include/glm/vec2.hpp" |
| 171 | + require_header "libs/json/include/nlohmann/json.hpp" |
| 172 | + require_header "libs/utf8/include/utf8.h" |
| 173 | + require_archive "libs/tess2/lib/${SUBPATH}/libtess2.a" |
| 174 | + require_archive "libs/zlib/lib/${SUBPATH}/zlib.a" |
| 175 | + # kiss is named libkiss.a on linux; optional if formula set omitted it |
| 176 | + if [[ -f "libs/kiss/lib/${SUBPATH}/libkiss.a" ]]; then |
| 177 | + require_archive "libs/kiss/lib/${SUBPATH}/libkiss.a" |
| 178 | + else |
| 179 | + note "kiss not deployed at libs/kiss/lib/${SUBPATH}/libkiss.a" |
| 180 | + fi |
| 181 | + |
| 182 | +elif [[ "$PLATFORM" == "msys2" ]]; then |
| 183 | + echo "--- trees under lib/msys2 ---" |
| 184 | + if list_lib_trees '*/lib/msys2' | grep -q .; then |
| 185 | + list_lib_trees '*/lib/msys2*' |
| 186 | + ok "found lib/msys2 folders" |
| 187 | + else |
| 188 | + bad "no lib/msys2 folders under libs/ or addons/" |
| 189 | + fi |
| 190 | + |
| 191 | + # Prefer nested arch folder, then flat lib/msys2 (same as the makefile). |
| 192 | + resolve_msys2_a() { |
| 193 | + local libname="$1" |
| 194 | + local aname="$2" |
| 195 | + if [[ -f "libs/${libname}/lib/msys2/${ARCH}/${aname}" ]]; then |
| 196 | + echo "libs/${libname}/lib/msys2/${ARCH}/${aname}" |
| 197 | + elif [[ -f "libs/${libname}/lib/msys2/${aname}" ]]; then |
| 198 | + echo "libs/${libname}/lib/msys2/${aname}" |
| 199 | + fi |
| 200 | + } |
| 201 | + |
| 202 | + check_msys2_a() { |
| 203 | + local libname="$1" |
| 204 | + local aname="$2" |
| 205 | + local p |
| 206 | + p=$(resolve_msys2_a "$libname" "$aname") |
| 207 | + if [[ -z "$p" ]]; then |
| 208 | + bad "missing ${aname} for ${libname} (tried lib/msys2/${ARCH}/ and lib/msys2/)" |
| 209 | + return |
| 210 | + fi |
| 211 | + ok "deployed $p" |
| 212 | + if [[ ! -s "$p" ]]; then |
| 213 | + bad "archive empty $p" |
| 214 | + return |
| 215 | + fi |
| 216 | + if is_gnu_ar "$p"; then |
| 217 | + ok "gnu ar magic $p ($(wc -c <"$p") bytes)" |
| 218 | + else |
| 219 | + bad "not a GNU ar archive $p" |
| 220 | + return |
| 221 | + fi |
| 222 | + if archive_lists_objects "$p"; then |
| 223 | + ok "ar members $p" |
| 224 | + ar t "$p" 2>/dev/null | head -8 || true |
| 225 | + else |
| 226 | + bad "ar could not list object members in $p (ld/lld will reject this)" |
| 227 | + ar t "$p" 2>&1 | head -20 || true |
| 228 | + fi |
| 229 | + } |
| 230 | + |
| 231 | + check_msys2_a tess2 libtess2.a |
| 232 | + check_msys2_a kiss libkiss.a |
| 233 | + check_msys2_a videoInput videoInput.a |
| 234 | +else |
| 235 | + echo "Unsupported platform: $PLATFORM" |
| 236 | + exit 1 |
| 237 | +fi |
| 238 | + |
| 239 | +echo |
| 240 | +echo "Passed: ${pass} Failed: ${fail} Warnings: ${warn}" |
| 241 | +if [[ "$fail" -ne 0 ]]; then |
| 242 | + exit 1 |
| 243 | +fi |
| 244 | +echo "Deployed library check OK" |
0 commit comments