From c19d2d4741f39c177d8138fc99ca8344b455303e Mon Sep 17 00:00:00 2001 From: Gabi Beyer Date: Tue, 5 Sep 2017 10:49:37 -0700 Subject: [PATCH] Add "whatrequires" files for package The file contains packages that require capabilities of the specified package using the repoquery --whatrequires command. This includes the recursive option to query for all packages, and the archlist=src to specify only SRPMS. To use the repoquery command a yum.conf file is required; the location of this is specified in the autospec.conf file. If a path is not provided, the path is set to the common location of the yum.conf file in clear. This file is informational and can be used by other tooling and package maintainers to identify which packages need to be rebuilt when this package is updated. It can also be used to track dependent packages and versions over time by inspecting git history. Signed-off-by: Gabi Beyer --- README.rst | 3 +++ autospec/autospec.py | 2 ++ autospec/config.py | 6 ++++++ autospec/git.py | 1 + autospec/pkg_scan.py | 48 ++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 60 insertions(+) create mode 100644 autospec/pkg_scan.py diff --git a/README.rst b/README.rst index 3497a8c..1abbb93 100644 --- a/README.rst +++ b/README.rst @@ -42,6 +42,9 @@ Example ``autospec.conf`` file:: **packages_file** Optional path to add autodetected runtime requirement checking against +**yum_conf** + Optional path to yum configuration + **upstream** Base URL for stored upstream tarballs diff --git a/autospec/autospec.py b/autospec/autospec.py index f56b56e..62974b1 100644 --- a/autospec/autospec.py +++ b/autospec/autospec.py @@ -35,6 +35,7 @@ import test import commitmessage import pkg_integrity import specfiles +import pkg_scan from util import print_fatal, binary_in_path, write_out from abireport import examine_abi @@ -219,6 +220,7 @@ def main(): pass examine_abi(build.download_path) + pkg_scan.get_whatrequires(tarball.name) write_out(build.download_path + "/release", tarball.release + "\n") diff --git a/autospec/config.py b/autospec/config.py index 6374d52..3058956 100644 --- a/autospec/config.py +++ b/autospec/config.py @@ -60,6 +60,7 @@ old_patches = list() old_keyid = None profile_payload = None signature = None +yum_conf = None failed_commands = {} maven_jars = {} @@ -452,6 +453,7 @@ def parse_config_files(path, bump, filemanager): global make_install_append global patches global autoreconf + global yum_conf packages_file = None @@ -470,6 +472,7 @@ def parse_config_files(path, bump, filemanager): license_fetch = config['autospec'].get('license_fetch', None) license_show = config['autospec'].get('license_show', None) packages_file = config['autospec'].get('packages_file', None) + yum_conf = config['autospec'].get('yum_conf', None) if not packages_file: print("Warning: Set [autospec][packages_file] path to package list file for " "requires validation") @@ -483,6 +486,9 @@ def parse_config_files(path, bump, filemanager): print("Warning: Set [autospec][license_fetch] uri for license fetch support") if not license_show: print("Warning: Set [autospec][license_show] uri for license link check support") + if not yum_conf: + print("Warning: Set [autospec][yum_conf] path to yum.conf file for whatrequires validation") + yum_conf = os.path.join(os.path.dirname(config_file), "image-creator/yum.conf") if packages_file: os_packages = set(read_conf_file(packages_file)) diff --git a/autospec/git.py b/autospec/git.py index 2881f24..2625f46 100644 --- a/autospec/git.py +++ b/autospec/git.py @@ -75,6 +75,7 @@ def commit_to_git(path): call("git add profile_payload", check=False, stderr=subprocess.DEVNULL, cwd=path) call("git add options.conf", check=False, stderr=subprocess.DEVNULL, cwd=path) call("git add configure_misses", check=False, stderr=subprocess.DEVNULL, cwd=path) + call("git add whatrequires", check=False, stderr=subprocess.DEVNULL, cwd=path) # remove deprecated config files call("git rm use_clang", check=False, stderr=subprocess.DEVNULL, cwd=path) diff --git a/autospec/pkg_scan.py b/autospec/pkg_scan.py new file mode 100644 index 0000000..2f9ca34 --- /dev/null +++ b/autospec/pkg_scan.py @@ -0,0 +1,48 @@ +# +# pkg_scan.py - part of autospec +# Copyright (C) 2017 Intel Corporation +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +import subprocess +import util +import config + + +def get_whatrequires(pkg): + """ + Write list of packages that require current package to file + using repoquery what-requires and --recursive commands + """ + + # clean up yum cache to avoid 'no more mirrors repo' error + subprocess.check_output(['yum', '--config', config.yum_conf, + 'clean', 'all']) + + try: + out = subprocess.check_output(['repoquery', '--config', config.yum_conf, + '--archlist=src', '--recursive', + '--whatrequires', pkg]).decode('utf-8') + + except subprocess.CalledProcessError as err: + util.print_warning("repoquery whatrequires for {} failed with: {}".format(pkg, err)) + return + + if 'filesystem' in out: + util.print_warning("Package contains filesystem as a whatrequires.\n" + + "BE CAREFUL building {}; may require full OS rebuild.\n".format(pkg)) + + util.write_out('whatrequires', + "# This file contains recursive sources that require this package\n" + \ + out)