Mailinglist Archive: opensuse-buildservice (137 mails)

< Previous Next >
Re: [opensuse-buildservice] Patch: drop "Suggests:" and "Recommends:" if rpm does not know them
Hi Brian,

On 16.11.2015 19:10, Brian K. White wrote:
On 11/14/2015 7:12 AM, Stefan Seyfried wrote:

I'm running an OBS instance, used amongst others to build stuff for
multiple distributions (SLES and RHEL, mostly).

Now if I import packages from openSUSE OBS, I often have to patch the
spec file. 95% of these patches are like this:

+%if 0%{?suse_version}
Recommends: not_really_necessary_thing_1
Suggests: totally_unnecessary_thing_2

I automated this task in build-recipe-spec: If the target's RPM does not
know "Recommends:" or "Suggests:", just drop these lines.

This is made configurable with the following prjconf
Buildflags: dropunknownrpmtags

here is the patch for discussion, if this would be interesting for
upstream, I'll prepare a proper pull request.

diff --git a/build-recipe-spec b/build-recipe-spec
index d72a3b7..f92d857 100644
--- a/build-recipe-spec
+++ b/build-recipe-spec
@@ -85,6 +85,40 @@ recipe_prepare_spec() {
test -z "$ABUILD_TARGET" || echo "build target is

+ DROP_UNKNOWN=$(queryconfig --dist "$BUILD_DIST" --configdir
"$CONFIG_DIR" --archpath "$BUILD_ARCH" buildflags dropunknownrpmtags)
+ if [ -n "$DROP_UNKNOWN" ]; then
+ declare -i SUSE_VERSION=$(chroot $BUILD_ROOT rpm --eval
'%{?suse_version}' 2>/dev/null)
+ if ! [ -e "$BUILD_ROOT/usr/bin/rpmbuild" ]; then
+ echo "NOTE: no /usr/bin/rpmbuild in target, no check for
unnown specfile tags"
+ elif ((SUSE_VERSION == 0)); then # just assume that every SUSE
has patched RPM...
+ # echo "SUSE_VERSION is zero"
+ for i in Suggests: Recommends:; do
+ # if no suggests/recommends, then we don't need to test
+ grep "^$i" "$BUILD_ROOT/" >/dev/null 2>&1 ||
+ rm -f "$BUILD_ROOT/.spec.test"
+ cat > "$BUILD_ROOT/.spec.test" <<-EOF
+ $i foo
+ Name: foo
+ Version: 0
+ Release: 0
+ Summary: foo
+ License: WTFPL
+ %description
+ foo
+ UNKNOWN="`chroot $BUILD_ROOT /bin/rpmbuild --nobuild
/.spec.test 2>&1`"
+ # echo "found unknown tag '$UNKNOWN'"
+ RES=$?
+ rm -f "$BUILD_ROOT/.spec.test"
+ test $RES = 0 && continue
+ # echo "nobuild result for $i $RES"
+ echo "WARNING: removing unknown tag on non-SUSE distro:
+ sed -i -e "/^$i/d" "$BUILD_ROOT/"

in the line above, the spec file is modified...

+ done
+ fi
+ fi
# report specfile changes
if test -f $BUILD_ROOT/ ; then
$BUILD_ROOT/ ; then

Is the original data lost or just not used to build?

If you had these tags in a spec on obs, what is in the spec of the
resulting .src.rpm?

AFAICT, the spec used to build is packaged in the .src.rpm, so if you
download the .src.rpm which is built for, say, CentOS-7, it will not
have the unknown tag.

But that's actually a thing I did not think about: the .src.rpm will
then have different contents, depending on the distribution it was built
That's a "price" I personally am willing to pay :-)

I think ideally, you want to output a .src.rpm that will build on the
target outside of obs, so *something* has to happen to them rather than
copy the original spec verbatim. But you also don't want to lose data,
and so the removed tags should be converted into comments for those
output src.rpm. Maybe even echo commands to make the comment visible at
install time.

Then we would need to automatically transform these lines into a %post
script. I'd rather not try to do that, because it might break more
things that it fixes.

But it's a tiny point.

I wish obs had this since 5 years ago or really since the first time obs
used an rpm that was newer than any build target.

As I know you are still building for rather old SUSE versions: do you
remember if the "Suggests:" / "Recommends:" is available for, say, SLES10?
If not, simply removing the SUSE_VERSION check might be better (and make
the code simpler).

Same for new convenience macros, though the action isn't usually as easy
as dropping the new/unknown macro. But it is often possible to replace
the new convenience macro with a lower denominator equivalent, or by
including a copy of the macro itself.

Well, these can be solved with prjconf, but unknown spec file syntax
unfortunately cannot.

Thank you for making this.

As there seems to be at least *some* interest, I'll put this into a
proper pull request on github.

For those who consider this useless: unless enabled with

Buildflags: dropunknownrpmtags

in prjconf, this will do nothing, so you do not need to use this. And
I'm not sure if it is a feature which should be enabled on the openSUSE
build service at all (or only for a few selected projects, e.g. where
projects are building their official packages for different distros on
OBS), but it is a feature which is very useful for many private OBS
installations, where people need to build for many different
distributions, and thist might make it easier for them to share code
with the "official" repositories (that was the use case which triggered
me to develop this thing).

Best regards,

Stefan Seyfried

"For a successful technology, reality must take precedence over
public relations, for nature cannot be fooled." -- Richard Feynman
To unsubscribe, e-mail: opensuse-buildservice+unsubscribe@xxxxxxxxxxxx
To contact the owner, e-mail: opensuse-buildservice+owner@xxxxxxxxxxxx

< Previous Next >
Follow Ups