run.sh 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #!/bin/sh
  2. # SQLite binding tests and showcase.
  3. set -e
  4. trap 'rm -f /tmp/m2-sqlite-utils.db' EXIT
  5. cd "$(dirname "$0")"
  6. ROOT="$(cd ../.. && pwd)"
  7. M2MAKE="$ROOT/tools/m2make/b_v3/M2make"
  8. if [ ! -x "$M2MAKE" ]; then
  9. echo "missing $M2MAKE; run tools/m2make/build_m2.sh" >&2
  10. exit 1
  11. fi
  12. # Allow an explicit override, then use pkg-config, ldconfig or a
  13. # platform-specific runtime library. The .so.0 fallback matters on
  14. # systems with the SQLite runtime but without the development package.
  15. if [ -n "${SQLITE_LIBS:-}" ]; then
  16. :
  17. elif command -v pkg-config >/dev/null 2>&1 && pkg-config --exists sqlite3; then
  18. SQLITE_LIBS="$(pkg-config --libs sqlite3)"
  19. else
  20. SQLITE_LIBS=""
  21. if command -v ldconfig >/dev/null 2>&1; then
  22. SQLITE_LIBS="$(ldconfig -p 2>/dev/null |
  23. awk '/libsqlite3\.so\.0/ { print $NF; exit }')"
  24. fi
  25. if [ -z "$SQLITE_LIBS" ] && command -v cc >/dev/null 2>&1; then
  26. cand="$(cc -print-file-name=libsqlite3.so 2>/dev/null || true)"
  27. if [ -n "$cand" ] && [ "$cand" != "libsqlite3.so" ] && [ -f "$cand" ]; then
  28. SQLITE_LIBS="$cand"
  29. fi
  30. if [ -z "$SQLITE_LIBS" ]; then
  31. cand="$(cc -print-file-name=libsqlite3.dylib 2>/dev/null || true)"
  32. if [ -n "$cand" ] && [ "$cand" != "libsqlite3.dylib" ] && [ -f "$cand" ]; then
  33. SQLITE_LIBS="$cand"
  34. fi
  35. fi
  36. fi
  37. if [ -z "$SQLITE_LIBS" ]; then
  38. for cand in \
  39. /usr/lib/x86_64-linux-gnu/libsqlite3.so.0 \
  40. /usr/lib/aarch64-linux-gnu/libsqlite3.so.0 \
  41. /usr/lib64/libsqlite3.so.0 \
  42. /usr/lib/libsqlite3.so.0 \
  43. /usr/local/lib/libsqlite3.so.0 \
  44. /opt/homebrew/opt/sqlite/lib/libsqlite3.dylib \
  45. /usr/local/opt/sqlite/lib/libsqlite3.dylib; do
  46. if [ -f "$cand" ]; then SQLITE_LIBS="$cand"; break; fi
  47. done
  48. fi
  49. if [ -z "$SQLITE_LIBS" ]; then
  50. SQLITE_LIBS="-lsqlite3"
  51. fi
  52. fi
  53. echo "SQLite library: $SQLITE_LIBS"
  54. build_and_run() {
  55. name="$1"
  56. src="${2:-tests/$name.mod}"
  57. out="${TMPDIR:-/tmp}/m2-sqlite-$name"
  58. "$M2MAKE" -c m2 \
  59. --m2bin "$ROOT/compiler/M2" \
  60. --shim "$ROOT/runtime/syslib/shim.c" \
  61. --lib "$SQLITE_LIBS" \
  62. -I "$ROOT/bindings/sqlite3" \
  63. -I "$ROOT/runtime/syslib" \
  64. -I "$ROOT/lib/common" \
  65. -o "$out" \
  66. "$src"
  67. set +e
  68. "$out"
  69. rc=$?
  70. set -e
  71. if [ "$rc" = 42 ]; then return 0; fi
  72. return 1
  73. }
  74. build_and_run SQLiteSmoke
  75. build_and_run SQLitePrepared
  76. build_and_run SQLiteParams
  77. build_and_run SQLitePrepareTail
  78. build_and_run SQLiteHelpers
  79. build_and_run SQLiteIntrospection
  80. build_and_run SQLiteScalar
  81. build_and_run SQLiteErrors
  82. build_and_run SQLiteBlob
  83. build_and_run SQLiteBlobErrors
  84. build_and_run SQLiteConstraints
  85. build_and_run SQLiteBackup
  86. build_and_run SQLiteCapi3c
  87. build_and_run SQLiteConnection
  88. build_and_run SQLiteCallback
  89. build_and_run SQLiteHooks
  90. build_and_run SQLiteShowcase showcase/SQLiteShowcase.mod
  91. build_and_run SQLiteFeatureShowcase showcase/SQLiteFeatureShowcase.mod