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]