diff --git a/cov_docker_script/common_build_utils.sh b/cov_docker_script/common_build_utils.sh index 0bb9f88..a47bcbd 100755 --- a/cov_docker_script/common_build_utils.sh +++ b/cov_docker_script/common_build_utils.sh @@ -40,6 +40,16 @@ check_dependencies() { return 0 } +# Get latest commit id +get_latest_sha() { + local repo_path="$1" + + git -C "$repo_path" rev-parse -is-inside-work-tree >/dev/null 2>&1 \ + || { echo "Invalid git repo"; return 1; } + + git -C "$repo_path" rev-parse --short HEAD +} + # Clone a git repository clone_repo() { local name="$1" repo="$2" branch="$3" dest="$4" diff --git a/cov_docker_script/setup_dependencies.sh b/cov_docker_script/setup_dependencies.sh index 7a5828f..b932544 100755 --- a/cov_docker_script/setup_dependencies.sh +++ b/cov_docker_script/setup_dependencies.sh @@ -39,7 +39,13 @@ initialize_environment() { [[ -d "$BUILD_DIR" ]] && rm -rf "$BUILD_DIR" [[ -d "$USR_DIR" ]] && rm -rf "$USR_DIR" fi - + + # Rebuild if requested + if [[ "${RE_BUILD:-false}" == "true" ]]; then + warn "Removing previous build completed flags" + [[ -d "$BUILD_DIR" ]] && find "$BUILD_DIR" -type f -name 'build_*.done' -print -delete + fi + # Create directories mkdir -p "$BUILD_DIR" mkdir -p "$USR_DIR/include/rdkb" @@ -100,6 +106,15 @@ build_repository() { log "No build configuration for $name (headers only)" return 0 fi + + local LATEST_SHA="$(get_latest_sha "$repo_dir")" + if [ -f "$repo_dir/build_${LATEST_SHA}.done" ]; then + # Copy libraries + copy_libraries "$repo_dir" "$USR_DIR/local/lib" + copy_libraries "$repo_dir" "$USR_DIR/lib" + log "Build already done for SHA: $LATEST_SHA, skipping rebuild." + return 0 + fi step "Building $name (type: $build_type)" @@ -174,6 +189,7 @@ build_repository() { copy_libraries "$repo_dir" "$USR_DIR/lib" ok "$name build completed" + touch "$repo_dir/build_${LATEST_SHA}.done" return 0 }