Skip to content

Commit e490139

Browse files
Implement fallback for package name to the recipename
1 parent 3a9f91f commit e490139

File tree

3 files changed

+88
-3
lines changed

3 files changed

+88
-3
lines changed

Build/Rpm.pm

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,6 +1322,11 @@ sub parse {
13221322
$$nfbline = [$$nfbline, undef ];
13231323
}
13241324
}
1325+
1326+
# if the name is missing or starts with a '%' (probably caused by an unknown macro),
1327+
# fall back to the recipename.
1328+
$ret->{'name'} = $1 if (!$ret->{'name'} || $ret->{'name'} =~ /^\%/) && ($options{'recipename'} || '') =~ /(.*)\.spec$/;
1329+
13251330
unshift @subpacks, $ret->{'name'} if defined $ret->{'name'};
13261331
$ret->{'subpacks'} = \@subpacks;
13271332
$ret->{'exclarch'} = $exclarch if $exclarch;

PBuild/Recipe.pm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,12 @@ sub parse {
125125
my $d;
126126
local $bconf->{'buildflavor'} = $p->{'flavor'};
127127
eval {
128-
$d = Build::parse_typed($bconf, "$p->{'dir'}/$recipe", $bt);
128+
$d = Build::parse_typed($bconf, "$p->{'dir'}/$recipe", $bt, 'recipename' => $recipe);
129129
die("can not parse $recipe\n") unless $d;
130130
if ($bconf_host && $d->{'nativebuild'}) {
131131
$p->{'native'} = 1;
132132
local $bconf_host->{'buildflavor'} = $p->{'flavor'};
133-
$d = Build::parse_typed($bconf_host, "$p->{'dir'}/$recipe", $bt);
133+
$d = Build::parse_typed($bconf_host, "$p->{'dir'}/$recipe", $bt, 'recipename' => $recipe);
134134
die("can not parse $recipe\n") unless $d;
135135
$arch = $arch_host;
136136
}

t/parse_spec.t

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/perl -w
22

33
use strict;
4-
use Test::More tests => 19;
4+
use Test::More tests => 22;
55

66
use Build;
77
use Build::Rpm;
@@ -495,3 +495,83 @@ $expected = {
495495
};
496496
$result = Build::Rpm::parse($conf, [ split("\n", $spec) ]);
497497
is_deeply($result, $expected, "option macros with negation");
498+
499+
# Test filename fallback when Name: tag is missing
500+
$spec = q{
501+
Version: 1.0
502+
Release: 1
503+
BuildRequires: foo
504+
};
505+
$expected = {
506+
'name' => 'test-package',
507+
'version' => '1.0',
508+
'release' => '1',
509+
'deps' => [ 'foo' ],
510+
'subpacks' => [ 'test-package' ],
511+
};
512+
$result = Build::Rpm::parse($conf, [ split("\n", $spec) ], 'recipename' => 'test-package.spec');
513+
is_deeply($result, $expected, "filename fallback for missing Name tag");
514+
515+
# Test filename fallback when Name: tag contains unresolved macro
516+
$spec = q{
517+
Name: %{undefined_macro}
518+
Version: 1.0
519+
Release: 1
520+
BuildRequires: bar
521+
};
522+
$expected = {
523+
'name' => 'my-package',
524+
'version' => '1.0',
525+
'release' => '1',
526+
'deps' => [ 'bar' ],
527+
'subpacks' => [ 'my-package' ],
528+
};
529+
$result = Build::Rpm::parse($conf, [ split("\n", $spec) ], 'recipename' => 'my-package.spec');
530+
is_deeply($result, $expected, "filename fallback for macro-based Name tag");
531+
532+
# Test rpmautospec-style spec file (similar to vazirmatn-fonts.spec)
533+
$spec = q{
534+
## START: Set by rpmautospec
535+
## RPMAUTOSPEC: autorelease, autochangelog
536+
%define autorelease(e:s:pb:n) %{?-p:0.}%{lua:
537+
release_number = 10;
538+
base_release_number = tonumber(rpm.expand("%{?-b*}%{!?-b:1}"));
539+
print(release_number + base_release_number - 1);
540+
}%{?-e:.%{-e*}}%{?-s:.%{-s*}}%{!?-n:%{?dist}}
541+
## END: Set by rpmautospec
542+
543+
Version: 33.003
544+
Release: %autorelease
545+
URL: https://example.com/project
546+
547+
%global fontlicense OFL-1.1
548+
%global common_description A test font package
549+
550+
Source0: https://example.com/release/v%{version}/font-v%{version}.zip
551+
552+
%prep
553+
%setup -q -c
554+
555+
%build
556+
# Build commands here
557+
558+
%install
559+
# Install commands here
560+
561+
%files
562+
# File list here
563+
564+
%changelog
565+
# Generated by rpmautospec
566+
};
567+
$expected = {
568+
'name' => 'vazirmatn-fonts',
569+
'version' => '33.003',
570+
'release' => '%{lua:',
571+
'url' => 'https://example.com/project',
572+
'source0' => 'https://example.com/release/v33.003/font-v33.003.zip',
573+
'deps' => [],
574+
'subpacks' => [ 'vazirmatn-fonts' ],
575+
};
576+
$result = Build::Rpm::parse($conf, [ split("\n", $spec) ], 'recipename' => 'vazirmatn-fonts.spec');
577+
is_deeply($result, $expected, "rpmautospec-style spec file with filename fallback");

0 commit comments

Comments
 (0)