]> git.pld-linux.org Git - projects/cleanbuild.git/blame - addbr
- one more "missing executable" detection
[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;
8my $msg = shift @ARGV or die;
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
19my $file = "$ENV{HOME}/rpm/packages/$fname/$fname.spec";
20-r $file or die;
21
22open FILE, "<", $file;
23my @in = <FILE>;
24close FILE;
25
171d3ec3 26my $brm = qr/#?(?:%{!?\?with_\S+:)?\s*BuildRequires:\s*(\S+)\s*(?:(>|>=|==|<=|<).*)?}?/i;
a7d61e66 27foreach ( @in ) {
28 if ( /^$brm$/o ) {
29 if ( $1 eq $add ) {
30 warn "$add already on the list\n";
31 exit;
32 }
33 }
34
35}
36
37my @out;
38while ( $_ = shift @in ) {
a75e2ecf 39 if ( /^\s*(build(requires|root|conflicts)|requires(\(.*\))?|provides|conflicts|obsoletes):/i ) {
a7d61e66 40 unshift @in, $_;
41 last;
42 }
43 push @out, $_;
44}
45
46my @buf;
47while ( $_ = shift @in ) {
48 if ( /^%if/ ) {
49 push @buf, $_;
50 my $i = 1;
51 while ( $_ = shift @in ) {
52 push @buf, $_;
53 if ( /^%if/ ) {
54 $i++;
55 } elsif ( /^%endif/ ) {
56 $i--;
57 last unless $i;
58 }
59 }
60
61 } elsif ( /^$brm$/o ) {
62 my $name = $1;
63 push @buf, $_;
64
65 if ( $add lt $name ) {
66 push @out, "# AUTO: $msg\n";
67 push @out, "BuildRequires:\t$add\n";
68 $add = undef;
69 }
70 push @out, @buf;
71 @buf = ();
72 } elsif ( /^\s*$/ or /^\s*#/ ) {
73 push @buf, $_;
74 } else {
75 push @buf, $_;
76 push @out, "# AUTO: $msg\n";
77 push @out, "BuildRequires:\t$add\n";
78 last;
79
80 }
81 last unless $add;
82}
83
84push @out, @buf;
85push @out, @in;
86
87
88open FILE, ">", $file;
89print FILE @out;
90close FILE;
This page took 0.083665 seconds and 4 git commands to generate.