[Rpm-maint] [rpm-software-management/rpm] Add %bcond macro for defining build conditionals (#1520)

Petr Viktorin notifications at github.com
Wed Jan 27 16:58:45 UTC 2021


The names `%bcond_with` and `%bcond_without` are based the inner workings of the macros. They describe the inverse of their default; anecdotal evidence sugests that this is quite confusing in practice. I personally always have to stop and think when using/reviewing them.

This PR adds the macro `%bcond`, which does the same thing as either `%bcond_with` or `%bcond_without`, based on a numeric "default" value:

```
# To build with "gnutls" by default (equivalent to %bcond_without gnutls):
%bcond gnutls 1
# To build without "gnutls" default (equivalent to %bcond_with gnutls):
%bcond gnutls 0
```
It allows more complex defaults, simplifying a common if-elif pattern (see https://github.com/rpm-software-management/rpm/issues/941):
```
# By default, build with openssl iff not building with gnutls (but allow building with none or both)
%bcond openssl %{without gnutls}

# Enable some new feature that only works on Fedora 30+ with the gnutls crypto
%bcond new_feature %[ 0%fedora > 30 && %{with gnutls} ]
```
Documentation is changed to mention `%bcond` first – the only disadvantage I can see vs. the existing macros is that old RPM versions won't have it.

---

This is my first contribution to RPM. Please tell me all the things I'm doing wrong!
(e.g. should this be discussed somewhere first?)
You can view, comment on, or merge this pull request online at:

  https://github.com/rpm-software-management/rpm/pull/1520

-- Commit Summary --

  * Add %bcond macro for defining build conditionals

-- File Changes --

    M doc/manual/conditionalbuilds.md (39)
    M macros.in (53)
    A tests/data/SPECS/bcondtest.spec (33)
    M tests/rpmbuild.at (62)
    M tests/rpmmacro.at (21)

-- Patch Links --

https://github.com/rpm-software-management/rpm/pull/1520.patch
https://github.com/rpm-software-management/rpm/pull/1520.diff

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/rpm-software-management/rpm/pull/1520
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rpm.org/pipermail/rpm-maint/attachments/20210127/0721d766/attachment-0001.html>


More information about the Rpm-maint mailing list