add support for dependencies with same name

Reported-by: Josh Stone <jistone@redhat.com>
References: https://internals.rust-lang.org/t/optional-dependencies-with-same-name/8728
Signed-off-by: Igor Gnatenko <ignatenkobrain@fedoraproject.org>
This commit is contained in:
Igor Gnatenko 2018-10-30 20:37:38 +01:00
parent 2cac5e5ad5
commit a1d3a84645
No known key found for this signature in database
GPG key ID: 695714BD1BBC5F4C

View file

@ -1,5 +1,6 @@
__all__ = ["Dependency", "Metadata"] __all__ = ["Dependency", "Metadata"]
import collections
import copy import copy
import json import json
import subprocess import subprocess
@ -126,9 +127,11 @@ class Metadata:
self.description = md.get("description") self.description = md.get("description")
# dependencies + build-dependencies → runtime # dependencies + build-dependencies → runtime
deps_by_name = {dep["name"]: Dependency.from_json(dep) deps_by_name = collections.defaultdict(list)
for dep in md["dependencies"] for dep in md["dependencies"]:
if dep["kind"] != "dev"} if dep["kind"] == "dev":
continue
deps_by_name[dep["name"]].append(Dependency.from_json(dep))
deps_by_feature = {} deps_by_feature = {}
for feature, f_deps in md["features"].items(): for feature, f_deps in md["features"].items():
@ -139,18 +142,23 @@ class Metadata:
features.add(dep) features.add(dep)
else: else:
pkg, _, f = dep.partition("/") pkg, _, f = dep.partition("/")
dep = copy.deepcopy(deps_by_name[pkg]) for dep in deps_by_name[pkg]:
if f: dep = copy.deepcopy(dep)
dep.features = {f} if f:
deps.add(dep) dep.features = {f}
deps.add(dep)
deps_by_feature[feature] = (features, deps) deps_by_feature[feature] = (features, deps)
mandatory_deps = set() mandatory_deps = set()
for dep in deps_by_name.values(): for name, deps in deps_by_name.items():
if dep.optional: fdeps = set()
deps_by_feature[dep.name] = ({None}, {copy.deepcopy(dep)}) for dep in deps:
else: if dep.optional:
mandatory_deps.add(copy.deepcopy(dep)) fdeps.add(copy.deepcopy(dep))
else:
mandatory_deps.add(copy.deepcopy(dep))
if fdeps:
deps_by_feature[name] = ({None}, fdeps)
deps_by_feature[None] = (set(), mandatory_deps) deps_by_feature[None] = (set(), mandatory_deps)
if "default" not in deps_by_feature: if "default" not in deps_by_feature: