- runscripts
authorMichael Schröder <mls@suse.de>
Tue, 12 Dec 2006 07:45:29 +0000 (07:45 +0000)
committerMichael Schröder <mls@suse.de>
Tue, 12 Dec 2006 07:45:29 +0000 (07:45 +0000)
- macro blocks
- read_config_dist
- useful xen exit status

Build.pm
build
expanddeps
getmacros
getoptflags
init_buildsystem
substitutedeps

index d2eeaf7..059ac54 100644 (file)
--- a/Build.pm
+++ b/Build.pm
@@ -17,16 +17,59 @@ sub unify {
   return grep(delete($h{$_}), @_);
 }
 
+sub read_config_dist {
+  my ($dist, $archpath, $configdir) = @_;
+
+  my $arch = $archpath;
+  $arch = 'noarch' unless defined $arch;
+  $arch =~ s/:.*//;
+  $arch = 'noarch' if $arch eq '';
+  die("Please specify a distribution!\n") unless defined $dist;
+  if ($dist !~ /\//) {
+    $configdir = '.' unless defined $configdir;
+    $dist =~ s/-.*//;
+    $dist = "sl$dist" if $dist =~ /^\d/;
+    $dist = "$configdir/$dist.conf";
+    $dist = "$configdir/default.conf" unless -e $dist;
+  }
+  die("$dist: $!\n") unless -e $dist;
+  my $cf = read_config($arch, $dist);
+  die("$dist: parse error\n") unless $cf;
+  return $cf;
+}
+
 sub read_config {
   my ($arch, $cfile) = @_;
-  return undef unless !defined($cfile) || ref($cfile) || -e $cfile;
   my @macros = split("\n", $std_macros);
   push @macros, "%define _target_cpu $arch";
   push @macros, "%define _target_os linux";
   my $config = {'macros' => \@macros};
-  my (@spec);
-  read_spec($config, $cfile, \@spec) if $cfile;
+  my @config;
+  if (ref($cfile)) {
+    @config = @$cfile;
+  } elsif (defined($cfile)) {
+    local *CONF;
+    return undef unless open(CONF, '<', $cfile);
+    @config = <CONF>;
+    close CONF;
+    chomp @config;
+  }
+  # create verbatim macro blobs
+  my @newconfig;
+  while (@config) {
+    push @newconfig, shift @config;
+    next unless $newconfig[-1] =~ /^\s*macros:\s*$/si;
+    $newconfig[-1] = "macros:\n";
+    while (@config) {
+      my $l = shift @config;
+      last if $l =~ /^\s*:macros\s*$/si;
+      $newconfig[-1] .= "$l\n";
+    }
+  }
+  my @spec;
+  read_spec($config, \@newconfig, \@spec);
   $config->{'preinstall'} = [];
+  $config->{'runscripts'} = [];
   $config->{'required'} = [];
   $config->{'support'} = [];
   $config->{'keep'} = [];
@@ -35,14 +78,8 @@ sub read_config {
   $config->{'conflict'} = [];
   $config->{'substitute'} = {};
   $config->{'optflags'} = {};
-  my $inmacro = 0;
+  $config->{'rawmacros'} = '';
   for my $l (@spec) {
-    if ($inmacro) {
-      my $m = ref($l) ? $l->[0] : $l;
-      $m =~ s/^%/%define / unless @macros && $macros[-1] =~ /\\$/;
-      push @macros, $m;
-      next;
-    }
     $l = $l->[1] if ref $l;
     next unless defined $l;
     my @l = split(' ', $l);
@@ -50,10 +87,11 @@ sub read_config {
     my $ll = shift @l;
     my $l0 = lc($ll);
     if ($l0 eq 'macros:') {
-      $inmacro = 1;
+      $l =~ s/.*?\n//s;
+      $config->{'rawmacros'} .= $l;
       next;
     }
-    if ($l0 eq 'preinstall:' || $l0 eq 'required:' || $l0 eq 'support:' || $l0 eq 'keep:' || $l0 eq 'prefer:' || $l0 eq 'ignore:' || $l0 eq 'conflict:') {
+    if ($l0 eq 'preinstall:' || $l0 eq 'required:' || $l0 eq 'support:' || $l0 eq 'keep:' || $l0 eq 'prefer:' || $l0 eq 'ignore:' || $l0 eq 'conflict:' || $l0 eq 'runscripts:') {
       push @{$config->{substr($l0, 0, -1)}}, @l;
     } elsif ($l0 eq 'substitute:') {
       next unless @l;
@@ -67,7 +105,7 @@ sub read_config {
       warn("unknown keyword in config: $l0\n");
     }
   }
-  for my $l (qw{preinstall required support keep}) {
+  for my $l (qw{preinstall required support keep runscripts}) {
     $config->{$l} = [ unify(@{$config->{$l}}) ];
   }
   for my $l (keys %{$config->{'substitute'}}) {
@@ -97,6 +135,16 @@ sub read_config {
   }
   $config->{'conflicth'} = \%conflicts;
   $config->{'type'} = (grep {$_ eq 'rpm'} @{$config->{'preinstall'} || []}) ? 'spec' : 'dsc';
+  # add rawmacros to our macro list
+  if ($config->{'rawmacros'} ne '') {
+    for my $rm (split("\n", $config->{'rawmacros'})) {
+      if ((@macros && $macros[-1] =~ /\\$/) || $rm !~ /^%/) {
+       push @macros, $rm;
+      } else {
+       push @macros, "%define ".substr($rm, 1);
+      }
+    }
+  }
   return $config;
 }
 
@@ -167,6 +215,11 @@ sub get_preinstalls {
   return @{$config->{'preinstall'}};
 }
 
+sub get_runscripts {
+  my ($config) = @_;
+  return @{$config->{'runscripts'}};
+}
+
 ###########################################################################
 
 sub readrpmdeps {
@@ -500,6 +553,12 @@ sub read_spec {
       $inspec = 1;
       last unless @$specdata;
       $line = shift @$specdata;
+      if (ref $line) {
+       $line = $line->[0]; # verbatim line
+        push @$xspec, $line if $xspec;
+        $xspec->[-1] = [ $line, undef ] if $xspec && $skip;
+       next;
+      }
     } else {
       $inspec = 1;
       $line = <SPEC>;
diff --git a/build b/build
index ab4dab4..645f39d 100755 (executable)
--- a/build
+++ b/build
@@ -113,20 +113,20 @@ function clean_build_root () {
 #  cleanup_and_exit
 #
 cleanup_and_exit () {
+    test -z "$1" && set 0
     if test -n "$RUNNING_IN_XEN" ; then
        cd /
-       test -n "$XENSWAP" && swapoff "$XENSWAP"
+       if test -n "$XENSWAP" ; then
+           swapoff "$XENSWAP"
+           echo -n "BUILDSTATUS$1" >"$XENSWAP"
+       fi
        exec >&0 2>&0   # so that the logging tee finishes
        sleep 1         # wait till tee terminates
        kill -9 -1      # goodbye cruel world
        exec /bin/bash -c 'mount -n -o remount,ro / ; halt -f'
        halt -f
     fi
-    if test "$1" = 0 -o -z "$1" ; then
-        exit 0
-    else
-        exit $1
-    fi
+    exit $1
 }
 
 function create_baselibs {
@@ -449,6 +449,7 @@ if test -n "$XENIMAGE" ; then
     fi
     mount -oloop $XENIMAGE $BUILD_ROOT || cleanup_and_exit 1
     if test -n "$XENSWAP" ; then
+       dd if=/dev/zero of="$XENSWAP" bs=12 count=1 conv=notrunc 2>/dev/null
        mkswap "$XENSWAP"
     fi
 fi
@@ -556,6 +557,7 @@ for SPECFILE in $SPECFILES ; do
        test -n "$XENSWAP" && echo "XENSWAP='/dev/hda2'" >> $BUILD_ROOT/.build/build.data
        PERSONALITY=`perl -e 'print syscall(135, 0)."\n"'`
        echo "PERSONALITY='$PERSONALITY'" >> $BUILD_ROOT/.build/build.data
+       echo "MYHOSTNAME='`hostname`'" >> $BUILD_ROOT/.build/build.data
        umount $BUILD_ROOT
        XMROOT=file:$XENIMAGE
        XMROOT=${XMROOT/#file:\/dev/phy:}
@@ -574,6 +576,15 @@ for SPECFILE in $SPECFILES ; do
        else
            xm create -c $BUILD_DIR/xen.conf name="build:$XENID" $XENMEMORY $XMROOT $XMSWAP extra="init=/.build/build panic=1"
        fi
+       if test -n "$XENSWAP" ; then
+           BUILDSTATUS=`dd if="$XENSWAP" bs=12 count=1 2>/dev/null`
+           case $BUILDSTATUS in
+             BUILDSTATUS[0-9])
+               exit ${BUILDSTATUS#BUILDSTATUS}
+               ;;
+           esac
+           exit 1
+       fi
        exit 0
     fi
 
@@ -647,7 +658,7 @@ for SPECFILE in $SPECFILES ; do
        # do buildrequires/release substitution
        substitutedeps $RELEASE --dist "$BUILD_DIST" --archpath "$BUILD_ARCH" --configdir "$BUILD_DIR/configs" "$BUILD_ROOT$TOPDIR/SOURCES/$SPECFILE" "$BUILD_ROOT/.spec.new" || cleanup_and_exit 1
        # extract macros from configuration
-       getmacros --dist "$BUILD_DIST" --configdir "$BUILD_DIR/configs" > $BUILD_ROOT/root/.rpmmacros
+       getmacros --dist "$BUILD_DIST" --archpath "$BUILD_ARCH" --configdir "$BUILD_DIR/configs" > $BUILD_ROOT/root/.rpmmacros
        test $BUILD_USER = abuild && cp -p $BUILD_ROOT/root/.rpmmacros $BUILD_ROOT/home/abuild/.rpmmacros
        # extract optflags from configuration
        getoptflags --dist "$BUILD_DIST" --configdir "$BUILD_DIR/configs" --archpath "$BUILD_ARCH" > $BUILD_ROOT/root/.rpmrc
@@ -686,6 +697,8 @@ for SPECFILE in $SPECFILES ; do
     echo -----------------------------------------------------------------
     mount -n -tproc none $BUILD_ROOT/proc 2> /dev/null
     mount -n -tdevpts none $BUILD_ROOT/dev/pts 2> /dev/null
+    test -n "$RUNNING_IN_XEN" && ifconfig lo 127.0.0.1 up
+    test -n "$RUNNING_IN_XEN" -a -n "$MYHOSTNAME" && hostname "$MYHOSTNAME"
 
     BUILD_SUCCEDED=false
 
index 825429e..e7518fe 100755 (executable)
@@ -107,14 +107,7 @@ if (!defined($dist) || $dist eq '') {
   }
 }
 
-my $cdist = $dist;
-$cdist =~ s/-.*//;
-$cdist = "sl$cdist" if $cdist =~ /^\d/;
-my $cf = Build::read_config($archs[0], "$configdir/$cdist.conf");
-if (!$cf) {
-  $cf = Build::read_config($archs[0], "$configdir/default.conf");
-  die("default config not found\n") unless $cf;
-}
+my $cf = Build::read_config_dist($dist, $archs[0], $configdir);
 
 #######################################################################
 
@@ -149,6 +142,7 @@ if ($useusedforbuild) {
     print "$_ $fn{$packs{$_}}\n";
   }
   print "preinstall: @{$cf->{'preinstall'} || []}\n";
+  print "runscripts: @{$cf->{'runscripts'} || []}\n";
   print "dist: $dist\n" if defined $dist;
   exit(0);
 }
@@ -217,4 +211,5 @@ for (@bdeps) {
   print "$_ $fn{$packs{$_}}\n";
 }
 print "preinstall: @{$cf->{'preinstall'} || []}\n";
+print "runscripts: @{$cf->{'runscripts'} || []}\n";
 print "dist: $dist\n" if defined $dist;
index 76429b9..4df5625 100755 (executable)
--- a/getmacros
+++ b/getmacros
@@ -1,8 +1,13 @@
 #!/usr/bin/perl -w
 
+BEGIN {
+  unshift @INC, ($::ENV{'BUILD_DIR'} || '/usr/lib/build');
+}
+
+use Build;
 use strict;
 
-my ($dist, $configdir);
+my ($dist, $configdir, $archs);
 
 while (@ARGV)  {
   if ($ARGV[0] eq '--dist') {
@@ -10,6 +15,11 @@ while (@ARGV)  {
     $dist = shift @ARGV;
     next;
   }
+  if ($ARGV[0] eq '--archpath') {
+    shift @ARGV;
+    $archs = shift @ARGV;
+    next;   
+  }
   if ($ARGV[0] eq '--configdir') {
     shift @ARGV;
     $configdir = shift @ARGV;
@@ -17,23 +27,7 @@ while (@ARGV)  {
   }
   last;
 }
-$configdir = '.' unless defined $configdir;
-$dist = '' unless defined $dist;
-
-die("Usage: getmacros --dist <dist> [--configdir <configdir>]\n") if !defined($dist) || @ARGV;
-local *F;
-if ($dist =~ /\//) {
-  open(F, '<', $dist) || die("$dist: $!\n");
-} else {
-  $dist =~ s/-.*//;
-  $dist = "sl$dist" if $dist =~ /^\d/;
-  open(F, '<', "$configdir/$dist.conf") || open(F, '<', "$configdir/default.conf") || die("config not found\n");
-}
-my $inmacro = 0;
-while(<F>) {
-  if (!$inmacro) {
-    $inmacro = 1 if /^\s*macros:/i;
-    next;
-  }
-  print;
-}
+die("Usage: getmacros --dist <dist> [--configdir <configdir>]\n") if @ARGV;
+my $cf = Build::read_config_dist($dist, $archs, $configdir);
+print $cf->{'rawmacros'} if exists $cf->{'rawmacros'};
+exit(0);
index abcc5a1..69f134a 100755 (executable)
@@ -28,29 +28,10 @@ while (@ARGV)  {
   }
   last;
 }
-$configdir = '.' unless defined $configdir;
-$archs = '' unless defined $archs;
-$dist = '' unless defined $dist;
 
-die("Usage: getoptflags --dist <dist> --archpath <archpath> [--configdir <configdir>]\n") if !defined($dist) || @ARGV;
-
-my @archs = split(':', $archs);
-push @archs, 'noarch' unless grep {$_ eq 'noarch'} @archs;
-
-my $cf;
-if ($dist =~ /\//) {
-  die("$dist: $!\n") unless -e $dist;
-  $cf = Build::read_config($archs[0], $dist);
-} else {
-  $dist =~ s/-.*//;
-  $dist = "sl$dist" if $dist =~ /^\d/;
-  $cf = Build::read_config($archs[0], "$configdir/$dist.conf");
-  if (!$cf) {
-    $cf = Build::read_config($archs[0], "$configdir/default.conf");
-  }
-}
-die("config not found\n") unless $cf;
+die("Usage: getoptflags --dist <dist> --archpath <archpath> [--configdir <configdir>]\n") if @ARGV;
 
+my $cf = Build::read_config_dist($dist, $archs, $configdir);
 exit 0 unless $cf->{'optflags'};
 my $all = $cf->{'optflags'}->{'*'};
 $all = defined($all) && $all ne '' ? " $all" : '';
index 6ee5a92..83a9d26 100755 (executable)
@@ -81,26 +81,30 @@ function preinstall {
         cd $BUILD_ROOT || cleanup_and_exit 1
        if test -e "$BUILD_ROOT/.init_b_cache/rpms/$1.rpm" ; then
            rpm2cpio "$BUILD_ROOT/.init_b_cache/rpms/$1.rpm" | cpio --extract --unconditional --preserve-modification-time --make-directories --no-absolute-filenames --quiet
-           rpm -qp --nodigest --nosignature --qf "%{PREIN}" "$BUILD_ROOT/.init_b_cache/rpms/$1.rpm" > .init_b_cache/scripts/$1.pre
-           rpm -qp --nodigest --nosignature --qf "%{POSTIN}" "$BUILD_ROOT/.init_b_cache/rpms/$1.rpm" > .init_b_cache/scripts/$1.post
-           echo -n '(none)' > .init_b_cache/scripts/.none
-           cmp -s .init_b_cache/scripts/$1.pre .init_b_cache/scripts/.none && rm -f .init_b_cache/scripts/$1.pre
-           cmp -s .init_b_cache/scripts/$1.post .init_b_cache/scripts/.none && rm -f .init_b_cache/scripts/$1.post
-           rm -f .init_b_cache/scripts/.none
+           if test -e .init_b_cache/scripts/$1.run ; then
+               rpm -qp --nodigest --nosignature --qf "%{PREIN}" "$BUILD_ROOT/.init_b_cache/rpms/$1.rpm" > .init_b_cache/scripts/$1.pre
+               rpm -qp --nodigest --nosignature --qf "%{POSTIN}" "$BUILD_ROOT/.init_b_cache/rpms/$1.rpm" > .init_b_cache/scripts/$1.post
+               echo -n '(none)' > .init_b_cache/scripts/.none
+               cmp -s .init_b_cache/scripts/$1.pre .init_b_cache/scripts/.none && rm -f .init_b_cache/scripts/$1.pre
+               cmp -s .init_b_cache/scripts/$1.post .init_b_cache/scripts/.none && rm -f .init_b_cache/scripts/$1.post
+               rm -f .init_b_cache/scripts/.none
+           fi
        elif test -e "$BUILD_ROOT/.init_b_cache/rpms/$1.deb" ; then
            ar x "$BUILD_ROOT/.init_b_cache/rpms/$1.deb" control.tar.gz data.tar.gz
            mkdir -p .init_b_cache/scripts/control
            tar -C .init_b_cache/scripts/control -xzf control.tar.gz
            tar xzf data.tar.gz
-           test -e .init_b_cache/scripts/control/preinst && mv .init_b_cache/scripts/control/preinst .init_b_cache/scripts/$1.pre
-           test -e .init_b_cache/scripts/control/postinst && mv .init_b_cache/scripts/control/postinst .init_b_cache/scripts/$1.post
+           if test -e .init_b_cache/scripts/$1.run ; then
+               test -e .init_b_cache/scripts/control/preinst && mv .init_b_cache/scripts/control/preinst .init_b_cache/scripts/$1.pre
+               test -e .init_b_cache/scripts/control/postinst && mv .init_b_cache/scripts/control/postinst .init_b_cache/scripts/$1.post
+           fi
            rm -rf .init_b_cache/scripts/control control.tar.gz data.tar.gz
        else
            echo "warning: package $1 does not exist"
        fi
     fi
     if test -n "$2" ; then
-        for PKG in $PACKAGES_TO_PREINSTALL ; do
+        for PKG in $PACKAGES_TO_RUNSCRIPTS ; do
             if test -e "$BUILD_ROOT/.init_b_cache/scripts/$PKG.pre" ; then
                 echo "running $PKG preinstall script"
                if test -e "$BUILD_ROOT/.init_b_cache/rpms/$PKG.rpm" ; then
@@ -290,6 +294,7 @@ else
        rm -f $BUILD_IS_RUNNING
        while read PKG SRC ; do
           test "$PKG" = "preinstall:" && continue
+          test "$PKG" = "runscripts:" && continue
           test "$PKG" = "dist:" && continue
           echo "${SRC##*/}"
        done < $BUILD_ROOT/.init_b_cache/rpmlist
@@ -298,6 +303,9 @@ else
     fi
 
     PACKAGES_TO_INSTALL=
+    PACKAGES_TO_PREINSTALL=
+    PACKAGES_TO_RUNSCRIPTS=
+    RUNSCRIPTS_SEEN=
     GUESSED_DIST=unknown
     mkdir -p $BUILD_ROOT/.init_b_cache/rpms
     while read PKG SRC ; do
@@ -305,6 +313,11 @@ else
            PACKAGES_TO_PREINSTALL=$SRC
            continue
        fi
+       if test "$PKG" = "runscripts:" ; then
+           RUNSCRIPTS_SEEN=true
+           PACKAGES_TO_RUNSCRIPTS=$SRC
+           continue
+       fi
        if test "$PKG" = "dist:" ; then
            GUESSED_DIST=$SRC
            continue
@@ -312,6 +325,10 @@ else
        ln -s "$SRC" "$BUILD_ROOT/.init_b_cache/rpms/$PKG.${SRC##*.}"
        PACKAGES_TO_INSTALL="$PACKAGES_TO_INSTALL $PKG"
     done < $RPMLIST
+
+    # compatibility...
+    test -z "$RUNSCRIPTS_SEEN" && PACKAGES_TO_RUNSCRIPTS="$PACKAGES_TO_PREINSTALL"
+
     echo "$GUESSED_DIST" > $BUILD_ROOT/.guessed_dist
     PSUF=rpm
     test -L $BUILD_ROOT/.init_b_cache/rpms/rpm.rpm || PSUF=deb
@@ -342,6 +359,9 @@ if test ! -f $BUILD_ROOT/var/lib/rpm/packages.rpm -a ! -f $BUILD_ROOT/var/lib/rp
        :> $BUILD_ROOT/var/log/dpkg.log
        :> $BUILD_ROOT/etc/ld.so.conf
     fi
+    for PKG in $PACKAGES_TO_RUNSCRIPTS ; do
+       : > $BUILD_ROOT/.init_b_cache/scripts/$PKG.run
+    done
     for PKG in $PACKAGES_TO_PREINSTALL ; do
        preinstall ${PKG##*/}
     done
@@ -356,7 +376,7 @@ fi
 if test -n "$PREPARE_XEN" ; then
     mkdir -p $BUILD_ROOT/.build
     echo "PACKAGES_TO_INSTALL='${PACKAGES_TO_INSTALL//\'/\'\\\'\'}'" > $BUILD_ROOT/.build/init_buildsystem.data
-    echo "PACKAGES_TO_PREINSTALL='${PACKAGES_TO_PREINSTALL//\'/\'\\\'\'}'" >> $BUILD_ROOT/.build/init_buildsystem.data
+    echo "PACKAGES_TO_RUNSCRIPTS='${PACKAGES_TO_RUNSCRIPTS//\'/\'\\\'\'}'" >> $BUILD_ROOT/.build/init_buildsystem.data
     echo "PSUF='$PSUF'" >> $BUILD_ROOT/.build/init_buildsystem.data
     echo "copying packages..."
     for PKG in $PACKAGES_TO_INSTALL ; do
index a95aef2..dfdf836 100755 (executable)
@@ -21,42 +21,23 @@ while (@ARGV)  {
     $archs = shift @ARGV;
     next;
   }
-  if ($ARGV[0] eq '--release') {
+  if ($ARGV[0] eq '--configdir') {
     shift @ARGV;
-    $release = shift @ARGV;
+    $configdir = shift @ARGV;
     next;
   }
-  if ($ARGV[0] eq '--configdir') {
+  if ($ARGV[0] eq '--release') {
     shift @ARGV;
-    $configdir = shift @ARGV;
+    $release = shift @ARGV;
     next;
   }
   last;
 }
-$configdir = '.' unless defined $configdir;
-$archs = '' unless defined $archs;
-$dist = '' unless defined $dist;
-
 die("Usage: substitutedeps --dist <dist> --archpath <archpath> [--configdir <configdir>] <specin> <specout>\n") unless @ARGV == 2;
 my $spec = $ARGV[0];
 my $newspec = $ARGV[1];
 
-my @archs = split(':', $archs);
-push @archs, 'noarch' unless grep {$_ eq 'noarch'} @archs;
-
-my $cf;
-if ($dist =~ /\//) {
-  die("$dist: $!\n") unless -e $dist;
-  $cf = Build::read_config($archs[0], $dist);
-} else {
-  $dist =~ s/-.*//;
-  $dist = "sl$dist" if $dist =~ /^\d/;
-  $cf = Build::read_config($archs[0], "$configdir/$dist.conf");
-  if (!$cf) {
-    $cf = Build::read_config($archs[0], "$configdir/default.conf");
-  }
-}
-die("config not found\n") unless $cf;
+my $cf = Build::read_config_dist($dist, $archs, $configdir);
 
 #######################################################################