2015-02-10 13:19:34 +00:00
|
|
|
# -*- 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
|
2016-09-21 12:49:13 +00:00
|
|
|
# along with this program; if not, see <https://gnu.org/licenses/>.
|
2015-02-10 13:19:34 +00:00
|
|
|
|
2019-06-13 05:22:47 +00:00
|
|
|
import os
|
2017-11-09 14:16:21 +00:00
|
|
|
from pprint import pformat
|
2020-03-12 08:47:00 +00:00
|
|
|
import re
|
2018-01-10 12:50:21 +00:00
|
|
|
import six
|
2015-02-10 13:19:34 +00:00
|
|
|
|
2015-03-12 21:12:38 +00:00
|
|
|
import pungi.arch
|
|
|
|
from pungi.util import pkg_is_rpm, pkg_is_srpm, pkg_is_debug
|
2017-06-21 11:35:36 +00:00
|
|
|
from pungi.wrappers.comps import CompsWrapper
|
2020-03-06 13:53:52 +00:00
|
|
|
from pungi.phases.pkgset.pkgsets import ExtendedRpmWrapper
|
2015-02-10 13:19:34 +00:00
|
|
|
|
2015-03-12 21:12:38 +00:00
|
|
|
import pungi.phases.gather.method
|
2017-06-13 12:39:33 +00:00
|
|
|
from kobo.pkgset import SimpleRpmWrapper, RpmWrapper
|
2015-02-10 13:19:34 +00:00
|
|
|
|
|
|
|
|
2015-03-12 21:12:38 +00:00
|
|
|
class GatherMethodNodeps(pungi.phases.gather.method.GatherMethodBase):
|
2015-02-10 13:19:34 +00:00
|
|
|
enabled = True
|
|
|
|
|
2017-11-09 14:16:21 +00:00
|
|
|
def __call__(self, arch, variant, *args, **kwargs):
|
2020-02-03 03:50:06 +00:00
|
|
|
fname = "gather-nodeps-%s" % variant.uid
|
2017-11-07 13:16:37 +00:00
|
|
|
if self.source_name:
|
2020-02-03 03:50:06 +00:00
|
|
|
fname += "-" + self.source_name
|
2017-11-07 13:16:37 +00:00
|
|
|
log_file = self.compose.paths.log.log_file(arch, fname)
|
2020-02-03 03:50:06 +00:00
|
|
|
with open(log_file, "w") as log:
|
2017-11-09 14:16:21 +00:00
|
|
|
return self.worker(log, arch, variant, *args, **kwargs)
|
|
|
|
|
2020-02-03 03:50:06 +00:00
|
|
|
def worker(
|
|
|
|
self,
|
|
|
|
log,
|
|
|
|
arch,
|
|
|
|
variant,
|
|
|
|
pkgs,
|
|
|
|
groups,
|
|
|
|
filter_packages,
|
|
|
|
multilib_whitelist,
|
|
|
|
multilib_blacklist,
|
|
|
|
package_sets,
|
|
|
|
path_prefix=None,
|
|
|
|
fulltree_excludes=None,
|
|
|
|
prepopulate=None,
|
|
|
|
):
|
2015-02-10 13:19:34 +00:00
|
|
|
result = {
|
|
|
|
"rpm": [],
|
|
|
|
"srpm": [],
|
|
|
|
"debuginfo": [],
|
|
|
|
}
|
|
|
|
|
2018-04-05 11:17:12 +00:00
|
|
|
group_packages = expand_groups(self.compose, arch, variant, groups)
|
2017-06-21 11:35:36 +00:00
|
|
|
packages = pkgs | group_packages
|
2020-02-03 03:50:06 +00:00
|
|
|
log.write("Requested packages:\n%s\n" % pformat(packages))
|
2017-06-21 11:35:36 +00:00
|
|
|
|
2015-02-10 13:19:34 +00:00
|
|
|
seen_rpms = {}
|
|
|
|
seen_srpms = {}
|
|
|
|
|
2015-03-12 21:12:38 +00:00
|
|
|
valid_arches = pungi.arch.get_valid_arches(arch, multilib=True)
|
2015-02-10 13:19:34 +00:00
|
|
|
compatible_arches = {}
|
|
|
|
for i in valid_arches:
|
2015-03-12 21:12:38 +00:00
|
|
|
compatible_arches[i] = pungi.arch.get_compatible_arches(i)
|
2015-02-10 13:19:34 +00:00
|
|
|
|
2020-02-03 03:50:06 +00:00
|
|
|
log.write("\nGathering rpms\n")
|
2019-07-25 08:15:14 +00:00
|
|
|
for pkg in iterate_packages(package_sets, arch):
|
2015-02-10 13:19:34 +00:00
|
|
|
if not pkg_is_rpm(pkg):
|
|
|
|
continue
|
2017-06-13 12:39:33 +00:00
|
|
|
for gathered_pkg, pkg_arch in packages:
|
2020-03-12 08:47:00 +00:00
|
|
|
if isinstance(gathered_pkg, six.string_types) and not re.match(
|
|
|
|
gathered_pkg.replace(".", "\\.")
|
|
|
|
.replace("+", "\\+")
|
|
|
|
.replace("*", ".*"),
|
|
|
|
pkg.name,
|
2020-02-03 03:50:06 +00:00
|
|
|
):
|
2017-06-13 12:39:33 +00:00
|
|
|
continue
|
2020-02-03 03:50:06 +00:00
|
|
|
elif (
|
2020-03-06 13:53:52 +00:00
|
|
|
type(gathered_pkg)
|
|
|
|
in [SimpleRpmWrapper, RpmWrapper, ExtendedRpmWrapper]
|
2020-02-03 03:50:06 +00:00
|
|
|
and pkg.nevra != gathered_pkg.nevra
|
|
|
|
):
|
2015-02-10 13:19:34 +00:00
|
|
|
continue
|
2020-02-03 03:50:06 +00:00
|
|
|
if (
|
|
|
|
pkg_arch is not None
|
|
|
|
and pkg.arch != pkg_arch
|
|
|
|
and pkg.arch != "noarch"
|
|
|
|
):
|
2015-02-10 13:19:34 +00:00
|
|
|
continue
|
2020-02-07 05:53:20 +00:00
|
|
|
result["rpm"].append({"path": pkg.file_path, "flags": ["input"]})
|
2015-02-10 13:19:34 +00:00
|
|
|
seen_rpms.setdefault(pkg.name, set()).add(pkg.arch)
|
|
|
|
seen_srpms.setdefault(pkg.sourcerpm, set()).add(pkg.arch)
|
2020-02-03 03:50:06 +00:00
|
|
|
log.write(
|
|
|
|
"Added %s (matched %s.%s) (sourcerpm: %s)\n"
|
|
|
|
% (pkg, gathered_pkg, pkg_arch, pkg.sourcerpm)
|
|
|
|
)
|
2015-02-10 13:19:34 +00:00
|
|
|
|
2020-02-03 03:50:06 +00:00
|
|
|
log.write("\nGathering source rpms\n")
|
2019-07-25 08:15:14 +00:00
|
|
|
for pkg in iterate_packages(package_sets, arch):
|
2015-02-10 13:19:34 +00:00
|
|
|
if not pkg_is_srpm(pkg):
|
|
|
|
continue
|
|
|
|
if pkg.file_name in seen_srpms:
|
2020-02-07 05:53:20 +00:00
|
|
|
result["srpm"].append({"path": pkg.file_path, "flags": ["input"]})
|
2020-02-03 03:50:06 +00:00
|
|
|
log.write("Adding %s\n" % pkg)
|
2015-02-10 13:19:34 +00:00
|
|
|
|
2020-02-03 03:50:06 +00:00
|
|
|
log.write("\nGathering debuginfo packages\n")
|
2019-07-25 08:15:14 +00:00
|
|
|
for pkg in iterate_packages(package_sets, arch):
|
2015-02-10 13:19:34 +00:00
|
|
|
if not pkg_is_debug(pkg):
|
|
|
|
continue
|
|
|
|
if pkg.sourcerpm not in seen_srpms:
|
2020-02-03 03:50:06 +00:00
|
|
|
log.write("Not considering %s: corresponding srpm not included\n" % pkg)
|
2015-02-10 13:19:34 +00:00
|
|
|
continue
|
2020-02-03 03:50:06 +00:00
|
|
|
pkg_arches = set(compatible_arches[pkg.arch]) - set(["noarch"])
|
|
|
|
seen_arches = set(seen_srpms[pkg.sourcerpm]) - set(["noarch"])
|
2017-07-20 12:54:54 +00:00
|
|
|
if not (pkg_arches & seen_arches):
|
|
|
|
# We only want to pull in a debuginfo if we have a binary
|
|
|
|
# package for a compatible arch. Noarch packages should not
|
|
|
|
# pull debuginfo (they would pull in all architectures).
|
2020-02-03 03:50:06 +00:00
|
|
|
log.write("Not including %s: no package for this arch\n" % pkg)
|
2015-02-10 13:19:34 +00:00
|
|
|
continue
|
2020-02-07 05:53:20 +00:00
|
|
|
result["debuginfo"].append({"path": pkg.file_path, "flags": ["input"]})
|
2020-02-03 03:50:06 +00:00
|
|
|
log.write("Adding %s\n" % pkg)
|
2015-02-10 13:19:34 +00:00
|
|
|
|
|
|
|
return result
|
2017-06-21 11:35:36 +00:00
|
|
|
|
|
|
|
|
2018-06-22 06:58:54 +00:00
|
|
|
def expand_groups(compose, arch, variant, groups, set_pkg_arch=True):
|
2018-04-05 11:17:12 +00:00
|
|
|
"""Read comps file filtered for given architecture and variant and return
|
|
|
|
all packages in given groups.
|
2017-06-21 11:35:36 +00:00
|
|
|
|
|
|
|
:returns: A set of tuples (pkg_name, arch)
|
|
|
|
"""
|
2017-07-20 11:11:06 +00:00
|
|
|
if not groups:
|
|
|
|
# No groups, nothing to do (this also covers case when there is no
|
|
|
|
# comps file.
|
|
|
|
return set()
|
2019-06-13 05:22:47 +00:00
|
|
|
comps = []
|
2018-04-05 11:17:12 +00:00
|
|
|
comps_file = compose.paths.work.comps(arch, variant, create_dir=False)
|
2019-06-13 05:22:47 +00:00
|
|
|
comps.append(CompsWrapper(comps_file))
|
2017-06-21 11:35:36 +00:00
|
|
|
|
2019-06-13 05:22:47 +00:00
|
|
|
if variant and variant.parent:
|
2020-02-03 03:50:06 +00:00
|
|
|
parent_comps_file = compose.paths.work.comps(
|
|
|
|
arch, variant.parent, create_dir=False
|
|
|
|
)
|
2019-06-13 05:22:47 +00:00
|
|
|
comps.append(CompsWrapper(parent_comps_file))
|
|
|
|
|
2020-02-03 03:50:06 +00:00
|
|
|
if variant.type == "optional":
|
2019-06-13 05:22:47 +00:00
|
|
|
for v in variant.parent.variants.values():
|
|
|
|
if v.id == variant.id:
|
|
|
|
continue
|
|
|
|
comps_file = compose.paths.work.comps(arch, v, create_dir=False)
|
|
|
|
if os.path.exists(comps_file):
|
|
|
|
comps.append(CompsWrapper(comps_file))
|
2018-06-22 06:58:54 +00:00
|
|
|
|
2019-06-13 05:22:47 +00:00
|
|
|
packages = set()
|
|
|
|
pkg_arch = arch if set_pkg_arch else None
|
2017-06-21 11:35:36 +00:00
|
|
|
for group in groups:
|
2019-06-13 05:22:47 +00:00
|
|
|
found = False
|
|
|
|
ex = None
|
|
|
|
for c in comps:
|
|
|
|
try:
|
|
|
|
packages.update([(pkg, pkg_arch) for pkg in c.get_packages(group)])
|
|
|
|
found = True
|
|
|
|
break
|
|
|
|
except KeyError as e:
|
|
|
|
ex = e
|
|
|
|
|
|
|
|
if not found:
|
|
|
|
raise ex
|
2017-06-21 11:35:36 +00:00
|
|
|
|
|
|
|
return packages
|
2019-07-25 08:15:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
def iterate_packages(package_sets, arch):
|
|
|
|
for pkgset in package_sets:
|
|
|
|
for pkg in pkgset[arch]:
|
|
|
|
yield pkgset[arch][pkg]
|