#!/usr/bin/env bash
# ---------------------------------------------------------
# Autoware 编译脚本
# ---------------------------------------------------------
set -euo pipefail

readonly RED='\033[0;31m'
readonly GREEN='\033[0;32m'
readonly NC='\033[0m'

log()  { echo -e "${GREEN}[INFO]${NC} $*"; }
warn() { echo -e "${RED}[WARN]${NC} $*" >&2; }

BUILD_ARGS=(
  colcon build
  --symlink-install
  --cmake-args -DCMAKE_BUILD_TYPE=Release
)

# 如需部分包编译，把 xxx 换成包名后取消下一行注释
# BUILD_ARGS+=(--packages-select autoware_pose_initializer)

log "Starting colcon build..."
if AUTOWARE_COMPILE_WITH_CUDA=1 "${BUILD_ARGS[@]}"; then
  log "Build succeeded. Sourcing workspace..."

  # 临时关闭 -u，避免 COLCON_TRACE 未定义报错
  set +u
  source install/setup.bash
  set -u

  log "Done."
else
  warn "Build failed, skip sourcing."
fi


