Skip to content

Commit

Permalink
- runscripts
Browse files Browse the repository at this point in the history
- macro blocks
- read_config_dist
- useful xen exit status
  • Loading branch information
mlschroe committed Dec 12, 2006
1 parent 8800263 commit 016e048
Show file tree
Hide file tree
Showing 7 changed files with 147 additions and 104 deletions.
85 changes: 72 additions & 13 deletions Build.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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'} = [];
Expand All @@ -35,25 +78,20 @@ 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);
next unless @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;
Expand All @@ -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'}}) {
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -167,6 +215,11 @@ sub get_preinstalls {
return @{$config->{'preinstall'}};
}

sub get_runscripts {
my ($config) = @_;
return @{$config->{'runscripts'}};
}

###########################################################################

sub readrpmdeps {
Expand Down Expand Up @@ -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>;
Expand Down
27 changes: 20 additions & 7 deletions build
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:}
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
11 changes: 3 additions & 8 deletions expanddeps
Original file line number Diff line number Diff line change
Expand Up @@ -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);

#######################################################################

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
36 changes: 15 additions & 21 deletions getmacros
Original file line number Diff line number Diff line change
@@ -1,39 +1,33 @@
#!/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') {
shift @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;
next;
}
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);
23 changes: 2 additions & 21 deletions getoptflags
Original file line number Diff line number Diff line change
Expand Up @@ -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" : '';
Expand Down
Loading

0 comments on commit 016e048

Please sign in to comment.