FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Redhat > Fedora Packaging

 
 
LinkBack Thread Tools
 
Old 08-19-2011, 03:52 PM
James Antill
 
Default Are brackets around macros required?

On Thu, 2011-08-18 at 21:57 +0200, Göran Uddeborg wrote:
> Tom Callaway:
> > %namev%version
> >
> > Is the macro %namev? %name? %na?
>
> Michael Schwendt:
> > RPM may accept it, but it cannot always parse it correctly either:
> >
> > echo "a=b" > %nameconfig.cfg
> >
> > won't do the right thing even with %name being defined by default.
>
> Are you joking? Or am I missing something? Of course, it means
> %namev and %nameconfig respectively.
>
> Reusing the analogy with the shell, if you in a shell script see the
> code
>
> echo $PATHTYPE
>
> would you be unsure if that meant the value of the variable PATH
> followed by the string "TYPE", or if it meant the value of the
> variable PATHTYPE? I don't think you would.
>
> Save for Fortran, in all programming languages I can recall the parser
> takes the longest sequence of characters that is a valid token to be
> the next token from the input.
>
> I don't understand what you find so different in the spec file case.

spec. files are _not_ a programming language. You can't do loops, for
example. Even reassigning variables is ... unwise. As a related point, a
significant number of people who want to look at them are not
programmers.
In general I'd expect to see %{foo} for normal variables and %foo for
"special" variables, like %add_to_maven_depmap or %py_byte_compile etc.

> Tom Callaway:
> > It is sloppy form.
>
> Oh, come on! I understand you prefer the style with brackets. And
> your opinion certainly has much more weight than mine in Fedora.

Indeed ... most of the reason for FPC and the guidelines is because
"good" consistency is better than "perfect" uniqueness. There are over
10,000 source packages in F15 GA, it makes a big difference.

--
packaging mailing list
packaging@lists.fedoraproject.org
https://admin.fedoraproject.org/mailman/listinfo/packaging
 
Old 08-19-2011, 06:00 PM
Michael Schwendt
 
Default Are brackets around macros required?

On Thu, 18 Aug 2011 21:57:43 +0200, GU (Göran) wrote:

> Tom Callaway:
> > %namev%version
> >
> > Is the macro %namev? %name? %na?
>
> Michael Schwendt:
> > RPM may accept it, but it cannot always parse it correctly either:
> >
> > echo "a=b" > %nameconfig.cfg
> >
> > won't do the right thing even with %name being defined by default.
>
> Are you joking? Or am I missing something? Of course, it means
> %namev and %nameconfig respectively.

What about these?

%define name emacs
ln -s %name %name23.2
ln -s %name %name-23.2
ln -s %name %name_23.2
ln -s %name %name_%version
ln -s %name %name23
mv %name.man %name.2

Do you parse them all without testing? (not even programming language knowledge
is helpful in all cases)

Unless we can teach editors (the most common ones used to edit RPM spec files)
to do the variable highlighting correctly, explicit brackets are the way to go.
If a variable name is surrounded by whitespace, missing brackets are okay.
--
packaging mailing list
packaging@lists.fedoraproject.org
https://admin.fedoraproject.org/mailman/listinfo/packaging
 
Old 08-19-2011, 08:37 PM
Tom Callaway
 
Default Are brackets around macros required?

On 08/19/2011 11:00 AM, Michael Schwendt wrote:
> Unless we can teach editors (the most common ones used to edit RPM spec files)
> to do the variable highlighting correctly, explicit brackets are the way to go.
> If a variable name is surrounded by whitespace, missing brackets are okay.

Or, you can just build a habit around always using brackets and avoid
spending an hour trying to figure out why a macro is evaluating
incorrectly or why a file name is being written out wrong.

~tom

==
Fedora Project
--
packaging mailing list
packaging@lists.fedoraproject.org
https://admin.fedoraproject.org/mailman/listinfo/packaging
 
Old 08-19-2011, 09:45 PM
"Göran Uddeborg"
 
Default Are brackets around macros required?

Michael Schwendt:
> Do you parse them all without testing?

>From your question I was kind of expecting some surprising exception.
But when I tested they all behaved the way I would have thought.

But it doesn't matter. I understand I'm not convincing anyone, and
I'll change my package to follow this rule.

