contrib/rpm: support default options for debug,test in generated spec file

"build_clean.sh" (and "build.sh") scripts can both create a source
tarball (via `make dist`/`make distcheck`), an SRPM (and a spec file),
or build RPMs from the SRPM.

Note that the generated spec file has various options, like

    %bcond_without nmtui
    %bcond_without debug
    %bcond_without test

When building an RPM from the SRPM, you can specify the "--with" or
"--without" option for rpmbuild. This is also what the "-w" / "-W" options
for "build_clean.sh" do.

However, the SRPM still has the intrinsic defaults, and if you later
build an RPM from it, you would have to pass "--with" / "--without"
to rpmbuild.

Often that is not conveniently possible, for example, when you build the
SRPM in koji.

Extend the scripts so that also the defaults for "-w debug" and "-w
test" can be specified when generating the SRPM. You can do that with
the new options "--default-for-{debug,test}" to "build_clean.sh".

Alternatively, it suffices to specify the previously supported
"-w" / "-W" options. That way, we will pass those options to rpmbuild,
but also set them as defaults in the generate spec file. The new
options "--default-for-{debug,test}" are only needed if you want
the default in the spec file to be different then what you use
when creating the SRPM.
This commit is contained in:
Thomas Haller 2020-12-03 15:45:13 +01:00
parent 3bf367594a
commit a3f2cee0e6
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728
3 changed files with 83 additions and 7 deletions

View file

@ -46,6 +46,22 @@
###############################################################################
%if "x__BCOND_DEFAULT_DEBUG__" == "x1" || "x__BCOND_DEFAULT_DEBUG__" == "x0"
%global bcond_default_debug __BCOND_DEFAULT_DEBUG__
%else
%global bcond_default_debug 0
%endif
%if "x__BCOND_DEFAULT_TEST__" == "x1" || "x__BCOND_DEFAULT_TEST__" == "x0"
%global bcond_default_test __BCOND_DEFAULT_TEST__
%else
%if 0%{?rhel} >= 9
%global bcond_default_test 1
%else
%global bcond_default_test 0
%endif
%endif
%bcond_with meson
%bcond_without adsl
%bcond_without bluetooth
@ -57,8 +73,12 @@
%bcond_without nmtui
%bcond_without nm_cloud_setup
%bcond_without regen_docs
%if %{bcond_default_debug}
%bcond_without debug
%else
%bcond_with debug
%if 0%{?rhel} >= 9
%endif
%if %{bcond_default_test}
%bcond_without test
%else
%bcond_with test

View file

