@@ -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} , " $log_dir /makeinstall.log" ,
285+ ' 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,14 @@ 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"
386- );
387- my $exit_status = $? >> 8;
394+ my $exit_status =
395+ _log_command_output( $self , qq{ abidiff "$old_file " "$new_file " --leaf-changes-only --no-added-syms --show-bytes} , $log_file , " abidiff for $key " ,
396+ 1 );
397+
388398 if ($exit_status != 0)
389399 {
390400 $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 ;
401+ push @diff_logs , $log_file ;
395402 print time_str(),
396403 " ABI difference found for $key . Log: $log_file \n "
397404 if $verbose ;
@@ -401,11 +408,11 @@ sub _compare_and_log_abi_diff
401408 elsif (-e $old_file xor -e $new_file )
402409 {
403410 $diff_found = 1;
411+ my $log_file =
412+ " $log_dir /$key -$old_commit_hash -$new_commit_hash .log" ;
404413 print time_str(),
405414 " ABI difference for $key : one file is missing (old: $old_file , new: $new_file ). Comparison skipped.\n "
406415 if $verbose ;
407- my $log_file =
408- " $log_dir /$key -$old_commit_hash -$new_commit_hash .log" ;
409416 open my $fh , ' >' , $log_file
410417 or warn " could not open $log_file : $! " ;
411418 if ($fh )
@@ -417,11 +424,33 @@ sub _compare_and_log_abi_diff
417424 . (-e $new_file ) . " )\n " ;
418425 close $fh ;
419426 }
427+ push @diff_logs , $log_file ;
420428 return 1 if $fail_fast ;
421429 }
422430 }
423431
424- if (!$diff_found )
432+ my $branch = $self -> {pgbranch };
433+ my $commit_info_file = " $log_dir /commit-info-$new_commit_hash .log" ;
434+ _log_command_output($self , qq{ git show $new_commit_hash --quiet --pretty=format:"%cn%n%ce%n%cd%n%s%n%n%b "} , $commit_info_file ,
435+ " git show for $new_commit_hash " , 1);
436+
437+ if ($diff_found )
438+ {
439+ my $log = $self -> {logs };
440+ my @saveout ;
441+ foreach my $diff_log (@diff_logs )
442+ {
443+ $log -> add_log($diff_log );
444+ }
445+
446+ $log -> add_log($commit_info_file );
447+ push (@saveout , $log -> log_string);
448+ my $orig_dir = Cwd::cwd();
449+ chdir $self -> {buildroot } . " /" . $self -> {pgbranch };
450+ writelog(" abi-comp-check-$new_commit_hash " , \@saveout );
451+ chdir $orig_dir ;
452+ }
453+ else
425454 {
426455 print time_str(),
427456 " No ABI differences found between $old_commit_hash and $new_commit_hash \n "
@@ -556,7 +585,7 @@ sub install
556585 print time_str(),
557586 " ABICompCheck: No previous commit hash found, comparing last 2 commits only.\n "
558587 if $verbose ;
559- my @two_commit_hashes = split /\n/, ` git rev-list --max-count=2 HEAD` ;
588+ my @two_commit_hashes = split /\n/, ` git rev-list --max-count=2 --abbrev-commit HEAD` ;
560589 print " Two commit hashes: @two_commit_hashes \n " if $verbose ;
561590 if (@two_commit_hashes < 2)
562591 {
@@ -570,7 +599,7 @@ sub install
570599 else
571600 {
572601 my @commits =
573- ` git rev-list --reverse $last_commit_hash ..$head_commit_hash ` ;
602+ ` git rev-list --reverse --abbrev-commit $last_commit_hash ..$head_commit_hash ` ;
574603 chomp @commits ;
575604 if (!@commits )
576605 {
@@ -586,6 +615,7 @@ sub install
586615 if $verbose ;
587616 _process_commits_list($self , \@commits , $last_commit_hash );
588617 }
618+ $steps_completed .= " ABICompCheck" ;
589619 $self -> {install_ok } = 1;
590620 return ;
591621}
0 commit comments