- don't stop sorting at empty lines in %description
- fix indenting of the script OBS-URL: https://build.opensuse.org/package/show/openSUSE:Tools/obs-service-format_spec_file?expand=0&rev=66
This commit is contained in:
parent
bab35e6fd3
commit
b6a7748a7b
@ -1,3 +1,9 @@
|
|||||||
|
-------------------------------------------------------------------
|
||||||
|
Fri Feb 24 09:48:57 UTC 2012 - coolo@suse.com
|
||||||
|
|
||||||
|
- don't stop sorting at empty lines in %description
|
||||||
|
- fix indenting of the script
|
||||||
|
|
||||||
-------------------------------------------------------------------
|
-------------------------------------------------------------------
|
||||||
Mon Feb 20 13:19:09 UTC 2012 - coolo@suse.com
|
Mon Feb 20 13:19:09 UTC 2012 - coolo@suse.com
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ Source3: patch_license
|
|||||||
Source4: licenses_changes.txt
|
Source4: licenses_changes.txt
|
||||||
Source100: COPYING
|
Source100: COPYING
|
||||||
Requires: osc-source_validator
|
Requires: osc-source_validator
|
||||||
BuildRoot: %{_tmppath}/%{name}-%{version}-build
|
BuildRoot: %{_tmppath}/%{name}-%{version}-build
|
||||||
BuildArch: noarch
|
BuildArch: noarch
|
||||||
|
|
||||||
%description
|
%description
|
||||||
|
533
prepare_spec
533
prepare_spec
@ -34,51 +34,49 @@ my $ifhandler;
|
|||||||
my $definelist;
|
my $definelist;
|
||||||
my $debug = 0;
|
my $debug = 0;
|
||||||
|
|
||||||
my @global_tags_list =
|
my @global_tags_list = (
|
||||||
(
|
'Autoreq',
|
||||||
'Autoreq',
|
'Autoreqprov',
|
||||||
'Autoreqprov',
|
'BuildArch',
|
||||||
'BuildArch',
|
'BuildArchitectures',
|
||||||
'BuildArchitectures',
|
'BuildRequires',
|
||||||
'BuildRequires',
|
'Conflicts',
|
||||||
'Conflicts',
|
'DocDir',
|
||||||
'DocDir',
|
'Enhances',
|
||||||
'Enhances',
|
'Enhances',
|
||||||
'Enhances',
|
'EssentialFor',
|
||||||
'EssentialFor',
|
'ExcludeArch',
|
||||||
'ExcludeArch',
|
'ExclusiveArch',
|
||||||
'ExclusiveArch',
|
'Freshens',
|
||||||
'Freshens',
|
'Group',
|
||||||
'Group',
|
'Name',
|
||||||
'Name',
|
'NoPatch',
|
||||||
'NoPatch',
|
'NoSource',
|
||||||
'NoSource',
|
'Obsoletes',
|
||||||
'Obsoletes',
|
'Patch\d*',
|
||||||
'Patch\d*',
|
'Prefix',
|
||||||
'Prefix',
|
'PreReq',
|
||||||
'PreReq',
|
'Provides',
|
||||||
'Provides',
|
'Recommends',
|
||||||
'Recommends',
|
'Requires',
|
||||||
'Requires',
|
'Source\d*',
|
||||||
'Source\d*',
|
'Suggests',
|
||||||
'Suggests',
|
'Summary',
|
||||||
'Summary',
|
'Supplements',
|
||||||
'Supplements',
|
'Url',
|
||||||
'Url',
|
|
||||||
);
|
);
|
||||||
|
|
||||||
my $global_tags_re = '^\s*(' . join("|", @global_tags_list) . ')\s*:';
|
my $global_tags_re = '^\s*(' . join("|", @global_tags_list) . ')\s*:';
|
||||||
|
|
||||||
my $section_tags_re ='^\s*%(?:clean|check|prep|build|install|pre|post|preun|postun|posttrans|package|' .
|
my $section_tags_re ='^\s*%(?:clean|check|prep|build|install|pre|post|preun|postun|posttrans|package|' .
|
||||||
'description|files|triggerin|triggerun|triggerpostun)\b';
|
'description|files|triggerin|triggerun|triggerpostun)\b';
|
||||||
|
|
||||||
sub unify {
|
sub unify {
|
||||||
my %h = map {$_ => 1} @_;
|
my %h = map {$_ => 1} @_;
|
||||||
return grep(delete($h{$_}), @_);
|
return grep(delete($h{$_}), @_);
|
||||||
}
|
}
|
||||||
|
|
||||||
sub capitalize_case($)
|
sub capitalize_case($) {
|
||||||
{
|
|
||||||
my ($tag) = @_;
|
my ($tag) = @_;
|
||||||
|
|
||||||
$tag = lc($tag);
|
$tag = lc($tag);
|
||||||
@ -95,22 +93,22 @@ sub capitalize_case($)
|
|||||||
}
|
}
|
||||||
|
|
||||||
sub compare_arrays {
|
sub compare_arrays {
|
||||||
my ($first, $second) = @_;
|
my ($first, $second) = @_;
|
||||||
return 0 unless @$first == @$second;
|
return 0 unless @$first == @$second;
|
||||||
for (my $i = 0; $i < @$first; $i++) {
|
for (my $i = 0; $i < @$first; $i++) {
|
||||||
return 0 if $first->[$i] ne $second->[$i];
|
return 0 if $first->[$i] ne $second->[$i];
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
|
||||||
|
|
||||||
sub maybe_add_empty_line()
|
|
||||||
{
|
|
||||||
push @oldspec, "XXXBLANKLINE"
|
|
||||||
if ($current_section ne "description" && $oldspec[-1] !~ /^\s*$/ && $oldspec[-1] !~ /^[#%]/);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sub change_section($)
|
sub maybe_add_empty_line() {
|
||||||
{
|
return if $current_section eq "description";
|
||||||
|
|
||||||
|
push @oldspec, "XXXBLANKLINE"
|
||||||
|
if ($oldspec[-1] !~ /^\s*$/ && $oldspec[-1] !~ /^[#%]/);
|
||||||
|
}
|
||||||
|
|
||||||
|
sub change_section($) {
|
||||||
my ($new_section) = @_;
|
my ($new_section) = @_;
|
||||||
|
|
||||||
maybe_add_empty_line();
|
maybe_add_empty_line();
|
||||||
@ -122,91 +120,87 @@ sub change_section($)
|
|||||||
my %license_replace = ();
|
my %license_replace = ();
|
||||||
use File::Basename;
|
use File::Basename;
|
||||||
|
|
||||||
sub load_license_map()
|
sub load_license_map() {
|
||||||
{
|
return if defined $license_replace{"GPL-2.0"};
|
||||||
return if defined $license_replace{"GPL-2.0"};
|
my $scriptdir = File::Basename::dirname($0);
|
||||||
my $scriptdir = File::Basename::dirname($0);
|
open(MAP, "$scriptdir/licenses_changes.txt") || die "can't open licenses_changes.txt";
|
||||||
open(MAP, "$scriptdir/licenses_changes.txt") || die "can't open licenses_changes.txt";
|
# ignore header
|
||||||
# ignore header
|
readline(*MAP);
|
||||||
readline(*MAP);
|
my %spdx;
|
||||||
my %spdx;
|
while (<MAP>) {
|
||||||
while (<MAP>) {
|
chomp;
|
||||||
chomp;
|
my ($license, $oldstring) = split(/\t/, $_, 2);
|
||||||
my ($license, $oldstring) = split(/\t/, $_, 2);
|
#$license =~ s,\s*$,,;
|
||||||
#$license =~ s,\s*$,,;
|
#$oldstring =~ s,\s*$,,;
|
||||||
#$oldstring =~ s,\s*$,,;
|
next unless length($license);
|
||||||
next unless length($license);
|
#print STDERR "$license\t$oldstring\n";
|
||||||
#print STDERR "$license\t$oldstring\n";
|
die "$oldstring is given twice in $_" if defined $license_replace{$oldstring};
|
||||||
die "$oldstring is given twice in $_" if defined $license_replace{$oldstring};
|
$license_replace{$oldstring} = $license;
|
||||||
$license_replace{$oldstring} = $license;
|
$spdx{$license} = 1;
|
||||||
$spdx{$license} = 1;
|
}
|
||||||
}
|
close(MAP);
|
||||||
close(MAP);
|
for (keys %spdx) {
|
||||||
for (keys %spdx) {
|
$license_replace{$_} = $_;
|
||||||
$license_replace{$_} = $_;
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sub replace_single_spdx($)
|
sub replace_single_spdx($) {
|
||||||
{
|
my ($l) = @_;
|
||||||
my ($l) = @_;
|
|
||||||
|
|
||||||
return '' if $l eq '';
|
return '' if $l eq '';
|
||||||
|
|
||||||
load_license_map();
|
load_license_map();
|
||||||
$l =~ s,ORlater,or later,g;
|
$l =~ s,ORlater,or later,g;
|
||||||
$l =~ s,ORsim,or similar,g;
|
$l =~ s,ORsim,or similar,g;
|
||||||
$l =~ s,^\s+,,;
|
$l =~ s,^\s+,,;
|
||||||
$l =~ s,\s+$,,;
|
$l =~ s,\s+$,,;
|
||||||
|
|
||||||
if (defined $license_replace{$l}) {
|
if (defined $license_replace{$l}) {
|
||||||
$l = $license_replace{$l};
|
$l = $license_replace{$l};
|
||||||
} else {
|
} else {
|
||||||
print STDERR "Unknown license '$l'\n";
|
print STDERR "Unknown license '$l'\n";
|
||||||
}
|
}
|
||||||
return $l;
|
return $l;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub replace_spdx_and($);
|
sub replace_spdx_and($);
|
||||||
sub replace_spdx_and($)
|
sub replace_spdx_and($) {
|
||||||
{
|
my ($license) = @_;
|
||||||
my ($license) = @_;
|
|
||||||
|
|
||||||
# special case as or later is common in our spec files
|
# special case as or later is common in our spec files
|
||||||
$license =~ s,or later,ORlater,g;
|
$license =~ s,or later,ORlater,g;
|
||||||
$license =~ s,or similar,ORsim,g;
|
$license =~ s,or similar,ORsim,g;
|
||||||
|
|
||||||
#print STDERR "ORIG '$license'\n";
|
|
||||||
my @licenses = ();
|
|
||||||
if ( $license =~ /^(.*?)\(([^)]*)\)(.*?)$/ ) {
|
|
||||||
my ($head, $paren, $tail) = ($1, $2, $3);
|
|
||||||
if ($paren =~ /and|or/) {
|
|
||||||
$head = replace_spdx_and($head);
|
|
||||||
$tail = replace_spdx_and($tail);
|
|
||||||
$paren = replace_spdx_and($paren);
|
|
||||||
#print STDERR "AFTE '$head($paren)$tail'\n";
|
|
||||||
return "$head($paren)$tail";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (split(/(\s+(?:and|or)\s+)/, $license, -1)) {
|
#print STDERR "ORIG '$license'\n";
|
||||||
$_ = replace_single_spdx($_) unless $_ eq '' || /(\s+(?:and|or)\s+)/;
|
my @licenses = ();
|
||||||
s/\s+/ /g;
|
if ( $license =~ /^(.*?)\(([^)]*)\)(.*?)$/ ) {
|
||||||
push @licenses, $_;
|
my ($head, $paren, $tail) = ($1, $2, $3);
|
||||||
|
if ($paren =~ /and|or/) {
|
||||||
|
$head = replace_spdx_and($head);
|
||||||
|
$tail = replace_spdx_and($tail);
|
||||||
|
$paren = replace_spdx_and($paren);
|
||||||
|
#print STDERR "AFTE '$head($paren)$tail'\n";
|
||||||
|
return "$head($paren)$tail";
|
||||||
}
|
}
|
||||||
#print STDERR "AFTE '" . join('', @licenses) . "'\n";
|
}
|
||||||
return join('', @licenses);
|
|
||||||
|
for (split(/(\s+(?:and|or)\s+)/, $license, -1)) {
|
||||||
|
$_ = replace_single_spdx($_) unless $_ eq '' || /(\s+(?:and|or)\s+)/;
|
||||||
|
s/\s+/ /g;
|
||||||
|
push @licenses, $_;
|
||||||
|
}
|
||||||
|
#print STDERR "AFTE '" . join('', @licenses) . "'\n";
|
||||||
|
return join('', @licenses);
|
||||||
}
|
}
|
||||||
|
|
||||||
sub replace_spdx($)
|
sub replace_spdx($) {
|
||||||
{
|
my ($license) = @_;
|
||||||
my ($license) = @_;
|
|
||||||
|
|
||||||
my @licenses = ();
|
my @licenses = ();
|
||||||
for (split(/\s*;\s*/, $license)) {
|
for (split(/\s*;\s*/, $license)) {
|
||||||
push @licenses, replace_spdx_and($_);
|
push @licenses, replace_spdx_and($_);
|
||||||
}
|
}
|
||||||
return join(' ; ', @licenses);
|
return join(' ; ', @licenses);
|
||||||
}
|
}
|
||||||
|
|
||||||
sub set_current_pkg {
|
sub set_current_pkg {
|
||||||
@ -262,80 +256,80 @@ sub read_and_parse_old_spec {
|
|||||||
$_ = shift @readspec;
|
$_ = shift @readspec;
|
||||||
|
|
||||||
if ( /^\s*$/ && $current_section ne "description") {
|
if ( /^\s*$/ && $current_section ne "description") {
|
||||||
# stop preamble parsing on two blank lines
|
# stop preamble parsing on two blank lines
|
||||||
if ($print_comments eq "false" && $oldspec[0] && $oldspec[-1] eq "XXXBLANKLINE") {
|
if ($print_comments eq "false" &&
|
||||||
$print_comments = "true";
|
$oldspec[0] && $oldspec[-1] eq "XXXBLANKLINE") {
|
||||||
push @oldspec, "XXXDOUBLELINE";
|
$print_comments = "true";
|
||||||
next;
|
push @oldspec, "XXXDOUBLELINE";
|
||||||
}
|
|
||||||
push @oldspec, "XXXBLANKLINE";
|
|
||||||
next;
|
next;
|
||||||
|
}
|
||||||
|
push @oldspec, "XXXBLANKLINE";
|
||||||
|
next;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( /^# vim:/ ) {
|
if ( /^# vim:/ ) {
|
||||||
$vim_modeline = $_;
|
$vim_modeline = $_;
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( /^#\s*needsrootforbuild\s*$/ ) {
|
if ( /^#\s*needsrootforbuild\s*$/ ) {
|
||||||
$needsrootforbuild = 1;
|
$needsrootforbuild = 1;
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
if ( /^#\s*needsbinariesforbuild\s*$/ ) {
|
if ( /^#\s*needsbinariesforbuild\s*$/ ) {
|
||||||
$needsbinariesforbuild = 1;
|
$needsbinariesforbuild = 1;
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
if ( /^#\s*norootforbuild/ ) {
|
if ( /^#\s*norootforbuild/ ) {
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( /^#\s*nodebuginfo\s*$/ ) {
|
if ( /^#\s*nodebuginfo\s*$/ ) {
|
||||||
$nodebuginfo = 1;
|
$nodebuginfo = 1;
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
if ( /^#\s*icecream/ ) {
|
if ( /^#\s*icecream/ ) {
|
||||||
$icecreamforbuild = $_;
|
$icecreamforbuild = $_;
|
||||||
$icecreamforbuild =~ s/^#\s*icecream\s*//;
|
$icecreamforbuild =~ s/^#\s*icecream\s*//;
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
if ( /^#\s*Copyright\s*/ ) {
|
if ( /^#\s*Copyright\s*/ ) {
|
||||||
my $lastlineblank = 0;
|
my $lastlineblank = 0;
|
||||||
for (;;)
|
for (;;) {
|
||||||
{
|
# check if line is ONLY a standard copyright line, if so, ignore.
|
||||||
# check if line is ONLY a standard copyright line, if so, ignore.
|
my $c = $_;
|
||||||
my $c = $_;
|
$c =~ s{\s*(\d+|copyrights?|\(c\)|suse|linux|products|gmbh|nuremberg|n..?rnberg|germany|\W+)\s*}{}gi;
|
||||||
$c =~ s{\s*(\d+|copyrights?|\(c\)|suse|linux|products|gmbh|nuremberg|n..?rnberg|germany|\W+)\s*}{}gi;
|
push(@copyrights, $_) if length $c > 5;
|
||||||
push(@copyrights, $_) if length $c > 5;
|
last if length $readspec[0] < 10 || $readspec[0] =~ m{modifications and additions}i || $readspec[0] !~ /^[\#\s]/
|
||||||
last if length $readspec[0] < 10 || $readspec[0] =~ m{modifications and additions}i || $readspec[0] !~ /^[\#\s]/
|
|| grep { $readspec[0] =~ /^#\s*$_/ } ("needsrootforbuild","needsbinariesforbuild","nodebuginfo","icecream","usedforbuild","Commandline","MD5SUM","!BuildIgnore");
|
||||||
|| grep { $readspec[0] =~ /^#\s*$_/ } ("needsrootforbuild","needsbinariesforbuild","nodebuginfo","icecream","usedforbuild","Commandline","MD5SUM","!BuildIgnore");
|
$_ = shift @readspec;
|
||||||
$_ = shift @readspec;
|
}
|
||||||
}
|
next;
|
||||||
next;
|
|
||||||
}
|
}
|
||||||
# evil epoch removal
|
# evil epoch removal
|
||||||
next if ( /^Epoch:/ );
|
next if ( /^Epoch:/ );
|
||||||
$_ =~ s/%{?epoch}?[:-]//g;
|
$_ =~ s/%{?epoch}?[:-]//g;
|
||||||
$_ =~ s/ 0:/ /g if ( /^requires/i || /^buildreq/i );
|
$_ =~ s/ 0:/ /g if ( /^requires/i || /^buildreq/i );
|
||||||
|
|
||||||
if ( /^BuildRequires:/i || /^Requires:/i || /^Provides:/i ) {
|
if ( /^BuildRequires:/i || /^Requires:/i || /^Provides:/i || /^Obsoletes:/i ) {
|
||||||
my $cur_tag = $_;
|
my $cur_tag = $_;
|
||||||
my $tag = '';
|
my $tag = '';
|
||||||
if (m/^(\S+):\s*(.*)$/) {
|
if (m/^(\S+):\s*(.*)$/) {
|
||||||
$tag = $1;
|
$tag = $1;
|
||||||
$cur_tag = $2;
|
$cur_tag = $2;
|
||||||
}
|
}
|
||||||
|
|
||||||
my %aa;
|
my %aa;
|
||||||
while ($cur_tag =~ m{([^,\s]+(\s*[<=>]+\s*[^,\s]+)?)}g) {
|
while ($cur_tag =~ m{([^,\s]+(\s*[<=>]+\s*[^,\s]+)?)}g) {
|
||||||
$aa{$1}=1;
|
$aa{$1}=1;
|
||||||
}
|
}
|
||||||
# ignore line if it looks like a "usedforbuild" line, i.e.
|
# ignore line if it looks like a "usedforbuild" line, i.e.
|
||||||
# if it contains too many base packages
|
# if it contains too many base packages
|
||||||
next if (grep {$aa{$_}} qw{gcc rpm glibc bash}) > 2;
|
next if (grep {$aa{$_}} qw{gcc rpm glibc bash}) > 2;
|
||||||
for my $value (sort keys(%aa)) {
|
for my $value (sort keys(%aa)) {
|
||||||
push (@oldspec, sprintf("%-16s%s", capitalize_case($tag) . ":", $value));
|
push (@oldspec, sprintf("%-16s%s", capitalize_case($tag) . ":", $value));
|
||||||
}
|
}
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
next if ( /^#\s*usedforbuild/ );
|
next if ( /^#\s*usedforbuild/ );
|
||||||
if ( /^%\?__\*BuildRequires:/ ) {
|
if ( /^%\?__\*BuildRequires:/ ) {
|
||||||
@ -354,14 +348,14 @@ sub read_and_parse_old_spec {
|
|||||||
if ( /^#/ && $current_section ne "description") {
|
if ( /^#/ && $current_section ne "description") {
|
||||||
warn "$_ $current_section\n" if $debug;
|
warn "$_ $current_section\n" if $debug;
|
||||||
if ( $print_comments eq "true" || $readspec[0] =~ /^%define/ || $readspec[0] =~ /^%if/) {
|
if ( $print_comments eq "true" || $readspec[0] =~ /^%define/ || $readspec[0] =~ /^%if/) {
|
||||||
push @oldspec, $_;
|
push @oldspec, $_;
|
||||||
}
|
}
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( /^%debug_package/ ) {
|
if ( /^%debug_package/ ) {
|
||||||
# remove, we add this ourselves
|
# remove, we add this ourselves
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
$print_comments = "true" unless /^#/;
|
$print_comments = "true" unless /^#/;
|
||||||
|
|
||||||
@ -380,42 +374,42 @@ sub read_and_parse_old_spec {
|
|||||||
$ifhandler->{"depth"}++;
|
$ifhandler->{"depth"}++;
|
||||||
my $if_not = 0;
|
my $if_not = 0;
|
||||||
if ( $args[1] =~ /^\!/ ) {
|
if ( $args[1] =~ /^\!/ ) {
|
||||||
$args[1] =~ s/^\!//;
|
$args[1] =~ s/^\!//;
|
||||||
$if_not = 1;
|
$if_not = 1;
|
||||||
}
|
}
|
||||||
$args[2] = "" unless $args[2];
|
$args[2] = "" unless $args[2];
|
||||||
if ( ($args[1] eq "0")
|
if ( ($args[1] eq "0")
|
||||||
|| ($args[1] eq "%name" && $args[2] eq "!=" && $args[3] eq $base_package)
|
|| ($args[1] eq "%name" && $args[2] eq "!=" && $args[3] eq $base_package)
|
||||||
|| ($args[1] eq "%name" && $args[2] eq "==" && $args[3] ne $base_package)
|
|| ($args[1] eq "%name" && $args[2] eq "==" && $args[3] ne $base_package)
|
||||||
|| ($args[1] && !$args[3] && !$if_not && $definelist->{$args[1]} && $definelist->{$args[1]} eq "0")
|
|| ($args[1] && !$args[3] && !$if_not && $definelist->{$args[1]} && $definelist->{$args[1]} eq "0")
|
||||||
|| ($args[2] eq "==" && $args[3] ne "0" && $definelist->{$args[1]} && $definelist->{$args[1]} eq "0")
|
|| ($args[2] eq "==" && $args[3] ne "0" && $definelist->{$args[1]} && $definelist->{$args[1]} eq "0")
|
||||||
|| ($args[2] eq "!=" && $args[3] eq "0" && $definelist->{$args[1]} && $definelist->{$args[1]} eq "0")
|
|| ($args[2] eq "!=" && $args[3] eq "0" && $definelist->{$args[1]} && $definelist->{$args[1]} eq "0")
|
||||||
|| ($args[1] && !$args[3] && $if_not && $definelist->{$args[1]} && $definelist->{$args[1]} eq "1")
|
|| ($args[1] && !$args[3] && $if_not && $definelist->{$args[1]} && $definelist->{$args[1]} eq "1")
|
||||||
|| ($args[1] && $args[2] eq "!=" && $args[3] eq "1" && $definelist->{$args[1]} && $definelist->{$args[1]} eq "1") ) {
|
|| ($args[1] && $args[2] eq "!=" && $args[3] eq "1" && $definelist->{$args[1]} && $definelist->{$args[1]} eq "1") ) {
|
||||||
$ifhandler->{"disabled"} = $ifhandler->{"depth"};
|
$ifhandler->{"disabled"} = $ifhandler->{"depth"};
|
||||||
$ifhandler->{"last_if_disabled"} = 1;
|
$ifhandler->{"last_if_disabled"} = 1;
|
||||||
}
|
}
|
||||||
} elsif ( /^\s*%if/ ) {
|
} elsif ( /^\s*%if/ ) {
|
||||||
$ifhandler->{"last_if_disabled"} = 0;
|
$ifhandler->{"last_if_disabled"} = 0;
|
||||||
$ifhandler->{"last_if_if"} = 0;
|
$ifhandler->{"last_if_if"} = 0;
|
||||||
$ifhandler->{"depth"}++;
|
$ifhandler->{"depth"}++;
|
||||||
} elsif ( /^\s*%endif/ ) {
|
} elsif ( /^\s*%endif/ ) {
|
||||||
$ifhandler->{"disabled"} = 0 if $ifhandler->{"disabled"} == $ifhandler->{"depth"};
|
$ifhandler->{"disabled"} = 0 if $ifhandler->{"disabled"} == $ifhandler->{"depth"};
|
||||||
$ifhandler->{"depth"}--;
|
$ifhandler->{"depth"}--;
|
||||||
} elsif ( /^\s*%else/ ) {
|
} elsif ( /^\s*%else/ ) {
|
||||||
if ($ifhandler->{"disabled"} == $ifhandler->{"depth"} && $ifhandler->{"last_if_disabled"} == 1) {
|
if ($ifhandler->{"disabled"} == $ifhandler->{"depth"} && $ifhandler->{"last_if_disabled"} == 1) {
|
||||||
$ifhandler->{"disabled"} = 0;
|
$ifhandler->{"disabled"} = 0;
|
||||||
} elsif ($ifhandler->{"disabled"} == 0 && $ifhandler->{"depth"} == 1 && $ifhandler->{"last_if_if"} == 1) {
|
} elsif ($ifhandler->{"disabled"} == 0 && $ifhandler->{"depth"} == 1 && $ifhandler->{"last_if_if"} == 1) {
|
||||||
$ifhandler->{"disabled"} = 1;
|
$ifhandler->{"disabled"} = 1;
|
||||||
}
|
}
|
||||||
} elsif ( /^\s*%define\s/ ) {
|
} elsif ( /^\s*%define\s/ ) {
|
||||||
my @args = split (/\s+/,$_);
|
my @args = split (/\s+/,$_);
|
||||||
$_ =~ s/[\{\}\"]//g for (@args);
|
$_ =~ s/[\{\}\"]//g for (@args);
|
||||||
$args[2] =~ s/\Q$_\E/$definelist->{$_}/g for sort { length($b) <=> length($a) } keys (%{$definelist});
|
$args[2] =~ s/\Q$_\E/$definelist->{$_}/g for sort { length($b) <=> length($a) } keys (%{$definelist});
|
||||||
if ( $args[2] !~ /[\(\)\{\}\@\%\"\\]/ ) {
|
if ( $args[2] !~ /[\(\)\{\}\@\%\"\\]/ ) {
|
||||||
$definelist->{"%".$args[1]} = $args[2] if $ifhandler->{"disabled"} == 0;
|
$definelist->{"%".$args[1]} = $args[2] if $ifhandler->{"disabled"} == 0;
|
||||||
$definelist->{"%{".$args[1]."}"} = $args[2] if $ifhandler->{"disabled"} == 0;
|
$definelist->{"%{".$args[1]."}"} = $args[2] if $ifhandler->{"disabled"} == 0;
|
||||||
$definelist->{"%{?".$args[1]."}"} = $args[2] if $ifhandler->{"disabled"} == 0;
|
$definelist->{"%{?".$args[1]."}"} = $args[2] if $ifhandler->{"disabled"} == 0;
|
||||||
}
|
}
|
||||||
while ($_ =~ /\\$/) {
|
while ($_ =~ /\\$/) {
|
||||||
$_ = shift @readspec;
|
$_ = shift @readspec;
|
||||||
@ -432,11 +426,11 @@ sub read_and_parse_old_spec {
|
|||||||
}
|
}
|
||||||
$_ =~ s/^(%\w+)/lc($1)/e;
|
$_ =~ s/^(%\w+)/lc($1)/e;
|
||||||
if ($debug) {
|
if ($debug) {
|
||||||
warn "key: $_ value: $definelist->{$_}\n" for (sort { length($b) <=> length($a) } keys (%{$definelist}));
|
warn "key: $_ value: $definelist->{$_}\n" for (sort { length($b) <=> length($a) } keys (%{$definelist}));
|
||||||
}
|
}
|
||||||
push @oldspec, $_;
|
push @oldspec, $_;
|
||||||
for my $xx (sort { length($b) <=> length($a) } keys (%{$definelist})) {
|
for my $xx (sort { length($b) <=> length($a) } keys (%{$definelist})) {
|
||||||
$_ =~ s/\Q$xx\E/$definelist->{$xx}/;
|
$_ =~ s/\Q$xx\E/$definelist->{$xx}/;
|
||||||
}
|
}
|
||||||
$_ =~ s/%{\?[^\}]*}//;
|
$_ =~ s/%{\?[^\}]*}//;
|
||||||
if ($debug) {
|
if ($debug) {
|
||||||
@ -461,7 +455,7 @@ sub read_and_parse_old_spec {
|
|||||||
}
|
}
|
||||||
if ( /^%changelog\b/i ) {
|
if ( /^%changelog\b/i ) {
|
||||||
change_section("changelog");
|
change_section("changelog");
|
||||||
# changelog comes always from *.changes. Skip what is in spec file
|
# changelog comes always from *.changes. Skip what is in spec file
|
||||||
# at the moment.
|
# at the moment.
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
@ -471,8 +465,8 @@ sub read_and_parse_old_spec {
|
|||||||
}
|
}
|
||||||
if ( /^%/ ) {
|
if ( /^%/ ) {
|
||||||
if ( m/$section_tags_re/oi ) {
|
if ( m/$section_tags_re/oi ) {
|
||||||
$_ =~ s/^(%\w+)/lc($1)/e;
|
$_ =~ s/^(%\w+)/lc($1)/e;
|
||||||
change_section("header") if (! m/\s*%files/i && !m/\s*%build/i);
|
change_section("header") if (! m/\s*%files/i && !m/\s*%build/i);
|
||||||
change_section("build") if m/\s*%build/i;
|
change_section("build") if m/\s*%build/i;
|
||||||
warn "changed to $current_section for $_\n" if $debug;
|
warn "changed to $current_section for $_\n" if $debug;
|
||||||
}
|
}
|
||||||
@ -486,65 +480,65 @@ sub read_and_parse_old_spec {
|
|||||||
$c_pack .= "_disabled" if $ifhandler->{"disabled"};
|
$c_pack .= "_disabled" if $ifhandler->{"disabled"};
|
||||||
|
|
||||||
if ( /^Vendor:/ || /^Distribution:/ || /^Packager:/ ) {
|
if ( /^Vendor:/ || /^Distribution:/ || /^Packager:/ ) {
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
# remove default value of Autoreqprov
|
# remove default value of Autoreqprov
|
||||||
if ( /^Autoreqprov\s*:\s*(.*)/i ) {
|
if ( /^Autoreqprov\s*:\s*(.*)/i ) {
|
||||||
next if ( lc($1) eq "on" || lc($1) eq "yes");
|
next if ( lc($1) eq "on" || lc($1) eq "yes");
|
||||||
}
|
}
|
||||||
# reset Release
|
# reset Release
|
||||||
if ( /^Release\s*:\s*(.*)/i ) {
|
if ( /^Release\s*:\s*(.*)/i ) {
|
||||||
if ($1 !~ m/^[0-9]*$/ && $oldspec[-1] eq "XXXRELEASE") {
|
if ($1 !~ m/^[0-9]*$/ && $oldspec[-1] eq "XXXRELEASE") {
|
||||||
pop @oldspec;
|
pop @oldspec;
|
||||||
push @oldspec, sprintf("%-16s%s","Release:", $1);
|
push @oldspec, sprintf("%-16s%s","Release:", $1);
|
||||||
}
|
}
|
||||||
# will be after Version
|
# will be after Version
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
if ( /^Summary\s*:\s*(.*)\s*$/i ) {
|
if ( /^Summary\s*:\s*(.*)\s*$/i ) {
|
||||||
push @oldspec, sprintf("%-16s%s", "Summary:", $1);
|
push @oldspec, sprintf("%-16s%s", "Summary:", $1);
|
||||||
push @oldspec, "XXXPOSTSUMMARY $current_package";
|
push @oldspec, "XXXPOSTSUMMARY $current_package";
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
|
|
||||||
# remove license and print out after license later
|
# remove license and print out after license later
|
||||||
if ( /^License\s*:\s*(.*)\s*$/i || /^Copyright\s*:\s*(.*)\s*$/i ) {
|
if ( /^License\s*:\s*(.*)\s*$/i || /^Copyright\s*:\s*(.*)\s*$/i ) {
|
||||||
my $license = replace_spdx($1);
|
my $license = replace_spdx($1);
|
||||||
$main_license = $license if (!$main_license);
|
$main_license = $license if (!$main_license);
|
||||||
$seen_licenses{$current_package} = $license;
|
$seen_licenses{$current_package} = $license;
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
|
|
||||||
# remove groups and print out after summary later
|
# remove groups and print out after summary later
|
||||||
if ( /^Group\s*:\s*(.*)\s*$/i ) {
|
if ( /^Group\s*:\s*(.*)\s*$/i ) {
|
||||||
my $group = $1;
|
my $group = $1;
|
||||||
$main_group = $group if (!$main_group);
|
$main_group = $group if (!$main_group);
|
||||||
$seen_groups{$current_package} = $group;
|
$seen_groups{$current_package} = $group;
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( /^BuildArchitectures\s*:/i ) {
|
if ( /^BuildArchitectures\s*:/i ) {
|
||||||
$_ =~ s/^[^:]+:/BuildArch:/;
|
$_ =~ s/^[^:]+:/BuildArch:/;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( /^BuildRoot\s*:/i ) {
|
if ( /^BuildRoot\s*:/i ) {
|
||||||
push @oldspec, "BuildRoot: %{_tmppath}/%{name}-%{version}-build";
|
push @oldspec, "BuildRoot: %{_tmppath}/%{name}-%{version}-build";
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( m/$global_tags_re\s*(.*)/oi ) {
|
if ( m/$global_tags_re\s*(.*)/oi ) {
|
||||||
my ($tag, $value) = ($1, $2);
|
my ($tag, $value) = ($1, $2);
|
||||||
$nosrc_result = 1 if ($tag =~ /(?:nosource|nopatch)/i);
|
$nosrc_result = 1 if ($tag =~ /(?:nosource|nopatch)/i);
|
||||||
push @oldspec, sprintf("%-16s%s", capitalize_case($tag) . ":", $value);
|
push @oldspec, sprintf("%-16s%s", capitalize_case($tag) . ":", $value);
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
if ( /^Version:/ ) {
|
if ( /^Version:/ ) {
|
||||||
warn "found Version, section = $current_section\n" if $debug;
|
warn "found Version, section = $current_section\n" if $debug;
|
||||||
$version{$c_pack} = $_;
|
$version{$c_pack} = $_;
|
||||||
$version{$c_pack} =~ s/^Version:\s*(.*)\s*/$1/;
|
$version{$c_pack} =~ s/^Version:\s*(.*)\s*/$1/;
|
||||||
push @oldspec, sprintf("%-16s%s","Version:",$version{$c_pack});
|
push @oldspec, sprintf("%-16s%s","Version:",$version{$c_pack});
|
||||||
push @oldspec, "XXXRELEASE";
|
push @oldspec, "XXXRELEASE";
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( $current_section ne "changelog" ) {
|
if ( $current_section ne "changelog" ) {
|
||||||
@ -595,8 +589,8 @@ while ( <SPE> ) {
|
|||||||
$base_package =~ s/^\s*Name:\s*(\S*)\s*/$1/;
|
$base_package =~ s/^\s*Name:\s*(\S*)\s*/$1/;
|
||||||
$base_package =~ s/\Q$_\E/$xdefinelist->{$_}/ for (sort { length($b) <=> length($a) } keys (%{$xdefinelist}));
|
$base_package =~ s/\Q$_\E/$xdefinelist->{$_}/ for (sort { length($b) <=> length($a) } keys (%{$xdefinelist}));
|
||||||
if ($debug) {
|
if ($debug) {
|
||||||
warn "DEBUG: base_package = $base_package\n";
|
warn "DEBUG: base_package = $base_package\n";
|
||||||
warn Dumper($xdefinelist);
|
warn Dumper($xdefinelist);
|
||||||
}
|
}
|
||||||
last;
|
last;
|
||||||
}
|
}
|
||||||
@ -608,6 +602,7 @@ warn ("base_package is $base_package\n") if $debug;
|
|||||||
if ( ! stat ((glob("$specdir/$base_package*.spec"))[0] || "") ) {
|
if ( ! stat ((glob("$specdir/$base_package*.spec"))[0] || "") ) {
|
||||||
$base_package =~ s/[0-9]$//;
|
$base_package =~ s/[0-9]$//;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! stat ((glob("$specdir/$base_package*.spec"))[0] || "") ) {
|
if ( ! stat ((glob("$specdir/$base_package*.spec"))[0] || "") ) {
|
||||||
$base_package =~ s/\-[^\-]*$//;
|
$base_package =~ s/\-[^\-]*$//;
|
||||||
}
|
}
|
||||||
@ -622,38 +617,38 @@ if ( ! stat ((glob("$specdir/$base_package*.spec"))[0] || "") ) {
|
|||||||
|
|
||||||
read_and_parse_old_spec ( $specfile, $base_package );
|
read_and_parse_old_spec ( $specfile, $base_package );
|
||||||
|
|
||||||
for my $tag (qw(BuildRequires Requires Provides)) {
|
for my $tag (qw(BuildRequires Requires Provides Obsoletes)) {
|
||||||
my $linesmoved = 1;
|
my $linesmoved = 1;
|
||||||
sortcycle: while ($linesmoved) {
|
sortcycle: while ($linesmoved) {
|
||||||
$linesmoved = 0;
|
$linesmoved = 0;
|
||||||
my @firstlines = ();
|
my @firstlines = ();
|
||||||
my @tags = ();
|
my @tags = ();
|
||||||
while ($oldspec[0]) {
|
while (defined $oldspec[0]) {
|
||||||
my $l = shift @oldspec;
|
my $l = shift @oldspec;
|
||||||
if ($l =~ m/^$tag:/ ) {
|
if ($l =~ m/^$tag:/i ) {
|
||||||
push(@tags, $l);
|
push(@tags, $l);
|
||||||
|
} else {
|
||||||
|
# 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);
|
||||||
|
if ($linesmoved) {
|
||||||
|
@oldspec = (@firstlines, @sortedtags, $l, @oldspec);
|
||||||
|
@firstlines = ();
|
||||||
|
@tags = ();
|
||||||
|
next sortcycle;
|
||||||
|
} else {
|
||||||
|
@firstlines = (@firstlines, @tags, $l);
|
||||||
|
@tags = ();
|
||||||
|
next;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
# if there are already tags, we need to sort and exit
|
push(@firstlines, $l);
|
||||||
if (@tags > 0) {
|
|
||||||
my @sortedtags = sort sort_tags_helper @tags;
|
|
||||||
$linesmoved = !compare_arrays(\@tags, \@sortedtags);
|
|
||||||
if ($linesmoved) {
|
|
||||||
@oldspec = (@firstlines, @sortedtags, $l, @oldspec);
|
|
||||||
@firstlines = ();
|
|
||||||
@tags = ();
|
|
||||||
next sortcycle;
|
|
||||||
} else {
|
|
||||||
@firstlines = (@firstlines, @tags, $l);
|
|
||||||
@tags = ();
|
|
||||||
next;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
push(@firstlines, $l);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@oldspec = (@firstlines, @oldspec);
|
@oldspec = (@firstlines, @oldspec);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -703,24 +698,24 @@ my $first_summary = 1;
|
|||||||
|
|
||||||
my $line;
|
my $line;
|
||||||
while (@oldspec) {
|
while (@oldspec) {
|
||||||
$line = shift @oldspec;
|
$line = shift @oldspec;
|
||||||
|
|
||||||
if ($line eq "XXXBLANKLINE") {
|
if ($line eq "XXXBLANKLINE") {
|
||||||
print "\n" unless $oldspec[0] && ($oldspec[0] =~ m/^XXX.*LINE/ || $oldspec[0] =~ /^\s*$/ || $oldspec[0] =~ /^\n/);
|
print "\n" unless $oldspec[0] && ($oldspec[0] =~ m/^XXX.*LINE/ || $oldspec[0] =~ /^\s*$/ || $oldspec[0] =~ /^\n/);
|
||||||
} elsif ($line eq "XXXDOUBLELINE") {
|
} elsif ($line eq "XXXDOUBLELINE") {
|
||||||
print "\n\n" unless $oldspec[0] && ($oldspec[0] =~ m/^XXX.*LINE/ || $oldspec[0] =~ /^\s*$/ || $oldspec[0] =~ /^\n/);
|
print "\n\n" unless $oldspec[0] && ($oldspec[0] =~ m/^XXX.*LINE/ || $oldspec[0] =~ /^\s*$/ || $oldspec[0] =~ /^\n/);
|
||||||
} elsif ($line eq "XXXRELEASE") {
|
} elsif ($line eq "XXXRELEASE") {
|
||||||
printf("%-16s%s\n", "Release:", "0") ;
|
printf("%-16s%s\n", "Release:", "0") ;
|
||||||
} elsif ($line =~ m/XXXPOSTSUMMARY (.*)$/) {
|
} elsif ($line =~ m/XXXPOSTSUMMARY (.*)$/) {
|
||||||
my $current_package = $1;
|
my $current_package = $1;
|
||||||
my $license = $seen_licenses{$current_package} || $main_license;
|
my $license = $seen_licenses{$current_package} || $main_license;
|
||||||
printf("%-16s%s\n", "License:", $license) if (!$license_unique || $first_summary);
|
printf("%-16s%s\n", "License:", $license) if (!$license_unique || $first_summary);
|
||||||
my $group = $seen_groups{$current_package} || $main_group;
|
my $group = $seen_groups{$current_package} || $main_group;
|
||||||
printf("%-16s%s\n", "Group:", $group) if (!$groups_unique || $first_summary);
|
printf("%-16s%s\n", "Group:", $group) if (!$groups_unique || $first_summary);
|
||||||
$first_summary = 0;
|
$first_summary = 0;
|
||||||
} else {
|
} else {
|
||||||
print "$line\n";
|
print "$line\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
print "\n" unless $line eq "XXXBLANKLINE";
|
print "\n" unless $line eq "XXXBLANKLINE";
|
||||||
|
Loading…
Reference in New Issue
Block a user