2015-06-25 12:37:23 +00:00
|
|
|
#!/usr/bin/python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
|
|
|
|
# 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; version 2 of the License.
|
|
|
|
#
|
|
|
|
# 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 Library General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License along
|
|
|
|
# with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import hawkey
|
2016-04-25 13:13:35 +00:00
|
|
|
import logging
|
2015-06-25 12:37:23 +00:00
|
|
|
import pungi.dnf_wrapper
|
|
|
|
import pungi.multilib_dnf
|
2016-04-06 08:30:50 +00:00
|
|
|
from pungi.profiler import Profiler
|
2016-04-25 13:13:35 +00:00
|
|
|
from kobo.rpmlib import parse_nvra
|
2015-06-25 12:37:23 +00:00
|
|
|
|
|
|
|
class GatherOptions(object):
|
|
|
|
def __init__(self, **kwargs):
|
|
|
|
super(GatherOptions, self).__init__()
|
|
|
|
|
|
|
|
# include all unused sub-packages of already included RPMs
|
|
|
|
self.fulltree = False
|
|
|
|
|
|
|
|
# include langpacks
|
|
|
|
self.langpacks = [] # format: [{"package": "langpack-pattern-%s"}]
|
|
|
|
|
|
|
|
# resolve dependencies
|
|
|
|
self.resolve_deps = True
|
|
|
|
|
|
|
|
# pull build dependencies
|
|
|
|
self.selfhosting = False
|
|
|
|
|
|
|
|
# none, all, build
|
|
|
|
# TODO: validate values
|
|
|
|
self.greedy_method = "none"
|
|
|
|
|
|
|
|
# multilib options
|
|
|
|
self.multilib_methods = []
|
|
|
|
self.multilib_blacklist = []
|
|
|
|
self.multilib_whitelist = []
|
|
|
|
|
|
|
|
# prepopulate
|
|
|
|
self.prepopulate = []
|
|
|
|
|
|
|
|
# lookaside repos; packages will be flagged accordingly
|
|
|
|
self.lookaside_repos = []
|
|
|
|
|
|
|
|
for key, value in kwargs.items():
|
|
|
|
if not hasattr(self, key):
|
|
|
|
raise ValueError("Invalid gather option: %s" % key)
|
|
|
|
setattr(self, key, value)
|
|
|
|
|
|
|
|
|
|
|
|
def filter_debug_packages(q, arch=None):
|
|
|
|
result = q.filter(arch__neq=["src", "nosrc"])
|
|
|
|
if arch:
|
|
|
|
arches = pungi.dnf_wrapper.ArchWrapper(arch).all_arches
|
|
|
|
result = result.filter(arch=arches)
|
|
|
|
result = result.filter(name__glob=["*-debuginfo", "*-debuginfo-*"])
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
def filter_native_debug_packages(q, arch):
|
|
|
|
result = q.filter(arch__neq=["src", "nosrc"])
|
|
|
|
arches = pungi.dnf_wrapper.ArchWrapper(arch).native_arches
|
|
|
|
result = result.filter(arch=arches)
|
|
|
|
result = result.filter(name__glob=["*-debuginfo", "*-debuginfo-*"])
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
def filter_multilib_debug_packages(q, arch):
|
|
|
|
result = q.filter(arch__neq=["src", "nosrc"])
|
|
|
|
arches = pungi.dnf_wrapper.ArchWrapper(arch).multilib_arches
|
|
|
|
result = result.filter(arch=arches)
|
|
|
|
result = result.filter(name__glob=["*-debuginfo", "*-debuginfo-*"])
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
def filter_source_packages(q):
|
|
|
|
result = q.filter(arch=["src", "nosrc"])
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
def filter_binary_packages(q, arch=None):
|
|
|
|
result = q.filter(arch__neq=["src", "nosrc"])
|
|
|
|
if arch:
|
|
|
|
arches = pungi.dnf_wrapper.ArchWrapper(arch).all_arches
|
|
|
|
result = result.filter(arch=arches)
|
|
|
|
result = result.filter(latest_per_arch=True)
|
|
|
|
result = result.filter(name__glob__not=["*-debuginfo", "*-debuginfo-*"])
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
def filter_native_binary_packages(q, arch):
|
|
|
|
result = q.filter(arch__neq=["src", "nosrc"])
|
|
|
|
arches = pungi.dnf_wrapper.ArchWrapper(arch).native_arches
|
|
|
|
result = result.filter(arch=arches)
|
|
|
|
result = result.filter(latest_per_arch=True)
|
|
|
|
result = result.filter(name__glob__not=["*-debuginfo", "*-debuginfo-*"])
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
def filter_multilib_binary_packages(q, arch):
|
|
|
|
result = q.filter(arch__neq=["src", "nosrc"])
|
|
|
|
arches = pungi.dnf_wrapper.ArchWrapper(arch).multilib_arches
|
|
|
|
result = result.filter(arch=arches)
|
|
|
|
result = result.filter(latest_per_arch=True)
|
|
|
|
result = result.filter(name__glob__not=["*-debuginfo", "*-debuginfo-*"])
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
def filter_binary_noarch_packages(q):
|
|
|
|
result = q.filter(arch="noarch")
|
|
|
|
result = result.filter(latest_per_arch=True)
|
|
|
|
result = result.filter(name__glob__not=["*-debuginfo", "*-debuginfo-*"])
|
|
|
|
return result
|
|
|
|
|
2016-04-06 08:30:50 +00:00
|
|
|
|
2016-04-06 10:12:55 +00:00
|
|
|
class QueryCache(object):
|
|
|
|
def __init__(self, queue, *args, **kwargs):
|
|
|
|
self.cache = {}
|
|
|
|
self.nargs = len(args)
|
2015-09-15 12:55:52 +00:00
|
|
|
|
2016-04-06 10:12:55 +00:00
|
|
|
if kwargs:
|
|
|
|
queue = queue.filter(**kwargs)
|
2016-04-06 08:30:50 +00:00
|
|
|
|
2016-04-06 10:12:55 +00:00
|
|
|
for pkg in queue:
|
|
|
|
key = tuple(getattr(pkg, arg) for arg in args)
|
|
|
|
pkgs = self.cache.setdefault(key, [])
|
|
|
|
if pkg not in pkgs:
|
|
|
|
# use list preserve package order
|
|
|
|
pkgs.append(pkg)
|
|
|
|
|
|
|
|
def get(self, *args):
|
|
|
|
if len(args) != self.nargs:
|
|
|
|
raise ValueError("Expected %s arguments, got %s" % (self.nargs, len(args)))
|
|
|
|
key = tuple(args)
|
|
|
|
return self.cache.get(key, None)
|
2015-09-15 12:55:52 +00:00
|
|
|
|
2015-06-25 12:37:23 +00:00
|
|
|
|
|
|
|
class GatherBase(object):
|
|
|
|
def __init__(self, dnf_obj):
|
|
|
|
self.dnf = dnf_obj
|
|
|
|
self.q_binary_packages = filter_binary_packages(self._query, arch=self.dnf.basearch).apply()
|
|
|
|
self.q_native_binary_packages = filter_native_binary_packages(self._query, arch=self.dnf.basearch).apply()
|
|
|
|
self.q_multilib_binary_packages = filter_multilib_binary_packages(self._query, arch=self.dnf.basearch).apply()
|
|
|
|
self.q_noarch_binary_packages = filter_binary_packages(self._query).apply()
|
|
|
|
self.q_debug_packages = filter_debug_packages(self._query, arch=self.dnf.basearch).apply()
|
|
|
|
self.q_native_debug_packages = filter_native_debug_packages(self._query, arch=self.dnf.basearch).apply()
|
|
|
|
self.q_multilib_debug_packages = filter_multilib_debug_packages(self._query, arch=self.dnf.basearch).apply()
|
|
|
|
self.q_source_packages = filter_source_packages(self._query).apply()
|
|
|
|
|
|
|
|
@property
|
|
|
|
def _query(self):
|
|
|
|
return self.dnf._sack.query()
|
|
|
|
|
|
|
|
def is_noarch_package(self, pkg):
|
|
|
|
return pkg.arch == "noarch"
|
|
|
|
|
|
|
|
def is_native_package(self, pkg):
|
|
|
|
if pkg.arch in ["src", "nosrc"]:
|
|
|
|
return False
|
|
|
|
if pkg.arch == "noarch":
|
|
|
|
return True
|
|
|
|
if pkg.arch in self.dnf.arch_wrapper.native_arches:
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
|
|
def is_multilib_package(self, pkg):
|
|
|
|
if pkg.arch in ["src", "nosrc"]:
|
|
|
|
return False
|
|
|
|
if pkg.arch == "noarch":
|
|
|
|
return False
|
|
|
|
if pkg.arch in self.dnf.arch_wrapper.multilib_arches:
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
class Gather(GatherBase):
|
2016-04-25 13:13:35 +00:00
|
|
|
def __init__(self, dnf_obj, gather_options, logger=None):
|
2015-06-25 12:37:23 +00:00
|
|
|
super(Gather, self).__init__(dnf_obj)
|
2016-04-25 13:13:35 +00:00
|
|
|
self.logger = logger
|
|
|
|
if not self.logger:
|
|
|
|
# Default logger
|
|
|
|
self.logger = logging.getLogger("gather_dnf")
|
|
|
|
self.logger.setLevel(logging.DEBUG)
|
|
|
|
|
2015-06-25 12:37:23 +00:00
|
|
|
self.opts = gather_options
|
2016-04-25 13:13:35 +00:00
|
|
|
self.logger.debug("Gather received gather_options=%s" % gather_options.__dict__)
|
2015-06-25 12:37:23 +00:00
|
|
|
self._multilib = pungi.multilib_dnf.Multilib(self.dnf._sack, gather_options.multilib_methods, blacklist=self.opts.multilib_blacklist, whitelist=self.opts.multilib_whitelist)
|
|
|
|
|
|
|
|
# already processed packages
|
|
|
|
self.finished_add_binary_package_deps = {} # {pkg: [deps]}
|
|
|
|
self.finished_add_debug_package_deps = {} # {pkg: [deps]}
|
|
|
|
self.finished_add_source_package_deps = {} # {pkg: [deps]}
|
|
|
|
|
|
|
|
self.finished_get_package_deps_reqs = {}
|
|
|
|
|
|
|
|
self.finished_add_conditional_packages = {} # {pkg: [pkgs]}
|
|
|
|
self.finished_add_source_packages = {} # {pkg: src-pkg|None}
|
2015-07-09 13:42:56 +00:00
|
|
|
self.sourcerpm_cache = {} # {src_nvra: src-pkg|None}
|
2015-06-25 12:37:23 +00:00
|
|
|
self.finished_add_debug_packages = {} # {pkg: [debug-pkgs]}
|
|
|
|
self.finished_add_fulltree_packages = {} # {pkg: [pkgs]}
|
|
|
|
self.finished_add_langpack_packages = {} # {pkg: [pkgs]}
|
|
|
|
self.finished_add_multilib_packages = {} # {pkg: pkg|None}
|
|
|
|
|
|
|
|
# result
|
|
|
|
self.result_binary_packages = set()
|
|
|
|
self.result_debug_packages = set()
|
|
|
|
self.result_source_packages = set()
|
|
|
|
self.result_package_flags = {}
|
|
|
|
|
|
|
|
def _set_flag(self, pkg, *flags):
|
|
|
|
self.result_package_flags.setdefault(pkg, set()).update(flags)
|
|
|
|
|
|
|
|
def _has_flag(self, pkg, flag):
|
|
|
|
return flag in self.result_package_flags.get(pkg, set())
|
|
|
|
|
|
|
|
def _get_best_package(self, package_list, pkg=None, req=None):
|
|
|
|
if not package_list:
|
|
|
|
return []
|
|
|
|
|
|
|
|
if self.opts.greedy_method == "all":
|
|
|
|
return list(package_list)
|
|
|
|
|
|
|
|
all_pkgs = list(package_list)
|
|
|
|
native_pkgs = self.q_native_binary_packages.filter(pkg=all_pkgs).apply()
|
2015-09-17 08:56:09 +00:00
|
|
|
multilib_pkgs = [pkg for pkg in all_pkgs if pkg.arch != "noarch"]
|
2015-06-25 12:37:23 +00:00
|
|
|
|
|
|
|
result = set()
|
|
|
|
|
|
|
|
# try seen native packages first
|
|
|
|
seen_pkgs = set(native_pkgs) & self.result_binary_packages
|
|
|
|
if seen_pkgs:
|
|
|
|
result = seen_pkgs
|
|
|
|
|
|
|
|
# then try seen multilib packages
|
|
|
|
if not result:
|
|
|
|
seen_pkgs = set(multilib_pkgs) & self.result_binary_packages
|
|
|
|
if seen_pkgs:
|
|
|
|
result = seen_pkgs
|
|
|
|
|
|
|
|
if not result:
|
|
|
|
result = set(native_pkgs)
|
|
|
|
|
|
|
|
if not result:
|
|
|
|
result = set(multilib_pkgs)
|
|
|
|
|
|
|
|
if not result:
|
|
|
|
return []
|
|
|
|
|
|
|
|
# return package with shortest name, alphabetically ordered
|
|
|
|
result = list(result)
|
|
|
|
result.sort(lambda x, y: cmp(x.name, y.name))
|
|
|
|
result.sort(lambda x, y: cmp(len(x.name), len(y.name)))
|
|
|
|
|
|
|
|
# best arch
|
|
|
|
arches = self.dnf.arch_wrapper.all_arches
|
|
|
|
result.sort(lambda x, y: cmp(arches.index(x.arch), arches.index(y.arch)))
|
|
|
|
match = result[0]
|
|
|
|
|
|
|
|
if self.opts.greedy_method == "build" and req:
|
|
|
|
if self.is_native_package(match):
|
|
|
|
return [i for i in native_pkgs if i.sourcerpm == match.sourcerpm]
|
|
|
|
# return list(native_pkgs.filter(sourcerpm=match.sourcerpm, provides=req))
|
|
|
|
else:
|
|
|
|
return [i for i in multilib_pkgs if i.sourcerpm == match.sourcerpm]
|
|
|
|
# return list(multilib_pkgs.filter(sourcerpm=match.sourcerpm, provides=req))
|
|
|
|
return [match]
|
|
|
|
|
|
|
|
def _add_packages(self, packages, pulled_by=None):
|
|
|
|
added = set()
|
|
|
|
for i in packages:
|
|
|
|
assert i is not None
|
|
|
|
if i not in self.result_binary_packages:
|
|
|
|
added.add(i)
|
|
|
|
pb = ""
|
|
|
|
if pulled_by:
|
2015-07-10 10:43:06 +00:00
|
|
|
pb = " (pulled by %s, repo: %s)" % (pulled_by, pulled_by.repo.id)
|
2016-04-25 13:13:35 +00:00
|
|
|
self.logger.debug("Added package %s%s" % (i, pb))
|
2015-06-25 12:37:23 +00:00
|
|
|
self.result_binary_packages.add(i)
|
|
|
|
# lookaside
|
|
|
|
if i.repoid in self.opts.lookaside_repos:
|
|
|
|
self._set_flag(i, "lookaside")
|
|
|
|
|
|
|
|
for pkg in added:
|
|
|
|
if pkg is None:
|
|
|
|
continue
|
|
|
|
for prov in pkg.provides:
|
|
|
|
self.finished_get_package_deps_reqs.setdefault(str(prov), set()).add(pkg)
|
|
|
|
|
|
|
|
self.result_binary_packages.update(added)
|
|
|
|
|
|
|
|
def _get_package_deps(self, pkg):
|
|
|
|
"""
|
|
|
|
Return all direct (1st level) deps for a package.
|
|
|
|
"""
|
|
|
|
assert pkg is not None
|
|
|
|
result = set()
|
|
|
|
|
2015-09-18 14:08:59 +00:00
|
|
|
q = self.q_binary_packages.filter(provides=pkg.requires).apply()
|
2015-06-25 12:37:23 +00:00
|
|
|
for req in pkg.requires:
|
|
|
|
deps = self.finished_get_package_deps_reqs.setdefault(str(req), set())
|
|
|
|
if deps:
|
|
|
|
result.update(deps)
|
|
|
|
continue
|
|
|
|
|
|
|
|
# TODO: need query also debuginfo
|
2015-09-18 14:08:59 +00:00
|
|
|
deps = q.filter(provides=req)
|
|
|
|
if deps:
|
|
|
|
deps = self._get_best_package(deps, req=req)
|
|
|
|
self.finished_get_package_deps_reqs[str(req)].update(deps)
|
|
|
|
result.update(deps)
|
2015-06-25 12:37:23 +00:00
|
|
|
|
|
|
|
return result
|
|
|
|
|
2016-04-06 08:30:50 +00:00
|
|
|
@Profiler("Gather.add_initial_packages()")
|
2015-06-25 12:37:23 +00:00
|
|
|
def add_initial_packages(self, pattern_list):
|
|
|
|
added = set()
|
|
|
|
|
|
|
|
excludes = []
|
|
|
|
includes = []
|
|
|
|
for pattern in pattern_list:
|
|
|
|
if pattern.startswith("-"):
|
|
|
|
excludes.append(pattern[1:])
|
|
|
|
else:
|
|
|
|
includes.append(pattern)
|
|
|
|
|
|
|
|
exclude = set()
|
|
|
|
for pattern in excludes:
|
2016-04-06 10:17:06 +00:00
|
|
|
with Profiler("Gather.add_initial_packages():exclude"):
|
|
|
|
# TODO: debug, source
|
|
|
|
if pattern.endswith(".+"):
|
|
|
|
pkgs = self.q_multilib_binary_packages.filter_autoglob(name=pattern[:-2])
|
|
|
|
else:
|
|
|
|
pkgs = self.q_binary_packages.filter_autoglob(name=pattern)
|
2015-06-25 12:37:23 +00:00
|
|
|
|
2016-04-06 10:17:06 +00:00
|
|
|
exclude.update(pkgs)
|
2016-04-25 13:13:35 +00:00
|
|
|
self.logger.debug("EXCLUDED: %s" % list(pkgs))
|
2016-04-06 10:17:06 +00:00
|
|
|
self.dnf._sack.add_excludes(pkgs)
|
2015-06-25 12:37:23 +00:00
|
|
|
|
|
|
|
# HACK
|
|
|
|
self.q_binary_packages = self.q_binary_packages.filter(pkg=[i for i in self.q_binary_packages if i not in exclude]).apply()
|
|
|
|
self.q_native_binary_packages = self.q_native_binary_packages.filter(pkg=[i for i in self.q_native_binary_packages if i not in exclude]).apply()
|
|
|
|
self.q_multilib_binary_packages = self.q_multilib_binary_packages.filter(pkg=[i for i in self.q_multilib_binary_packages if i not in exclude]).apply()
|
|
|
|
self.q_noarch_binary_packages = self.q_noarch_binary_packages.filter(pkg=[i for i in self.q_noarch_binary_packages if i not in exclude]).apply()
|
|
|
|
|
2016-04-06 10:12:55 +00:00
|
|
|
self.init_query_cache()
|
|
|
|
|
2015-06-25 12:37:23 +00:00
|
|
|
for pattern in includes:
|
2016-04-06 10:17:06 +00:00
|
|
|
with Profiler("Gather.add_initial_packages():include"):
|
|
|
|
if pattern == "system-release" and self.opts.greedy_method == "all":
|
|
|
|
pkgs = self.q_binary_packages.filter(provides=hawkey.Reldep(self.dnf.sack, "system-release")).apply()
|
2015-06-25 12:37:23 +00:00
|
|
|
else:
|
2016-04-06 10:17:06 +00:00
|
|
|
if pattern.endswith(".+"):
|
|
|
|
pkgs = self.q_multilib_binary_packages.filter_autoglob(name=pattern[:-2]).apply()
|
|
|
|
else:
|
|
|
|
pkgs = self.q_binary_packages.filter_autoglob(name=pattern).apply()
|
|
|
|
|
|
|
|
pkgs = self._get_best_package(pkgs)
|
|
|
|
if pkgs:
|
|
|
|
added.update(pkgs)
|
|
|
|
else:
|
2016-04-25 13:13:35 +00:00
|
|
|
self.logger.error("Doesn't match: %s" % pattern)
|
2015-06-25 12:37:23 +00:00
|
|
|
|
|
|
|
for pkg in added:
|
|
|
|
self._set_flag(pkg, "input")
|
|
|
|
|
2016-04-06 10:50:53 +00:00
|
|
|
native_binary_packages = set(self.q_native_binary_packages)
|
|
|
|
|
2015-06-25 12:37:23 +00:00
|
|
|
if self.opts.greedy_method == "build":
|
|
|
|
for pkg in added.copy():
|
2016-04-06 10:17:06 +00:00
|
|
|
with Profiler("Gather.add_initial_packages():greedy-build"):
|
2016-04-06 10:50:53 +00:00
|
|
|
if pkg in native_binary_packages:
|
|
|
|
greedy_build_packages = self.q_native_pkgs_by_sourcerpm_cache.get(pkg.sourcerpm) or []
|
2016-04-06 10:17:06 +00:00
|
|
|
else:
|
2016-04-06 10:50:53 +00:00
|
|
|
greedy_build_packages = self.q_multilib_pkgs_by_sourcerpm_cache.get(pkg.sourcerpm) or []
|
|
|
|
greedy_build_packages += self.q_noarch_pkgs_by_sourcerpm_cache.get(pkg.sourcerpm) or []
|
|
|
|
|
|
|
|
for greedy_pkg in greedy_build_packages[:]:
|
|
|
|
# filter out packages that don't provide package name
|
|
|
|
provides = set([str(i).split(" ")[0] for i in greedy_pkg.provides])
|
|
|
|
if pkg.name not in provides:
|
|
|
|
greedy_build_packages.remove(greedy_pkg)
|
|
|
|
|
2016-04-06 10:17:06 +00:00
|
|
|
for i in greedy_build_packages:
|
|
|
|
self._set_flag(i, "input", "greedy:build")
|
|
|
|
added.add(i)
|
2015-06-25 12:37:23 +00:00
|
|
|
|
|
|
|
return added
|
|
|
|
|
2016-04-06 10:12:55 +00:00
|
|
|
@Profiler("Gather.init_query_cache()")
|
|
|
|
def init_query_cache(self):
|
|
|
|
# HACK: workaround for insufficient hawkey query performance
|
|
|
|
# Must be executed *after* add_initial_packages() to exclude packages properly.
|
|
|
|
|
|
|
|
# source
|
|
|
|
self.source_pkgs_cache = QueryCache(self.q_source_packages, "name", "version", "release")
|
|
|
|
|
|
|
|
# debug
|
|
|
|
self.native_debug_packages_cache = QueryCache(self.q_native_debug_packages, "sourcerpm")
|
|
|
|
self.multilib_debug_packages_cache = QueryCache(self.q_multilib_debug_packages, "sourcerpm")
|
|
|
|
|
2016-04-06 10:50:53 +00:00
|
|
|
# packages by sourcerpm
|
|
|
|
self.q_native_pkgs_by_sourcerpm_cache = QueryCache(self.q_native_binary_packages, "sourcerpm", arch__neq="noarch")
|
|
|
|
self.q_multilib_pkgs_by_sourcerpm_cache = QueryCache(self.q_multilib_binary_packages, "sourcerpm", arch__neq="noarch")
|
|
|
|
self.q_noarch_pkgs_by_sourcerpm_cache = QueryCache(self.q_native_binary_packages, "sourcerpm", arch="noarch")
|
2016-04-06 10:12:55 +00:00
|
|
|
|
|
|
|
# multilib
|
|
|
|
self.q_multilib_binary_packages_cache = QueryCache(self.q_multilib_binary_packages, "name", "version", "release", arch__neq="noarch")
|
|
|
|
|
2016-04-06 10:22:55 +00:00
|
|
|
# prepopulate
|
|
|
|
self.prepopulate_cache = QueryCache(self.q_binary_packages, "name", "arch")
|
|
|
|
|
2016-04-06 08:30:50 +00:00
|
|
|
@Profiler("Gather.add_prepopulate_packages()")
|
2015-06-25 12:37:23 +00:00
|
|
|
def add_prepopulate_packages(self):
|
|
|
|
added = set()
|
|
|
|
|
|
|
|
for name_arch in self.opts.prepopulate:
|
|
|
|
name, arch = name_arch.rsplit(".", 1)
|
2016-04-06 10:22:55 +00:00
|
|
|
pkgs = self.prepopulate_cache.get(name, arch)
|
2015-06-25 12:37:23 +00:00
|
|
|
pkgs = self._get_best_package(pkgs)
|
|
|
|
if pkgs:
|
|
|
|
added.update(pkgs)
|
|
|
|
else:
|
2016-04-25 13:13:35 +00:00
|
|
|
self.logger.warn("Prepopulate: Doesn't match: %s" % name_arch)
|
2015-06-25 12:37:23 +00:00
|
|
|
|
|
|
|
for pkg in added:
|
|
|
|
self._set_flag(pkg, "prepopulate")
|
|
|
|
|
|
|
|
return added
|
|
|
|
|
2016-04-06 08:30:50 +00:00
|
|
|
@Profiler("Gather.add_binary_package_deps()")
|
2015-06-25 12:37:23 +00:00
|
|
|
def add_binary_package_deps(self):
|
|
|
|
added = set()
|
|
|
|
|
|
|
|
if not self.opts.resolve_deps:
|
|
|
|
return added
|
|
|
|
|
|
|
|
for pkg in self.result_binary_packages.copy():
|
|
|
|
assert pkg is not None
|
|
|
|
|
|
|
|
try:
|
|
|
|
deps = self.finished_add_binary_package_deps[pkg]
|
|
|
|
except KeyError:
|
|
|
|
deps = self._get_package_deps(pkg)
|
|
|
|
for i in deps:
|
|
|
|
if i not in self.result_binary_packages:
|
|
|
|
self._add_packages([i], pulled_by=pkg)
|
|
|
|
added.add(i)
|
2015-07-09 13:19:58 +00:00
|
|
|
self.finished_add_binary_package_deps[pkg] = deps
|
2015-06-25 12:37:23 +00:00
|
|
|
|
|
|
|
return added
|
|
|
|
|
2016-04-06 08:30:50 +00:00
|
|
|
@Profiler("Gather.add_conditional_packages()")
|
2015-06-25 12:37:23 +00:00
|
|
|
def add_conditional_packages(self):
|
|
|
|
"""
|
|
|
|
For each binary package add their conditional dependencies as specified in comps.
|
|
|
|
Return newly added packages.
|
|
|
|
"""
|
|
|
|
added = set()
|
|
|
|
|
|
|
|
if not self.opts.resolve_deps:
|
|
|
|
return added
|
|
|
|
|
|
|
|
for pkg in self.result_binary_packages.copy():
|
|
|
|
assert pkg is not None
|
|
|
|
|
|
|
|
try:
|
|
|
|
deps = self.finished_add_conditional_packages[pkg]
|
|
|
|
except KeyError:
|
|
|
|
deps = set()
|
|
|
|
for cond in self.conditional_packages:
|
|
|
|
if cond["name"] != pkg.name:
|
|
|
|
continue
|
|
|
|
pkgs = self.q_binary_packages.filter(name=cond["install"]).apply()
|
|
|
|
pkgs = self._get_best_package(pkgs) # TODO: multilib?
|
|
|
|
deps.update(pkgs)
|
2015-07-09 13:19:58 +00:00
|
|
|
self.finished_add_conditional_packages[pkg] = deps
|
2015-06-25 12:37:23 +00:00
|
|
|
|
|
|
|
for i in deps:
|
|
|
|
if i not in self.result_binary_packages:
|
|
|
|
self._add_packages([i], pulled_by=pkg)
|
|
|
|
self._set_flag(pkg, "conditional")
|
|
|
|
added.add(i)
|
|
|
|
|
|
|
|
return added
|
|
|
|
|
2016-04-06 08:30:50 +00:00
|
|
|
@Profiler("Gather.add_source_package_deps()")
|
2015-06-25 12:37:23 +00:00
|
|
|
def add_source_package_deps(self):
|
|
|
|
added = set()
|
|
|
|
|
2016-04-25 14:52:35 +00:00
|
|
|
if not self.opts.resolve_deps:
|
|
|
|
return added
|
2015-06-25 12:37:23 +00:00
|
|
|
if not self.opts.selfhosting:
|
|
|
|
return added
|
|
|
|
|
|
|
|
for pkg in self.result_source_packages:
|
|
|
|
assert pkg is not None
|
|
|
|
|
|
|
|
try:
|
|
|
|
deps = self.finished_add_source_package_deps[pkg]
|
|
|
|
except KeyError:
|
|
|
|
deps = self._get_package_deps(pkg)
|
2015-07-09 13:19:58 +00:00
|
|
|
self.finished_add_source_package_deps[pkg] = deps
|
2015-06-25 12:37:23 +00:00
|
|
|
for i in deps:
|
|
|
|
if i not in self.result_binary_packages:
|
|
|
|
self._add_packages([i], pulled_by=pkg)
|
|
|
|
added.add(i)
|
|
|
|
self._set_flag(pkg, "self-hosting")
|
|
|
|
|
|
|
|
return added
|
|
|
|
|
2016-04-06 08:30:50 +00:00
|
|
|
@Profiler("Gather.add_source_packages()")
|
2015-06-25 12:37:23 +00:00
|
|
|
def add_source_packages(self):
|
|
|
|
"""
|
|
|
|
For each binary package add it's source package.
|
|
|
|
Return newly added source packages.
|
|
|
|
"""
|
|
|
|
added = set()
|
|
|
|
|
|
|
|
for pkg in self.result_binary_packages:
|
|
|
|
assert pkg is not None
|
|
|
|
|
|
|
|
try:
|
|
|
|
source_pkg = self.finished_add_source_packages[pkg]
|
|
|
|
except KeyError:
|
|
|
|
source_pkg = None
|
|
|
|
if pkg.sourcerpm:
|
2015-07-09 13:42:56 +00:00
|
|
|
source_pkg = self.sourcerpm_cache.get(pkg.sourcerpm, None)
|
|
|
|
if source_pkg is None:
|
|
|
|
nvra = parse_nvra(pkg.sourcerpm)
|
2016-04-06 10:12:55 +00:00
|
|
|
source_pkgs = self.source_pkgs_cache.get(nvra["name"], nvra["version"], nvra["release"])
|
2015-07-09 13:42:56 +00:00
|
|
|
if source_pkgs:
|
|
|
|
source_pkg = list(source_pkgs)[0]
|
|
|
|
self.sourcerpm_cache[pkg.sourcerpm] = source_pkg
|
2015-07-09 13:19:58 +00:00
|
|
|
self.finished_add_source_packages[pkg] = source_pkg
|
2015-06-25 12:37:23 +00:00
|
|
|
|
2016-04-06 10:12:55 +00:00
|
|
|
if not source_pkg:
|
|
|
|
continue
|
|
|
|
|
|
|
|
lookaside = self._has_flag(pkg, "lookaside")
|
|
|
|
if lookaside:
|
|
|
|
self._set_flag(source_pkg, "lookaside")
|
|
|
|
if source_pkg not in self.result_source_packages:
|
|
|
|
added.add(source_pkg)
|
|
|
|
self.result_source_packages.add(source_pkg)
|
2015-06-25 12:37:23 +00:00
|
|
|
|
|
|
|
return added
|
|
|
|
|
2016-04-06 08:30:50 +00:00
|
|
|
@Profiler("Gather.add_debug_packages()")
|
2015-06-25 12:37:23 +00:00
|
|
|
def add_debug_packages(self):
|
|
|
|
"""
|
|
|
|
For each binary package add debuginfo packages built from the same source.
|
|
|
|
Return newly added debug packages.
|
|
|
|
"""
|
|
|
|
added = set()
|
|
|
|
|
|
|
|
for pkg in self.result_binary_packages:
|
|
|
|
assert pkg is not None
|
|
|
|
|
|
|
|
if self.is_noarch_package(pkg):
|
|
|
|
self.finished_add_debug_packages[pkg] = []
|
|
|
|
continue
|
|
|
|
|
|
|
|
try:
|
|
|
|
debug_pkgs = self.finished_add_debug_packages[pkg]
|
|
|
|
except KeyError:
|
|
|
|
debug_pkgs = []
|
|
|
|
if pkg.sourcerpm:
|
|
|
|
if self.is_native_package(pkg):
|
2016-04-06 10:12:55 +00:00
|
|
|
debug_pkgs = self.native_debug_packages_cache.get(pkg.sourcerpm)
|
2015-06-25 12:37:23 +00:00
|
|
|
else:
|
2016-04-06 10:12:55 +00:00
|
|
|
debug_pkgs = self.multilib_debug_packages_cache.get(pkg.sourcerpm)
|
|
|
|
|
|
|
|
if not debug_pkgs:
|
|
|
|
continue
|
2015-06-25 12:37:23 +00:00
|
|
|
|
|
|
|
lookaside = self._has_flag(pkg, "lookaside")
|
|
|
|
for i in debug_pkgs:
|
|
|
|
if lookaside:
|
|
|
|
self._set_flag(i, "lookaside")
|
|
|
|
if i not in self.result_debug_packages:
|
|
|
|
added.add(i)
|
|
|
|
|
|
|
|
self.finished_add_debug_packages[pkg] = debug_pkgs
|
|
|
|
self.result_debug_packages.update(debug_pkgs)
|
|
|
|
|
|
|
|
return added
|
|
|
|
|
2016-04-06 08:30:50 +00:00
|
|
|
@Profiler("Gather.add_fulltree_packages()")
|
2015-06-25 12:37:23 +00:00
|
|
|
def add_fulltree_packages(self):
|
|
|
|
"""
|
|
|
|
For each binary package add all binary packages built from the same source.
|
|
|
|
Return newly added binary packages.
|
|
|
|
"""
|
|
|
|
added = set()
|
|
|
|
|
|
|
|
if not self.opts.fulltree:
|
|
|
|
return added
|
|
|
|
|
|
|
|
for pkg in sorted(self.result_binary_packages):
|
|
|
|
assert pkg is not None
|
|
|
|
|
|
|
|
try:
|
|
|
|
fulltree_pkgs = self.finished_add_fulltree_packages[pkg]
|
|
|
|
except KeyError:
|
2016-04-06 10:50:53 +00:00
|
|
|
native_fulltree_pkgs = self.q_native_pkgs_by_sourcerpm_cache.get(pkg.sourcerpm) or []
|
|
|
|
multilib_fulltree_pkgs = self.q_multilib_pkgs_by_sourcerpm_cache.get(pkg.sourcerpm) or []
|
|
|
|
noarch_fulltree_pkgs = self.q_noarch_pkgs_by_sourcerpm_cache.get(pkg.sourcerpm) or []
|
2015-06-25 12:37:23 +00:00
|
|
|
|
|
|
|
if not native_fulltree_pkgs:
|
|
|
|
# no existing native pkgs -> pull multilib
|
|
|
|
pull_native = False
|
2016-04-06 10:12:55 +00:00
|
|
|
elif set(native_fulltree_pkgs) & self.result_binary_packages:
|
2015-06-25 12:37:23 +00:00
|
|
|
# native pkgs in result -> pull native
|
|
|
|
pull_native = True
|
2016-04-06 10:12:55 +00:00
|
|
|
elif set(multilib_fulltree_pkgs) & self.result_binary_packages:
|
2015-06-25 12:37:23 +00:00
|
|
|
# multilib pkgs in result -> pull multilib
|
|
|
|
pull_native = False
|
|
|
|
else:
|
|
|
|
# fallback / default
|
|
|
|
pull_native = True
|
|
|
|
|
|
|
|
if pull_native:
|
2016-04-06 10:12:55 +00:00
|
|
|
fulltree_pkgs = native_fulltree_pkgs
|
2015-06-25 12:37:23 +00:00
|
|
|
else:
|
2016-04-06 10:12:55 +00:00
|
|
|
fulltree_pkgs = multilib_fulltree_pkgs
|
2015-06-25 12:37:23 +00:00
|
|
|
|
|
|
|
# always pull all noarch subpackages
|
2016-04-06 10:12:55 +00:00
|
|
|
fulltree_pkgs += noarch_fulltree_pkgs
|
2015-06-25 12:37:23 +00:00
|
|
|
|
|
|
|
for i in fulltree_pkgs:
|
|
|
|
if i not in self.result_binary_packages:
|
|
|
|
self._add_packages([i])
|
|
|
|
self._set_flag(i, "fulltree")
|
|
|
|
added.add(i)
|
|
|
|
|
2015-07-23 12:04:42 +00:00
|
|
|
# don't run fulltree on added packages
|
|
|
|
self.finished_add_fulltree_packages[i] = []
|
|
|
|
|
2015-06-25 12:37:23 +00:00
|
|
|
self.finished_add_fulltree_packages[pkg] = fulltree_pkgs
|
|
|
|
|
|
|
|
return added
|
|
|
|
|
2016-04-06 08:30:50 +00:00
|
|
|
@Profiler("Gather.add_langpack_packages()")
|
2015-06-25 12:37:23 +00:00
|
|
|
def add_langpack_packages(self, langpack_patterns):
|
|
|
|
"""
|
|
|
|
For each binary package add all matching langpack packages.
|
|
|
|
Return newly added binary packages.
|
|
|
|
|
|
|
|
langpack_patterns: [{"name": <str>, "install": <str>}]
|
|
|
|
"""
|
|
|
|
added = set()
|
|
|
|
|
|
|
|
if not self.opts.langpacks:
|
|
|
|
return added
|
|
|
|
|
|
|
|
exceptions = ["man-pages-overrides"]
|
|
|
|
|
|
|
|
for pkg in sorted(self.result_binary_packages):
|
|
|
|
assert pkg is not None
|
|
|
|
|
|
|
|
try:
|
|
|
|
langpack_pkgs = self.finished_add_langpack_packages[pkg]
|
|
|
|
except KeyError:
|
|
|
|
patterns = [i["install"] for i in langpack_patterns if i["name"] == pkg.name]
|
|
|
|
patterns = [i.replace("%s", "*") for i in patterns]
|
2015-09-18 14:08:59 +00:00
|
|
|
|
|
|
|
if not patterns:
|
|
|
|
self.finished_add_langpack_packages[pkg] = []
|
|
|
|
continue
|
|
|
|
|
2015-06-25 12:37:23 +00:00
|
|
|
langpack_pkgs = self.q_binary_packages.filter(name__glob=patterns).apply()
|
|
|
|
langpack_pkgs = langpack_pkgs.filter(name__glob__not=["*-devel", "*-static"])
|
|
|
|
langpack_pkgs = langpack_pkgs.filter(name__neq=exceptions)
|
|
|
|
|
|
|
|
pkgs_by_name = {}
|
|
|
|
for i in langpack_pkgs:
|
|
|
|
pkgs_by_name.setdefault(i.name, set()).add(i)
|
|
|
|
|
|
|
|
langpack_pkgs = set()
|
|
|
|
for name in sorted(pkgs_by_name):
|
|
|
|
pkgs = pkgs_by_name[name]
|
|
|
|
i = self._get_best_package(pkgs)
|
|
|
|
if i:
|
|
|
|
# TODO: greedy
|
|
|
|
i = i[0]
|
|
|
|
langpack_pkgs.add(i)
|
|
|
|
self._set_flag(i, "langpack")
|
|
|
|
if i not in self.result_binary_packages:
|
|
|
|
self._add_packages([i], pulled_by=pkg)
|
|
|
|
added.add(pkg)
|
|
|
|
self.finished_add_langpack_packages[pkg] = langpack_pkgs
|
|
|
|
|
|
|
|
return added
|
|
|
|
|
2016-04-06 08:30:50 +00:00
|
|
|
@Profiler("Gather.add_multilib_packages()")
|
2015-06-25 12:37:23 +00:00
|
|
|
def add_multilib_packages(self):
|
|
|
|
added = set()
|
|
|
|
|
|
|
|
if not self.opts.multilib_methods or self.opts.multilib_methods == ["none"]:
|
|
|
|
return added
|
|
|
|
|
|
|
|
for pkg in sorted(self.result_binary_packages):
|
|
|
|
try:
|
|
|
|
self.finished_add_multilib_packages[pkg]
|
|
|
|
except KeyError:
|
|
|
|
|
|
|
|
if pkg.arch in ("noarch", "src", "nosrc"):
|
|
|
|
self.finished_add_multilib_packages[pkg] = None
|
|
|
|
continue
|
|
|
|
|
|
|
|
if pkg.arch in self.dnf.arch_wrapper.multilib_arches:
|
|
|
|
self.finished_add_multilib_packages[pkg] = None
|
|
|
|
continue
|
|
|
|
|
2016-04-06 10:12:55 +00:00
|
|
|
pkgs = self.q_multilib_binary_packages_cache.get(pkg.name, pkg.version, pkg.release)
|
2015-06-25 12:37:23 +00:00
|
|
|
pkgs = self._get_best_package(pkgs)
|
|
|
|
multilib_pkgs = []
|
|
|
|
for i in pkgs:
|
|
|
|
is_multilib = self._multilib.is_multilib(i)
|
|
|
|
if is_multilib:
|
|
|
|
multilib_pkgs.append(i)
|
|
|
|
added.add(i)
|
|
|
|
self._set_flag(i, "multilib")
|
|
|
|
self._add_packages([i])
|
|
|
|
self.finished_add_multilib_packages[pkg] = i
|
|
|
|
# TODO: ^^^ may get multiple results; i686, i586, etc.
|
|
|
|
|
|
|
|
return added
|
|
|
|
|
2016-04-06 08:30:50 +00:00
|
|
|
@Profiler("Gather.gather()")
|
2015-06-25 12:37:23 +00:00
|
|
|
def gather(self, pattern_list, conditional_packages=None):
|
|
|
|
self.conditional_packages = conditional_packages or []
|
|
|
|
|
2016-04-25 13:13:35 +00:00
|
|
|
self.logger.debug("INITIAL PACKAGES")
|
2015-06-25 12:37:23 +00:00
|
|
|
added = self.add_initial_packages(pattern_list)
|
|
|
|
self._add_packages(added)
|
|
|
|
|
2016-04-25 13:13:35 +00:00
|
|
|
self.logger.debug("PREPOPULATE")
|
2015-06-25 12:37:23 +00:00
|
|
|
added = self.add_prepopulate_packages()
|
|
|
|
self._add_packages(added)
|
|
|
|
|
|
|
|
pass_num = 0
|
|
|
|
added = False
|
|
|
|
while 1:
|
|
|
|
if pass_num > 0 and not added:
|
|
|
|
break
|
|
|
|
pass_num += 1
|
2016-04-25 13:13:35 +00:00
|
|
|
self.logger.debug("PASS %s" % pass_num)
|
2015-06-25 12:37:23 +00:00
|
|
|
|
2016-04-25 13:13:35 +00:00
|
|
|
self.logger.debug("DEPS")
|
2015-06-25 12:37:23 +00:00
|
|
|
added = self.add_conditional_packages()
|
2016-04-25 13:13:35 +00:00
|
|
|
self.logger.debug("ADDED: %s" % bool(added))
|
2015-06-25 12:37:23 +00:00
|
|
|
if added:
|
|
|
|
continue
|
|
|
|
|
|
|
|
# resolve deps
|
2016-04-25 13:13:35 +00:00
|
|
|
self.logger.debug("DEPS")
|
2015-06-25 12:37:23 +00:00
|
|
|
added = self.add_binary_package_deps()
|
2016-04-25 13:13:35 +00:00
|
|
|
self.logger.debug("ADDED: %s" % bool(added))
|
2015-06-25 12:37:23 +00:00
|
|
|
if added:
|
|
|
|
continue
|
|
|
|
|
|
|
|
added = self.add_source_package_deps()
|
2016-04-25 13:13:35 +00:00
|
|
|
self.logger.debug("ADDED: %s" % bool(added))
|
2015-06-25 12:37:23 +00:00
|
|
|
if added:
|
|
|
|
continue
|
|
|
|
|
2016-04-25 13:13:35 +00:00
|
|
|
self.logger.debug("SOURCE PACKAGES")
|
2015-06-25 12:37:23 +00:00
|
|
|
added = self.add_source_packages()
|
2016-04-25 13:13:35 +00:00
|
|
|
self.logger.debug("ADDED: %s" % bool(added))
|
2015-06-25 12:37:23 +00:00
|
|
|
if added:
|
|
|
|
continue
|
|
|
|
|
2016-04-25 13:13:35 +00:00
|
|
|
self.logger.debug("DEBUG PACKAGES")
|
2015-06-25 12:37:23 +00:00
|
|
|
added = self.add_debug_packages()
|
2016-04-25 13:13:35 +00:00
|
|
|
self.logger.debug("ADDED: %s" % bool(added))
|
2015-06-25 12:37:23 +00:00
|
|
|
if added:
|
|
|
|
continue
|
|
|
|
# TODO: debug deps
|
|
|
|
|
2016-04-25 13:13:35 +00:00
|
|
|
self.logger.debug("FULLTREE")
|
2015-06-25 12:37:23 +00:00
|
|
|
added = self.add_fulltree_packages()
|
2016-04-25 13:13:35 +00:00
|
|
|
self.logger.debug("ADDED: %s" % bool(added))
|
2015-06-25 12:37:23 +00:00
|
|
|
if added:
|
|
|
|
continue
|
|
|
|
|
2016-04-25 13:13:35 +00:00
|
|
|
self.logger.debug("LANGPACKS")
|
2015-06-25 12:37:23 +00:00
|
|
|
added = self.add_langpack_packages(self.opts.langpacks)
|
2016-04-25 13:13:35 +00:00
|
|
|
self.logger.debug("ADDED: %s" % bool(added))
|
2015-06-25 12:37:23 +00:00
|
|
|
if added:
|
|
|
|
continue
|
|
|
|
|
2016-04-25 13:13:35 +00:00
|
|
|
self.logger.debug("MULTILIB")
|
2015-06-25 12:37:23 +00:00
|
|
|
added = self.add_multilib_packages()
|
2016-04-25 13:13:35 +00:00
|
|
|
self.logger.debug("ADDED: %s" % bool(added))
|
2015-06-25 12:37:23 +00:00
|
|
|
if added:
|
|
|
|
continue
|
|
|
|
|
|
|
|
# nothing added -> break depsolving cycle
|
|
|
|
break
|