| 1 |
#!/bin/bash |
| 2 |
# Test that libabpoa.a does not export bare klib symbols. |
| 3 |
# All klib symbols must be prefixed with abpoa_ to avoid collisions |
| 4 |
# with minimap2, htslib, and other klib-bundling libraries. |
| 5 |
set -e |
| 6 |
|
| 7 |
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" |
| 8 |
PROJECT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)" |
| 9 |
cd "$PROJECT_DIR" |
| 10 |
|
| 11 |
LIB="lib/libabpoa.a" |
| 12 |
if [ ! -f "$LIB" ]; then |
| 13 |
echo "SKIP: $LIB not found (run make first)" |
| 14 |
exit 1 |
| 15 |
fi |
| 16 |
|
| 17 |
SYMBOLS=$(nm -g "$LIB" 2>/dev/null | grep " T " | awk '{print $3}' | sed 's/^_//') |
| 18 |
ERRORS=0 |
| 19 |
|
| 20 |
# These bare symbols must NOT appear |
| 21 |
BARE_SYMBOLS="kmalloc krealloc kcalloc kfree km_init km_init2 km_destroy km_stat |
| 22 |
kvsprintf ksprintf ksplit_core kstrtok kgetline kmemmem kstrstr kstrnstr |
| 23 |
kseq_init kseq_destroy kseq_read kseq_copy |
| 24 |
ks_heapdown_128 ks_heapmake_128 ks_ksmall_128 |
| 25 |
ks_heapdown_64 ks_heapmake_64 ks_ksmall_64" |
| 26 |
|
| 27 |
for sym in $BARE_SYMBOLS; do |
| 28 |
if echo "$SYMBOLS" | grep -qx "$sym"; then |
| 29 |
echo "FAIL: bare symbol '$sym' found in $LIB" |
| 30 |
ERRORS=$((ERRORS + 1)) |
| 31 |
fi |
| 32 |
done |
| 33 |
|
| 34 |
# These prefixed symbols MUST appear |
| 35 |
PREFIXED_SYMBOLS="abpoa_kmalloc abpoa_krealloc abpoa_kcalloc abpoa_kfree |
| 36 |
abpoa_km_init abpoa_km_init2 abpoa_km_destroy abpoa_km_stat |
| 37 |
abpoa_kvsprintf abpoa_ksprintf abpoa_ksplit_core abpoa_kstrtok |
| 38 |
abpoa_kgetline abpoa_kmemmem abpoa_kstrstr abpoa_kstrnstr |
| 39 |
abpoa_kseq_init abpoa_kseq_destroy abpoa_kseq_read abpoa_kseq_copy |
| 40 |
abpoa_ks_heapdown_128 abpoa_ks_heapmake_128 abpoa_ks_ksmall_128 |
| 41 |
abpoa_ks_heapdown_64 abpoa_ks_heapmake_64 abpoa_ks_ksmall_64" |
| 42 |
|
| 43 |
for sym in $PREFIXED_SYMBOLS; do |
| 44 |
if ! echo "$SYMBOLS" | grep -qx "$sym"; then |
| 45 |
echo "FAIL: prefixed symbol '$sym' NOT found in $LIB" |
| 46 |
ERRORS=$((ERRORS + 1)) |
| 47 |
fi |
| 48 |
done |
| 49 |
|
| 50 |
if [ $ERRORS -gt 0 ]; then |
| 51 |
echo "$ERRORS symbol namespacing errors" |
| 52 |
exit 1 |
| 53 |
fi |
| 54 |
|
| 55 |
echo "All klib symbols properly namespaced" |
| 56 |
exit 0 |