Skip to content

Commit

Permalink
Merge pull request #59 from marcus-h/spec_query_fixes
Browse files Browse the repository at this point in the history
Spec query fixes
  • Loading branch information
scarabeusiv committed Nov 16, 2017
2 parents 7000752 + 4895529 commit 1e990f0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
2 changes: 1 addition & 1 deletion 20-files-present-and-referenced
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ esac
for i in $DIR_TO_CHECK/*.spec ; do
test -f "$i" || continue
$HELPERS_DIR/spec_query --specfile "$i" --print-sources \
--no-conditionals --unique-sources \
--no-conditionals --keep-name-conditionals --disambiguate-sources \
>> "$TMPDIR/sources" 2>"$TMPDIR/sources.err"
# ignore expand errors with macro scripts
sed -i "/can't expand %(...)/d" "$TMPDIR/sources.err"
Expand Down
41 changes: 25 additions & 16 deletions helpers/spec_query
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,17 @@ use Build::Rpm;
# to query certain information from the specfile.

sub prepare_spec {
my ($fn, $no_conditionals, $unique_sources, $disambiguate_sources) = @_;
my ($fn, $no_conditionals, $keep_name_conditionals, $unique_sources,
$disambiguate_sources) = @_;
return $fn unless $no_conditionals;
my $spec;
open(F, '<', $fn) || die("open: $!\n");
my %seen;
my $dtags;
while (<F>) {
next if /^\s*%(?:if|else|endif)/;
if (/^\s*%(?:if|else|endif)/) {
next unless $keep_name_conditionals && /^\s*%if\s+.*%\{?name/;
}
chomp;
if (($unique_sources || $disambiguate_sources) &&
/^\s*((?:Source|Patch)\d*)\s*:(.*)$/i) {
Expand Down Expand Up @@ -53,10 +56,10 @@ sub prepare_spec {
}

sub parse {
my ($fn, $arch, $no_conditionals, $unique_sources,
my ($fn, $arch, $no_conditionals, $keep_name_conditionals, $unique_sources,
$disambiguate_sources) = @_;
my $spec = prepare_spec($fn, $no_conditionals, $unique_sources,
$disambiguate_sources);
my $spec = prepare_spec($fn, $no_conditionals, $keep_name_conditionals,
$unique_sources, $disambiguate_sources);
my $config = Build::read_config($arch, []);
$config->{'warnings'} = 1;
my $descr = Build::Rpm::parse($config, $spec);
Expand Down Expand Up @@ -87,15 +90,18 @@ sub usage {
print <<EOF;
Usage: $0 --specfile <specfile> [<options>]
Options:
--specfile <specfile>: the specfile that should be queried
--arch <arch>: arch that is used during parsing (default: noarch)
--no-conditionals: do not take %if* conditionals into account during
parsing
--unique-sources: fail if source/patch tags are not unique
--disambiguate-sources: disambiguate non-unique source/patch tags (only
needed for a "pathological" specfile)
--print-subpacks: print names of the main package and all subpackages
--print-sources: print names of all sources, patches, and icons
--specfile <specfile>: the specfile that should be queried
--arch <arch>: arch that is used during parsing (default: noarch)
--no-conditionals: do not take %if* conditionals into account during
parsing
--keep-name-conditionals: take conditionals of the form "%if ... %{name} ..."
into account (only useful to restrict the
--no-conditionals option)
--unique-sources: fail if source/patch tags are not unique
--disambiguate-sources: disambiguate non-unique source/patch tags (only
needed for a "pathological" specfile)
--print-subpacks: print names of the main package and all subpackages
--print-sources: print names of all sources, patches, and icons
EOF
exit($ret);
Expand All @@ -106,6 +112,7 @@ my $arch = 'noarch';
my $print_subpacks;
my $print_sources;
my $no_conditionals;
my $keep_name_conditionals;
my $unique_sources;
my $disambiguate_sources;

Expand All @@ -123,6 +130,8 @@ while (@ARGV) {
$print_sources = 1;
} elsif ($opt eq '--no-conditionals') {
$no_conditionals = 1;
} elsif ($opt eq '--keep-name-conditionals') {
$keep_name_conditionals = 1;
} elsif ($opt eq '--unique-sources') {
$unique_sources = 1;
} elsif ($opt eq '--disambiguate-sources') {
Expand All @@ -134,7 +143,7 @@ while (@ARGV) {
}
}

my $descr = parse($specfile, $arch, $no_conditionals, $unique_sources,
$disambiguate_sources);
my $descr = parse($specfile, $arch, $no_conditionals, $keep_name_conditionals,
$unique_sources, $disambiguate_sources);
print_subpacks($descr) if $print_subpacks;
print_sources($descr) if $print_sources;

0 comments on commit 1e990f0

Please sign in to comment.