@@ -220,23 +220,55 @@ main() {
220220
221221 # Build or locate existing libraries
222222 if $skip_build ; then
223- # Skip build, just find existing libraries
224- log_info " Skipping build, locating existing libraries..."
223+ # Skip build, but verify libraries are up-to-date with current commit
224+ log_info " Skipping build, verifying libraries are up-to-date ..."
225225 BASELINE_LIB=" ${BASELINE_WORKTREE} /ddprof-lib/build/lib/main/release/linux/x64/libjavaProfiler.so"
226226 OPTIMIZED_LIB=" ${OPTIMIZED_WORKTREE} /ddprof-lib/build/lib/main/release/linux/x64/libjavaProfiler.so"
227227
228- if [ ! -f " ${BASELINE_LIB} " ] || [ ! -f " ${OPTIMIZED_LIB} " ]; then
229- log_error " Libraries not found. Run with --build-only first."
230- log_error " Baseline: ${BASELINE_LIB} "
231- log_error " Optimized: ${OPTIMIZED_LIB} "
228+ BASELINE_HASH_FILE=" ${BASELINE_WORKTREE} /ddprof-lib/build/.build_commit_hash"
229+ OPTIMIZED_HASH_FILE=" ${OPTIMIZED_WORKTREE} /ddprof-lib/build/.build_commit_hash"
230+
231+ # Get current commit hashes
232+ cd " ${BASELINE_WORKTREE} "
233+ local baseline_current_hash=$( git rev-parse HEAD)
234+ cd " ${OPTIMIZED_WORKTREE} "
235+ local optimized_current_hash=$( git rev-parse HEAD)
236+
237+ # Check if libraries exist and match current commit
238+ local need_rebuild=false
239+ if [ ! -f " ${BASELINE_LIB} " ] || [ ! -f " ${BASELINE_HASH_FILE} " ]; then
240+ log_warn " Baseline library not found or missing hash file"
241+ need_rebuild=true
242+ elif [ " $( cat ${BASELINE_HASH_FILE} ) " != " ${baseline_current_hash} " ]; then
243+ log_warn " Baseline library built from different commit: $( cat ${BASELINE_HASH_FILE} ) != ${baseline_current_hash} "
244+ need_rebuild=true
245+ fi
246+
247+ if [ ! -f " ${OPTIMIZED_LIB} " ] || [ ! -f " ${OPTIMIZED_HASH_FILE} " ]; then
248+ log_warn " Optimized library not found or missing hash file"
249+ need_rebuild=true
250+ elif [ " $( cat ${OPTIMIZED_HASH_FILE} ) " != " ${optimized_current_hash} " ]; then
251+ log_warn " Optimized library built from different commit: $( cat ${OPTIMIZED_HASH_FILE} ) != ${optimized_current_hash} "
252+ need_rebuild=true
253+ fi
254+
255+ if $need_rebuild ; then
256+ log_error " Libraries are out of date. Run with --build-only first to rebuild."
232257 exit 1
233258 fi
259+
260+ log_info " Libraries are up-to-date:"
261+ log_info " Baseline: ${BASELINE_LIB} (commit: ${baseline_current_hash: 0: 8} )"
262+ log_info " Optimized: ${OPTIMIZED_LIB} (commit: ${optimized_current_hash: 0: 8} )"
234263 else
235264 # Build baseline
236265 log_step " 3/6: Building baseline version..."
237266 cd " ${BASELINE_WORKTREE} "
238267 ./gradlew ddprof-lib:buildrelease -x test
239268
269+ # Record the commit hash for this build
270+ git rev-parse HEAD > ddprof-lib/build/.build_commit_hash
271+
240272 # Find the baseline library (prefer release, fallback to any .so)
241273 local baseline_lib_check=" ${BASELINE_WORKTREE} /ddprof-lib/build/lib/main/release/linux/x64/libjavaProfiler.so"
242274 if [ ! -f " ${baseline_lib_check} " ]; then
@@ -251,12 +283,16 @@ main() {
251283 log_info " Using baseline library: ${baseline_lib_check} "
252284 fi
253285 BASELINE_LIB=" ${baseline_lib_check} "
286+ log_info " Built baseline from commit: $( cat ddprof-lib/build/.build_commit_hash | cut -c1-8) "
254287
255288 # Build optimized
256289 log_step " 4/6: Building optimized version..."
257290 cd " ${OPTIMIZED_WORKTREE} "
258291 ./gradlew ddprof-lib:buildrelease -x test
259292
293+ # Record the commit hash for this build
294+ git rev-parse HEAD > ddprof-lib/build/.build_commit_hash
295+
260296 # Find the optimized library (prefer release, fallback to any .so)
261297 local optimized_lib_check=" ${OPTIMIZED_WORKTREE} /ddprof-lib/build/lib/main/release/linux/x64/libjavaProfiler.so"
262298 if [ ! -f " ${optimized_lib_check} " ]; then
@@ -271,6 +307,7 @@ main() {
271307 log_info " Using optimized library: ${optimized_lib_check} "
272308 fi
273309 OPTIMIZED_LIB=" ${optimized_lib_check} "
310+ log_info " Built optimized from commit: $( cat ddprof-lib/build/.build_commit_hash | cut -c1-8) "
274311 fi
275312
276313 # If build-only mode, exit here
0 commit comments