@ -23,6 +23,8 @@
# SOURCE_SYSCTL_RP_FILTER_REDHAT=
# SIGN_SOURCE=
# DO_RELEASE=
# BCOND_DEFAULT_DEBUG=
# BCOND_DEFAULT_TEST=
die() {
echo "$*" >&2
@ -48,6 +50,15 @@ coerce_bool() {
esac
}
in_set() {
local v="$1"
shift
for v2; do
test "$v" == "$v2" && return 0
done
return 1
}
abs_path() {
local F="$1"
@ -157,10 +168,15 @@ LOG "SOURCE_CONFIG_CONNECTIVITY_REDHAT=$SOURCE_CONFIG_CONNECTIVITY_REDHAT"
LOG "SOURCE_SYSCTL_RP_FILTER_REDHAT=$SOURCE_SYSCTL_RP_FILTER_REDHAT"
LOG "BUILDTYPE=$BUILDTYPE"
LOG "NM_RPMBUILD_ARGS=$NM_RPMBUILD_ARGS"
LOG "BCOND_DEFAULT_DEBUG=$BCOND_DEFAULT_DEBUG"
LOG "BCOND_DEFAULT_TEST=$BCOND_DEFAULT_TEST"
LOG ""
LOG "UUID=$UUID"
LOG "BASEDIR=$TEMP"
in_set "$BCOND_DEFAULT_DEBUG" "" 0 1 || die "Invalid value for \$BCOND_DEFAULT_DEBUG: \"$BCOND_DEFAULT_DEBUG\""
in_set "$BCOND_DEFAULT_TEST" "" 0 1 || die "Invalid value for \$BCOND_DEFAULT_TEST: \"$BCOND_DEFAULT_TEST\""
ln -snf "$TEMPBASE" ./latest0
ln "$BUILDLOG" "$TEMPBASE/build.log"
rm -f "$BUILDLOG"
@ -186,6 +202,8 @@ sed -e "s/__VERSION__/$VERSION/g" \
-e "s/__COMMIT_FULL__/$COMMIT_FULL/g" \
-e "s/__SNAPSHOT__/$SNAPSHOT/g" \
-e "s/__SOURCE1__/$(basename "$SOURCE")/g" \
-e "s/__BCOND_DEFAULT_DEBUG__/$BCOND_DEFAULT_DEBUG/g" \
-e "s/__BCOND_DEFAULT_TEST__/$BCOND_DEFAULT_TEST/g" \
"$SPECFILE" |
sed -e "/^__CHANGELOG__$/ \
{

View file

@ -25,8 +25,18 @@ usage() {
echo " -W|--without \$OPTION: pass --without \$OPTION to rpmbuild. For example --without debug"
echo " -s|--snapshot TEXT: use TEXT as the snapshot version for the new package (overwrites \$NM_BUILD_SNAPSHOT environment)"
echo " -r|--release: built a release tarball (this option must be alone)"
echo " --default-for-debug \$OPTION: set the default for "debug" option in the generated spec file"
echo " --default-for-test \$OPTION: set the default for "test" option in the generated spec file"
}
in_set() {
local v="$1"
shift
for v2; do
test "$v" == "$v2" && return 0
done
return 1
}
ORIGDIR="$(readlink -f "$PWD")"
SCRIPTDIR="$(dirname "$(readlink -f "$0")")"
@ -45,6 +55,8 @@ WITH_LIST=()
SOURCE_FROM_GIT=0
SNAPSHOT="$NM_BUILD_SNAPSHOT"
DO_RELEASE=0
unset BCOND_DEFAULT_DEBUG
unset BCOND_DEFAULT_TEST
ADD_WITH_TEST=1
@ -94,17 +106,29 @@ while [[ $# -gt 0 ]]; do
-w|--with)
[[ $# -gt 0 ]] || die "Missing argument to $A"
WITH_LIST=("${WITH_LIST[@]}" "--with" "$1")
if [[ "$1" == test ]]; then
ADD_WITH_TEST=0
fi
case "$1" in
debug)
[[ -z ${BCOND_DEFAULT_DEBUG+.} ]] && BCOND_DEFAULT_DEBUG=1
;;
test)
ADD_WITH_TEST=0
[[ -z ${BCOND_DEFAULT_TEST+.} ]] && BCOND_DEFAULT_TEST=1
;;
esac
shift
;;
-W|--without)
[[ $# -gt 0 ]] || die "Missing argument to $A"
WITH_LIST=("${WITH_LIST[@]}" "--without" "$1")
if [[ "$1" == test ]]; then
ADD_WITH_TEST=0
fi
case "$1" in
debug)
[[ -z ${BCOND_DEFAULT_DEBUG+.} ]] && BCOND_DEFAULT_DEBUG=0
;;
test)
ADD_WITH_TEST=0
[[ -z ${BCOND_DEFAULT_TEST+.} ]] && BCOND_DEFAULT_TEST=0
;;
esac
shift
;;
--no-auto-with-test)
@ -115,6 +139,18 @@ while [[ $# -gt 0 ]]; do
# or "-W test".
ADD_WITH_TEST=0
;;
--default-for-debug)
[[ $# -gt 0 ]] || die "Missing argument to $A"
in_set "$1" "" 0 1 || die "invalid argument $A \"$1\""
BCOND_DEFAULT_DEBUG="$1"
shift
;;
--default-for-test)
[[ $# -gt 0 ]] || die "Missing argument to $A"
in_set "$1" "" 0 1 || die "invalid argument $A \"$1\""
BCOND_DEFAULT_TEST="$1"
shift
;;
*)
usage
die "Unexpected argument \"$A\""
@ -184,6 +220,8 @@ export BUILDTYPE
export NM_RPMBUILD_ARGS="${WITH_LIST[@]}"
export SNAPSHOT
export DO_RELEASE
export BCOND_DEFAULT_DEBUG="$BCOND_DEFAULT_DEBUG"
export BCOND_DEFAULT_TEST="$BCOND_DEFAULT_TEST"
"$SCRIPTDIR"/build.sh