aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Scherer <misc@mandriva.com>2004-10-24 17:08:56 +0000
committerMichael Scherer <misc@mandriva.com>2004-10-24 17:08:56 +0000
commit0b66d96352ca4b3923735053642a65783d61e69a (patch)
tree7b3ddab4f9a2d4f5ef9bc8f3a172bde28293cabe
parenteee422be4762f56c2d5346f04bb8861b1f33c6e1 (diff)
downloadbootsplash-0b66d96352ca4b3923735053642a65783d61e69a.tar
bootsplash-0b66d96352ca4b3923735053642a65783d61e69a.tar.gz
bootsplash-0b66d96352ca4b3923735053642a65783d61e69a.tar.bz2
bootsplash-0b66d96352ca4b3923735053642a65783d61e69a.tar.xz
bootsplash-0b66d96352ca4b3923735053642a65783d61e69a.zip
- allow to build from a spec file
- add noupdate, to not modify the specfile - allow multiple SRPM dir for --srpms - add berlios.de autodetection - remove some dead code
-rwxr-xr-xrpmbuildupdate220
1 files changed, 137 insertions, 83 deletions
diff --git a/rpmbuildupdate b/rpmbuildupdate
index c9fd26d..1a86dfb 100755
--- a/rpmbuildupdate
+++ b/rpmbuildupdate
@@ -15,6 +15,7 @@
# TODO
# do not hardcode sudo urpmi command ( to use --deps on cluster )
# rework configuration option
+# add more dwimess ( ie, autodetect if we give a spec, a src.rpm, or a package name )
use strict;
use AppConfig;
@@ -26,6 +27,8 @@ use File::Spec;
my %config;
+my ($log, $top, $rpm);
+
sub system_die {
my ($command, $message) = @_;
$message ||= "$command failed";
@@ -33,13 +36,7 @@ sub system_die {
system($command) and die $message;
}
-sub build_from_src {
- $_ = shift;
- my $nv = shift;
- my $b = basename($_);
- if ($b =~ m|^(.*)-([^-]+)-([^-]+)\.[^\.]+\.rpm|)
- { build($1, $nv, $_) }
-}
+
sub file_not_found {
my ($basename) = @_;
@@ -114,56 +111,102 @@ sub fetch_http {
return ! file_not_found($basename);
}
-sub build {
- my $pkg = shift;
- my $newversion = shift;
- my $pkgrpm = shift;
- $pkgrpm = File::Spec->rel2abs($pkgrpm);
- my ($rpm, $log);
- my ($release_prefix, $newrelease, $message);
- my $found = 0;
- my ($version, $release);
- my ($spec, @url, @rpms, %specvars);
- my $top = $config{top} || `rpm --eval '%_topdir'`;
+sub fill_global_variable {
+ my ($pkgrpm) = @_;
+ $top = $config{top} || `rpm --eval '%_topdir'`;
chomp($top);
- chdir("$top/SOURCES") or die "Unable to chdir to $top/SOURCES";
-
- $rpm = qq(rpm --define "_topdir $top");
-
- if ($newversion) {
- print "===> Building $pkg $newversion\n";
- } else {
- print "===> Rebuilding $pkg\n";
+ if ($config{log})
+ {
+ my $basename = basename($pkgrpm);
+ mkdir_p("$top/log");
+ my $logfile = "$top/log/${basename}.log";
+ $log = " >> $logfile 2>&1";
+ print "Logs are in $logfile\n";
+ } else {
+ $log = "";
}
+ $rpm = qq(rpm --define "_topdir $top");
+}
-
-
+
+sub build_from_spec {
+ my ($spec_path, $newversion) = @_;
+ my $rpm_tag = (split(/\n/,`rpm -q --queryformat '%{NAME} %{VERSION} %{RELEASE}\n' --specfile $spec_path`))[0];
+ my ($pkg, $version, $release) = split(/ /, $rpm_tag);
+ fill_global_variable($pkg);
+ chdir("$top/SOURCES") or die "Unable to chdir to $top/SOURCES";
+ build($spec_path,$pkg,$version,$release,$newversion);
+}
+
+sub build_from_repository {
+ my ($pkg, $newversion) = @_;
my $pkge = $pkg;
$pkge =~ s/\+/\\+/;
-
- # Search for file if we do not use --src
- if (!$config{src})
- {
- opendir(MP, $config{srpms}) or die "$config{srpms} is not a directory";
- @rpms = readdir(MP);
+ my $found = 0;
+ my $pkgrpm;
+ foreach my $srpm_dir (split(/,/, $config{srpms})) {
+ opendir(MP, $srpm_dir) or die "$srpm_dir is not a directory";
+ my @rpms = readdir(MP);
foreach (@rpms)
{
if (m|^($pkge)-([^-]+)-([^-]+)\.[^\.]+\.rpm|)
- { $config{src} = $pkgrpm = "$config{srpms}/$_"; $version = $2; $release = $3; $found = 1; last }
+ { $config{src} = $pkgrpm = "$srpm_dir/$_"; $found = 1; last }
+ #{ $config{src} = $pkgrpm = "$srpm_dir/$_"; $version = $2; $release = $3; $found = 1; last }
}
-
closedir(MP);
-
- if ($found == 0) { print "Package $pkg has no source, skipping.\n\n"; return }
- } else {
- my $pkgrpm_basename = basename($pkgrpm);
- if ($pkgrpm_basename =~ m|^(.*)-([^-]+)-([^-]+)\.[^\.]+\.rpm|)
- { $pkg=$1; $version = $2; $release = $3; $found = 1 }
+ last if $found;
+ }
+ if ($found == 0) { print "Package $pkg has no source, skipping.\n\n"; return }
+ build_from_src($pkgrpm,$newversion);
+}
+
+sub build_from_src {
+ $_ = shift;
+ my $newversion = shift;
+ my $b = basename($_);
+ die "Cannot parse the name of rpm " if $b !~ m|^(.*)-([^-]+)-([^-]+)\.[^\.]+\.rpm|;
+
+ my $pkgrpm = $_;
+ my $pkg = $1;
+
+ $pkgrpm = File::Spec->rel2abs($pkgrpm);
+ fill_global_variable($pkgrpm);
+ my $found = 0;
+ my ($version, $release);
+
+ chdir("$top/SOURCES") or die "Unable to chdir to $top/SOURCES";
+
+ my $pkge = $pkg;
+ $pkge =~ s/\+/\\+/;
+
+ my $pkgrpm_basename = basename($pkgrpm);
+ if ($pkgrpm_basename =~ m|^(.*)-([^-]+)-([^-]+)\.[^\.]+\.rpm|)
+ { $pkg=$1; $version = $2; $release = $3 }
+
+ if ($config{deps})
+ {
+ system_die("sudo /usr/sbin/urpmi --auto --force $pkgrpm $log");
+ }
+
+ system_die("$rpm -ivh $pkgrpm $log");
+
+ my $spec_path="../SPECS/$pkg.spec";
+ build($spec_path,$pkg,$version,$release,$newversion);
+}
+
+sub build {
+ my ($spec_path, $pkg, $version, $release, $newversion) = @_;
+ my ($message, $spec, @url, %specvars);
+ my ($newrelease, $release_prefix) = ($1,$2) if $release =~ /^(.*\d+)(\D*)$/g;
+
+ if ($newversion) {
+ print "===> Building $pkg $newversion\n";
+ } else {
+ print "===> Rebuilding $pkg\n";
}
- ($newrelease,$release_prefix) = ($1,$2) if $release =~ /^(.*\d+)(\D*)$/g;
if (! defined($newversion)) {
$newversion = $version;
@@ -176,33 +219,10 @@ sub build {
$newrelease = "1$release_prefix";
}
$newrelease = $config{release} if $config{release};
-
- if ($config{log})
- {
- my $basename = basename($pkgrpm);
- mkdir_p("$top/log");
- $log = " >> $top/log/${basename}.log 2>&1";
- } else {
- $log = "";
- }
-
- if ($config{deps})
- {
- system_die("sudo /usr/sbin/urpmi --auto --force $pkgrpm $log");
- }
-
- if ($config{src})
- {
- system_die("$rpm -ivh $pkgrpm $log");
- $config{src} = 0;
- } elsif (!$config{nosource}) {
- system_die("/usr/sbin/urpmi --install-src --force $config{srpms} $log");
- }
- $found = 0;
my $SPECFILE;
- if (!open($SPECFILE, "../SPECS/$pkg.spec"))
+ if (!open($SPECFILE, $spec_path))
{
print STDERR "Unable to open spec file !\n";
return;
@@ -244,18 +264,25 @@ sub build {
close($SPECFILE);
- if (!$url[0] )
+ if (!$url[0])
{
print "URL of sources was not found ! Trying to guess it with url tag ...\n";
+
my $url = $specvars{url};
+ #TODO some factorisation
+ # add gna.org, savanah, jabberstudio
if ($url =~ m!http://(.*)\.((?:sourceforge|sf)\.net)/(.*)!)
{
$url="http://prdownloads.$2/$1/$3" unless $1 eq 'prdownloads';
}
+ if ($url =~ m!http://(.*)\.berlios.de/(.*)!)
+ {
+ $url="http://download.berlios.de/$1/$2" unless $1 eq 'download';
+ }
push(@url, "$url/$tar_ball")
}
- $found = 0;
+ my $found = 0;
foreach (@url)
{
@@ -288,6 +315,9 @@ sub build {
my @rpmsrh = readdir(MP);
my $pkgrpmrh;
+ my $pkge = $pkg;
+ $pkge =~ s/\+/\\+/;
+
foreach (@rpmsrh)
{
if (m|^($pkge)-([^-]+)-([^-]+)\.[^\.]+\.rpm|)
@@ -335,11 +365,13 @@ sub build {
# some specs have no source ( php )
$found++ if ! $tar_ball;
- # TODO use output ?
- open($SPECFILE, ">../SPECS/$pkg.spec") or die "Unable to open $pkg.spec";
- print $SPECFILE $spec;
- close($SPECFILE);
-
+ unless ($config{noupdate})
+ {
+ # TODO use output ?
+ open($SPECFILE, ">$spec_path") or die "Unable to open $pkg.spec";
+ print $SPECFILE $spec;
+ close($SPECFILE);
+ }
if (!$found)
{
@@ -350,10 +382,10 @@ sub build {
return;
}
- if (system("$rpm -ba ../SPECS/$pkg.spec $log"))
+ if (system("$rpm -ba $spec_path $log"))
{
print "Binary build fails: building source only\n";
- system("$rpm -bs --nodeps ../SPECS/$pkg.spec $log");
+ system("$rpm -bs --nodeps $spec_path $log");
}
}
@@ -389,6 +421,10 @@ sub parse_argv {
ALIAS => "s",
ARGCOUNT => AppConfig::ARGCOUNT_ONE }
);
+ $conf->define("spec",
+ { ARGS => "=s",
+ ARGCOUNT => AppConfig::ARGCOUNT_ONE }
+ );
$conf->define("fedora",
{ ARGS => "=s",
@@ -408,6 +444,11 @@ sub parse_argv {
DEFAULT => 0,
ARGCOUNT => AppConfig::ARGCOUNT_NONE }
);
+ $conf->define("noupdate",
+ {
+ DEFAULT => 0,
+ ARGCOUNT => AppConfig::ARGCOUNT_NONE }
+ );
$conf->define("top",
{ ARGS => "=t",
@@ -443,8 +484,10 @@ sub parse_argv {
$config{rpmmon} = $conf->get("rpmmon");
$config{deps} = $conf->get("deps");
$config{srpms} = $conf->get("srpms");
+ $config{spec} = $conf->get("spec");
$config{src} = $conf->get("src");
$config{release} = $conf->get("release");
+ $config{noupdate} = $conf->get("noupdate");
$config{nosource} = $conf->get("nosource");
$config{fedora} = $conf->get("fedora");
$config{top} = $conf->get("top");
@@ -462,13 +505,15 @@ sub usage {
print "Usage: rpmbuildupdate [options] [pkg] [newversion]\n\n";
print " --rpmmon <file>: parse output of rpmmon from file\n";
- print " --srpms <path_to_srpms>: specify SRPMS path\n";
+ print " --srpms <path_to_srpms>: specify SRPMS path, separate folder with a comma\n";
print " --src <src.rpm file> <new version>: build new version from this source RPM\n";
+ print " --spec <spec file> <new version>: build new version from this spec file\n";
print " --release <mdk_release>: release version of package (default: 1mdk)\n";
print " --changelog <changelog message>: use a alternate message. \%\%VERSION is replace by version\n";
print " --deps: install builds dependencies\n";
print " --log: log builds\n";
print " --nosource: do not install source from (urpmi x.src.rpm)\n";
+ print " --noupdate: do not touch to the spec file\n";
print " --top <dir>: specify rpm top dir (default: `rpm --eval %_topdir`)\n";
print " --nobuild|-c: do not build the package. Only download files.\n";
exit 0;
@@ -481,33 +526,42 @@ sub parse_rpmmon {
open(my $RPMMON, $f);
while (<$RPMMON>)
{
- build($1, $3) if /^\s+(\S+)\s+(\S+)\s+(\S+)$/ && ! /Package/;
- build($2, $4) if /^(\S+)\s+(\S+)\s+(\S+)\s+(\S+)$/ && ! /Package/;
+ build_from_repository($1, $3) if /^\s+(\S+)\s+(\S+)\s+(\S+)$/ && ! /Package/;
+ build_from_repository($2, $4) if /^(\S+)\s+(\S+)\s+(\S+)\s+(\S+)$/ && ! /Package/;
}
close($RPMMON);
}
sub check_dir {
$_ = shift;
- -d $_ or die $_ . " is not a directory.\n";
+ foreach my $dir (split(/,/))
+ {
+ -d $dir or die $dir . " is not a directory.\n";
+ }
}
sub main {
parse_argv;
-
wget_check;
-
+ # FIXME clean this
if ($config{rpmmon}) {
print($config{srpms});
parse_rpmmon($config{rpmmon})
} elsif ($config{src} && $ARGV[0]) {
build_from_src($config{src}, $ARGV[0])
+ } elsif ($config{spec} && $ARGV[0]) {
+ build_from_spec($config{spec}, $ARGV[0])
} elsif ($ARGV[0] && $ARGV[1]) {
check_dir($config{srpms});
- build($ARGV[0], $ARGV[1])
+ build_from_repository($ARGV[0], $ARGV[1])
} elsif ($config{src}) {
build_from_src($config{src})
+ } elsif ($config{spec}) {
+ build_from_spec($config{spec})
+ } elsif ($ARGV[0]) {
+ check_dir($config{srpms});
+ build_from_repository($ARGV[0])
} else {
usage
}