SVN: toys/tools/cleanbuild/addbr

sparky sparky at pld-linux.org
Sun Dec 6 15:35:40 CET 2009


Author: sparky
Date: Sun Dec  6 15:35:38 2009
New Revision: 11008

Added:
   toys/tools/cleanbuild/addbr   (contents, props changed)
Log:
- NEW; add guessed BuildRequires to spec file


Added: toys/tools/cleanbuild/addbr
==============================================================================
--- (empty file)
+++ toys/tools/cleanbuild/addbr	Sun Dec  6 15:35:38 2009
@@ -0,0 +1,90 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+my $fname = shift @ARGV or die;
+my $add = shift @ARGV or die;
+my $msg = shift @ARGV or die;
+
+$SIG{__WARN__} = sub
+{
+	local $_ = shift;
+	chomp;
+	print STDERR "\033[32;1m" . $_ . "\033[0m\n"
+};
+
+warn "Adding: $add\n";
+
+my $file = "$ENV{HOME}/rpm/packages/$fname/$fname.spec";
+-r $file or die;
+
+open FILE, "<", $file;
+my @in = <FILE>;
+close FILE;
+
+my $brm = qr/#?(?:%{!?\?with_\S+:)?\s*BuildRequires:\s*(\S+)\s*(?:(>=|==|<=).*)?}?/i;
+foreach ( @in ) {
+	if ( /^$brm$/o ) {
+		if ( $1 eq $add ) {
+			warn "$add already on the list\n";
+			exit;
+		}
+	}
+
+}
+
+my @out;
+while ( $_ = shift @in ) {
+	if ( /^\s*(build(requires|root|conflicts)|requires|provides|conflicts|obsoletes):/i ) {
+		unshift @in, $_;
+		last;
+	}
+	push @out, $_;
+}
+
+my @buf;
+while ( $_ = shift @in ) {
+	if ( /^%if/ ) {
+		push @buf, $_;
+		my $i = 1;
+		while ( $_ = shift @in ) {
+			push @buf, $_;
+			if ( /^%if/ ) {
+				$i++;
+			} elsif ( /^%endif/ ) {
+				$i--;
+				last unless $i;
+			}
+		}
+
+	} elsif ( /^$brm$/o ) {
+		my $name = $1;
+		push @buf, $_;
+
+		if ( $add lt $name ) {
+			push @out, "# AUTO: $msg\n";
+			push @out, "BuildRequires:\t$add\n";
+			$add = undef;
+		}
+		push @out, @buf;
+		@buf = ();
+	} elsif ( /^\s*$/ or /^\s*#/ ) {
+		push @buf, $_;
+	} else {
+		push @buf, $_;
+		push @out, "# AUTO: $msg\n";
+		push @out, "BuildRequires:\t$add\n";
+		last;
+
+	}
+	last unless $add;
+}
+
+push @out, @buf;
+push @out, @in;
+
+
+open FILE, ">", $file;
+print FILE @out;
+close FILE;


More information about the pld-cvs-commit mailing list