I'm new to RPM packaging. I've recently forked a repository, and one of the first things I tried to do was clean up formatting of the .spec file. Particularly the %if blocks were hard to follow because the previous author did not use any indentation at all. However, it seems like maybe indentation breaks tags. %if blocks that only contained other %macros inside seem to work okay, but if I have any leading whitespace on the lines for tags such as `Source1:` I get errors like this...
error: line 102: Unknown tag: Source1: firefox-45.0a2.tar.bz2
...and removing the leading whitespace removes the error.
I'm having a hard time finding anything that explicitly says whether or not leading whitespace is allowed in the spec file, so I'm hoping that I'm just making some silly and simple mistake. Otherwise, not being able to indent inside %if blocks is going to make working on this spec file more painful than it could / should be.
On 12/01/16 10:18 PM, Andrew Toskin wrote:
I'm new to RPM packaging. I've recently forked a repository, and one of the first things I tried to do was clean up formatting of the .spec file. Particularly the %if blocks were hard to follow because the previous author did not use any indentation at all. However, it seems like maybe indentation breaks tags. %if blocks that only contained other %macros inside seem to work okay, but if I have any leading whitespace on the lines for tags such as `Source1:` I get errors like this...
error: line 102: Unknown tag: Source1: firefox-45.0a2.tar.bz2
...and removing the leading whitespace removes the error.
I'm having a hard time finding anything that explicitly says whether or not leading whitespace is allowed in the spec file, so I'm hoping that I'm just making some silly and simple mistake. Otherwise, not being able to indent inside %if blocks is going to make working on this spec file more painful than it could / should be.
devel mailing list devel@lists.fedoraproject.org http://lists.fedoraproject.org/admin/lists/devel@lists.fedoraproject.org
Hello Andrew, In general, leading whitespace is only allowed when making conditional statement or using backslash like these following examples:
--- Example #1 --- %if (0%{?fedora} && 0%{?fedora} < 19) || (0%{?rhel} && 0%{?rhel} < 7) --vendor="fedora" \ %endif --dir=${RPM_BUILD_ROOT}%{_datadir}/applications \ %{name}.desktop
--- Example #2 --- for f in scribus/plugins/scriptplugin/{samples,scripts}/*.py do sed '1{/#!/usr/bin/env|#!/usr/bin/python/d}' $f > $f.new touch -r $f $f.new mv $f.new $f done ----------
Hope it helps.
On 01/13/2016 08:24 AM, Luya Tshimbalanga wrote:
In general, leading whitespace is only allowed when making conditional statement or using backslash like these following examples:
--- Example #1 --- %if (0%{?fedora} && 0%{?fedora} < 19) || (0%{?rhel} && 0%{?rhel} < 7) --vendor="fedora" \ %endif --dir=${RPM_BUILD_ROOT}%{_datadir}/applications \ %{name}.desktop
--- Example #2 --- for f in scribus/plugins/scriptplugin/{samples,scripts}/*.py do sed '1{/#!/usr/bin/env|#!/usr/bin/python/d}' $f > $f.new touch -r $f $f.new mv $f.new $f done
But these are part of scriptlets, so whitespace is passed to the shell, which then ignores it (except where it is significant, like the line ending before the “do”). I don't think it has to do with backslashes or conditional/control flow statements.
Florian
On Wed, 13 Jan 2016 06:18:31 -0000, Andrew Toskin wrote:
error: line 102: Unknown tag: Source1: firefox-45.0a2.tar.bz2
...and removing the leading whitespace removes the error.
If you test with elemental tags, such as Name, Version and Release, you can observe that they are not recognised, if there's leading whitespace.
However, trailing whitespace before and after the colon is accepted:
Name : something
That's in the documentation somewhere. Maximum RPM community edition probably.
I think it has been like that always. Syntax-highlighting performed inside Emacs also doesn't recognize tags with leading whitespace.
That's unfortunate. The spec file I've forked has certain tags *inside* of %if blocks. Things like this:
%if %{?system_cairo} BuildRequires: pkgconfig(cairo) >= %{cairo_version} %endif
In some of the longer blocks, no indentation makes it much harder to tell where the %if begins and ends.
Is there a way to convert tags like "BuildRequires:" into %macros so that they *can* be indented?
On 13/01/16 23:19 -0000, Andrew Toskin wrote:
Is there a way to convert tags like "BuildRequires:" into %macros so that they *can* be indented?
That would be highly unconventional, and so unlikely to make the .spec file easier to follow.
If it's really a problem you could use comments:
%if %{some_condition} BuildRequires: foo BuildRequires: bar BuildRequires: baz %endif # some_condition
"AT" == Andrew Toskin andrew@tosk.in writes:
AT> Is there a way to convert tags like "BuildRequires:" into %macros so AT> that they *can* be indented?
Sure there is, but.... please don't actually try to do that in Fedora packages. There are cases where such things might be easier to read, but in general I don't think that would be the case.
A better approach if you care about readability is to stop trying to use one spec across everything. You don't need any %if clauses at all if you do that.
Or you could locate the situations which cause large numbers of packages to require %if clauses in order to keep spec compatibility across multiple releases. Make lists and bring them forward for discussion. It might be possible to do something about it.
- J<
On Wed, Jan 13, 2016 at 06:35:08PM -0600, Jason L Tibbitts III wrote:
"AT" == Andrew Toskin andrew@tosk.in writes:
AT> Is there a way to convert tags like "BuildRequires:" into %macros so AT> that they *can* be indented?
Sure there is, but.... please don't actually try to do that in Fedora packages. There are cases where such things might be easier to read, but in general I don't think that would be the case.
A better approach if you care about readability is to stop trying to use one spec across everything. You don't need any %if clauses at all if you do that.
Agreed, except ...
Or you could locate the situations which cause large numbers of packages to require %if clauses in order to keep spec compatibility across multiple releases. Make lists and bring them forward for discussion. It might be possible to do something about it.
%ifarch is essential when dealing with secondard architectures that may not build all the features/packages required for a big package. Example:
http://pkgs.fedoraproject.org/cgit/rpms/libguestfs.git/tree/libguestfs.spec#...
Also being able to build subsets of packages (when building manually) is a nice to have sometimes, eg:
http://pkgs.fedoraproject.org/cgit/rpms/libvirt.git/tree/libvirt.spec#n393
(Hmmmm, why is libvirt.spec not using bcond?)
Rich.
A better approach if you care about readability is to stop trying to use one spec across everything. You don't need any %if clauses at all if you do that.
Well, I have not yet even written anything new to the spec file. This is a fork of an official Fedora package, and I'm still trying to make sense of everything. All the tags contained inside %if blocks, and all the patches and so on, existed before I started. So I assume the Mozilla packaging team knows some things that I don't.
Really, I think another great solution would be to make the RPM spec file more whitespace-agnostic. Why allow indentation for %macros, but ban it for tags?
But, point taken: I'll see if splitting into multiple spec files would make things easier to manage.