@@ -11,12 +11,14 @@ See accompanying License file for license details
1111
1212package PGBuild::Modules::ABICompCheck ;
1313
14+ use PGBuild::Log;
1415use PGBuild::Options;
1516use PGBuild::SCM;
16- use PGBuild::Utils;
17+ use PGBuild::Utils qw( :DEFAULT $tmpdir $steps_completed ) ;
1718
1819use strict;
1920use warnings;
21+ use File::Basename;
2022
2123# strip required namespace from package name
2224(my $MODULE = __PACKAGE__ ) =~ s / PGBuild::Modules::// ;
@@ -96,6 +98,7 @@ sub setup
9698 clone_name => ' pgsql' ,
9799 last_commit_hash => $last_commit_hash ,
98100 install_ok => 0,
101+ logs => PGBuild::Log-> new(" abi-comp-check-$branch " )
99102 };
100103 bless ($self , $class );
101104
@@ -215,18 +218,24 @@ sub _checkout_commit
215218
216219sub _log_command_output
217220{
218- my ($self , $cmd , $log_dir , $cmd_desc ) = @_ ;
219-
220- # Ensure log directory exists
221- mkdir $log_dir unless -d $log_dir ;
222-
223- my $log_file = " $log_dir /$cmd_desc .log" ;
221+ my ($self , $cmd , $log_file , $cmd_desc , $no_die ) = @_ ;
224222
225223 print time_str(), " Executing: $cmd_desc \n " if $verbose ;
226224
227- run_log(qq{ $cmd > " $log_file " 2>&1 } );
225+ my @output = run_log(qq{ $cmd } );
228226 my $exit_status = $? >> 8;
229- if ($exit_status )
227+
228+ if (@output )
229+ {
230+ open my $fh , ' >' , $log_file or warn " could not open $log_file : $! " ;
231+ if ($fh )
232+ {
233+ print $fh @output ;
234+ close $fh ;
235+ }
236+ }
237+
238+ if ($exit_status && !$no_die )
230239 {
231240 die " $cmd_desc failed with status $exit_status . Log: $log_file " ;
232241 }
@@ -235,7 +244,7 @@ sub _log_command_output
235244 print time_str(), " Successfully executed $cmd_desc \n "
236245 if $verbose ;
237246 }
238- return ;
247+ return $exit_status ;
239248}
240249
241250sub _configure_make_and_build
@@ -252,6 +261,7 @@ sub _configure_make_and_build
252261 " Cannot change to PostgreSQL source directory: $abi_compare_root /$self ->{clone_name} for commit $commit_hash " ;
253262
254263 my $log_dir = " $abi_compare_root /logs/$commit_hash " ;
264+ mkdir $log_dir unless -d $log_dir ;
255265 my $make = $self -> {bfconf }-> {make };
256266 my $make_jobs = $self -> {bfconf }-> {make_jobs };
257267 my $config_opts = $self -> {bfconf }-> {config_opts } || [];
@@ -265,13 +275,14 @@ sub _configure_make_and_build
265275 my $cmdd =
266276 qq{ ./configure $configure_options --prefix=$abi_compare_root /install/} ;
267277
268- _log_command_output($self , $cmdd , $log_dir , ' configure' );
278+ _log_command_output($self , $cmdd , " $log_dir /configure.log " , ' configure' );
269279 my $make_cmd = $make ;
270280 $make_cmd = " $make -j $make_jobs "
271281 if ($make_jobs > 1);
272- _log_command_output($self , $make_cmd , $log_dir , ' make' );
282+ _log_command_output($self , $make_cmd , " $log_dir /make.log " , ' make' );
273283
274- _log_command_output($self , qq{ $make install} , $log_dir , ' makeinstall' );
284+ _log_command_output($self , qq{ $make install} ,
285+ " $log_dir /makeinstall.log" , ' makeinstall' );
275286
276287 return ;
277288}
@@ -318,12 +329,11 @@ sub _generate_abidw_xml
318329 {
319330 my $cmd =
320331 qq{ abidw --out-file "$output_file " "$input_path " $abidw_flags_str } ;
321- print time_str(), " Executing: $cmd \n " if $verbose ;
322-
323- my @abidw_log = run_log($cmd );
324- my $exit_status = $? >> 8;
325-
326- print_logs(\@abidw_log );
332+ my $log_dir = " $abi_compare_root /logs/$commit_hash " ;
333+ my $log_file = " $log_dir /abidw-$target_name .log" ;
334+ my $exit_status =
335+ _log_command_output($self , $cmd , $log_file ,
336+ " abidw for $target_name " , 1);
327337
328338 if ($exit_status )
329339 {
@@ -351,7 +361,6 @@ sub _generate_abidw_xml
351361sub _compare_and_log_abi_diff
352362{
353363 my ($self , $old_commit_hash , $new_commit_hash , $fail_fast ) = @_ ;
354-
355364 if (!defined $old_commit_hash || !defined $new_commit_hash )
356365 {
357366 print time_str(),
@@ -371,6 +380,7 @@ sub _compare_and_log_abi_diff
371380 my $log_dir = " $abi_compare_root /diffs" ;
372381 mkdir $log_dir unless -d $log_dir ;
373382 my $diff_found = 0;
383+ my @diff_logs ;
374384
375385 foreach my $key (keys %{ $self -> {binaries_rel_path } })
376386 {
@@ -381,17 +391,18 @@ sub _compare_and_log_abi_diff
381391 {
382392 my $log_file =
383393 " $log_dir /$key -$old_commit_hash -$new_commit_hash .log" ;
384- my @output = run_log(
385- " abidiff \" $old_file \" \" $new_file \" --leaf-changes-only --no-added-syms --show-bytes"
394+ my $exit_status = _log_command_output(
395+ $self ,
396+ qq{ abidiff "$old_file " "$new_file " --leaf-changes-only --no-added-syms --show-bytes} ,
397+ $log_file ,
398+ " abidiff for $key " ,
399+ 1
386400 );
387- my $exit_status = $? >> 8;
401+
388402 if ($exit_status != 0)
389403 {
390404 $diff_found = 1;
391- open my $fh , ' >' , $log_file
392- or warn " could not open $log_file : $! " ;
393- print $fh @output if $fh ;
394- close $fh if $fh ;
405+ push @diff_logs , $log_file ;
395406 print time_str(),
396407 " ABI difference found for $key . Log: $log_file \n "
397408 if $verbose ;
@@ -401,11 +412,11 @@ sub _compare_and_log_abi_diff
401412 elsif (-e $old_file xor -e $new_file )
402413 {
403414 $diff_found = 1;
415+ my $log_file =
416+ " $log_dir /$key -$old_commit_hash -$new_commit_hash .log" ;
404417 print time_str(),
405418 " ABI difference for $key : one file is missing (old: $old_file , new: $new_file ). Comparison skipped.\n "
406419 if $verbose ;
407- my $log_file =
408- " $log_dir /$key -$old_commit_hash -$new_commit_hash .log" ;
409420 open my $fh , ' >' , $log_file
410421 or warn " could not open $log_file : $! " ;
411422 if ($fh )
@@ -417,11 +428,38 @@ sub _compare_and_log_abi_diff
417428 . (-e $new_file ) . " )\n " ;
418429 close $fh ;
419430 }
431+ push @diff_logs , $log_file ;
420432 return 1 if $fail_fast ;
421433 }
422434 }
423435
424- if (!$diff_found )
436+ my $branch = $self -> {pgbranch };
437+ my $commit_info_file = " $log_dir /commit-info-$new_commit_hash .log" ;
438+ _log_command_output(
439+ $self ,
440+ qq{ git show $new_commit_hash --quiet --pretty=format:"%cn%n%ce%n%cd%n%s%n%n%b "} ,
441+ $commit_info_file ,
442+ " git show for $new_commit_hash " ,
443+ 1
444+ );
445+
446+ if ($diff_found )
447+ {
448+ my $log = $self -> {logs };
449+ my @saveout ;
450+ foreach my $diff_log (@diff_logs )
451+ {
452+ $log -> add_log($diff_log );
453+ }
454+
455+ $log -> add_log($commit_info_file );
456+ push (@saveout , $log -> log_string);
457+ my $orig_dir = Cwd::cwd();
458+ chdir $self -> {buildroot } . " /" . $self -> {pgbranch };
459+ writelog(" abi-comp-check-$new_commit_hash " , \@saveout );
460+ chdir $orig_dir ;
461+ }
462+ else
425463 {
426464 print time_str(),
427465 " No ABI differences found between $old_commit_hash and $new_commit_hash \n "
@@ -533,8 +571,8 @@ sub _process_commits_list
533571sub print_logs
534572{
535573 my ($logss ) = @_ ;
536-
537574 print " ABICompCheck: " , @$logss if @$logss ;
575+ return ;
538576}
539577
540578sub install
@@ -556,7 +594,8 @@ sub install
556594 print time_str(),
557595 " ABICompCheck: No previous commit hash found, comparing last 2 commits only.\n "
558596 if $verbose ;
559- my @two_commit_hashes = split /\n/, ` git rev-list --max-count=2 HEAD` ;
597+ my @two_commit_hashes = split /\n/,
598+ ` git rev-list --max-count=2 --abbrev-commit HEAD` ;
560599 print " Two commit hashes: @two_commit_hashes \n " if $verbose ;
561600 if (@two_commit_hashes < 2)
562601 {
@@ -570,7 +609,7 @@ sub install
570609 else
571610 {
572611 my @commits =
573- ` git rev-list --reverse $last_commit_hash ..$head_commit_hash ` ;
612+ ` git rev-list --reverse --abbrev-commit $last_commit_hash ..$head_commit_hash ` ;
574613 chomp @commits ;
575614 if (!@commits )
576615 {
@@ -586,6 +625,7 @@ sub install
586625 if $verbose ;
587626 _process_commits_list($self , \@commits , $last_commit_hash );
588627 }
628+ $steps_completed .= " ABICompCheck" ;
589629 $self -> {install_ok } = 1;
590630 return ;
591631}
0 commit comments