|
|
fa6a06 |
From 7b1fc619a5c828828dad7c1f61f525d957b9e2c5 Mon Sep 17 00:00:00 2001
|
|
|
fa6a06 |
From: Petr Viktorin <pviktori@redhat.com>
|
|
|
fa6a06 |
Date: Wed, 27 Jan 2021 17:32:51 +0100
|
|
|
fa6a06 |
Subject: [PATCH] Add %bcond macro for defining build conditionals
|
|
|
fa6a06 |
|
|
|
fa6a06 |
Move documentation from comments to reference manual
|
|
|
fa6a06 |
Fixes: https://github.com/rpm-software-management/rpm/issues/941
|
|
|
fa6a06 |
|
|
|
fa6a06 |
(cherry picked from commit a99b6373af0774f4bef62aa89defc84cfcacc078)
|
|
|
fa6a06 |
---
|
|
|
fa6a06 |
macros.in | 54 +++++++----------------
|
|
|
fa6a06 |
tests/Makefile.am | 1 +
|
|
|
fa6a06 |
tests/data/SPECS/bcondtest.spec | 33 +++++++++++++++
|
|
|
fa6a06 |
tests/rpmbuild.at | 73 ++++++++++++++++++++++++++++++++
|
|
|
fa6a06 |
5 files changed, 157 insertions(+), 42 deletions(-)
|
|
|
fa6a06 |
create mode 100644 tests/data/SPECS/bcondtest.spec
|
|
|
fa6a06 |
|
|
|
fa6a06 |
diff --git a/macros.in b/macros.in
|
|
|
fa6a06 |
index 7c458f5d8a..35462c933c 100644
|
|
|
fa6a06 |
--- a/macros.in
|
|
|
fa6a06 |
+++ b/macros.in
|
|
|
fa6a06 |
@@ -78,47 +78,25 @@
|
|
|
fa6a06 |
%defined() %{expand:%%{?%{1}:1}%%{!?%{1}:0}}
|
|
|
fa6a06 |
%undefined() %{expand:%%{?%{1}:0}%%{!?%{1}:1}}
|
|
|
fa6a06 |
|
|
|
fa6a06 |
-# Shorthand for %{defined with_...}
|
|
|
fa6a06 |
+# Handle conditional builds.
|
|
|
fa6a06 |
+# (see 'conditionalbuilds' in the manual)
|
|
|
fa6a06 |
+#
|
|
|
fa6a06 |
+# Internally, the `--with foo` option defines the macro `_with_foo` and the
|
|
|
fa6a06 |
+# `--without foo` option defines the macro `_without_foo`.
|
|
|
fa6a06 |
+# Based on those and a default (used when neither is given), bcond macros
|
|
|
fa6a06 |
+# define the macro `with_foo`, which should later be checked:
|
|
|
fa6a06 |
+
|
|
|
fa6a06 |
+%bcond() %[ (%2)\
|
|
|
fa6a06 |
+ ? "%{expand:%%{!?_without_%{1}:%%global with_%{1} 1}}"\
|
|
|
fa6a06 |
+ : "%{expand:%%{?_with_%{1}:%%global with_%{1} 1}}"\
|
|
|
fa6a06 |
+]
|
|
|
fa6a06 |
+%bcond_with() %bcond %{1} 0
|
|
|
fa6a06 |
+%bcond_without() %bcond %{1} 1
|
|
|
fa6a06 |
+
|
|
|
fa6a06 |
+# Shorthands for %{defined with_...}:
|
|
|
fa6a06 |
%with() %{expand:%%{?with_%{1}:1}%%{!?with_%{1}:0}}
|
|
|
fa6a06 |
%without() %{expand:%%{?with_%{1}:0}%%{!?with_%{1}:1}}
|
|
|
fa6a06 |
|
|
|
fa6a06 |
-# Handle conditional builds. %bcond_with is for case when feature is
|
|
|
fa6a06 |
-# default off and needs to be activated with --with ... command line
|
|
|
fa6a06 |
-# switch. %bcond_without is for the dual case.
|
|
|
fa6a06 |
-#
|
|
|
fa6a06 |
-# %bcond_with foo defines symbol with_foo if --with foo was specified on
|
|
|
fa6a06 |
-# command line.
|
|
|
fa6a06 |
-# %bcond_without foo defines symbol with_foo if --without foo was *not*
|
|
|
fa6a06 |
-# specified on command line.
|
|
|
fa6a06 |
-#
|
|
|
fa6a06 |
-# For example (spec file):
|
|
|
fa6a06 |
-#
|
|
|
fa6a06 |
-# (at the beginning)
|
|
|
fa6a06 |
-# %bcond_with extra_fonts
|
|
|
fa6a06 |
-# %bcond_without static
|
|
|
fa6a06 |
-# (and later)
|
|
|
fa6a06 |
-# %if %{with extra_fonts}
|
|
|
fa6a06 |
-# ...
|
|
|
fa6a06 |
-# %else
|
|
|
fa6a06 |
-# ...
|
|
|
fa6a06 |
-# %endif
|
|
|
fa6a06 |
-# %if ! %{with static}
|
|
|
fa6a06 |
-# ...
|
|
|
fa6a06 |
-# %endif
|
|
|
fa6a06 |
-# %if %{with static}
|
|
|
fa6a06 |
-# ...
|
|
|
fa6a06 |
-# %endif
|
|
|
fa6a06 |
-# %{?with_static: ... }
|
|
|
fa6a06 |
-# %{!?with_static: ... }
|
|
|
fa6a06 |
-# %{?with_extra_fonts: ... }
|
|
|
fa6a06 |
-# %{!?with_extra_fonts: ... }
|
|
|
fa6a06 |
-
|
|
|
fa6a06 |
-#
|
|
|
fa6a06 |
-# The bottom line: never use without_foo, _with_foo nor _without_foo, only
|
|
|
fa6a06 |
-# with_foo. This way changing default set of bconds for given spec is just
|
|
|
fa6a06 |
-# a matter of changing single line in it and syntax is more readable.
|
|
|
fa6a06 |
-%bcond_with() %{expand:%%{?_with_%{1}:%%global with_%{1} 1}}
|
|
|
fa6a06 |
-%bcond_without() %{expand:%%{!?_without_%{1}:%%global with_%{1} 1}}
|
|
|
fa6a06 |
#
|
|
|
fa6a06 |
#==============================================================================
|
|
|
fa6a06 |
# ---- Required rpmrc macros.
|
|
|
fa6a06 |
diff --git a/tests/Makefile.am b/tests/Makefile.am
|
|
|
fa6a06 |
index 66cee3273b..6d41ef93c5 100644
|
|
|
fa6a06 |
--- a/tests/Makefile.am
|
|
|
fa6a06 |
+++ b/tests/Makefile.am
|
|
|
fa6a06 |
@@ -40,6 +40,7 @@ EXTRA_DIST += $(TESTSUITE_AT)
|
|
|
fa6a06 |
|
|
|
fa6a06 |
## testsuite data
|
|
|
fa6a06 |
EXTRA_DIST += data/SPECS/attrtest.spec
|
|
|
fa6a06 |
+EXTRA_DIST += data/SPECS/bcondtest.spec
|
|
|
fa6a06 |
EXTRA_DIST += data/SPECS/buildrequires.spec
|
|
|
fa6a06 |
EXTRA_DIST += data/SPECS/docmiss.spec
|
|
|
fa6a06 |
EXTRA_DIST += data/SPECS/hello.spec
|
|
|
fa6a06 |
diff --git a/tests/data/SPECS/bcondtest.spec b/tests/data/SPECS/bcondtest.spec
|
|
|
fa6a06 |
new file mode 100644
|
|
|
fa6a06 |
index 0000000000..7172a31d29
|
|
|
fa6a06 |
--- /dev/null
|
|
|
fa6a06 |
+++ b/tests/data/SPECS/bcondtest.spec
|
|
|
fa6a06 |
@@ -0,0 +1,33 @@
|
|
|
fa6a06 |
+Name: bcondtest
|
|
|
fa6a06 |
+Version: 1.0
|
|
|
fa6a06 |
+Release: 1
|
|
|
fa6a06 |
+Group: Testing
|
|
|
fa6a06 |
+License: CC0
|
|
|
fa6a06 |
+BuildArch: noarch
|
|
|
fa6a06 |
+Summary: Test package for the bcond macro
|
|
|
fa6a06 |
+
|
|
|
fa6a06 |
+%bcond normally_on 1
|
|
|
fa6a06 |
+%bcond normally_off 0
|
|
|
fa6a06 |
+%bcond both_features %[%{with normally_on} && %{with normally_off}]
|
|
|
fa6a06 |
+
|
|
|
fa6a06 |
+%if %{with normally_on}
|
|
|
fa6a06 |
+Provides: has_bcond(normally_on)
|
|
|
fa6a06 |
+%endif
|
|
|
fa6a06 |
+%if %{with normally_off}
|
|
|
fa6a06 |
+Provides: has_bcond(normally_off)
|
|
|
fa6a06 |
+%endif
|
|
|
fa6a06 |
+%if %{with both_features}
|
|
|
fa6a06 |
+Provides: has_bcond(both_features)
|
|
|
fa6a06 |
+%endif
|
|
|
fa6a06 |
+
|
|
|
fa6a06 |
+%description
|
|
|
fa6a06 |
+%{summary}
|
|
|
fa6a06 |
+
|
|
|
fa6a06 |
+%install
|
|
|
fa6a06 |
+mkdir -p %{buildroot}/opt
|
|
|
fa6a06 |
+touch %{buildroot}/opt/file
|
|
|
fa6a06 |
+
|
|
|
fa6a06 |
+%files
|
|
|
fa6a06 |
+/opt/file
|
|
|
fa6a06 |
+
|
|
|
fa6a06 |
+%changelog
|
|
|
fa6a06 |
diff --git a/tests/rpmbuild.at b/tests/rpmbuild.at
|
|
|
fa6a06 |
index 30d8e6895d..f378a4af2a 100644
|
|
|
fa6a06 |
--- a/tests/rpmbuild.at
|
|
|
fa6a06 |
+++ b/tests/rpmbuild.at
|
|
|
fa6a06 |
@@ -1801,3 +1801,76 @@ runroot rpmbuild -ba --quiet \
|
|
|
fa6a06 |
[],
|
|
|
fa6a06 |
[])
|
|
|
fa6a06 |
AT_CLEANUP
|
|
|
fa6a06 |
+
|
|
|
fa6a06 |
+AT_SETUP([bcond macro])
|
|
|
fa6a06 |
+AT_KEYWORDS([bcond build])
|
|
|
fa6a06 |
+RPMDB_INIT
|
|
|
fa6a06 |
+
|
|
|
fa6a06 |
+# basic bcond behavior with --eval
|
|
|
fa6a06 |
+AT_CHECK([
|
|
|
fa6a06 |
+runroot rpm \
|
|
|
fa6a06 |
+ --eval "%bcond normally_on 1" \
|
|
|
fa6a06 |
+ --eval "%bcond normally_off 0" \
|
|
|
fa6a06 |
+ --eval "%bcond both_features %[[%{with normally_on} && %{with normally_off}]]" \
|
|
|
fa6a06 |
+ --eval "%{with normally_on}" \
|
|
|
fa6a06 |
+ --eval "%{with normally_off}" \
|
|
|
fa6a06 |
+ --eval "%{with both_features}"
|
|
|
fa6a06 |
+],
|
|
|
fa6a06 |
+[0],
|
|
|
fa6a06 |
+[
|
|
|
fa6a06 |
+
|
|
|
fa6a06 |
+
|
|
|
fa6a06 |
+1
|
|
|
fa6a06 |
+0
|
|
|
fa6a06 |
+0
|
|
|
fa6a06 |
+],
|
|
|
fa6a06 |
+[])
|
|
|
fa6a06 |
+
|
|
|
fa6a06 |
+# bcond behavior, without CLI options
|
|
|
fa6a06 |
+AT_CHECK([
|
|
|
fa6a06 |
+runroot rpmbuild -bb --quiet /data/SPECS/bcondtest.spec
|
|
|
fa6a06 |
+runroot rpm -q --provides -p /build/RPMS/noarch/bcondtest-1.0-1.noarch.rpm |
|
|
|
fa6a06 |
+ grep has_bcond | sort
|
|
|
fa6a06 |
+],
|
|
|
fa6a06 |
+[0],
|
|
|
fa6a06 |
+[has_bcond(normally_on)
|
|
|
fa6a06 |
+],
|
|
|
fa6a06 |
+[])
|
|
|
fa6a06 |
+
|
|
|
fa6a06 |
+# bcond behavior, --with
|
|
|
fa6a06 |
+AT_CHECK([
|
|
|
fa6a06 |
+runroot rpmbuild -bb --quiet --with normally_on --with normally_off \
|
|
|
fa6a06 |
+ /data/SPECS/bcondtest.spec
|
|
|
fa6a06 |
+runroot rpm -q --provides -p /build/RPMS/noarch/bcondtest-1.0-1.noarch.rpm |
|
|
|
fa6a06 |
+ grep has_bcond | sort
|
|
|
fa6a06 |
+],
|
|
|
fa6a06 |
+[0],
|
|
|
fa6a06 |
+[has_bcond(both_features)
|
|
|
fa6a06 |
+has_bcond(normally_off)
|
|
|
fa6a06 |
+has_bcond(normally_on)
|
|
|
fa6a06 |
+],
|
|
|
fa6a06 |
+[])
|
|
|
fa6a06 |
+
|
|
|
fa6a06 |
+# bcond behavior, --without
|
|
|
fa6a06 |
+AT_CHECK([
|
|
|
fa6a06 |
+runroot rpmbuild -bb --quiet --without normally_on --without normally_off \
|
|
|
fa6a06 |
+ /data/SPECS/bcondtest.spec
|
|
|
fa6a06 |
+runroot rpm -q --provides -p /build/RPMS/noarch/bcondtest-1.0-1.noarch.rpm |
|
|
|
fa6a06 |
+ grep has_bcond | sort
|
|
|
fa6a06 |
+],
|
|
|
fa6a06 |
+[0],
|
|
|
fa6a06 |
+[],
|
|
|
fa6a06 |
+[])
|
|
|
fa6a06 |
+
|
|
|
fa6a06 |
+# bcond behavior, CLI overriding a complex defailt
|
|
|
fa6a06 |
+AT_CHECK([
|
|
|
fa6a06 |
+runroot rpmbuild -bb --quiet --with both_features /data/SPECS/bcondtest.spec
|
|
|
fa6a06 |
+runroot rpm -q --provides -p /build/RPMS/noarch/bcondtest-1.0-1.noarch.rpm |
|
|
|
fa6a06 |
+ grep has_bcond | sort
|
|
|
fa6a06 |
+],
|
|
|
fa6a06 |
+[0],
|
|
|
fa6a06 |
+[has_bcond(both_features)
|
|
|
fa6a06 |
+has_bcond(normally_on)
|
|
|
fa6a06 |
+],
|
|
|
fa6a06 |
+[])
|
|
|
fa6a06 |
+AT_CLEANUP
|