From 61e7b5fc7a860de3378b82d5c9f3bec21de1772f Mon Sep 17 00:00:00 2001 From: Zbigniew Jędrzejewski-Szmek Date: Jul 12 2022 08:48:16 +0000 Subject: [PATCH 1/3] Add parser and evaluator for rust cfg expressions --- diff --git a/rust2rpm/cfg.py b/rust2rpm/cfg.py new file mode 100644 index 0000000..efccf87 --- /dev/null +++ b/rust2rpm/cfg.py @@ -0,0 +1,113 @@ +import ast +import ctypes +import functools +import platform +import sys + +import pyparsing as pp + +pp.ParserElement.enable_packrat() + +# ConfigurationPredicate : +# ConfigurationOption +# | ConfigurationAll +# | ConfigurationAny +# | ConfigurationNot +# ConfigurationOption : +# IDENTIFIER (= (STRING_LITERAL | RAW_STRING_LITERAL))? +# ConfigurationAll +# all ( ConfigurationPredicateList? ) +# ConfigurationAny +# any ( ConfigurationPredicateList? ) +# ConfigurationNot +# not ( ConfigurationPredicate ) +# ConfigurationPredicateList +# ConfigurationPredicate (, ConfigurationPredicate)* ,? + +# cfg(target_os = "macos") +# cfg(any(foo, bar)) +# cfg(all(unix, target_pointer_width = "32")) +# cfg(not(foo)) + +def _call(word, arg): + return pp.Group(pp.Literal(word) + pp.Suppress('(') + arg + pp.Suppress(')'), aslist=True) + +@functools.cache +def cfg_grammar(): + pred = pp.Forward() + + ident = pp.Word(pp.alphas + '_', pp.alphanums + '_') + option = pp.Group(ident + pp.Optional(pp.Suppress('=') + pp.quotedString), aslist=True) + + not_ = _call('not', pred) + + # pp.pyparsing_common.comma_separated_list? + # any_ = _call('any', pp.pyparsing_common.comma_separated_list(pred)) + # all_ = _call('all', pp.pyparsing_common.comma_separated_list(pred)) + # all_ = _call('all', pp.delimited_list(pred)) + + any_ = _call('any', pred + pp.ZeroOrMore(pp.Suppress(',') + pred)) + all_ = _call('all', pred + pp.ZeroOrMore(pp.Suppress(',') + pred)) + + pred <<= not_ | any_ | all_ | option + + grammar = _call('cfg', pred) + return grammar + +@functools.cache +def evaluate_variable(name): + # print(f'evaluate_variable: {expr}') + match name: + case 'target_arch': + return platform.machine() + + case 'target_os': + return 'linux' + + case 'target_family': + return 'unix' + + case 'unix': + return evaluate_variable('target_family') == 'unix' + + case 'windows': + return evaluate_variable('target_family') == 'windows' + + case 'target_env': + # Key-value option set with further disambiguating information about the + # target platform with information about the ABI or libc used + return ... + + case 'target_endian': + return sys.byteorder + + case 'target_pointer_width': + return str(ctypes.sizeof(ctypes.c_voidp) * 8) + + case 'target_vendor': + return 'unknown' + + case _: + print(f'Unknown variable {name}, assuming False') + return False + +def evaluate(expr, nested=False): + # print(f'evaluate: {expr}') + match expr: + case ['cfg', expr] if not nested: + return evaluate(expr, True) + case ['not', expr] if nested: + return not evaluate(expr, True) + case ['all', *args] if nested: + return all(evaluate(arg, True) for arg in args) + case ['any', *args] if nested: + return any(evaluate(arg, True) for arg in args) + case [variable, value] if nested: + v = ast.literal_eval(value) + x = evaluate_variable(variable) + return x == v + case [variable] if nested: + x = evaluate_variable(variable) + return x + case _: + raise ValueError diff --git a/rust2rpm/tests/test_cfg.py b/rust2rpm/tests/test_cfg.py new file mode 100644 index 0000000..ea89b6b --- /dev/null +++ b/rust2rpm/tests/test_cfg.py @@ -0,0 +1,60 @@ +import pytest + +from rust2rpm import cfg + +def test_pyparsing_run_tests(): + g = cfg.cfg_grammar() + + g.run_tests("""\ + cfg(target_os = "macos") + cfg(any(foo, bar)) + cfg(all(unix, target_pointer_width = "32")) + cfg(not(foo)) + """) + +@pytest.mark.parametrize('expr, expected', [ + ('cfg(target_os = "macos")', + False), + ('cfg(any(foo, bar))', + False), + ('cfg(all(unix, target_pointer_width = "16"))', + False), + ('cfg(not(foo))', + True), + + ('cfg(unix)', + True), + ('cfg(not(unix))', + False), + ('cfg(windows)', + False), + ('cfg(linux)', # not defined + False), + ('cfg(not(windows))', + True), + ('cfg(any(unix, windows))', + True), + ('cfg(any(windows, unix))', + True), + ('cfg(any(windows, windows, windows))', + False), + + ('cfg(target_os = "linux")', + True), + ('cfg(any(target_os = "linux"))', + True), + ('cfg(all(target_os = "linux"))', + True), + ('cfg(any(target_os = "linux", target_os = "macos"))', + True), + + ('cfg(any(target_pointer_width = "16", target_pointer_width = "32", target_pointer_width = "64"))', + True), + ('cfg(all(target_pointer_width = "16", target_pointer_width = "32", target_pointer_width = "64"))', + False), + +]) +def test_expressions(expr, expected): + parsed = cfg.cfg_grammar().parse_string(expr) + value = cfg.evaluate(parsed[0]) + assert value == expected From d326bb018032cb78484a8939df6c3b863940fc07 Mon Sep 17 00:00:00 2001 From: Zbigniew Jędrzejewski-Szmek Date: Jul 12 2022 08:48:16 +0000 Subject: [PATCH 2/3] Add cfg.parse_and_evaluate() --- diff --git a/rust2rpm/cfg.py b/rust2rpm/cfg.py index efccf87..9385b20 100644 --- a/rust2rpm/cfg.py +++ b/rust2rpm/cfg.py @@ -111,3 +111,7 @@ def evaluate(expr, nested=False): return x case _: raise ValueError + +def parse_and_evaluate(expr): + parsed = cfg_grammar().parse_string(expr) + return evaluate(parsed[0]) diff --git a/rust2rpm/tests/test_cfg.py b/rust2rpm/tests/test_cfg.py index ea89b6b..4a86abb 100644 --- a/rust2rpm/tests/test_cfg.py +++ b/rust2rpm/tests/test_cfg.py @@ -55,6 +55,5 @@ def test_pyparsing_run_tests(): ]) def test_expressions(expr, expected): - parsed = cfg.cfg_grammar().parse_string(expr) - value = cfg.evaluate(parsed[0]) + value = cfg.parse_and_evaluate(expr) assert value == expected From a57d4b2c95a25777ddace9e773f3579a076a0d8a Mon Sep 17 00:00:00 2001 From: Zbigniew Jędrzejewski-Szmek Date: Jul 12 2022 08:48:16 +0000 Subject: [PATCH 3/3] Automatically strip foreign dependencies The basic workflow is that very similarly to how we would open an editor to do manual patching of Cargo.toml, we automatically rewrite the file first. In this automatic rewrite, for any sections like [target.cfg(…)], we evaluate the conditional and drop the whole section if the conditional is known to be false. When the conditional cannot be evaluated because it uses some form that we don't understand, it is left untouched. But it seems that the conditionals used in practice don't have too much variety. If parser and evaluator certainly don't cover all the corner cases, but it might not matter in practice. We can always fix them later if unsupported cases are found. Removed dependencies are filter out from [feature] lists: For example for tokio: [features] -net = ["libc", "mio/os-poll", "mio/os-ext", "mio/net", "socket2", "winapi/namedpipeapi"] +net = ["libc", "mio/os-poll", "mio/os-ext", "mio/net", "socket2"] If -p was used, after the automatic filtering, the editor is opened for the user to do further manual patching. Automatic and manual changes land in separate patches. Fixes #2. --- diff --git a/rust2rpm/__main__.py b/rust2rpm/__main__.py index f258e29..c304491 100644 --- a/rust2rpm/__main__.py +++ b/rust2rpm/__main__.py @@ -20,7 +20,7 @@ import subprocess import requests import tqdm -from . import Metadata, licensing, generator +from . import Metadata, cfg, licensing, generator DEFAULT_EDITOR = "vi" XDG_CACHE_HOME = os.getenv("XDG_CACHE_HOME", os.path.expanduser("~/.cache")) @@ -36,6 +36,18 @@ LICENSES = re.compile(r""" (?:AGPL|APACHE|BSD|GFDL|GNU|L?GPL|MIT|MPL|OFL)-.*[0-9].* """, re.VERBOSE) +# [target.'cfg(not(any(target_os="windows", target_os="macos")))'.dependencies] +# [target."cfg(windows)".dependencies.winapi] +# [target."cfg(target_arch = \"wasm32\")".dev-dependencies.wasm-bindgen-test] + +TARGET_DEPENDENCY_LINE = re.compile(r''' + ^ \[ target\.(?P(?P['"])cfg\(.*\)(?P=quote)) + \. + (?P dependencies|build-dependencies|dev-dependencies) + (?:\. (?P[a-zA-Z0-9_-]+) )? + \] \s* $ + ''', re.VERBOSE) + def sortify(func): """Return a sorted list from a generator""" def wrapper(*args, **kwargs): @@ -198,35 +210,119 @@ def files_from_crate(cratef, crate, version): license_files = get_license_files(root_path) yield toml, doc_files, license_files -def make_patch(args, toml, tmpfile=False): - """Spawns editor on toml and returns a unified diff after editor closes""" - if not args.patch: - return [] +def filter_out_features_re(dropped_features): + # This is a bit simplistic. But it doesn't seem worth the trouble to write + # a grammar for this. Can be always done later. If we parse this using a + # grammar, we beget the question how to preserve formatting idiosyncrasies. + # Regexp replacement makes it trivial to minimize changes. + match_features = '|'.join(dropped_features) + match_suffix = f'(?:/[{cfg.IDENT_CHARS[1]}]+)?' + + return re.compile(fr'''(?P ,)? \s* (?P['"]) + ({match_features}) {match_suffix} + (?P=quote) \s* (?(comma) |,?) \s* + ''', re.VERBOSE) + +def drop_foreign_dependencies(lines): + dropped_lines = 0 + dropped_features = set() + good_lines = [] + + value = True + for line in lines: + # print(f'{line=}') + # [target.'cfg(not(any(target_os="windows", target_os="macos")))'.dependencies] + if m := TARGET_DEPENDENCY_LINE.match(line): + expr = m.group('cfg') + expr = ast.literal_eval(expr) + # print(f'matched: {expr=}') + try: + value = cfg.parse_and_evaluate(expr) + except (ValueError, cfg.ParseException): + print(f'Could not evaluate {expr!r}, treating as true') + value = True + + if not value: + feature = m.group('feature') + print(f'Skipping section {line.rstrip()} ({feature=})') + dropped_features.add(feature) + + elif line.startswith('['): + # previous section ended, let's keep printing lines again + value = True + + # print(f'→ {value}') + + if value: + good_lines += [line] + else: + dropped_lines += 1 + + if not dropped_lines: + # nothing to do, let's bail out + return None + + good_lines2 = [] + in_features = False + filt = filter_out_features_re(dropped_features) + for line in good_lines: + if line.rstrip() == '[features]': + in_features = True + elif line.startswith('['): + in_features = False + elif in_features: + line = re.sub(filt, '', line) + if not line: + continue + + good_lines2 += [line] + + return good_lines2 + + +def make_diff(path, lines1, mtime1, lines2, mtime2): + relpath = "/".join(path.split("/")[-2:]) + return list(difflib.unified_diff(lines1, lines2, + fromfile=path, tofile=path, + fromfiledate=mtime1, tofiledate=mtime2)) + - editor = detect_editor() +def make_patches(args, toml): + """Returns up to two patches (automatic and manual). + For the manual patch, an editor is spawned on toml and a diff is + made after the editor returns. + """ mtime_before = file_mtime(toml) toml_before = open(toml).readlines() - # When we are editing a git checkout, we should not modify the real file. - # When we are editing an unpacked crate, we are free to edit anything. - # Let's keep the file name as close as possible to make editing easier. - if tmpfile: - tmpfile = tempfile.NamedTemporaryFile("w+t", dir=os.path.dirname(toml), - prefix="Cargo.", suffix=".toml") - tmpfile.writelines(toml_before) - tmpfile.flush() - fname = tmpfile.name + diff1 = diff2 = None + + # We always do the automatic part before asking the user for more edits. + if toml_after := args.patch_foreign and drop_foreign_dependencies(toml_before): + diff1 = make_diff(toml, + toml_before, mtime_before, + toml_after, mtime_before) else: - fname = toml - subprocess.check_call([editor, fname]) - mtime_after = file_mtime(toml) - toml_after = open(fname).readlines() - toml_relpath = "/".join(toml.split("/")[-2:]) - diff = list(difflib.unified_diff(toml_before, toml_after, - fromfile=toml_relpath, tofile=toml_relpath, - fromfiledate=mtime_before, tofiledate=mtime_after)) - return diff + toml_after = toml_before + + if args.patch: + with tempfile.NamedTemporaryFile("w+t", dir=os.path.dirname(toml), + prefix="Cargo.", suffix=".toml") as tmpfile: + tmpfile.writelines(toml_after) + tmpfile.flush() + + editor = detect_editor() + subprocess.check_call([editor, tmpfile.name]) + + mtime_after2 = file_mtime(tmpfile.name) + toml_after2 = open(tmpfile.name).readlines() + + diff2 = make_diff(toml, + toml_after, mtime_before, + toml_after2, mtime_after2) + + return diff1, diff2 def _is_path(path): return "/" in path or path in {".", ".."} @@ -300,12 +396,12 @@ def make_diff_metadata(args, crate, version): raise ValueError("--store-crate can only be used for a crate") toml, crate, version, doc_files, license_files = local_toml(crate, version) - diff = make_patch(args, toml, tmpfile=True) + diffs = make_patches(args, toml) metadata = Metadata.from_file(toml) if len(metadata) > 1: print(f"Warning: multiple metadata for {toml}") metadata = metadata[0] - return metadata.name, diff, metadata, doc_files, license_files + return metadata.name, diffs, metadata, doc_files, license_files else: cratef, crate, version = download(crate, version) @@ -313,14 +409,14 @@ def make_diff_metadata(args, crate, version): if not license_files: print(f"Warning: no license files detected in {crate}") - diff = make_patch(args, toml) + diffs = make_patches(args, toml) metadata = Metadata.from_file(toml) if len(metadata) > 1: print(f"Warning: multiple metadata for {toml}, ignoring everything except the first") metadata = metadata[0] if args.store_crate: shutil.copy2(cratef, os.path.join(os.getcwd(), f"{metadata.name}-{version}.crate")) - return crate, diff, metadata, doc_files, license_files + return crate, diffs, metadata, doc_files, license_files def detect_rpmautospec(default_target, spec_file): @@ -417,8 +513,11 @@ def get_parser(): parser.add_argument("-t", "--target", action="store", choices=("plain", "fedora", "mageia", "opensuse"), default=default_target, help="Distribution target") + parser.add_argument("--no-patch-foreign", action="store_false", + default=True, dest="patch_foreign", + help="Do not automatically drop foreign dependencies in Cargo.toml") parser.add_argument("-p", "--patch", action="store_true", - help="Do initial patching of Cargo.toml") + help="Do manual patching of Cargo.toml") parser.add_argument("-s", "--store-crate", action="store_true", help="Store crate in current directory") parser.add_argument("-a", "--rpmautospec", action="store_true", @@ -469,11 +568,13 @@ def main(): if args.crate is None: parser.error("crate/path argument missing and autodetection failed") - crate, diff, metadata, doc_files, license_files = make_diff_metadata(args, args.crate, args.version) - - patch_file = f"{metadata.name}-fix-metadata.diff" if diff else None + crate, diffs, metadata, doc_files, license_files = make_diff_metadata(args, args.crate, args.version) pkg_name = package_name_suffixed(metadata.name, args.suffix) + + patch_files = (f"{metadata.name}-automatic.diff" if diffs[0] else None, + f"{metadata.name}-manual.diff" if diffs[1] else None) + spec_file = pathlib.Path(f"{pkg_name}.spec") if args.target in {"fedora"} and args.existence_check and not os.path.exists(spec_file): @@ -522,7 +623,8 @@ def main(): pkg_name = pkg_name, crate = crate, metadata = metadata, - patch_file = patch_file, + patch_file_automatic=patch_files[0], + patch_file_manual=patch_files[1], packager_identity = packager_identity, doc_files = doc_files, license_files = license_files, @@ -533,18 +635,20 @@ def main(): if args.stdout: print(f"# {spec_file}") print(spec_contents) - if patch_file is not None: - print(f"# {patch_file}") - print("".join(diff), end="") + for fname, diff in zip(patch_files, diffs): + if fname: + print(f"# {fname}") + print("".join(diff), end="") else: with open(spec_file, "w") as fobj: fobj.write(spec_contents) fobj.write("\n") print(f'Wrote {fobj.name}') - if patch_file is not None: - with open(patch_file, "w") as fobj: - fobj.writelines(diff) - print(f'Wrote {fobj.name}') + for fname, diff in zip(patch_files, diffs): + if fname: + with open(fname, "w") as fobj: + fobj.writelines(diff) + print(f'Wrote {fobj.name}') if __name__ == "__main__": main() diff --git a/rust2rpm/cfg.py b/rust2rpm/cfg.py index 9385b20..5e3d10b 100644 --- a/rust2rpm/cfg.py +++ b/rust2rpm/cfg.py @@ -5,6 +5,7 @@ import platform import sys import pyparsing as pp +from pyparsing.exceptions import ParseException pp.ParserElement.enable_packrat() @@ -29,6 +30,8 @@ pp.ParserElement.enable_packrat() # cfg(all(unix, target_pointer_width = "32")) # cfg(not(foo)) +IDENT_CHARS = pp.alphas + '_', pp.alphanums + '_' + def _call(word, arg): return pp.Group(pp.Literal(word) + pp.Suppress('(') + arg + pp.Suppress(')'), aslist=True) @@ -36,7 +39,7 @@ def _call(word, arg): def cfg_grammar(): pred = pp.Forward() - ident = pp.Word(pp.alphas + '_', pp.alphanums + '_') + ident = pp.Word(IDENT_CHARS[0], IDENT_CHARS[1]) option = pp.Group(ident + pp.Optional(pp.Suppress('=') + pp.quotedString), aslist=True) not_ = _call('not', pred) diff --git a/rust2rpm/generator.py b/rust2rpm/generator.py index 6d5d641..d9e6f95 100644 --- a/rust2rpm/generator.py +++ b/rust2rpm/generator.py @@ -29,7 +29,8 @@ def spec_file_render( pkg_name, crate, metadata, - patch_file, + patch_file_manual, + patch_file_automatic, packager_identity, doc_files, license_files, @@ -105,7 +106,8 @@ def spec_file_render( spec_contents = template.render( metadata=metadata, - patch_file=patch_file, + patch_file_manual=patch_file_manual, + patch_file_automatic=patch_file_automatic, **kwargs) + '\n' return spec_contents diff --git a/rust2rpm/templates/main.spec b/rust2rpm/templates/main.spec index 4f0c09b..842d97f 100644 --- a/rust2rpm/templates/main.spec +++ b/rust2rpm/templates/main.spec @@ -34,13 +34,17 @@ License: {{ license|default("# FIXME") }} {% endif %} URL: https://crates.io/crates/{{ crate }} Source: %{crates_source} -{% if patch_file is not none %} +{% if patch_file_automatic is not none %} +# Automatically generated patch to strip foreign dependencies +Patch: {{ patch_file_automatic }} +{% endif %} +{% if patch_file_manual is not none %} {% if target == "opensuse" %} -# PATCH-FIX-OPENSUSE {{ patch_file }} -- Initial patched metadata +# PATCH-FIX-OPENSUSE {{ patch_file_manual }} — Maintainer patch to adjust dependencies {% else %} -# Initial patched metadata +# Maintainer patch to adjust dependencies {% endif %} -Patch: {{ patch_file }} +Patch: {{ patch_file_manual }} {% endif %} ExclusiveArch: %{rust_arches} diff --git a/rust2rpm/tests/samples/cxx-build-1.0.71.fedora.spec b/rust2rpm/tests/samples/cxx-build-1.0.71.fedora.spec index 5d80487..0bbddc9 100644 --- a/rust2rpm/tests/samples/cxx-build-1.0.71.fedora.spec +++ b/rust2rpm/tests/samples/cxx-build-1.0.71.fedora.spec @@ -12,8 +12,10 @@ Summary: C++ code generator for integrating `cxx` crate into a Cargo buil License: MIT OR Apache-2.0 URL: https://crates.io/crates/cxx-build-1.0.71 Source: %{crates_source} -# Initial patched metadata +# Automatically generated patch to strip foreign dependencies Patch: cxx-build-1.0.71-patch1.diff +# Maintainer patch to adjust dependencies +Patch: cxx-build-1.0.71-patch2.diff ExclusiveArch: %{rust_arches} diff --git a/rust2rpm/tests/samples/cxx-build-1.0.71.mageia.spec b/rust2rpm/tests/samples/cxx-build-1.0.71.mageia.spec index 41c830f..4043f9b 100644 --- a/rust2rpm/tests/samples/cxx-build-1.0.71.mageia.spec +++ b/rust2rpm/tests/samples/cxx-build-1.0.71.mageia.spec @@ -14,8 +14,10 @@ Group: Development/Rust License: MIT or ASL 2.0 URL: https://crates.io/crates/cxx-build-1.0.71 Source: %{crates_source} -# Initial patched metadata +# Automatically generated patch to strip foreign dependencies Patch: cxx-build-1.0.71-patch1.diff +# Maintainer patch to adjust dependencies +Patch: cxx-build-1.0.71-patch2.diff ExclusiveArch: %{rust_arches} diff --git a/rust2rpm/tests/samples/cxx-build-1.0.71.opensuse.spec b/rust2rpm/tests/samples/cxx-build-1.0.71.opensuse.spec index 63cc21f..2f39cad 100644 --- a/rust2rpm/tests/samples/cxx-build-1.0.71.opensuse.spec +++ b/rust2rpm/tests/samples/cxx-build-1.0.71.opensuse.spec @@ -30,8 +30,10 @@ Group: Development/Libraries/Rust License: MIT OR Apache-2.0 URL: https://crates.io/crates/cxx-build-1.0.71 Source: %{crates_source} -# PATCH-FIX-OPENSUSE cxx-build-1.0.71-patch1.diff -- Initial patched metadata +# Automatically generated patch to strip foreign dependencies Patch: cxx-build-1.0.71-patch1.diff +# PATCH-FIX-OPENSUSE cxx-build-1.0.71-patch2.diff — Maintainer patch to adjust dependencies +Patch: cxx-build-1.0.71-patch2.diff ExclusiveArch: %{rust_arches} diff --git a/rust2rpm/tests/samples/cxx-build-1.0.71.plain.spec b/rust2rpm/tests/samples/cxx-build-1.0.71.plain.spec index 3466690..dc997fb 100644 --- a/rust2rpm/tests/samples/cxx-build-1.0.71.plain.spec +++ b/rust2rpm/tests/samples/cxx-build-1.0.71.plain.spec @@ -12,8 +12,10 @@ Summary: C++ code generator for integrating `cxx` crate into a Cargo buil License: MIT OR Apache-2.0 URL: https://crates.io/crates/cxx-build-1.0.71 Source: %{crates_source} -# Initial patched metadata +# Automatically generated patch to strip foreign dependencies Patch: cxx-build-1.0.71-patch1.diff +# Maintainer patch to adjust dependencies +Patch: cxx-build-1.0.71-patch2.diff ExclusiveArch: %{rust_arches} diff --git a/rust2rpm/tests/samples/nix-0.24.1.fedora.spec b/rust2rpm/tests/samples/nix-0.24.1.fedora.spec index eea1da3..5071597 100644 --- a/rust2rpm/tests/samples/nix-0.24.1.fedora.spec +++ b/rust2rpm/tests/samples/nix-0.24.1.fedora.spec @@ -12,8 +12,10 @@ Summary: Rust friendly bindings to *nix APIs License: MIT URL: https://crates.io/crates/nix-0.24.1 Source: %{crates_source} -# Initial patched metadata +# Automatically generated patch to strip foreign dependencies Patch: nix-0.24.1-patch1.diff +# Maintainer patch to adjust dependencies +Patch: nix-0.24.1-patch2.diff ExclusiveArch: %{rust_arches} @@ -30,7 +32,6 @@ BuildRequires: (crate(lazy_static/default) >= 1.2.0 with crate(lazy_static/defa BuildRequires: (crate(parking_lot/default) >= 0.11.2 with crate(parking_lot/default) < 0.12.0~) BuildRequires: (crate(rand/default) >= 0.8.0 with crate(rand/default) < 0.9.0~) BuildRequires: (crate(semver/default) >= 1.0.0 with crate(semver/default) < 2.0.0~) -BuildRequires: (crate(sysctl/default) >= 0.1.0 with crate(sysctl/default) < 0.2.0~) BuildRequires: (crate(tempfile/default) >= 3.2.0 with crate(tempfile/default) < 4.0.0~) %endif diff --git a/rust2rpm/tests/samples/nix-0.24.1.mageia.spec b/rust2rpm/tests/samples/nix-0.24.1.mageia.spec index f72fe57..f532731 100644 --- a/rust2rpm/tests/samples/nix-0.24.1.mageia.spec +++ b/rust2rpm/tests/samples/nix-0.24.1.mageia.spec @@ -13,8 +13,10 @@ Group: Development/Rust License: MIT URL: https://crates.io/crates/nix-0.24.1 Source: %{crates_source} -# Initial patched metadata +# Automatically generated patch to strip foreign dependencies Patch: nix-0.24.1-patch1.diff +# Maintainer patch to adjust dependencies +Patch: nix-0.24.1-patch2.diff ExclusiveArch: %{rust_arches} @@ -31,7 +33,6 @@ BuildRequires: (crate(lazy_static/default) >= 1.2.0 with crate(lazy_static/defa BuildRequires: (crate(parking_lot/default) >= 0.11.2 with crate(parking_lot/default) < 0.12.0~) BuildRequires: (crate(rand/default) >= 0.8.0 with crate(rand/default) < 0.9.0~) BuildRequires: (crate(semver/default) >= 1.0.0 with crate(semver/default) < 2.0.0~) -BuildRequires: (crate(sysctl/default) >= 0.1.0 with crate(sysctl/default) < 0.2.0~) BuildRequires: (crate(tempfile/default) >= 3.2.0 with crate(tempfile/default) < 4.0.0~) %endif diff --git a/rust2rpm/tests/samples/nix-0.24.1.opensuse.spec b/rust2rpm/tests/samples/nix-0.24.1.opensuse.spec index fbfca43..510fc66 100644 --- a/rust2rpm/tests/samples/nix-0.24.1.opensuse.spec +++ b/rust2rpm/tests/samples/nix-0.24.1.opensuse.spec @@ -30,8 +30,10 @@ Group: Development/Libraries/Rust License: MIT URL: https://crates.io/crates/nix-0.24.1 Source: %{crates_source} -# PATCH-FIX-OPENSUSE nix-0.24.1-patch1.diff -- Initial patched metadata +# Automatically generated patch to strip foreign dependencies Patch: nix-0.24.1-patch1.diff +# PATCH-FIX-OPENSUSE nix-0.24.1-patch2.diff — Maintainer patch to adjust dependencies +Patch: nix-0.24.1-patch2.diff ExclusiveArch: %{rust_arches} @@ -48,7 +50,6 @@ BuildRequires: (crate(lazy_static/default) >= 1.2.0 with crate(lazy_static/defa BuildRequires: (crate(parking_lot/default) >= 0.11.2 with crate(parking_lot/default) < 0.12.0~) BuildRequires: (crate(rand/default) >= 0.8.0 with crate(rand/default) < 0.9.0~) BuildRequires: (crate(semver/default) >= 1.0.0 with crate(semver/default) < 2.0.0~) -BuildRequires: (crate(sysctl/default) >= 0.1.0 with crate(sysctl/default) < 0.2.0~) BuildRequires: (crate(tempfile/default) >= 3.2.0 with crate(tempfile/default) < 4.0.0~) %endif diff --git a/rust2rpm/tests/samples/nix-0.24.1.plain.spec b/rust2rpm/tests/samples/nix-0.24.1.plain.spec index d8950ea..8b8ec01 100644 --- a/rust2rpm/tests/samples/nix-0.24.1.plain.spec +++ b/rust2rpm/tests/samples/nix-0.24.1.plain.spec @@ -12,8 +12,10 @@ Summary: Rust friendly bindings to *nix APIs License: MIT URL: https://crates.io/crates/nix-0.24.1 Source: %{crates_source} -# Initial patched metadata +# Automatically generated patch to strip foreign dependencies Patch: nix-0.24.1-patch1.diff +# Maintainer patch to adjust dependencies +Patch: nix-0.24.1-patch2.diff ExclusiveArch: %{rust_arches} @@ -30,7 +32,6 @@ BuildRequires: (crate(lazy_static/default) >= 1.2.0 with crate(lazy_static/defa BuildRequires: (crate(parking_lot/default) >= 0.11.2 with crate(parking_lot/default) < 0.12.0~) BuildRequires: (crate(rand/default) >= 0.8.0 with crate(rand/default) < 0.9.0~) BuildRequires: (crate(semver/default) >= 1.0.0 with crate(semver/default) < 2.0.0~) -BuildRequires: (crate(sysctl/default) >= 0.1.0 with crate(sysctl/default) < 0.2.0~) BuildRequires: (crate(tempfile/default) >= 3.2.0 with crate(tempfile/default) < 4.0.0~) %endif diff --git a/rust2rpm/tests/samples/tokio-1.19.2.fedora.spec b/rust2rpm/tests/samples/tokio-1.19.2.fedora.spec index 9cb33f6..da5f02e 100644 --- a/rust2rpm/tests/samples/tokio-1.19.2.fedora.spec +++ b/rust2rpm/tests/samples/tokio-1.19.2.fedora.spec @@ -12,8 +12,10 @@ Summary: Event-driven, non-blocking I/O platform for writing asynchronous License: MIT URL: https://crates.io/crates/tokio-1.19.2 Source: %{crates_source} -# Initial patched metadata +# Automatically generated patch to strip foreign dependencies Patch: tokio-1.19.2-patch1.diff +# Maintainer patch to adjust dependencies +Patch: tokio-1.19.2-patch2.diff ExclusiveArch: %{rust_arches} @@ -24,22 +26,15 @@ BuildRequires: (crate(async-stream/default) >= 0.3.0 with crate(async-stream/de BuildRequires: (crate(futures/async-await) >= 0.3.0 with crate(futures/async-await) < 0.4.0~) BuildRequires: (crate(futures/default) >= 0.3.0 with crate(futures/default) < 0.4.0~) BuildRequires: (crate(libc/default) >= 0.2.42 with crate(libc/default) < 0.3.0~) -BuildRequires: (crate(loom/checkpoint) >= 0.5.2 with crate(loom/checkpoint) < 0.6.0~) -BuildRequires: (crate(loom/default) >= 0.5.2 with crate(loom/default) < 0.6.0~) -BuildRequires: (crate(loom/futures) >= 0.5.2 with crate(loom/futures) < 0.6.0~) -BuildRequires: (crate(mio-aio/default) >= 0.6.0 with crate(mio-aio/default) < 0.7.0~) -BuildRequires: (crate(mio-aio/tokio) >= 0.6.0 with crate(mio-aio/tokio) < 0.7.0~) BuildRequires: (crate(mockall/default) >= 0.11.1 with crate(mockall/default) < 0.12.0~) BuildRequires: (crate(nix/fs) >= 0.24.0 with crate(nix/fs) < 0.25.0~) BuildRequires: (crate(nix/socket) >= 0.24.0 with crate(nix/socket) < 0.25.0~) -BuildRequires: (crate(ntapi/default) >= 0.3.6 with crate(ntapi/default) < 0.4.0~) BuildRequires: (crate(proptest/default) >= 1.0.0 with crate(proptest/default) < 2.0.0~) BuildRequires: (crate(rand/default) >= 0.8.0 with crate(rand/default) < 0.9.0~) BuildRequires: (crate(socket2/default) >= 0.4.0 with crate(socket2/default) < 0.5.0~) BuildRequires: (crate(tempfile/default) >= 3.1.0 with crate(tempfile/default) < 4.0.0~) BuildRequires: (crate(tokio-stream/default) >= 0.1.0 with crate(tokio-stream/default) < 0.2.0~) BuildRequires: (crate(tokio-test/default) >= 0.4.0 with crate(tokio-test/default) < 0.5.0~) -BuildRequires: (crate(wasm-bindgen-test/default) >= 0.3.0 with crate(wasm-bindgen-test/default) < 0.4.0~) %endif %global _description %{expand: @@ -376,30 +371,6 @@ use the "tokio-macros" feature of the "%{crate}" crate. %files -n %{name}+tokio-macros-devel %ghost %{crate_instdir}/Cargo.toml -%package -n %{name}+tracing-devel -Summary: %{summary} -BuildArch: noarch - -%description -n %{name}+tracing-devel %{_description} - -This package contains library source intended for building other packages which -use the "tracing" feature of the "%{crate}" crate. - -%files -n %{name}+tracing-devel -%ghost %{crate_instdir}/Cargo.toml - -%package -n %{name}+winapi-devel -Summary: %{summary} -BuildArch: noarch - -%description -n %{name}+winapi-devel %{_description} - -This package contains library source intended for building other packages which -use the "winapi" feature of the "%{crate}" crate. - -%files -n %{name}+winapi-devel -%ghost %{crate_instdir}/Cargo.toml - %prep %autosetup -n %{real_crate}-%{version_no_tilde} -p1 %cargo_prep diff --git a/rust2rpm/tests/samples/tokio-1.19.2.mageia.spec b/rust2rpm/tests/samples/tokio-1.19.2.mageia.spec index 099a229..f214226 100644 --- a/rust2rpm/tests/samples/tokio-1.19.2.mageia.spec +++ b/rust2rpm/tests/samples/tokio-1.19.2.mageia.spec @@ -13,8 +13,10 @@ Group: Development/Rust License: MIT URL: https://crates.io/crates/tokio-1.19.2 Source: %{crates_source} -# Initial patched metadata +# Automatically generated patch to strip foreign dependencies Patch: tokio-1.19.2-patch1.diff +# Maintainer patch to adjust dependencies +Patch: tokio-1.19.2-patch2.diff ExclusiveArch: %{rust_arches} @@ -25,22 +27,15 @@ BuildRequires: (crate(async-stream/default) >= 0.3.0 with crate(async-stream/de BuildRequires: (crate(futures/async-await) >= 0.3.0 with crate(futures/async-await) < 0.4.0~) BuildRequires: (crate(futures/default) >= 0.3.0 with crate(futures/default) < 0.4.0~) BuildRequires: (crate(libc/default) >= 0.2.42 with crate(libc/default) < 0.3.0~) -BuildRequires: (crate(loom/checkpoint) >= 0.5.2 with crate(loom/checkpoint) < 0.6.0~) -BuildRequires: (crate(loom/default) >= 0.5.2 with crate(loom/default) < 0.6.0~) -BuildRequires: (crate(loom/futures) >= 0.5.2 with crate(loom/futures) < 0.6.0~) -BuildRequires: (crate(mio-aio/default) >= 0.6.0 with crate(mio-aio/default) < 0.7.0~) -BuildRequires: (crate(mio-aio/tokio) >= 0.6.0 with crate(mio-aio/tokio) < 0.7.0~) BuildRequires: (crate(mockall/default) >= 0.11.1 with crate(mockall/default) < 0.12.0~) BuildRequires: (crate(nix/fs) >= 0.24.0 with crate(nix/fs) < 0.25.0~) BuildRequires: (crate(nix/socket) >= 0.24.0 with crate(nix/socket) < 0.25.0~) -BuildRequires: (crate(ntapi/default) >= 0.3.6 with crate(ntapi/default) < 0.4.0~) BuildRequires: (crate(proptest/default) >= 1.0.0 with crate(proptest/default) < 2.0.0~) BuildRequires: (crate(rand/default) >= 0.8.0 with crate(rand/default) < 0.9.0~) BuildRequires: (crate(socket2/default) >= 0.4.0 with crate(socket2/default) < 0.5.0~) BuildRequires: (crate(tempfile/default) >= 3.1.0 with crate(tempfile/default) < 4.0.0~) BuildRequires: (crate(tokio-stream/default) >= 0.1.0 with crate(tokio-stream/default) < 0.2.0~) BuildRequires: (crate(tokio-test/default) >= 0.4.0 with crate(tokio-test/default) < 0.5.0~) -BuildRequires: (crate(wasm-bindgen-test/default) >= 0.3.0 with crate(wasm-bindgen-test/default) < 0.4.0~) %endif %global _description %{expand: @@ -404,32 +399,6 @@ use the "tokio-macros" feature of the "%{crate}" crate. %files -n %{name}+tokio-macros-devel %ghost %{crate_instdir}/Cargo.toml -%package -n %{name}+tracing-devel -Summary: %{summary} -Group: Development/Rust -BuildArch: noarch - -%description -n %{name}+tracing-devel %{_description} - -This package contains library source intended for building other packages which -use the "tracing" feature of the "%{crate}" crate. - -%files -n %{name}+tracing-devel -%ghost %{crate_instdir}/Cargo.toml - -%package -n %{name}+winapi-devel -Summary: %{summary} -Group: Development/Rust -BuildArch: noarch - -%description -n %{name}+winapi-devel %{_description} - -This package contains library source intended for building other packages which -use the "winapi" feature of the "%{crate}" crate. - -%files -n %{name}+winapi-devel -%ghost %{crate_instdir}/Cargo.toml - %prep %autosetup -n %{real_crate}-%{version_no_tilde} -p1 %cargo_prep diff --git a/rust2rpm/tests/samples/tokio-1.19.2.opensuse.spec b/rust2rpm/tests/samples/tokio-1.19.2.opensuse.spec index 48678dc..00f059d 100644 --- a/rust2rpm/tests/samples/tokio-1.19.2.opensuse.spec +++ b/rust2rpm/tests/samples/tokio-1.19.2.opensuse.spec @@ -30,8 +30,10 @@ Group: Development/Libraries/Rust License: MIT URL: https://crates.io/crates/tokio-1.19.2 Source: %{crates_source} -# PATCH-FIX-OPENSUSE tokio-1.19.2-patch1.diff -- Initial patched metadata +# Automatically generated patch to strip foreign dependencies Patch: tokio-1.19.2-patch1.diff +# PATCH-FIX-OPENSUSE tokio-1.19.2-patch2.diff — Maintainer patch to adjust dependencies +Patch: tokio-1.19.2-patch2.diff ExclusiveArch: %{rust_arches} @@ -42,22 +44,15 @@ BuildRequires: (crate(async-stream/default) >= 0.3.0 with crate(async-stream/de BuildRequires: (crate(futures/async-await) >= 0.3.0 with crate(futures/async-await) < 0.4.0~) BuildRequires: (crate(futures/default) >= 0.3.0 with crate(futures/default) < 0.4.0~) BuildRequires: (crate(libc/default) >= 0.2.42 with crate(libc/default) < 0.3.0~) -BuildRequires: (crate(loom/checkpoint) >= 0.5.2 with crate(loom/checkpoint) < 0.6.0~) -BuildRequires: (crate(loom/default) >= 0.5.2 with crate(loom/default) < 0.6.0~) -BuildRequires: (crate(loom/futures) >= 0.5.2 with crate(loom/futures) < 0.6.0~) -BuildRequires: (crate(mio-aio/default) >= 0.6.0 with crate(mio-aio/default) < 0.7.0~) -BuildRequires: (crate(mio-aio/tokio) >= 0.6.0 with crate(mio-aio/tokio) < 0.7.0~) BuildRequires: (crate(mockall/default) >= 0.11.1 with crate(mockall/default) < 0.12.0~) BuildRequires: (crate(nix/fs) >= 0.24.0 with crate(nix/fs) < 0.25.0~) BuildRequires: (crate(nix/socket) >= 0.24.0 with crate(nix/socket) < 0.25.0~) -BuildRequires: (crate(ntapi/default) >= 0.3.6 with crate(ntapi/default) < 0.4.0~) BuildRequires: (crate(proptest/default) >= 1.0.0 with crate(proptest/default) < 2.0.0~) BuildRequires: (crate(rand/default) >= 0.8.0 with crate(rand/default) < 0.9.0~) BuildRequires: (crate(socket2/default) >= 0.4.0 with crate(socket2/default) < 0.5.0~) BuildRequires: (crate(tempfile/default) >= 3.1.0 with crate(tempfile/default) < 4.0.0~) BuildRequires: (crate(tokio-stream/default) >= 0.1.0 with crate(tokio-stream/default) < 0.2.0~) BuildRequires: (crate(tokio-test/default) >= 0.4.0 with crate(tokio-test/default) < 0.5.0~) -BuildRequires: (crate(wasm-bindgen-test/default) >= 0.3.0 with crate(wasm-bindgen-test/default) < 0.4.0~) %endif %global _description %{expand: @@ -421,32 +416,6 @@ use the "tokio-macros" feature of the "%{crate}" crate. %files -n %{name}+tokio-macros-devel %ghost %{crate_instdir}/Cargo.toml -%package -n %{name}+tracing-devel -Summary: %{summary} -Group: Development/Libraries/Rust -BuildArch: noarch - -%description -n %{name}+tracing-devel %{_description} - -This package contains library source intended for building other packages which -use the "tracing" feature of the "%{crate}" crate. - -%files -n %{name}+tracing-devel -%ghost %{crate_instdir}/Cargo.toml - -%package -n %{name}+winapi-devel -Summary: %{summary} -Group: Development/Libraries/Rust -BuildArch: noarch - -%description -n %{name}+winapi-devel %{_description} - -This package contains library source intended for building other packages which -use the "winapi" feature of the "%{crate}" crate. - -%files -n %{name}+winapi-devel -%ghost %{crate_instdir}/Cargo.toml - %prep %autosetup -n %{real_crate}-%{version_no_tilde} -p1 %cargo_prep diff --git a/rust2rpm/tests/samples/tokio-1.19.2.plain.spec b/rust2rpm/tests/samples/tokio-1.19.2.plain.spec index 8e3141c..f891e8a 100644 --- a/rust2rpm/tests/samples/tokio-1.19.2.plain.spec +++ b/rust2rpm/tests/samples/tokio-1.19.2.plain.spec @@ -12,8 +12,10 @@ Summary: Event-driven, non-blocking I/O platform for writing asynchronous License: MIT URL: https://crates.io/crates/tokio-1.19.2 Source: %{crates_source} -# Initial patched metadata +# Automatically generated patch to strip foreign dependencies Patch: tokio-1.19.2-patch1.diff +# Maintainer patch to adjust dependencies +Patch: tokio-1.19.2-patch2.diff ExclusiveArch: %{rust_arches} @@ -24,22 +26,15 @@ BuildRequires: (crate(async-stream/default) >= 0.3.0 with crate(async-stream/de BuildRequires: (crate(futures/async-await) >= 0.3.0 with crate(futures/async-await) < 0.4.0~) BuildRequires: (crate(futures/default) >= 0.3.0 with crate(futures/default) < 0.4.0~) BuildRequires: (crate(libc/default) >= 0.2.42 with crate(libc/default) < 0.3.0~) -BuildRequires: (crate(loom/checkpoint) >= 0.5.2 with crate(loom/checkpoint) < 0.6.0~) -BuildRequires: (crate(loom/default) >= 0.5.2 with crate(loom/default) < 0.6.0~) -BuildRequires: (crate(loom/futures) >= 0.5.2 with crate(loom/futures) < 0.6.0~) -BuildRequires: (crate(mio-aio/default) >= 0.6.0 with crate(mio-aio/default) < 0.7.0~) -BuildRequires: (crate(mio-aio/tokio) >= 0.6.0 with crate(mio-aio/tokio) < 0.7.0~) BuildRequires: (crate(mockall/default) >= 0.11.1 with crate(mockall/default) < 0.12.0~) BuildRequires: (crate(nix/fs) >= 0.24.0 with crate(nix/fs) < 0.25.0~) BuildRequires: (crate(nix/socket) >= 0.24.0 with crate(nix/socket) < 0.25.0~) -BuildRequires: (crate(ntapi/default) >= 0.3.6 with crate(ntapi/default) < 0.4.0~) BuildRequires: (crate(proptest/default) >= 1.0.0 with crate(proptest/default) < 2.0.0~) BuildRequires: (crate(rand/default) >= 0.8.0 with crate(rand/default) < 0.9.0~) BuildRequires: (crate(socket2/default) >= 0.4.0 with crate(socket2/default) < 0.5.0~) BuildRequires: (crate(tempfile/default) >= 3.1.0 with crate(tempfile/default) < 4.0.0~) BuildRequires: (crate(tokio-stream/default) >= 0.1.0 with crate(tokio-stream/default) < 0.2.0~) BuildRequires: (crate(tokio-test/default) >= 0.4.0 with crate(tokio-test/default) < 0.5.0~) -BuildRequires: (crate(wasm-bindgen-test/default) >= 0.3.0 with crate(wasm-bindgen-test/default) < 0.4.0~) %endif %global _description %{expand: @@ -256,7 +251,6 @@ Requires: cargo Requires: (crate(mio/net) >= 0.8.1 with crate(mio/net) < 0.9.0~) Requires: (crate(mio/os-ext) >= 0.8.1 with crate(mio/os-ext) < 0.9.0~) Requires: (crate(mio/os-poll) >= 0.8.1 with crate(mio/os-poll) < 0.9.0~) -Requires: (crate(winapi/namedpipeapi) >= 0.3.8 with crate(winapi/namedpipeapi) < 0.4.0~) Requires: crate(tokio) = 1.19.2 Requires: crate(tokio/libc) = 1.19.2 Requires: crate(tokio/socket2) = 1.19.2 @@ -325,7 +319,6 @@ Requires: cargo Requires: (crate(mio/net) >= 0.8.1 with crate(mio/net) < 0.9.0~) Requires: (crate(mio/os-ext) >= 0.8.1 with crate(mio/os-ext) < 0.9.0~) Requires: (crate(mio/os-poll) >= 0.8.1 with crate(mio/os-poll) < 0.9.0~) -Requires: (crate(winapi/threadpoollegacyapiset) >= 0.3.8 with crate(winapi/threadpoollegacyapiset) < 0.4.0~) Requires: crate(tokio) = 1.19.2 Requires: crate(tokio/bytes) = 1.19.2 Requires: crate(tokio/libc) = 1.19.2 @@ -381,7 +374,6 @@ Requires: cargo Requires: (crate(mio/net) >= 0.8.1 with crate(mio/net) < 0.9.0~) Requires: (crate(mio/os-ext) >= 0.8.1 with crate(mio/os-ext) < 0.9.0~) Requires: (crate(mio/os-poll) >= 0.8.1 with crate(mio/os-poll) < 0.9.0~) -Requires: (crate(winapi/consoleapi) >= 0.3.8 with crate(winapi/consoleapi) < 0.4.0~) Requires: crate(tokio) = 1.19.2 Requires: crate(tokio/libc) = 1.19.2 Requires: crate(tokio/once_cell) = 1.19.2 @@ -507,43 +499,6 @@ use the "tokio-macros" feature of the "%{crate}" crate. %files -n %{name}+tokio-macros-devel %ghost %{crate_instdir}/Cargo.toml -%package -n %{name}+tracing-devel -Summary: %{summary} -BuildArch: noarch -Provides: crate(tokio/tracing) = 1.19.2 -Requires: cargo -Requires: (crate(tracing/std) >= 0.1.25 with crate(tracing/std) < 0.2.0~) -Requires: crate(tokio) = 1.19.2 - -%description -n %{name}+tracing-devel %{_description} - -This package contains library source intended for building other packages which -use the "tracing" feature of the "%{crate}" crate. - -%files -n %{name}+tracing-devel -%ghost %{crate_instdir}/Cargo.toml - -%package -n %{name}+winapi-devel -Summary: %{summary} -BuildArch: noarch -Provides: crate(tokio/winapi) = 1.19.2 -Requires: cargo -Requires: (crate(winapi/handleapi) >= 0.3.8 with crate(winapi/handleapi) < 0.4.0~) -Requires: (crate(winapi/mswsock) >= 0.3.8 with crate(winapi/mswsock) < 0.4.0~) -Requires: (crate(winapi/std) >= 0.3.8 with crate(winapi/std) < 0.4.0~) -Requires: (crate(winapi/winsock2) >= 0.3.8 with crate(winapi/winsock2) < 0.4.0~) -Requires: (crate(winapi/ws2ipdef) >= 0.3.8 with crate(winapi/ws2ipdef) < 0.4.0~) -Requires: (crate(winapi/ws2tcpip) >= 0.3.8 with crate(winapi/ws2tcpip) < 0.4.0~) -Requires: crate(tokio) = 1.19.2 - -%description -n %{name}+winapi-devel %{_description} - -This package contains library source intended for building other packages which -use the "winapi" feature of the "%{crate}" crate. - -%files -n %{name}+winapi-devel -%ghost %{crate_instdir}/Cargo.toml - %prep %autosetup -n %{real_crate}-%{version_no_tilde} -p1 %cargo_prep diff --git a/rust2rpm/tests/test_generator.py b/rust2rpm/tests/test_generator.py index 1d2d21b..68cb28c 100644 --- a/rust2rpm/tests/test_generator.py +++ b/rust2rpm/tests/test_generator.py @@ -10,7 +10,8 @@ from rust2rpm.generator import to_list, spec_file_render from rust2rpm.__main__ import ( Metadata, get_parser, - package_name_suffixed) + package_name_suffixed, + drop_foreign_dependencies) def test_to_list(): @@ -47,9 +48,10 @@ def mock_spec_file_render(crate, tomlfile, target, tmpdir): pkg_name = package_name_suffixed(crate, args.suffix) toml_before = open(tomlfile).readlines() + toml_after = drop_foreign_dependencies(toml_before) or toml_before fake_toml = tmpdir / 'Cargo.toml' - fake_toml.write_text('\n'.join(toml_before)) + fake_toml.write_text('\n'.join(toml_after)) metadata, = Metadata.from_file(fake_toml) @@ -58,7 +60,8 @@ def mock_spec_file_render(crate, tomlfile, target, tmpdir): pkg_name = pkg_name, crate = crate, metadata = metadata, - patch_file = f'{crate}-patch1.diff', + patch_file_automatic = f'{crate}-patch1.diff', + patch_file_manual = f'{crate}-patch2.diff', packager_identity = 'Jane Jane ', doc_files = ['DOC1', 'DOC2'], license_files = ['LIC1', 'LIC2'],