]> git.pld-linux.org Git - projects/cleanbuild.git/blame - addbr
use ccache
[projects/cleanbuild.git] / addbr
CommitLineData
a7d61e66 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6my $fname = shift @ARGV or die;
7my $add = shift @ARGV or die;
b8ef893a 8my $msg = shift @ARGV || "requested";
a7d61e66 9
10$SIG{__WARN__} = sub
11{
12 local $_ = shift;
13 chomp;
14 print STDERR "\033[32;1m" . $_ . "\033[0m\n"
15};
16
17warn "Adding: $add\n";
18
614c5b13 19my $file = $fname;
20$file = "$ENV{HOME}/rpm/packages/$fname/$fname.spec"
21 unless -r $file;
a7d61e66 22-r $file or die;
23
24open FILE, "<", $file;
25my @in = <FILE>;
26close FILE;
27
171d3ec3 28my $brm = qr/#?(?:%{!?\?with_\S+:)?\s*BuildRequires:\s*(\S+)\s*(?:(>|>=|==|<=|<).*)?}?/i;
a7d61e66 29foreach ( @in ) {
30 if ( /^$brm$/o ) {
31 if ( $1 eq $add ) {
32 warn "$add already on the list\n";
33 exit;
34 }
35 }
36
37}
38
39my @out;
40while ( $_ = shift @in ) {
37893947 41 if ( /^\s*(build(requires|root|conflicts|arch)|requires(\(.*\))?|provides|conflicts|obsoletes|excludearch):/i ) {
a7d61e66 42 unshift @in, $_;
43 last;
44 }
45 push @out, $_;
46}
47
48my @buf;
49while ( $_ = shift @in ) {
50 if ( /^%if/ ) {
51 push @buf, $_;
52 my $i = 1;
53 while ( $_ = shift @in ) {
54 push @buf, $_;
55 if ( /^%if/ ) {
56 $i++;
57 } elsif ( /^%endif/ ) {
58 $i--;
59 last unless $i;
60 }
61 }
62
63 } elsif ( /^$brm$/o ) {
64 my $name = $1;
65 push @buf, $_;
66
67 if ( $add lt $name ) {
68 push @out, "# AUTO: $msg\n";
69 push @out, "BuildRequires:\t$add\n";
70 $add = undef;
71 }
72 push @out, @buf;
73 @buf = ();
74 } elsif ( /^\s*$/ or /^\s*#/ ) {
75 push @buf, $_;
76 } else {
77 push @buf, $_;
78 push @out, "# AUTO: $msg\n";
79 push @out, "BuildRequires:\t$add\n";
80 last;
81
82 }
83 last unless $add;
84}
85
86push @out, @buf;
87push @out, @in;
88
89
90open FILE, ">", $file;
91print FILE @out;
92close FILE;
This page took 0.497658 seconds and 4 git commands to generate.