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'} = [];
$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);
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;
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'}}) {
}
$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;
}
return @{$config->{'preinstall'}};
}
+sub get_runscripts {
+ my ($config) = @_;
+ return @{$config->{'runscripts'}};
+}
+
###########################################################################
sub readrpmdeps {
$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>;
# 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 {
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
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:}
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
# 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
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
}
}
-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);
#######################################################################
print "$_ $fn{$packs{$_}}\n";
}
print "preinstall: @{$cf->{'preinstall'} || []}\n";
+ print "runscripts: @{$cf->{'runscripts'} || []}\n";
print "dist: $dist\n" if defined $dist;
exit(0);
}
print "$_ $fn{$packs{$_}}\n";
}
print "preinstall: @{$cf->{'preinstall'} || []}\n";
+print "runscripts: @{$cf->{'runscripts'} || []}\n";
print "dist: $dist\n" if defined $dist;
#!/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') {
$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;
}
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);
}
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" : '';
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
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
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
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
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
:> $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
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
$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);
#######################################################################