This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
In bisect-runner.pl, "patch" ext/IPC/SysV/SysV.xs to the current SHMLBA code.
authorNicholas Clark <nick@ccl4.org>
Fri, 7 Oct 2011 13:33:31 +0000 (15:33 +0200)
committerNicholas Clark <nick@ccl4.org>
Fri, 7 Oct 2011 13:33:31 +0000 (15:33 +0200)
For some historical revisions, it's not good enough simply taking out the
first #include <asm/page.h>, because other code changes in that area can
break the build. Instead, replace any old version of that #ifdef forest with
the current code. Additionally, do this editing unconditionally, even if the
target is "miniperl". Skipping it on target "miniperl" causes surprises if
one is trying to debug the build by getting bisect-runner.pl to build to
miniperl (or skip), and then using make lib/auto/IPC/SysV/SysV.so
as the test case.

This adds an edit_file() function. Move apply_patch() next to it, to group
related functions together.

Porting/bisect-runner.pl

index 22137ab..db498da 100755 (executable)
@@ -389,6 +389,28 @@ sub extract_from_file {
     return;
 }
 
+sub edit_file {
+    my ($file, $munger) = @_;
+    local $/;
+    open my $fh, '<', $file or die "Can't open $file: $!";
+    my $orig = <$fh>;
+    die "Can't read $file: $!" unless defined $orig && close $fh;
+    my $new = $munger->($orig);
+    return if $new eq $orig;
+    open $fh, '>', $file or die "Can't open $file: $!";
+    print $fh $new or die "Can't print to $file: $!";
+    close $fh or die "Can't close $file: $!";
+}
+
+sub apply_patch {
+    my $patch = shift;
+
+    my ($file) = $patch =~ qr!^diff.*a/(\S+) b/\1!;
+    open my $fh, '|-', 'patch', '-p1' or die "Can't run patch: $!";
+    print $fh $patch;
+    close $fh or die "Can't patch $file: $?, $!";
+}
+
 sub clean {
     if ($options{clean}) {
         # Needed, because files that are build products in this checked out
@@ -454,15 +476,6 @@ sub match_and_exit {
                     'no matches for', $match);
 }
 
-sub apply_patch {
-    my $patch = shift;
-
-    my ($file) = $patch =~ qr!^diff.*a/(\S+) b/\1!;
-    open my $fh, '|-', 'patch', '-p1' or die "Can't run patch: $!";
-    print $fh $patch;
-    close $fh or die "Can't patch $file: $?, $!";
-}
-
 # Not going to assume that system perl is yet new enough to have autodie
 system 'git clean -dxf </dev/null' and die;
 
@@ -848,6 +861,45 @@ index 03c4d48..3c814a2 100644
 EOPATCH
 }
 
+if ($major < 10 and -f 'ext/IPC/SysV/SysV.xs') {
+    edit_file('ext/IPC/SysV/SysV.xs', sub {
+                  my $xs = shift;
+                  my $fixed = <<'EOFIX';
+
+#include <sys/types.h>
+#if defined(HAS_MSG) || defined(HAS_SEM) || defined(HAS_SHM)
+#ifndef HAS_SEM
+#   include <sys/ipc.h>
+#endif
+#   ifdef HAS_MSG
+#       include <sys/msg.h>
+#   endif
+#   ifdef HAS_SHM
+#       if defined(PERL_SCO) || defined(PERL_ISC)
+#           include <sys/sysmacros.h>  /* SHMLBA */
+#       endif
+#      include <sys/shm.h>
+#      ifndef HAS_SHMAT_PROTOTYPE
+           extern Shmat_t shmat (int, char *, int);
+#      endif
+#      if defined(HAS_SYSCONF) && defined(_SC_PAGESIZE)
+#          undef  SHMLBA /* not static: determined at boot time */
+#          define SHMLBA sysconf(_SC_PAGESIZE)
+#      elif defined(HAS_GETPAGESIZE)
+#          undef  SHMLBA /* not static: determined at boot time */
+#          define SHMLBA getpagesize()
+#      endif
+#   endif
+#endif
+EOFIX
+                  $xs =~ s!
+#include <sys/types\.h>
+.*
+(#ifdef newCONSTSUB|/\* Required)!$fixed$1!ms;
+                  return $xs;
+              });
+}
+
 # Parallel build for miniperl is safe
 system "make $j miniperl </dev/null";
 
@@ -871,25 +923,6 @@ if ($target ne 'miniperl') {
         }
     }
 
-    if ($major < 10
-       and -f 'ext/IPC/SysV/SysV.xs',
-       and my ($line) = extract_from_file('ext/IPC/SysV/SysV.xs',
-                                          qr!^(# *include <asm/page.h>)$!)) {
-       apply_patch(<<"EOPATCH");
-diff --git a/ext/IPC/SysV/SysV.xs b/ext/IPC/SysV/SysV.xs
-index 35a8fde..62a7965 100644
---- a/ext/IPC/SysV/SysV.xs
-+++ b/ext/IPC/SysV/SysV.xs
-\@\@ -4,7 +4,6 \@\@
- #include <sys/types.h>
- #ifdef __linux__
--$line
- #endif
- #if defined(HAS_MSG) || defined(HAS_SEM) || defined(HAS_SHM)
- #ifndef HAS_SEM
-EOPATCH
-    }
     system "make $j $real_target </dev/null";
 }