One more detail before I go away. Spec files do contain small scripts
(%build, %post, etc.) These scripts can use both spec file macros and
shell variables. The exchangable %{buildroot} and ${RPM_BUILD_ROOT}
for example. Does the rule to to always use brackets apply to both,
or only to the spec macros?
--
packaging mailing list
packaging@lists.fedoraproject.org
https://admin.fedoraproject.org/mailman/listinfo/packaging
 
Old 08-20-2011, 05:16 AM
Ralf Corsepius
 
Default Are brackets around macros required?

On 08/19/2011 11:45 PM, Göran Uddeborg wrote:
> Michael Schwendt:
>> Do you parse them all without testing?

I sense a misunderstanding.

People seem to presume rpm.specs to be written in a "well defined
programming language" using a lexical scanner and parser underneath.

This does not apply, the "rpm.spec language" is a "macro language",
similar to regexes and m4, using macro sets underneath, similar to
autoconf or sendmail, with all kind of ambiguities and "historic
heritage and historic heuristics" underneath.

I.e. rpm doesn't actually "parse" spec files in the sense
compilers/interpreters would parse/interpret a well "defined language",
it expands macros and passes the results to other parties.

>> From your question I was kind of expecting some surprising exception.
> But when I tested they all behaved the way I would have thought.
>
> But it doesn't matter. I understand I'm not convincing anyone, and
> I'll change my package to follow this rule.
>
> One more detail before I go away. Spec files do contain small scripts
> (%build, %post, etc.) These scripts can use both spec file macros and
> shell variables. The exchangable %{buildroot} and ${RPM_BUILD_ROOT}
> for example. Does the rule to to always use brackets apply to both,
> or only to the spec macros?

They are supposed to be complete independent.

Actually, rpmbuild first expands the macros inside of spec's scriptlet
and then hands the results over to the shell.

I.e. rpm itself is supposed not even to touch to let it pass through as
"arbitrary text".

Ralf
--
packaging mailing list
packaging@lists.fedoraproject.org
https://admin.fedoraproject.org/mailman/listinfo/packaging
 
Old 08-20-2011, 11:40 AM
Michael Schwendt
 
Default Are brackets around macros required?

On Sat, 20 Aug 2011 07:16:25 +0200, RC (Ralf) wrote:

> On 08/19/2011 11:45 PM, Göran Uddeborg wrote:
> > Michael Schwendt:
> >> Do you parse them all without testing?
>
> I sense a misunderstanding.
>
> People seem to presume rpm.specs to be written in a "well defined
> programming language" using a lexical scanner and parser underneath.

To clarify my use of the term "parse" above, what I meant is the human
parser. Whether the reader of the spec file is able to _recognise_ a macro
easily/immediately. Especially in situations where they are surrounded by
non-space characters. Brackets not only aid the human reader but also the
machine that substitutes macros with their values. Or the editor that
applies syntax highlighting.

> This does not apply, the "rpm.spec language" is a "macro language",
> similar to regexes and m4, using macro sets underneath, similar to
> autoconf or sendmail, with all kind of ambiguities and "historic
> heritage and historic heuristics" underneath.
>
> I.e. rpm doesn't actually "parse" spec files in the sense
> compilers/interpreters would parse/interpret a well "defined language",
> it expands macros and passes the results to other parties.

What constitutes a macro? What is the grammar? If we restrict ourselves
to using only a subset of the possible expressions that build macro names,
we can avoid errors and increase readability.

Since you talk about "ambiguities", those commonly lead to bugs with
poorly named variables in programming languages, too, not just RPM spec
files.

In a sufficiently large spec file with more than the default set of
macros, it isn't obvious whether %name2 is expected to be %{name}2 instead
and what lib%name_* is meant to match. rpmbuild wouldn't complain. Unexpanded
macros have lead to errors in packages before. Mixed macro usage like
%version and %ver has been seen before, too, a pitfall when replacing %ver
with something else and either messing up %version or forgetting a single
%{ver}.

Btw, do you agree with making explicit brackets a SHOULD?
--
packaging mailing list
packaging@lists.fedoraproject.org
https://admin.fedoraproject.org/mailman/listinfo/packaging
 

Thread Tools




All times are GMT. The time now is 07:49 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2007 - 2008, www.linux-archive.org