#!/usr/bin/env bash set -euo pipefail # cleanup_workspace.sh — Archive logs and remove build artifacts # - Archives logs to archive/cleanup_YYYYmmdd_HHMMSS/{logs} # - Runs make clean # - Removes re-buildable bench binaries and helper copies ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")"/.. && pwd)" cd "$ROOT_DIR" ts="$(date +%Y%m%d_%H%M%S)" DEST="archive/cleanup_${ts}" mkdir -p "${DEST}/logs" log_patterns=( "*out.txt" "*stdout.log" "*stderr.log" "ring*.txt" "asan_*.log" "run_*.log" ) echo "[cleanup] Archiving logs to ${DEST}/logs" | tee "${DEST}/CLEANUP_SUMMARY.txt" for pat in "${log_patterns[@]}"; do shopt -s nullglob for f in $pat; do if [[ -f "$f" ]]; then echo "log: $f" >> "${DEST}/LOGS_LIST.txt" mv -f "$f" "${DEST}/logs/" fi done done echo "[cleanup] Running make clean" | tee -a "${DEST}/CLEANUP_SUMMARY.txt" if command -v make >/dev/null 2>&1; then ( make clean >/dev/null 2>&1 || true ) echo "make clean: done" >> "${DEST}/CLEANUP_SUMMARY.txt" else echo "make not found, skipping" >> "${DEST}/CLEANUP_SUMMARY.txt" fi # Remove common bench/wrapper binaries (rebuildable) echo "[cleanup] Removing rebuildable binaries" | tee -a "${DEST}/CLEANUP_SUMMARY.txt" rm -f \ larson_hakmem larson_hakmem_asan larson_hakmem_tsan larson_hakmem_ubsan \ bench_*_hakmem bench_*_system bench_*_mi \ bench_tiny bench_tiny_mt phase6_bench_tiny_simple test_hakmem # Report large files remaining at top-level echo "[cleanup] Large files remaining (top-level, >1MB)" | tee -a "${DEST}/CLEANUP_SUMMARY.txt" { find . -maxdepth 1 -type f -size +1M -printf "%f\t%k KB\n" 2>/dev/null || true; } | tee -a "${DEST}/POST_CLEAN_LARGE_FILES.txt" echo "[cleanup] Done. Summary at ${DEST}/CLEANUP_SUMMARY.txt"