PackagingDrafts/global preferred over define

From FedoraProject

Jump to: navigation, search

Contents

 %global preferred over %define

current usage of %define beneath Packaging

all uses are for either

  • %{!?foo:%define foo ...} usage, or
  • global top level macro definitions.

So both can be simply s/%define/%global/g.

Proposal for addition into the 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 a 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.

The reason this hasn't bitten us as often is that due to a minor bug in rpm the invalidated local macro definition is not garbage collected unless other events force rpm to. So the bug is seldomly triggered, but when it is, it is difficult to diagnose the issue. That's why we'd like to keep away from %defines and educate packagers to use %global by default to avoid creation of new latent bugs.