Skip to content

Commit

Permalink
More spec file parser cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
mlschroe committed Mar 13, 2024
1 parent 83a59b9 commit 470713f
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions Build/Rpm.pm
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,7 @@ sub parse {
next;
}
}
if ($multilinecondition || $line =~ /^\s*\%\{[?!]*-?[0-9a-zA-Z_]+:\s*$/s) {
if ($multilinecondition || $line =~ /^\s*%\{[?!]*-?[0-9a-zA-Z_]+:\s*$/s) {
# is this a multi-line macro condition?
$line = "$multilinecondition\n$line" if defined $multilinecondition;
undef $multilinecondition;
Expand Down Expand Up @@ -794,8 +794,7 @@ sub parse {
# skip was set before, so we did not expand macros
$line = expandmacros($config, $line, $lineno, \%macros, \%macros_args);
$line = splitexpansionresult($line, \@includelines) if $line =~ /\n/s;
}
if ($skip) {
} elsif ($skip) {
$skip += 2 if $line =~ /^\s*%if/; # increase nesting level for %if statements
$xspec->[-1] = [ $xspec->[-1], undef ] if $doxspec;
$ifdeps = 1 if $line =~ /^(?:BuildRequires|BuildPrereq|BuildConflicts|\#\!BuildIgnore|\#\!BuildConflicts|\#\!BuildRequires)\s*:\s*\S/i;
Expand Down Expand Up @@ -836,11 +835,11 @@ sub parse {
next;
}

# do this always?
$xspec->[-1] = [ $xspec->[-1], $line ] if $doxspec && $config->{'save_expanded'};

# fast check if this is an interesting line
if ($line !~ /[%:\!]/) {
$xspec->[-1] = [ $xspec->[-1], $line ] if $doxspec && $config->{'save_expanded'};
next;
}
next if $line !~ /[%:\!]/;

# handle %include statement
if ($includecallback && $line =~ /^\s*%include\s+(.*)\s*$/) {
Expand All @@ -852,6 +851,7 @@ sub parse {
}
}


# generic parsing is done, the rest is spec specific
my $keyword;
my $arg;
Expand Down Expand Up @@ -931,14 +931,18 @@ sub parse {
if (defined($hasnfb) && $keyword eq 'buildrequires') {
if ((grep {$_ eq 'glibc' || $_ eq 'rpm' || $_ eq 'gcc' || $_ eq 'bash'} @ndeps) > 2) {
# ignore old generated BuildRequire lines.
$xspec->[-1] = [ $xspec->[-1], undef ] if $doxspec;
if ($doxspec) {
$xspec->[-1] = $xspec->[-1]->[0] if ref($xspec->[-1]);
$xspec->[-1] = [ $xspec->[-1], undef ] if $doxspec;
}
next;
}
}
# put filtered line into xspec if we did filtering by qualifier
if ($replace && $doxspec && $line !~ /^#/) {
die unless $line =~ /(.*?):/;
$xspec->[-1] = [ $xspec->[-1], @ndeps ? "$1: ".join(' ', @ndeps) : '' ];
$xspec->[-1] = $xspec->[-1]->[0] if ref($xspec->[-1]);
$xspec->[-1] = [ $xspec->[-1], @ndeps ? "$1: ".join(' ', @ndeps) : '' ] if $doxspec;
}
if ($keyword eq 'buildrequires' || $keyword eq 'buildprereq' || $keyword eq '#!buildrequires') {
push @packdeps, @ndeps;
Expand Down Expand Up @@ -978,6 +982,7 @@ sub parse {
push @prereqs, $pack unless grep {$_ eq $pack} @prereqs;
}
}
next;
}

if ($keyword && !defined($arg)) {
Expand All @@ -988,6 +993,7 @@ sub parse {
} elsif ($keyword eq '#!remoteasset') {
$remoteasset = {};
}
next;
}

# need to special case because of tagextra...
Expand All @@ -1011,6 +1017,7 @@ sub parse {
push @{$ret->{'remoteassets'}}, $remoteasset;
}
$remoteasset = undef;
next;
}

if (!$preamble && ($line =~ /^(Source\d*|Patch\d*|Url|Icon|BuildRequires|BuildPrereq|BuildConflicts|\#\!BuildIgnore|\#\!BuildConflicts|\#\!BuildRequires)\s*:\s*(\S.*)$/i)) {
Expand All @@ -1028,10 +1035,6 @@ sub parse {
$preamble = 0;
}

# do this always?
if ($doxspec && $config->{'save_expanded'}) {
$xspec->[-1] = [ $xspec->[-1], $line ];
}
}
close SPEC unless ref $specfile;
if (defined($hasnfb)) {
Expand All @@ -1043,8 +1046,8 @@ sub parse {
}
unshift @subpacks, $ret->{'name'} if defined $ret->{'name'};
$ret->{'subpacks'} = \@subpacks;
$ret->{'exclarch'} = $exclarch if defined $exclarch;
$ret->{'badarch'} = $badarch if defined $badarch;
$ret->{'exclarch'} = $exclarch if $exclarch;
$ret->{'badarch'} = $badarch if $badarch;
$ret->{'deps'} = \@packdeps;
$ret->{'prereqs'} = \@prereqs if @prereqs;
$ret->{'onlynative'} = \@onlynative if @onlynative;
Expand Down

0 comments on commit 470713f

Please sign in to comment.