From c9e7cf51e4ffacbcd3e4133017c5acd695586b07 Mon Sep 17 00:00:00 2001 From: Igor Gnatenko Date: Mon, 8 Jan 2018 14:37:29 +0100 Subject: [PATCH] optional dependencies are also features References: https://github.com/rust-lang/cargo/issues/4911 Signed-off-by: Igor Gnatenko --- rust2rpm/metadata.py | 7 ++++++- test.py | 24 ++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/rust2rpm/metadata.py b/rust2rpm/metadata.py index e163e78..0d5490e 100644 --- a/rust2rpm/metadata.py +++ b/rust2rpm/metadata.py @@ -1,5 +1,6 @@ __all__ = ["Dependency", "Metadata"] +import itertools import json import subprocess import sys @@ -162,7 +163,11 @@ class Metadata(object): self.targets = [Target(tgt["kind"][0], tgt["name"]) for tgt in md["targets"]] # Provides - provides = Dependency(self.name, version, features=md["features"], provides=True) + # All optional depdencies are also features + # https://github.com/rust-lang/cargo/issues/4911 + features = itertools.chain((x["name"] for x in md["dependencies"] if x["optional"]), + md["features"]) + provides = Dependency(self.name, version, features=features, provides=True) self.provides = str(provides).split(" and ") # Dependencies diff --git a/test.py b/test.py index c69cbe6..b856fdd 100644 --- a/test.py +++ b/test.py @@ -75,6 +75,30 @@ def cargo_toml(request): "crate(hello/color) = 1.2.3"], []), + # Provides for optional dependencies + (""" + [package] + name = "hello" + version = "1.2.3" + + [dependencies] + non_optional = "1" + serde = { version = "1", optional = true } + rand = { version = "0.4", optional = true } + + [features] + std = [] + v1 = ["rand"] + """, + ["crate(hello) = 1.2.3", + "crate(hello/rand) = 1.2.3", + "crate(hello/serde) = 1.2.3", + "crate(hello/std) = 1.2.3", + "crate(hello/v1) = 1.2.3"], + ["(crate(non_optional) >= 1.0.0 with crate(non_optional) < 2.0.0)", + "(crate(rand) >= 0.4.0 with crate(rand) < 0.5.0)", + "(crate(serde) >= 1.0.0 with crate(serde) < 2.0.0)"]), + # Caret requirements (""" [package]