ferdnyc left a comment (rpm-software-management/rpm#3661)

The issue I just opened against the Fedora Packaging Guidelines, "[Outdated 
advice regarding %global vs. 
%define](https://pagure.io/packaging-committee/issue/1449). As you'll see, I 
dropped your name liberally @pmatilai 😉.

----

While its advice has been softened somewhat through the addition of some 
disclaimer language, the thrust of the section on how to define spec variables 
is still communicated by its title:

> ## [`%global` Preferred Over 
> `%define`](https://docs.fedoraproject.org/en-US/packaging-guidelines/#_global_preferred_over_define)
>
> Use `%global` instead of `%define`, unless you really need only locally 
> defined submacros within other macro definitions (a very rare case).
> 
> Rationale: The two macro defining statements behave the same when they are at 
> the top level of rpm’s nesting level.
> 
> But when they are used in nested macro expansions (like in `%{!?foo: ... }` 
> constructs, `%define` theoretically only lasts until the end brace (local 
> scope), while `%global` definitions have global scope.
> 
> Note that %define and %global differ in more ways than just scope: the body 
> of a %define’d macro is lazily expanded (i.e., when used), but the body of 
> %global is expanded at definition time. It’s possible to use %%-escaping to 
> force lazy expansion of %global.

This is, in [the words of RPM core developer Panu 
Matilainen](https://github.com/rpm-software-management/rpm/issues/3661#issuecomment-2728634266),
 "bad advice that spread far and wide". Accompanied by a fuller explanation of  
how  scoping (now) works for `%define` variables:

> That used to be the case in rpm < 4.14 (prior to rhel-8 if you like). The 
> worst issue with it was that %define _appeared_ to worked in those situations 
> but then an unrelated spec change could break suddenly break it. It was bad, 
> but the "always use global" cure is worse than the disease.
> 
> Since 4.14 only parametric macros have locally scoped macros.

We are strongly encouraged to stop telling people that they should be using 
`%global` everywhere, or really **anywhere**, unless it's absolutely necessary. 
(Meaning, unless immediate expansion of the variable is required.) For most 
specfile needs, the lazy expansion provided by `%define` is preferred.


-- 
Reply to this email directly or view it on GitHub:
https://github.com/rpm-software-management/rpm/issues/3661#issuecomment-2770440738
You are receiving this because you are subscribed to this thread.

Message ID: <rpm-software-management/rpm/issues/3661/[email protected]>
_______________________________________________
Rpm-maint mailing list
[email protected]
https://lists.rpm.org/mailman/listinfo/rpm-maint

Reply via email to