|
@@ -16,7 +16,15 @@ PROJECT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
|
|
|
|
|
|
|
|
BASE_IMAGE_NAME="smartbotic-db-build-base:debian13"
|
|
BASE_IMAGE_NAME="smartbotic-db-build-base:debian13"
|
|
|
BUILD_JOBS="${BUILD_JOBS:-$(nproc)}"
|
|
BUILD_JOBS="${BUILD_JOBS:-$(nproc)}"
|
|
|
-DEB_REPO_DIR="${DEB_REPO_DIR:-/data/smartbotics-deb-repo}"
|
|
|
|
|
|
|
+BUILD_DIR="$PROJECT_DIR/build"
|
|
|
|
|
+
|
|
|
|
|
+# Where the smartbotics-deb-repo checkout lives. Only --repo / --sync need it.
|
|
|
|
|
+#
|
|
|
|
|
+# No absolute default: the old one (/data/smartbotics-deb-repo) was one
|
|
|
|
|
+# machine's layout, and when that checkout moved, a publish failed only AFTER
|
|
|
|
|
+# a full package build. Resolution order: $DEB_REPO_DIR, then a checkout next
|
|
|
|
|
+# to this one. Resolved and validated before anything is built.
|
|
|
|
|
+DEB_REPO_DIR="${DEB_REPO_DIR:-}"
|
|
|
|
|
|
|
|
# Output directories — separate to prevent local/Docker overwriting each other
|
|
# Output directories — separate to prevent local/Docker overwriting each other
|
|
|
# dist/local/ — native build for current system
|
|
# dist/local/ — native build for current system
|
|
@@ -32,6 +40,7 @@ GIT_COMMIT="$(git -C "$PROJECT_DIR" rev-parse --short HEAD 2>/dev/null || echo "
|
|
|
LOCAL_MODE=0
|
|
LOCAL_MODE=0
|
|
|
INSTALL_AFTER=0
|
|
INSTALL_AFTER=0
|
|
|
SKIP_TESTS=0
|
|
SKIP_TESTS=0
|
|
|
|
|
+NO_PACKAGE=0
|
|
|
DEB_REVISION=1
|
|
DEB_REVISION=1
|
|
|
REBUILD_BASE=0
|
|
REBUILD_BASE=0
|
|
|
NO_CACHE=0
|
|
NO_CACHE=0
|
|
@@ -60,6 +69,7 @@ Build modes:
|
|
|
|
|
|
|
|
Options:
|
|
Options:
|
|
|
--install Install .debs locally after build (--local only)
|
|
--install Install .debs locally after build (--local only)
|
|
|
|
|
+ --no-package Stop after the build: no .debs (--local only)
|
|
|
--skip-tests Skip running tests
|
|
--skip-tests Skip running tests
|
|
|
--deb-revision N Debian revision suffix (default: 1)
|
|
--deb-revision N Debian revision suffix (default: 1)
|
|
|
--rebuild-base Force rebuild Docker base image
|
|
--rebuild-base Force rebuild Docker base image
|
|
@@ -70,7 +80,12 @@ Options:
|
|
|
|
|
|
|
|
Environment variables:
|
|
Environment variables:
|
|
|
BUILD_JOBS Parallel build jobs (default: nproc)
|
|
BUILD_JOBS Parallel build jobs (default: nproc)
|
|
|
- DEB_REPO_DIR Path to smartbotics-deb-repo (default: /data/smartbotics-deb-repo)
|
|
|
|
|
|
|
+ DEB_REPO_DIR Path to a smartbotics-deb-repo checkout, for --repo/--sync
|
|
|
|
|
+ (default: ../smartbotics-deb-repo next to this checkout)
|
|
|
|
|
+
|
|
|
|
|
+If this host cannot build natively (missing yyjson/lmdb, a different protobuf),
|
|
|
|
|
+use packaging/dev.sh, which runs the same --local build inside the Debian 13
|
|
|
|
|
+build image.
|
|
|
EOF
|
|
EOF
|
|
|
exit 0
|
|
exit 0
|
|
|
}
|
|
}
|
|
@@ -83,6 +98,7 @@ while [[ $# -gt 0 ]]; do
|
|
|
--local) LOCAL_MODE=1; shift ;;
|
|
--local) LOCAL_MODE=1; shift ;;
|
|
|
--install) INSTALL_AFTER=1; shift ;;
|
|
--install) INSTALL_AFTER=1; shift ;;
|
|
|
--skip-tests) SKIP_TESTS=1; shift ;;
|
|
--skip-tests) SKIP_TESTS=1; shift ;;
|
|
|
|
|
+ --no-package) NO_PACKAGE=1; shift ;;
|
|
|
--deb-revision) DEB_REVISION="$2"; shift 2 ;;
|
|
--deb-revision) DEB_REVISION="$2"; shift 2 ;;
|
|
|
--rebuild-base) REBUILD_BASE=1; shift ;;
|
|
--rebuild-base) REBUILD_BASE=1; shift ;;
|
|
|
--no-cache) NO_CACHE=1; shift ;;
|
|
--no-cache) NO_CACHE=1; shift ;;
|
|
@@ -103,15 +119,47 @@ if [[ $INSTALL_AFTER -eq 1 && $LOCAL_MODE -eq 0 ]]; then
|
|
|
exit 1
|
|
exit 1
|
|
|
fi
|
|
fi
|
|
|
|
|
|
|
|
|
|
+if [[ $NO_PACKAGE -eq 1 && $LOCAL_MODE -eq 0 ]]; then
|
|
|
|
|
+ log_error "--no-package is only supported with --local"
|
|
|
|
|
+ exit 1
|
|
|
|
|
+fi
|
|
|
|
|
+
|
|
|
|
|
+if [[ $NO_PACKAGE -eq 1 && $INSTALL_AFTER -eq 1 ]]; then
|
|
|
|
|
+ log_error "--no-package and --install contradict each other"
|
|
|
|
|
+ exit 1
|
|
|
|
|
+fi
|
|
|
|
|
+
|
|
|
if [[ $DO_SYNC -eq 1 && $DO_REPO -eq 0 ]]; then
|
|
if [[ $DO_SYNC -eq 1 && $DO_REPO -eq 0 ]]; then
|
|
|
DO_REPO=1
|
|
DO_REPO=1
|
|
|
fi
|
|
fi
|
|
|
|
|
|
|
|
|
|
+if [[ $DO_REPO -eq 1 && $NO_PACKAGE -eq 1 ]]; then
|
|
|
|
|
+ log_error "--repo/--sync need packages; drop --no-package"
|
|
|
|
|
+ exit 1
|
|
|
|
|
+fi
|
|
|
|
|
+
|
|
|
if [[ $DO_REPO -eq 1 && -z "$SUITE" ]]; then
|
|
if [[ $DO_REPO -eq 1 && -z "$SUITE" ]]; then
|
|
|
log_error "--repo requires --suite NAME"
|
|
log_error "--repo requires --suite NAME"
|
|
|
exit 1
|
|
exit 1
|
|
|
fi
|
|
fi
|
|
|
|
|
|
|
|
|
|
+# Find the apt repository tooling NOW, not after the build. A publish that
|
|
|
|
|
+# cannot possibly succeed should cost seconds, not a full package build.
|
|
|
|
|
+if [[ $DO_REPO -eq 1 ]]; then
|
|
|
|
|
+ if [[ -z "$DEB_REPO_DIR" ]]; then
|
|
|
|
|
+ DEB_REPO_DIR="$(dirname "$PROJECT_DIR")/smartbotics-deb-repo"
|
|
|
|
|
+ fi
|
|
|
|
|
+ for tool in add-packages.sh create-repo.sh sync-repo.sh; do
|
|
|
|
|
+ if [[ ! -x "$DEB_REPO_DIR/scripts/$tool" ]]; then
|
|
|
|
|
+ log_error "apt repository tooling not found: $DEB_REPO_DIR/scripts/$tool"
|
|
|
|
|
+ log_error "Set DEB_REPO_DIR to your smartbotics-deb-repo checkout, e.g."
|
|
|
|
|
+ log_error " DEB_REPO_DIR=/path/to/smartbotics-deb-repo $0 --repo --suite $SUITE"
|
|
|
|
|
+ exit 1
|
|
|
|
|
+ fi
|
|
|
|
|
+ done
|
|
|
|
|
+ DEB_REPO_DIR="$(cd "$DEB_REPO_DIR" && pwd)"
|
|
|
|
|
+fi
|
|
|
|
|
+
|
|
|
# ---------------------------------------------------------------------------
|
|
# ---------------------------------------------------------------------------
|
|
|
# Set output directory based on mode
|
|
# Set output directory based on mode
|
|
|
# ---------------------------------------------------------------------------
|
|
# ---------------------------------------------------------------------------
|
|
@@ -120,7 +168,9 @@ if [[ $LOCAL_MODE -eq 1 ]]; then
|
|
|
else
|
|
else
|
|
|
OUTPUT_DIR="${DIST_BASE}/debian13"
|
|
OUTPUT_DIR="${DIST_BASE}/debian13"
|
|
|
fi
|
|
fi
|
|
|
-mkdir -p "$OUTPUT_DIR"
|
|
|
|
|
|
|
+if [[ $NO_PACKAGE -eq 0 ]]; then
|
|
|
|
|
+ mkdir -p "$OUTPUT_DIR"
|
|
|
|
|
+fi
|
|
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# ---------------------------------------------------------------------------
|
|
|
# Banner
|
|
# Banner
|
|
@@ -132,14 +182,63 @@ if [[ $LOCAL_MODE -eq 1 ]]; then
|
|
|
else
|
|
else
|
|
|
log_info "Mode: Docker (Debian 13)"
|
|
log_info "Mode: Docker (Debian 13)"
|
|
|
fi
|
|
fi
|
|
|
-log_info "Output: ${OUTPUT_DIR}"
|
|
|
|
|
|
|
+if [[ $NO_PACKAGE -eq 0 ]]; then
|
|
|
|
|
+ log_info "Output: ${OUTPUT_DIR}"
|
|
|
|
|
+fi
|
|
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# ---------------------------------------------------------------------------
|
|
|
# Local build
|
|
# Local build
|
|
|
# ---------------------------------------------------------------------------
|
|
# ---------------------------------------------------------------------------
|
|
|
|
|
+# A CMake build tree belongs to the place and the toolchain that configured it.
|
|
|
|
|
+# It records absolute source and binary paths and refuses to be used from
|
|
|
|
|
+# anywhere else, and it caches every library path it found. Both go stale for
|
|
|
|
|
+# ordinary reasons:
|
|
|
|
|
+#
|
|
|
|
|
+# - the checkout was moved or renamed, or the tree was built in a container
|
|
|
|
|
+# that mounted the repository at a different path;
|
|
|
|
|
+# - the tree was built in the build image (packaging/dev.sh) and someone then
|
|
|
|
|
+# ran cmake against it on the host, or the other way round. The paths match
|
|
|
|
|
+# but the cache now holds another system's libraries.
|
|
|
|
|
+#
|
|
|
|
|
+# CMake's own errors for these do not say what to do. Dropping the cache makes
|
|
|
|
|
+# the next configure start clean; nothing else needs removing, because every
|
|
|
|
|
+# compile command changes and Ninja rebuilds what is affected.
|
|
|
|
|
+#
|
|
|
|
|
+# The second case is detected by the CMake version that last wrote the cache.
|
|
|
|
|
+# Two environments sharing one tree almost never share a CMake version, and a
|
|
|
|
|
+# cache written by a different CMake is worth a clean configure regardless.
|
|
|
|
|
+forget_foreign_build_tree() {
|
|
|
|
|
+ local cache="$BUILD_DIR/CMakeCache.txt"
|
|
|
|
|
+ [[ -f "$cache" ]] || return 0
|
|
|
|
|
+
|
|
|
|
|
+ cached() { sed -n "s/^$1:[A-Z]*=//p" "$cache" | head -n1; }
|
|
|
|
|
+
|
|
|
|
|
+ local why=""
|
|
|
|
|
+ local configured_src configured_bin
|
|
|
|
|
+ configured_src="$(cached CMAKE_HOME_DIRECTORY)"
|
|
|
|
|
+ configured_bin="$(cached CMAKE_CACHEFILE_DIR)"
|
|
|
|
|
+ if [[ "$configured_src" != "$PROJECT_DIR" || "$configured_bin" != "$BUILD_DIR" ]]; then
|
|
|
|
|
+ why="it was configured for ${configured_src:-an unknown location}, not $PROJECT_DIR"
|
|
|
|
|
+ else
|
|
|
|
|
+ local wrote running
|
|
|
|
|
+ wrote="$(cached CMAKE_CACHE_MAJOR_VERSION).$(cached CMAKE_CACHE_MINOR_VERSION).$(cached CMAKE_CACHE_PATCH_VERSION)"
|
|
|
|
|
+ running="$(cmake --version | sed -n '1s/^cmake version //p')"
|
|
|
|
|
+ if [[ "$wrote" != "$running" ]]; then
|
|
|
|
|
+ why="it was last configured by CMake $wrote and this is CMake $running (a different system)"
|
|
|
|
|
+ fi
|
|
|
|
|
+ fi
|
|
|
|
|
+ [[ -n "$why" ]] || return 0
|
|
|
|
|
+
|
|
|
|
|
+ log_warn "build/ cannot be reused: $why."
|
|
|
|
|
+ log_warn "Reconfiguring from scratch; anything whose build command changed is rebuilt."
|
|
|
|
|
+ rm -f -- "$cache"
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
build_local() {
|
|
build_local() {
|
|
|
|
|
+ forget_foreign_build_tree
|
|
|
|
|
+
|
|
|
log_info "Configuring CMake (Release)..."
|
|
log_info "Configuring CMake (Release)..."
|
|
|
- cmake -B "$PROJECT_DIR/build" -G Ninja \
|
|
|
|
|
|
|
+ cmake -B "$BUILD_DIR" -G Ninja \
|
|
|
-DCMAKE_BUILD_TYPE=Release \
|
|
-DCMAKE_BUILD_TYPE=Release \
|
|
|
-DSMARTBOTIC_DB_BUILD_SERVICE=ON \
|
|
-DSMARTBOTIC_DB_BUILD_SERVICE=ON \
|
|
|
-DSMARTBOTIC_DB_BUILD_CLIENT=ON \
|
|
-DSMARTBOTIC_DB_BUILD_CLIENT=ON \
|
|
@@ -149,18 +248,23 @@ build_local() {
|
|
|
-S "$PROJECT_DIR"
|
|
-S "$PROJECT_DIR"
|
|
|
|
|
|
|
|
log_info "Building with ${BUILD_JOBS} jobs..."
|
|
log_info "Building with ${BUILD_JOBS} jobs..."
|
|
|
- cmake --build "$PROJECT_DIR/build" -j"$BUILD_JOBS"
|
|
|
|
|
|
|
+ cmake --build "$BUILD_DIR" -j"$BUILD_JOBS"
|
|
|
log_success "Build completed"
|
|
log_success "Build completed"
|
|
|
|
|
|
|
|
if [[ $SKIP_TESTS -eq 0 ]]; then
|
|
if [[ $SKIP_TESTS -eq 0 ]]; then
|
|
|
log_info "Running tests..."
|
|
log_info "Running tests..."
|
|
|
- LD_LIBRARY_PATH="$PROJECT_DIR/build/client" \
|
|
|
|
|
- "$PROJECT_DIR/build/tests/test_vector_storage"
|
|
|
|
|
|
|
+ LD_LIBRARY_PATH="$BUILD_DIR/client" \
|
|
|
|
|
+ "$BUILD_DIR/tests/test_vector_storage"
|
|
|
log_success "Tests passed"
|
|
log_success "Tests passed"
|
|
|
else
|
|
else
|
|
|
log_warn "Tests skipped (--skip-tests)"
|
|
log_warn "Tests skipped (--skip-tests)"
|
|
|
fi
|
|
fi
|
|
|
|
|
|
|
|
|
|
+ if [[ $NO_PACKAGE -eq 1 ]]; then
|
|
|
|
|
+ log_info "Packaging skipped (--no-package)"
|
|
|
|
|
+ return 0
|
|
|
|
|
+ fi
|
|
|
|
|
+
|
|
|
log_info "Creating .deb packages..."
|
|
log_info "Creating .deb packages..."
|
|
|
OUTPUT_DIR="$OUTPUT_DIR" BUILD_DEB_REVISION="$DEB_REVISION" "$PROJECT_DIR/packaging/deb/create-debs.sh"
|
|
OUTPUT_DIR="$OUTPUT_DIR" BUILD_DEB_REVISION="$DEB_REVISION" "$PROJECT_DIR/packaging/deb/create-debs.sh"
|
|
|
log_success "Packages created"
|
|
log_success "Packages created"
|
|
@@ -241,15 +345,30 @@ else
|
|
|
build_docker
|
|
build_docker
|
|
|
fi
|
|
fi
|
|
|
|
|
|
|
|
|
|
+if [[ $NO_PACKAGE -eq 1 ]]; then
|
|
|
|
|
+ echo ""
|
|
|
|
|
+ log_success "Build complete: $BUILD_DIR"
|
|
|
|
|
+ exit 0
|
|
|
|
|
+fi
|
|
|
|
|
+
|
|
|
# ---------------------------------------------------------------------------
|
|
# ---------------------------------------------------------------------------
|
|
|
# List created packages
|
|
# List created packages
|
|
|
# ---------------------------------------------------------------------------
|
|
# ---------------------------------------------------------------------------
|
|
|
|
|
+# Only what THIS run produced. dist/ accumulates every version ever built, and
|
|
|
|
|
+# both the listing and the publish step used to take the whole directory - so a
|
|
|
|
|
+# publish re-staged every historical package, and anything else sitting in
|
|
|
|
|
+# dist/ went to the repository with it.
|
|
|
|
|
+shopt -s nullglob
|
|
|
|
|
+BUILT_DEBS=("$OUTPUT_DIR"/*_"${VERSION}-${DEB_REVISION}"_*.deb)
|
|
|
|
|
+shopt -u nullglob
|
|
|
|
|
+if [[ ${#BUILT_DEBS[@]} -eq 0 ]]; then
|
|
|
|
|
+ log_error "No ${VERSION}-${DEB_REVISION} .deb files found in $OUTPUT_DIR"
|
|
|
|
|
+ exit 1
|
|
|
|
|
+fi
|
|
|
|
|
+
|
|
|
echo ""
|
|
echo ""
|
|
|
log_info "Created packages:"
|
|
log_info "Created packages:"
|
|
|
-ls -lh "$OUTPUT_DIR"/*.deb 2>/dev/null || {
|
|
|
|
|
- log_error "No .deb files found in $OUTPUT_DIR"
|
|
|
|
|
- exit 1
|
|
|
|
|
-}
|
|
|
|
|
|
|
+ls -lh "${BUILT_DEBS[@]}"
|
|
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# ---------------------------------------------------------------------------
|
|
|
# Repository operations
|
|
# Repository operations
|
|
@@ -258,12 +377,7 @@ if [[ $DO_REPO -eq 1 ]]; then
|
|
|
echo ""
|
|
echo ""
|
|
|
log_info "Adding packages to repository (suite: ${SUITE})..."
|
|
log_info "Adding packages to repository (suite: ${SUITE})..."
|
|
|
|
|
|
|
|
- if [[ ! -x "$DEB_REPO_DIR/scripts/add-packages.sh" ]]; then
|
|
|
|
|
- log_error "Repository tool not found: $DEB_REPO_DIR/scripts/add-packages.sh"
|
|
|
|
|
- exit 1
|
|
|
|
|
- fi
|
|
|
|
|
-
|
|
|
|
|
- "$DEB_REPO_DIR/scripts/add-packages.sh" "$OUTPUT_DIR"
|
|
|
|
|
|
|
+ "$DEB_REPO_DIR/scripts/add-packages.sh" "${BUILT_DEBS[@]}"
|
|
|
log_success "Packages added to staging"
|
|
log_success "Packages added to staging"
|
|
|
|
|
|
|
|
"$DEB_REPO_DIR/scripts/create-repo.sh" --suite "$SUITE"
|
|
"$DEB_REPO_DIR/scripts/create-repo.sh" --suite "$SUITE"
|