From 5a3b3bf30c37ebdcf7f3e25d4eac7039acfe57c4 Mon Sep 17 00:00:00 2001
From: Marek Blaha <mblaha@redhat.com>
Date: Fri, 31 May 2019 09:48:13 +0200
Subject: [PATCH] [builddep] Report all rpm errors (RhBug:1663619,1658292,1724668)
Dnf uses rpm for parsing .spec and srpm files. Any parsing
errors were not reported to the user, but swallowed by dnf.
User was only informed that the spec file could not be parsed:
$ dnf builddep gdb.spec
Failed to open: 'gdb.spec', not a valid spec file: can't parse specfile
This patch also prints messages from rpm error log to the user so he
could better understand what the root cause of the problem is:
$ dnf builddep gdb.spec
RPM: error: Unable to open /root/rpmbuild/SOURCES/_gdb.spec.Patch.include: No such file or directory
Failed to open: 'gdb.spec', not a valid spec file: can't parse specfile
https://bugzilla.redhat.com/show_bug.cgi?id=1663619
https://bugzilla.redhat.com/show_bug.cgi?id=1658292
https://bugzilla.redhat.com/show_bug.cgi?id=1724668
---
dnf-plugins-core.spec | 2 +-
plugins/builddep.py | 38 +++++++++-----------------------------
2 files changed, 10 insertions(+), 30 deletions(-)
diff --git a/dnf-plugins-core.spec b/dnf-plugins-core.spec
index be01cd2..b84477f 100644
--- a/dnf-plugins-core.spec
+++ b/dnf-plugins-core.spec
@@ -1,4 +1,4 @@
-%{?!dnf_lowest_compatible: %global dnf_lowest_compatible 4.2.1}
+%{?!dnf_lowest_compatible: %global dnf_lowest_compatible 4.2.8}
%global dnf_plugins_extra 2.0.0
%global hawkey_version 0.34.0
%global yum_utils_subpackage_name dnf-utils
diff --git a/plugins/builddep.py b/plugins/builddep.py
index bc3b257..0252d1f 100644
--- a/plugins/builddep.py
+++ b/plugins/builddep.py
@@ -21,44 +21,18 @@
from __future__ import absolute_import
from __future__ import unicode_literals
-from dnfpluginscore import _, logger, rpm_logger
+from dnfpluginscore import _, logger
import argparse
import dnf
import dnf.cli
import dnf.exceptions
import dnf.rpm.transaction
-import functools
-import logging
+import dnf.yum.rpmtrans
import os
import rpm
-class redirect_rpm_logging(object):
- def __init__(self):
- self.sink = None
-
- def __call__(self, func):
- @functools.wraps(func)
- def inner(*args, **kwds):
- with self:
- return func(*args, **kwds)
- return inner
-
- def __enter__(self):
- for handler in rpm_logger.handlers:
- if isinstance(handler, logging.FileHandler):
- rpm.setLogFile(handler.stream)
- break
- else:
- self.sink = open('/dev/null', 'w')
- rpm.setLogFile(self.sink)
-
- def __exit__(self, exc_type, exc, exc_tb):
- if self.sink:
- self.sink.close()
-
-
@dnf.plugin.register_command
class BuildDepCommand(dnf.cli.Command):
@@ -91,6 +65,10 @@ class BuildDepCommand(dnf.cli.Command):
ptype.add_argument('--srpm', action='store_true',
help=_('treat commandline arguments as source rpm'))
+ def pre_configure(self):
+ if not self.opts.rpmverbosity:
+ self.opts.rpmverbosity = 'error'
+
def configure(self):
demands = self.cli.demands
demands.available_repos = True
@@ -107,8 +85,8 @@ class BuildDepCommand(dnf.cli.Command):
self.base.repos.enable_source_repos()
break
- @redirect_rpm_logging()
def run(self):
+ rpmlog = dnf.yum.rpmtrans.RPMTransaction(self.base)
# Push user-supplied macro definitions for spec parsing
for macro in self.opts.define:
rpm.addMacro(macro[0], macro[1])
@@ -127,6 +105,8 @@ class BuildDepCommand(dnf.cli.Command):
else:
self._remote_deps(pkgspec)
except dnf.exceptions.Error as e:
+ for line in rpmlog.messages():
+ logger.error(_("RPM: {}").format(line))
logger.error(e)
pkg_errors = True
--
libgit2 0.28.2