From 7af897a69c6f4c0c9a623b54c4d77ef57156615859b15a4027ef88697454faae Mon Sep 17 00:00:00 2001 From: Stephan Kulow Date: Mon, 20 Feb 2012 08:16:23 +0000 Subject: [PATCH 1/2] - not only break buildrequires per (sorted) line, but also Requires and Provides OBS-URL: https://build.opensuse.org/package/show/openSUSE:Tools/obs-service-format_spec_file?expand=0&rev=63 --- obs-service-format_spec_file.changes | 6 ++++ prepare_spec | 43 ++++++++++++++++------------ 2 files changed, 31 insertions(+), 18 deletions(-) diff --git a/obs-service-format_spec_file.changes b/obs-service-format_spec_file.changes index 6761f38..e4610cf 100644 --- a/obs-service-format_spec_file.changes +++ b/obs-service-format_spec_file.changes @@ -1,3 +1,9 @@ +------------------------------------------------------------------- +Mon Feb 20 08:15:52 UTC 2012 - coolo@suse.com + +- not only break buildrequires per (sorted) line, but also + Requires and Provides + ------------------------------------------------------------------- Tue Feb 14 11:05:24 UTC 2012 - coolo@suse.com diff --git a/prepare_spec b/prepare_spec index 2c4756a..24ddfbb 100644 --- a/prepare_spec +++ b/prepare_spec @@ -230,7 +230,7 @@ sub set_current_pkg { return ($curpack, $curlang); } -sub sort_buildrequires_helper { +sub sort_tags_helper { if (($a =~ /^[^#]*\(/) != ($b =~ /^[^#]*\(/)) { if ($a =~ /^[^#]*\(/) { 1; @@ -317,18 +317,23 @@ sub read_and_parse_old_spec { $_ =~ s/%{?epoch}?[:-]//g; $_ =~ s/ 0:/ /g if ( /^requires/i || /^buildreq/i ); - if ( /^BuildRequires:/ ) { - my $cur_buildreq = $_; - $cur_buildreq =~ s/^BuildRequires:\s*//; + if ( /^BuildRequires:/i || /^Requires:/i || /^Provides:/i ) { + my $cur_tag = $_; + my $tag = ''; + if (m/^(\S+):\s*(.*)$/) { + $tag = $1; + $cur_tag = $2; + } + my %aa; - while ($cur_buildreq =~ m{([^,\s]+(\s*[<=>]+\s*[^,\s]+)?)}g) { + while ($cur_tag =~ m{([^,\s]+(\s*[<=>]+\s*[^,\s]+)?)}g) { $aa{$1}=1; } # ignore line if it looks like a "usedforbuild" line, i.e. # if it contains too many base packages next if (grep {$aa{$_}} qw{gcc rpm glibc bash}) > 2; - for my $br (sort keys(%aa)) { - push @oldspec, "BuildRequires: $br"; + for my $value (sort keys(%aa)) { + push (@oldspec, sprintf("%-16s%s", capitalize_case($tag) . ":", $value)); } next; } @@ -617,23 +622,24 @@ if ( ! stat ((glob("$specdir/$base_package*.spec"))[0] || "") ) { read_and_parse_old_spec ( $specfile, $base_package ); -my $linesmoved = 1; -while ($linesmoved) { +for my $tag (qw(BuildRequires Requires Provides)) { + my $linesmoved = 1; + while ($linesmoved) { $linesmoved = 0; my @firstlines = (); - my @buildrequires = (); + my @tags = (); while ($oldspec[0]) { my $l = shift @oldspec; - if ($l =~ m/^BuildRequires:/ ) { - push(@buildrequires, $l); + if ($l =~ m/^$tag:/ ) { + push(@tags, $l); } else { - # if there are already buildrequires, we need to sort and exit - if (@buildrequires > 0) { - my @sortedbrs = sort sort_buildrequires_helper @buildrequires; - $linesmoved = !compare_arrays(\@buildrequires, \@sortedbrs); - @oldspec = (@firstlines, @sortedbrs, $l, @oldspec); + # if there are already tags, we need to sort and exit + if (@tags > 0) { + my @sortedtags = sort sort_tags_helper @tags; + $linesmoved = !compare_arrays(\@tags, \@sortedtags); + @oldspec = (@firstlines, @sortedtags, $l, @oldspec); @firstlines = (); - @buildrequires = (); + @tags = (); last; } else { push(@firstlines, $l); @@ -641,6 +647,7 @@ while ($linesmoved) { } } @oldspec = (@firstlines, @oldspec); + } } From bab35e6fd3fd343ecad45213580fca95679f42daa9771a48d6d73eab0db30656 Mon Sep 17 00:00:00 2001 From: Stephan Kulow Date: Mon, 20 Feb 2012 13:19:27 +0000 Subject: [PATCH 2/2] - fix sorting of tag lines that are not on the beginning of the file OBS-URL: https://build.opensuse.org/package/show/openSUSE:Tools/obs-service-format_spec_file?expand=0&rev=64 --- obs-service-format_spec_file.changes | 5 +++++ prepare_spec | 16 +++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/obs-service-format_spec_file.changes b/obs-service-format_spec_file.changes index e4610cf..b2e50a9 100644 --- a/obs-service-format_spec_file.changes +++ b/obs-service-format_spec_file.changes @@ -1,3 +1,8 @@ +------------------------------------------------------------------- +Mon Feb 20 13:19:09 UTC 2012 - coolo@suse.com + +- fix sorting of tag lines that are not on the beginning of the file + ------------------------------------------------------------------- Mon Feb 20 08:15:52 UTC 2012 - coolo@suse.com diff --git a/prepare_spec b/prepare_spec index 24ddfbb..5c48ee0 100644 --- a/prepare_spec +++ b/prepare_spec @@ -624,7 +624,7 @@ read_and_parse_old_spec ( $specfile, $base_package ); for my $tag (qw(BuildRequires Requires Provides)) { my $linesmoved = 1; - while ($linesmoved) { + sortcycle: while ($linesmoved) { $linesmoved = 0; my @firstlines = (); my @tags = (); @@ -637,10 +637,16 @@ for my $tag (qw(BuildRequires Requires Provides)) { if (@tags > 0) { my @sortedtags = sort sort_tags_helper @tags; $linesmoved = !compare_arrays(\@tags, \@sortedtags); - @oldspec = (@firstlines, @sortedtags, $l, @oldspec); - @firstlines = (); - @tags = (); - last; + if ($linesmoved) { + @oldspec = (@firstlines, @sortedtags, $l, @oldspec); + @firstlines = (); + @tags = (); + next sortcycle; + } else { + @firstlines = (@firstlines, @tags, $l); + @tags = (); + next; + } } else { push(@firstlines, $l); }