Skip to content

Commit

Permalink
Fix merging empty sections
Browse files Browse the repository at this point in the history
Perl does not like "deep" recursions, so fall back to goto
  • Loading branch information
coolo committed Jan 27, 2021
1 parent defabca commit 1026443
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 21 deletions.
26 changes: 15 additions & 11 deletions prepare_spec
Expand Up @@ -164,8 +164,8 @@ our $base_package = "";
if ($self->{after_lines}) {
for (my $i = 0; $i < $self->{after_lines}; $i++) { push(@{$self->{lines}}, ""); }
$self->{after_lines} = 0;

}
die "Don't add to empty" if $self->{name} eq 'empty';
push(@{$self->{lines}}, $line);
}
else {
Expand Down Expand Up @@ -360,7 +360,7 @@ EOF
sub create_icecream_section {
my ($self, $line) = @_;
$line =~ s/^#\s*icecream\s*//;
$self->find("preamble")->add_footer("# icecream $line");
$self->find("preamble")->add_footer("# icecream $line") if $line ne '';
}

sub create_copyright_section {
Expand Down Expand Up @@ -529,10 +529,8 @@ EOF
next;
}

if (/^#\s*norootforbuild/) {
$self->current()->add_footer("# norootforbuild");
next;
}
next if m/^#\s*usedforbuild/;
next if m/^#\s*norootforbuild/;

if (/^#\s*nodebuginfo\s*$/) {
$self->current()->add_footer("# nodebuginfo");
Expand All @@ -548,8 +546,6 @@ EOF
$self->create_copyright_section($_);
next;
}

next if (/^#\s*usedforbuild/);
}

if (/^%\?__\*BuildRequires:/ || /^#!__\*BuildRequires:/) {
Expand Down Expand Up @@ -688,7 +684,7 @@ EOF
$self->create_section("section", $_);
}
else {
if ($self->current_name() eq 'preamble') {
if ($self->current_name() eq 'preamble' || $self->current_name() eq 'empty') {
$self->create_section("header", $_);
}
else {
Expand Down Expand Up @@ -728,6 +724,10 @@ EOF
next;
}

if (m/^(Summary\([^:\s]*\))\s*:\s*(.*)/oi) {
$self->create_tag_section($self->capitalize_case($1), $2);
next;
}
if (m/$global_tags_re\s*(.*)/oi) {
$self->create_tag_section($self->capitalize_case($1), $2);
next;
Expand Down Expand Up @@ -809,25 +809,29 @@ EOF
sub merge_empty_sections {
my $self = shift;

sections_before:

# first we merge empty with sections before
my $lastsection;
for my $section (@{$self->{sections}}) {
if ($section->name() eq 'empty') {
if ($lastsection->merge_with_empty_after($section)) {
$self->delete_section($section);
return $self->merge_empty_sections();
goto sections_before;
}
}
$lastsection = $section;
}

sections_after:

# and then try to do the same with sections after (as tags can't be merged)
$lastsection = undef;
for my $section (@{$self->{sections}}) {
if ($lastsection && $lastsection->name() eq 'empty') {
if ($section->merge_with_empty_before($lastsection)) {
$self->delete_section($lastsection);
return $self->merge_empty_sections();
goto sections_after;
}
}
$lastsection = $section;
Expand Down
4 changes: 2 additions & 2 deletions testing/gdb.spec.out
Expand Up @@ -54,8 +54,8 @@ ExclusiveArch: do_not_build

%if %{build_main}
Summary: A GNU source-level debugger for C, C++, Fortran and other languages
License: SUSE-Public-Domain
Group: Development/Languages/C and C++
License: GPL-3.0-or-later AND GPL-3.0-with-GCC-exception AND LGPL-2.1-or-later AND LGPL-3.0-or-later
Group: Development/Tools/Debuggers
%endif
%if %{build_testsuite}
Summary: GDB testsuite results
Expand Down
6 changes: 1 addition & 5 deletions testing/header.spec.out
Expand Up @@ -17,13 +17,9 @@

# Please submit bugfixes or comments via https://bugs.opensuse.org/
#
# needsrootforbuild
# needsbinariesforbuild
# nodebuginfo
# needsrootforbuild
# needssslcertforbuild


# binariesforbuild
# rootforbuild

%changelog
9 changes: 7 additions & 2 deletions testing/interestingheader.spec.out
Expand Up @@ -29,15 +29,20 @@ BuildRequires: tcl-devel >= 8.5
BuildRequires: update-desktop-files

Summary: .spec file cleaner
License: GPL-2.0-or-later
Group: Productivity/Multimedia/Sound/Midi
Summary(de): Ein Synthesizer der dritten Art
Name: din
Version: 5.2.1
Release: 0.1
Source: %{name}-%{version}.tar.bz2
Source1: %{name}.png
Group: Productivity/Multimedia/Sound/Midi
License: GPL-2.0-or-later
URL: http://www.dinisnoise.org/
Prefix: /usr

Requires: Mesa
Requires: fftw3
Requires: jack
Requires: tcl >= 8.5

%changelog
2 changes: 1 addition & 1 deletion testing/removepath.spec.out
Expand Up @@ -24,6 +24,6 @@ Provides: %name-pool-nonempty
Conflicts: otherproviders(%name-pool)
Requires: %name = %version
BuildArch: noarch
RemovePathPostfixes: .opensuse
Removepathpostfixes:.opensuse

%changelog

0 comments on commit 1026443

Please sign in to comment.