87 lines
2.6 KiB
Bash
Executable File
87 lines
2.6 KiB
Bash
Executable File
#!/bin/bash
|
|
set -e
|
|
|
|
# run.sh - Build (only if needed) and run the sovereign-browser binary.
|
|
#
|
|
# Usage:
|
|
# ./run.sh [args...] # build if stale, then run with args
|
|
# ./run.sh --build # force a rebuild, then run
|
|
# ./run.sh --no-build # run without building (fails if missing)
|
|
#
|
|
# The binary is rebuilt only when it is missing or when any source file
|
|
# (src/**, Cargo.toml, Cargo.lock, www/**) is newer than the binary.
|
|
|
|
# Colors for output
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
BLUE='\033[0;34m'
|
|
NC='\033[0m'
|
|
|
|
print_status() { echo -e "${BLUE}[INFO]${NC} $1" >&2; }
|
|
print_success() { echo -e "${GREEN}[SUCCESS]${NC} $1" >&2; }
|
|
print_warning() { echo -e "${YELLOW}[WARNING]${NC} $1" >&2; }
|
|
print_error() { echo -e "${RED}[ERROR]${NC} $1" >&2; }
|
|
|
|
# --- Config -------------------------------------------------------------
|
|
# Resolve the project root as the directory containing this script.
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
cd "$SCRIPT_DIR"
|
|
|
|
BIN_NAME="sovereign-browser"
|
|
BIN_PATH="target/release/${BIN_NAME}"
|
|
|
|
# --- Args ---------------------------------------------------------------
|
|
FORCE_BUILD=false
|
|
NO_BUILD=false
|
|
RUN_ARGS=()
|
|
|
|
for arg in "$@"; do
|
|
case "$arg" in
|
|
--build)
|
|
FORCE_BUILD=true
|
|
;;
|
|
--no-build)
|
|
NO_BUILD=true
|
|
;;
|
|
*)
|
|
RUN_ARGS+=("$arg")
|
|
;;
|
|
esac
|
|
done
|
|
|
|
# --- Determine whether a build is needed --------------------------------
|
|
needs_build() {
|
|
# No binary yet -> must build.
|
|
[[ ! -x "$BIN_PATH" ]] && return 0
|
|
|
|
# Any tracked source file newer than the binary -> rebuild.
|
|
local newer
|
|
newer="$(find src www Cargo.toml Cargo.lock \
|
|
-type f -newer "$BIN_PATH" -print -quit 2>/dev/null || true)"
|
|
[[ -n "$newer" ]]
|
|
}
|
|
|
|
# --- Build --------------------------------------------------------------
|
|
if [[ "$NO_BUILD" == true ]]; then
|
|
if [[ ! -x "$BIN_PATH" ]]; then
|
|
print_error "Binary not found at ${BIN_PATH} and --no-build was given."
|
|
exit 1
|
|
fi
|
|
print_status "Skipping build (--no-build)."
|
|
elif [[ "$FORCE_BUILD" == true ]]; then
|
|
print_status "Forcing rebuild of ${BIN_NAME} (release)..."
|
|
cargo build --release
|
|
print_success "Build complete."
|
|
elif needs_build; then
|
|
print_status "Sources changed or binary missing; building ${BIN_NAME} (release)..."
|
|
cargo build --release
|
|
print_success "Build complete."
|
|
else
|
|
print_status "Binary is up to date; skipping build."
|
|
fi
|
|
|
|
# --- Run ----------------------------------------------------------------
|
|
print_status "Running ${BIN_PATH} ${RUN_ARGS[*]}"
|
|
exec "$BIN_PATH" "${RUN_ARGS[@]}"
|