diff --git a/rust2rpm/__main__.py b/rust2rpm/__main__.py index 9d41114..49a704a 100644 --- a/rust2rpm/__main__.py +++ b/rust2rpm/__main__.py @@ -11,7 +11,7 @@ from rust2rpm.conf import load_config from rust2rpm.crate import process_project from rust2rpm.cratesio import NoVersionsError from rust2rpm.distgit import get_package_info -from rust2rpm.generator import spec_render_crate, spec_render_workspace +from rust2rpm.generator import spec_render_crate, spec_render_project, spec_render_workspace from rust2rpm.licensing import dump_sdpx_to_fedora_map, translate_license from rust2rpm.metadata import guess_main_package, warn_if_package_uses_restrictive_dependencies from rust2rpm.utils import ( @@ -47,7 +47,7 @@ def main(): parser.error("crate/path argument missing and autodetection failed") try: - project, version, diffs, metadata, doc_files, license_files = process_project( + project, version, diffs, metadata, doc_files, license_files, is_local = process_project( args.crate, args.version, args.patch, args.patch_foreign, args.store_crate ) except NoVersionsError: @@ -57,6 +57,11 @@ def main(): if metadata.is_workspace(): base_name = project rpm_name = project + + elif is_local: + base_name = metadata.packages[0].name + rpm_name = base_name + else: base_name = metadata.packages[0].name @@ -99,7 +104,8 @@ def main(): else: tomlconf = load_config(set(), args.target) - if not metadata.is_workspace(): + # package for an actual Rust crate + if not metadata.is_workspace() and not is_local: package = metadata.packages[0] if build_meta := Version.parse(package.version).build: @@ -126,6 +132,34 @@ def main(): packager=packager, ) + # package for non-crate, non-workspace project + elif not metadata.is_workspace() and is_local: + package = metadata.packages[0] + + if build_meta := Version.parse(package.version).build: + log.error(f"Crate version {package.version!r} contains build metadata: '+{build_meta}'") + log.error(f"This is not supported by rust2rpm; remove the '+{build_meta}' suffix.") + sys.exit(1) + + warn_if_package_uses_restrictive_dependencies(package) + + spec_contents = spec_render_project( + metadata=metadata, + upstream_version=version, + target=args.target, + rpm_name=rpm_name, + patch_file_automatic=patch_files[0], + patch_file_manual=patch_files[1], + license_files=license_files, + doc_files=doc_files, + tomlconf=tomlconf, + feature_flags=FeatureFlags(all_features=args.all_features), + rpmautospec=args.rpmautospec, + auto_changelog_entry=args.auto_changelog_entry, + packager=packager, + ) + + # package for a workspace project else: try: main_package = guess_main_package(metadata, hint=project, interactive=args.interactive) diff --git a/rust2rpm/crate.py b/rust2rpm/crate.py index 1c384a8..44ec7b1 100644 --- a/rust2rpm/crate.py +++ b/rust2rpm/crate.py @@ -191,8 +191,8 @@ def process_project_local( with toml_temp_copy(toml_path) as temp_toml: diffs = make_patches(name, package.version, patch, patch_foreign, temp_toml, features) - # ensure metadata is up-to-date with changes from patches - metadata = Metadata.from_cargo(toml_path) + # ensure metadata is up-to-date with changes from patches + metadata = Metadata.from_cargo(temp_toml) return name, version, diffs, metadata, doc_files, license_files @@ -233,14 +233,14 @@ def process_project( patch: bool, patch_foreign: bool, store_crate: bool, -) -> tuple[str, str, tuple[Optional[list[str]], Optional[list[str]]], Metadata, list[str], list[str]]: +) -> tuple[str, str, tuple[Optional[list[str]], Optional[list[str]]], Metadata, list[str], list[str], bool]: if project_is_path(project) and not project.endswith(".crate"): # project points into unpacked sources: if store_crate: raise ValueError("The '--store-crate' / '-s' flag cannot be used for unpacked sources.") # process unpacked sources - return process_project_local(project, patch, patch_foreign) + return (*process_project_local(project, patch, patch_foreign), True) if project_is_path(project) and project.endswith(".crate"): # project points at a local .crate file @@ -287,4 +287,4 @@ def process_project( # ensure metadata is up-to-date with changes from patches metadata = Metadata.from_cargo(toml_path) - return name, version, diffs, metadata, doc_files, license_files + return name, version, diffs, metadata, doc_files, license_files, False diff --git a/rust2rpm/generator.py b/rust2rpm/generator.py index ebaa781..b2b6848 100644 --- a/rust2rpm/generator.py +++ b/rust2rpm/generator.py @@ -385,7 +385,7 @@ def spec_render_project( "rpm_version": Version.parse(package.version).to_rpm(), "rpm_summary": tomlconf.package_summary or summary, "rpm_description": tomlconf.package_description or description, - "rpm_url": package.homepage or package.repository or "# FIXME", + "rpm_url": package.repository or package.homepage or "# FIXME", "rpm_license": rpm_license, "rpm_license_comments": rpm_license_comments, "rpm_patch_file_automatic": patch_file_automatic, @@ -440,7 +440,6 @@ def spec_render_project( def spec_render_workspace( *, metadata: Metadata, - upstream_version: str, main_package: Package, target: str, rpm_name: str, @@ -461,7 +460,9 @@ def spec_render_workspace( is_cdylib = metadata.is_cdylib() - rpm_version = Version.parse(main_package.version).to_rpm() + upstream_version = main_package.version + rpm_version = Version.parse(upstream_version).to_rpm() + rpm_description = main_package.get_description() rpm_summary = main_package.get_summary() diff --git a/rust2rpm/tests/samples/stgit-2.3.3.fedora.spec b/rust2rpm/tests/samples/stgit-2.3.3.fedora.spec new file mode 100644 index 0000000..06a06d9 --- /dev/null +++ b/rust2rpm/tests/samples/stgit-2.3.3.fedora.spec @@ -0,0 +1,62 @@ +# Generated by rust2rpm NNN +%bcond_without check + +# prevent library files from being installed +%global __cargo_is_lib() 0 + +%global crate stgit + +Name: stgit +Version: 2.3.3 +Release: %autorelease +Summary: Stack-based patch management for Git + +SourceLicense: GPL-2.0-only +# FIXME: paste output of %%cargo_license_summary here +License: # FIXME +# LICENSE.dependencies contains a full license breakdown + +URL: https://github.com/stacked-git/stgit +Source: # FIXME +# Automatically generated patch to strip dependencies and normalize metadata +Patch: stgit-patch1.diff +# Manually created patch for downstream crate metadata changes +Patch: stgit-patch2.diff + +BuildRequires: cargo-rpm-macros >= 24 + +%global _description %{expand: +Stack-based patch management for Git.} + +%description %{_description} + +%prep +%autosetup -n %{crate}-%{version} -p1 +%cargo_prep + +%generate_buildrequires +%cargo_generate_buildrequires + +%build +%cargo_build +%{cargo_license_summary} +%{cargo_license} > LICENSE.dependencies + +%install +%cargo_install + +%if %{with check} +%check +%cargo_test +%endif + +%files +%license LIC1 +%license LIC2 +%license LICENSE.dependencies +%doc DOC1 +%doc DOC2 +%{_bindir}/stg + +%changelog +%autochangelog diff --git a/rust2rpm/tests/samples/stgit-2.3.3.json b/rust2rpm/tests/samples/stgit-2.3.3.json new file mode 100644 index 0000000..aa8a218 --- /dev/null +++ b/rust2rpm/tests/samples/stgit-2.3.3.json @@ -0,0 +1 @@ +{"packages":[{"name":"stgit","version":"2.3.3","id":"stgit 2.3.3 (path+file:///home/deca/Downloads/stgit-2.3.3)","license":"GPL-2.0-only","license_file":null,"description":"Stack-based patch management for Git","source":null,"dependencies":[{"name":"anstyle","source":"registry+https://github.com/rust-lang/crates.io-index","req":"^1.0","kind":null,"rename":null,"optional":false,"uses_default_features":true,"features":["std"],"target":null,"registry":null},{"name":"anyhow","source":"registry+https://github.com/rust-lang/crates.io-index","req":"^1.0","kind":null,"rename":null,"optional":false,"uses_default_features":true,"features":[],"target":null,"registry":null},{"name":"bstr","source":"registry+https://github.com/rust-lang/crates.io-index","req":"^1.6","kind":null,"rename":null,"optional":false,"uses_default_features":false,"features":["std"],"target":null,"registry":null},{"name":"bzip2-rs","source":"registry+https://github.com/rust-lang/crates.io-index","req":"^0.1","kind":null,"rename":null,"optional":false,"uses_default_features":true,"features":[],"target":null,"registry":null},{"name":"clap","source":"registry+https://github.com/rust-lang/crates.io-index","req":"~4.4","kind":null,"rename":null,"optional":false,"uses_default_features":false,"features":["color","help","std","string","suggestions","usage","wrap_help"],"target":null,"registry":null},{"name":"ctrlc","source":"registry+https://github.com/rust-lang/crates.io-index","req":"^3.4","kind":null,"rename":null,"optional":false,"uses_default_features":true,"features":[],"target":null,"registry":null},{"name":"curl","source":"registry+https://github.com/rust-lang/crates.io-index","req":"^0.4","kind":null,"rename":null,"optional":true,"uses_default_features":true,"features":[],"target":null,"registry":null},{"name":"encoding_rs","source":"registry+https://github.com/rust-lang/crates.io-index","req":"^0.8","kind":null,"rename":null,"optional":false,"uses_default_features":true,"features":[],"target":null,"registry":null},{"name":"flate2","source":"registry+https://github.com/rust-lang/crates.io-index","req":"^1","kind":null,"rename":null,"optional":false,"uses_default_features":true,"features":[],"target":null,"registry":null},{"name":"gix","source":"registry+https://github.com/rust-lang/crates.io-index","req":"^0.54","kind":null,"rename":null,"optional":false,"uses_default_features":false,"features":["revision"],"target":null,"registry":null},{"name":"indexmap","source":"registry+https://github.com/rust-lang/crates.io-index","req":"^2.0","kind":null,"rename":null,"optional":false,"uses_default_features":true,"features":[],"target":null,"registry":null},{"name":"is-terminal","source":"registry+https://github.com/rust-lang/crates.io-index","req":"^0.4","kind":null,"rename":null,"optional":false,"uses_default_features":true,"features":[],"target":null,"registry":null},{"name":"nom","source":"registry+https://github.com/rust-lang/crates.io-index","req":"^7","kind":null,"rename":null,"optional":false,"uses_default_features":false,"features":["std"],"target":null,"registry":null},{"name":"serde","source":"registry+https://github.com/rust-lang/crates.io-index","req":"^1.0","kind":null,"rename":null,"optional":false,"uses_default_features":true,"features":["derive"],"target":null,"registry":null},{"name":"serde_json","source":"registry+https://github.com/rust-lang/crates.io-index","req":"^1.0","kind":null,"rename":null,"optional":false,"uses_default_features":true,"features":[],"target":null,"registry":null},{"name":"strsim","source":"registry+https://github.com/rust-lang/crates.io-index","req":"^0.10","kind":null,"rename":null,"optional":false,"uses_default_features":true,"features":[],"target":null,"registry":null},{"name":"tar","source":"registry+https://github.com/rust-lang/crates.io-index","req":"^0.4","kind":null,"rename":null,"optional":false,"uses_default_features":true,"features":[],"target":null,"registry":null},{"name":"tempfile","source":"registry+https://github.com/rust-lang/crates.io-index","req":"^3","kind":null,"rename":null,"optional":false,"uses_default_features":true,"features":[],"target":null,"registry":null},{"name":"termcolor","source":"registry+https://github.com/rust-lang/crates.io-index","req":"^1.1","kind":null,"rename":null,"optional":false,"uses_default_features":true,"features":[],"target":null,"registry":null},{"name":"thiserror","source":"registry+https://github.com/rust-lang/crates.io-index","req":"~1.0","kind":null,"rename":null,"optional":false,"uses_default_features":true,"features":[],"target":null,"registry":null},{"name":"time","source":"registry+https://github.com/rust-lang/crates.io-index","req":"^0.3.23","kind":null,"rename":null,"optional":false,"uses_default_features":false,"features":["local-offset","formatting","macros","parsing"],"target":null,"registry":null}],"targets":[{"kind":["bin"],"crate_types":["bin"],"name":"stg","src_path":"/home/deca/Downloads/stgit-2.3.3/src/main.rs","edition":"2021","doc":true,"doctest":false,"test":true},{"kind":["custom-build"],"crate_types":["bin"],"name":"build-script-build","src_path":"/home/deca/Downloads/stgit-2.3.3/build.rs","edition":"2021","doc":false,"doctest":false,"test":false}],"features":{"default":["import-url"],"import-url":["dep:curl"]},"manifest_path":"/home/deca/Downloads/stgit-2.3.3/Cargo.toml","metadata":{"deb":{"assets":[["target/release/stg","usr/bin/","755"],["README.md","usr/share/doc/stgit/","644"],["COPYING","usr/share/doc/stgit/copyright","644"],["Documentation/*.1","usr/share/man/man1/","644"],["completion/stgit.zsh","usr/share/zsh/vendor-completions/_stg","644"],["completion/stg.fish","usr/share/fish/vendor-completions.d/","644"],["completion/stgit.bash","usr/share/bash-completion/completions/stg","644"],["contrib/vim/ftdetect/stg.vim","usr/share/vim/addons/ftdetect/","644"],["contrib/vim/syntax/*.vim","usr/share/vim/addons/syntax/","644"]],"depends":"git","extended-description":"","maintainer":"Peter Grayson ","priority":"optional","recommends":"git-email","section":"vcs"},"generate-rpm":{"assets":[{"dest":"/usr/bin/","mode":"755","source":"target/release/stg"},{"dest":"/usr/share/doc/stgit/","mode":"644","source":"README.md"},{"dest":"/usr/share/licenses/stgit/","mode":"644","source":"COPYING"},{"dest":"/usr/share/man/man1/","doc":true,"mode":"644","source":"Documentation/*.1"},{"dest":"/usr/share/zsh/site-functions/_stg","mode":"644","source":"completion/stgit.zsh"},{"dest":"/usr/share/fish/vendor_completions.d/","mode":"644","source":"completion/stg.fish"},{"dest":"/usr/share/bash-completion/completions/stg","mode":"644","source":"completion/stgit.bash"},{"dest":"/usr/share/vim/vimfiles/ftdetect/","mode":"644","source":"contrib/vim/ftdetect/stg.vim"},{"dest":"/usr/share/vim/vimfiles/syntax/","mode":"644","source":"contrib/vim/syntax/*.vim"}],"requires":{"git-core":"*","git-email":"*","vim-filesystem":"*"}}},"publish":null,"authors":["Catalin Marinas ","Peter Grayson "],"categories":[],"keywords":[],"readme":"README.md","repository":"https://github.com/stacked-git/stgit","homepage":"https://stacked-git.github.io/","documentation":null,"edition":"2021","links":null,"default_run":null,"rust_version":"1.67.1"}],"workspace_members":["stgit 2.3.3 (path+file:///home/deca/Downloads/stgit-2.3.3)"],"workspace_default_members":["stgit 2.3.3 (path+file:///home/deca/Downloads/stgit-2.3.3)"],"resolve":null,"target_directory":"/home/deca/Downloads/stgit-2.3.3/target","version":1,"workspace_root":"/home/deca/Downloads/stgit-2.3.3","metadata":null} diff --git a/rust2rpm/tests/samples/stgit-2.3.3.mageia.spec b/rust2rpm/tests/samples/stgit-2.3.3.mageia.spec new file mode 100644 index 0000000..fc1f2b8 --- /dev/null +++ b/rust2rpm/tests/samples/stgit-2.3.3.mageia.spec @@ -0,0 +1,102 @@ +# Generated by rust2rpm NNN +%bcond_without check + +# prevent library files from being installed +%global __cargo_is_lib() 0 + +%global crate stgit + +Name: stgit +Version: 2.3.3 +Release: %mkrel 1 +Summary: Stack-based patch management for Git +Group: Development/Rust + +# Upstream license specification: GPL-2.0-only +SourceLicense: GPLv2 +# FIXME: paste output of %%cargo_license_summary here +License: # FIXME +# LICENSE.dependencies contains a full license breakdown + +URL: https://github.com/stacked-git/stgit +Source: # FIXME +# Automatically generated patch to strip dependencies and normalize metadata +Patch: stgit-patch1.diff +# Manually created patch for downstream crate metadata changes +Patch: stgit-patch2.diff + +ExclusiveArch: %{rust_arches} + +BuildRequires: cargo-rpm-macros >= 24 +BuildRequires: (crate(anstyle/default) >= 1.0.0 with crate(anstyle/default) < 2.0.0~) +BuildRequires: (crate(anstyle/std) >= 1.0.0 with crate(anstyle/std) < 2.0.0~) +BuildRequires: (crate(anyhow/default) >= 1.0.0 with crate(anyhow/default) < 2.0.0~) +BuildRequires: (crate(bstr) >= 1.6.0 with crate(bstr) < 2.0.0~) +BuildRequires: (crate(bstr/std) >= 1.6.0 with crate(bstr/std) < 2.0.0~) +BuildRequires: (crate(bzip2-rs/default) >= 0.1.0 with crate(bzip2-rs/default) < 0.2.0~) +BuildRequires: (crate(clap) >= 4.4.0 with crate(clap) < 4.5.0~) +BuildRequires: (crate(clap/color) >= 4.4.0 with crate(clap/color) < 4.5.0~) +BuildRequires: (crate(clap/help) >= 4.4.0 with crate(clap/help) < 4.5.0~) +BuildRequires: (crate(clap/std) >= 4.4.0 with crate(clap/std) < 4.5.0~) +BuildRequires: (crate(clap/string) >= 4.4.0 with crate(clap/string) < 4.5.0~) +BuildRequires: (crate(clap/suggestions) >= 4.4.0 with crate(clap/suggestions) < 4.5.0~) +BuildRequires: (crate(clap/usage) >= 4.4.0 with crate(clap/usage) < 4.5.0~) +BuildRequires: (crate(clap/wrap_help) >= 4.4.0 with crate(clap/wrap_help) < 4.5.0~) +BuildRequires: (crate(ctrlc/default) >= 3.4.0 with crate(ctrlc/default) < 4.0.0~) +BuildRequires: (crate(curl/default) >= 0.4.0 with crate(curl/default) < 0.5.0~) +BuildRequires: (crate(encoding_rs/default) >= 0.8.0 with crate(encoding_rs/default) < 0.9.0~) +BuildRequires: (crate(flate2/default) >= 1.0.0 with crate(flate2/default) < 2.0.0~) +BuildRequires: (crate(gix) >= 0.54.0 with crate(gix) < 0.55.0~) +BuildRequires: (crate(gix/revision) >= 0.54.0 with crate(gix/revision) < 0.55.0~) +BuildRequires: (crate(indexmap/default) >= 2.0.0 with crate(indexmap/default) < 3.0.0~) +BuildRequires: (crate(is-terminal/default) >= 0.4.0 with crate(is-terminal/default) < 0.5.0~) +BuildRequires: (crate(nom) >= 7.0.0 with crate(nom) < 8.0.0~) +BuildRequires: (crate(nom/std) >= 7.0.0 with crate(nom/std) < 8.0.0~) +BuildRequires: (crate(serde/default) >= 1.0.0 with crate(serde/default) < 2.0.0~) +BuildRequires: (crate(serde/derive) >= 1.0.0 with crate(serde/derive) < 2.0.0~) +BuildRequires: (crate(serde_json/default) >= 1.0.0 with crate(serde_json/default) < 2.0.0~) +BuildRequires: (crate(strsim/default) >= 0.10.0 with crate(strsim/default) < 0.11.0~) +BuildRequires: (crate(tar/default) >= 0.4.0 with crate(tar/default) < 0.5.0~) +BuildRequires: (crate(tempfile/default) >= 3.0.0 with crate(tempfile/default) < 4.0.0~) +BuildRequires: (crate(termcolor/default) >= 1.1.0 with crate(termcolor/default) < 2.0.0~) +BuildRequires: (crate(thiserror/default) >= 1.0.0 with crate(thiserror/default) < 1.1.0~) +BuildRequires: (crate(time) >= 0.3.23 with crate(time) < 0.4.0~) +BuildRequires: (crate(time/formatting) >= 0.3.23 with crate(time/formatting) < 0.4.0~) +BuildRequires: (crate(time/local-offset) >= 0.3.23 with crate(time/local-offset) < 0.4.0~) +BuildRequires: (crate(time/macros) >= 0.3.23 with crate(time/macros) < 0.4.0~) +BuildRequires: (crate(time/parsing) >= 0.3.23 with crate(time/parsing) < 0.4.0~) +BuildRequires: rust >= 1.67.1 + +%global _description %{expand: +Stack-based patch management for Git.} + +%description %{_description} + +%prep +%autosetup -n %{crate}-%{version} -p1 +%cargo_prep + +%build +%cargo_build +%{cargo_license_summary} +%{cargo_license} > LICENSE.dependencies + +%install +%cargo_install + +%if %{with check} +%check +%cargo_test +%endif + +%files +%license LIC1 +%license LIC2 +%license LICENSE.dependencies +%doc DOC1 +%doc DOC2 +%{_bindir}/stg + +%changelog +* Thu Jan 01 1970 Jane Jane - 2.3.3-1 +- Initial package diff --git a/rust2rpm/tests/samples/stgit-2.3.3.opensuse.spec b/rust2rpm/tests/samples/stgit-2.3.3.opensuse.spec new file mode 100644 index 0000000..b951dcc --- /dev/null +++ b/rust2rpm/tests/samples/stgit-2.3.3.opensuse.spec @@ -0,0 +1,119 @@ +# +# spec file for package stgit +# +# Copyright (c) XXXX Jane Jane . +# +# All modifications and additions to the file contributed by third parties +# remain the property of their copyright owners, unless otherwise agreed +# upon. The license for this file, and modifications and additions to the +# file, is the same license as for the pristine package itself (unless the +# license for the pristine package is not an Open Source License, in which +# case the license is the MIT License). An "Open Source License" is a +# license that conforms to the Open Source Definition (Version 1.9) +# published by the Open Source Initiative. + +# Please submit bugfixes or comments via https://bugs.opensuse.org/ +# + +# Generated by rust2rpm NNN +%bcond_without check + +# prevent library files from being installed +%global __cargo_is_lib() 0 + +%global crate stgit + +Name: stgit +Version: 2.3.3 +Release: 0 +Summary: Stack-based patch management for Git +Group: Development/Libraries/Rust + +SourceLicense: GPL-2.0-only +# FIXME: paste output of %%cargo_license_summary here +License: # FIXME +# LICENSE.dependencies contains a full license breakdown + +URL: https://github.com/stacked-git/stgit +Source: # FIXME +# Automatically generated patch to strip dependencies and normalize metadata +Patch: stgit-patch1.diff +# PATCH-FIX-OPENSUSE stgit-patch2.diff — Manually created patch for downstream crate metadata changes +Patch: stgit-patch2.diff + +ExclusiveArch: %{rust_arches} + +BuildRequires: cargo-rpm-macros >= 24 +BuildRequires: (crate(anstyle/default) >= 1.0.0 with crate(anstyle/default) < 2.0.0~) +BuildRequires: (crate(anstyle/std) >= 1.0.0 with crate(anstyle/std) < 2.0.0~) +BuildRequires: (crate(anyhow/default) >= 1.0.0 with crate(anyhow/default) < 2.0.0~) +BuildRequires: (crate(bstr) >= 1.6.0 with crate(bstr) < 2.0.0~) +BuildRequires: (crate(bstr/std) >= 1.6.0 with crate(bstr/std) < 2.0.0~) +BuildRequires: (crate(bzip2-rs/default) >= 0.1.0 with crate(bzip2-rs/default) < 0.2.0~) +BuildRequires: (crate(clap) >= 4.4.0 with crate(clap) < 4.5.0~) +BuildRequires: (crate(clap/color) >= 4.4.0 with crate(clap/color) < 4.5.0~) +BuildRequires: (crate(clap/help) >= 4.4.0 with crate(clap/help) < 4.5.0~) +BuildRequires: (crate(clap/std) >= 4.4.0 with crate(clap/std) < 4.5.0~) +BuildRequires: (crate(clap/string) >= 4.4.0 with crate(clap/string) < 4.5.0~) +BuildRequires: (crate(clap/suggestions) >= 4.4.0 with crate(clap/suggestions) < 4.5.0~) +BuildRequires: (crate(clap/usage) >= 4.4.0 with crate(clap/usage) < 4.5.0~) +BuildRequires: (crate(clap/wrap_help) >= 4.4.0 with crate(clap/wrap_help) < 4.5.0~) +BuildRequires: (crate(ctrlc/default) >= 3.4.0 with crate(ctrlc/default) < 4.0.0~) +BuildRequires: (crate(curl/default) >= 0.4.0 with crate(curl/default) < 0.5.0~) +BuildRequires: (crate(encoding_rs/default) >= 0.8.0 with crate(encoding_rs/default) < 0.9.0~) +BuildRequires: (crate(flate2/default) >= 1.0.0 with crate(flate2/default) < 2.0.0~) +BuildRequires: (crate(gix) >= 0.54.0 with crate(gix) < 0.55.0~) +BuildRequires: (crate(gix/revision) >= 0.54.0 with crate(gix/revision) < 0.55.0~) +BuildRequires: (crate(indexmap/default) >= 2.0.0 with crate(indexmap/default) < 3.0.0~) +BuildRequires: (crate(is-terminal/default) >= 0.4.0 with crate(is-terminal/default) < 0.5.0~) +BuildRequires: (crate(nom) >= 7.0.0 with crate(nom) < 8.0.0~) +BuildRequires: (crate(nom/std) >= 7.0.0 with crate(nom/std) < 8.0.0~) +BuildRequires: (crate(serde/default) >= 1.0.0 with crate(serde/default) < 2.0.0~) +BuildRequires: (crate(serde/derive) >= 1.0.0 with crate(serde/derive) < 2.0.0~) +BuildRequires: (crate(serde_json/default) >= 1.0.0 with crate(serde_json/default) < 2.0.0~) +BuildRequires: (crate(strsim/default) >= 0.10.0 with crate(strsim/default) < 0.11.0~) +BuildRequires: (crate(tar/default) >= 0.4.0 with crate(tar/default) < 0.5.0~) +BuildRequires: (crate(tempfile/default) >= 3.0.0 with crate(tempfile/default) < 4.0.0~) +BuildRequires: (crate(termcolor/default) >= 1.1.0 with crate(termcolor/default) < 2.0.0~) +BuildRequires: (crate(thiserror/default) >= 1.0.0 with crate(thiserror/default) < 1.1.0~) +BuildRequires: (crate(time) >= 0.3.23 with crate(time) < 0.4.0~) +BuildRequires: (crate(time/formatting) >= 0.3.23 with crate(time/formatting) < 0.4.0~) +BuildRequires: (crate(time/local-offset) >= 0.3.23 with crate(time/local-offset) < 0.4.0~) +BuildRequires: (crate(time/macros) >= 0.3.23 with crate(time/macros) < 0.4.0~) +BuildRequires: (crate(time/parsing) >= 0.3.23 with crate(time/parsing) < 0.4.0~) +BuildRequires: rust >= 1.67.1 + +%global _description %{expand: +Stack-based patch management for Git.} + +%description %{_description} + +%prep +%autosetup -n %{crate}-%{version} -p1 +%cargo_prep + +%build +%cargo_build +%{cargo_license_summary} +%{cargo_license} > LICENSE.dependencies + +%install +%cargo_install + +%if %{with check} +%check +%cargo_test +%endif + +%files +%license LIC1 +%license LIC2 +%license LICENSE.dependencies +%doc DOC1 +%doc DOC2 +%{_bindir}/stg + +%changelog +* Thu Jan 01 03:25:45 GMT 1970 Jane Jane +- Version 2.3.3 +- Initial package diff --git a/rust2rpm/tests/samples/stgit-2.3.3.plain.spec b/rust2rpm/tests/samples/stgit-2.3.3.plain.spec new file mode 100644 index 0000000..c4b02ec --- /dev/null +++ b/rust2rpm/tests/samples/stgit-2.3.3.plain.spec @@ -0,0 +1,100 @@ +# Generated by rust2rpm NNN +%bcond_without check + +# prevent library files from being installed +%global __cargo_is_lib() 0 + +%global crate stgit + +Name: stgit +Version: 2.3.3 +Release: 1%{?dist} +Summary: Stack-based patch management for Git + +SourceLicense: GPL-2.0-only +# FIXME: paste output of %%cargo_license_summary here +License: # FIXME +# LICENSE.dependencies contains a full license breakdown + +URL: https://github.com/stacked-git/stgit +Source: # FIXME +# Automatically generated patch to strip dependencies and normalize metadata +Patch: stgit-patch1.diff +# Manually created patch for downstream crate metadata changes +Patch: stgit-patch2.diff + +ExclusiveArch: %{rust_arches} + +BuildRequires: cargo-rpm-macros >= 24 +BuildRequires: (crate(anstyle/default) >= 1.0.0 with crate(anstyle/default) < 2.0.0~) +BuildRequires: (crate(anstyle/std) >= 1.0.0 with crate(anstyle/std) < 2.0.0~) +BuildRequires: (crate(anyhow/default) >= 1.0.0 with crate(anyhow/default) < 2.0.0~) +BuildRequires: (crate(bstr) >= 1.6.0 with crate(bstr) < 2.0.0~) +BuildRequires: (crate(bstr/std) >= 1.6.0 with crate(bstr/std) < 2.0.0~) +BuildRequires: (crate(bzip2-rs/default) >= 0.1.0 with crate(bzip2-rs/default) < 0.2.0~) +BuildRequires: (crate(clap) >= 4.4.0 with crate(clap) < 4.5.0~) +BuildRequires: (crate(clap/color) >= 4.4.0 with crate(clap/color) < 4.5.0~) +BuildRequires: (crate(clap/help) >= 4.4.0 with crate(clap/help) < 4.5.0~) +BuildRequires: (crate(clap/std) >= 4.4.0 with crate(clap/std) < 4.5.0~) +BuildRequires: (crate(clap/string) >= 4.4.0 with crate(clap/string) < 4.5.0~) +BuildRequires: (crate(clap/suggestions) >= 4.4.0 with crate(clap/suggestions) < 4.5.0~) +BuildRequires: (crate(clap/usage) >= 4.4.0 with crate(clap/usage) < 4.5.0~) +BuildRequires: (crate(clap/wrap_help) >= 4.4.0 with crate(clap/wrap_help) < 4.5.0~) +BuildRequires: (crate(ctrlc/default) >= 3.4.0 with crate(ctrlc/default) < 4.0.0~) +BuildRequires: (crate(curl/default) >= 0.4.0 with crate(curl/default) < 0.5.0~) +BuildRequires: (crate(encoding_rs/default) >= 0.8.0 with crate(encoding_rs/default) < 0.9.0~) +BuildRequires: (crate(flate2/default) >= 1.0.0 with crate(flate2/default) < 2.0.0~) +BuildRequires: (crate(gix) >= 0.54.0 with crate(gix) < 0.55.0~) +BuildRequires: (crate(gix/revision) >= 0.54.0 with crate(gix/revision) < 0.55.0~) +BuildRequires: (crate(indexmap/default) >= 2.0.0 with crate(indexmap/default) < 3.0.0~) +BuildRequires: (crate(is-terminal/default) >= 0.4.0 with crate(is-terminal/default) < 0.5.0~) +BuildRequires: (crate(nom) >= 7.0.0 with crate(nom) < 8.0.0~) +BuildRequires: (crate(nom/std) >= 7.0.0 with crate(nom/std) < 8.0.0~) +BuildRequires: (crate(serde/default) >= 1.0.0 with crate(serde/default) < 2.0.0~) +BuildRequires: (crate(serde/derive) >= 1.0.0 with crate(serde/derive) < 2.0.0~) +BuildRequires: (crate(serde_json/default) >= 1.0.0 with crate(serde_json/default) < 2.0.0~) +BuildRequires: (crate(strsim/default) >= 0.10.0 with crate(strsim/default) < 0.11.0~) +BuildRequires: (crate(tar/default) >= 0.4.0 with crate(tar/default) < 0.5.0~) +BuildRequires: (crate(tempfile/default) >= 3.0.0 with crate(tempfile/default) < 4.0.0~) +BuildRequires: (crate(termcolor/default) >= 1.1.0 with crate(termcolor/default) < 2.0.0~) +BuildRequires: (crate(thiserror/default) >= 1.0.0 with crate(thiserror/default) < 1.1.0~) +BuildRequires: (crate(time) >= 0.3.23 with crate(time) < 0.4.0~) +BuildRequires: (crate(time/formatting) >= 0.3.23 with crate(time/formatting) < 0.4.0~) +BuildRequires: (crate(time/local-offset) >= 0.3.23 with crate(time/local-offset) < 0.4.0~) +BuildRequires: (crate(time/macros) >= 0.3.23 with crate(time/macros) < 0.4.0~) +BuildRequires: (crate(time/parsing) >= 0.3.23 with crate(time/parsing) < 0.4.0~) +BuildRequires: rust >= 1.67.1 + +%global _description %{expand: +Stack-based patch management for Git.} + +%description %{_description} + +%prep +%autosetup -n %{crate}-%{version} -p1 +%cargo_prep + +%build +%cargo_build +%{cargo_license_summary} +%{cargo_license} > LICENSE.dependencies + +%install +%cargo_install + +%if %{with check} +%check +%cargo_test +%endif + +%files +%license LIC1 +%license LIC2 +%license LICENSE.dependencies +%doc DOC1 +%doc DOC2 +%{_bindir}/stg + +%changelog +* Thu Jan 01 1970 Jane Jane - 2.3.3-1 +- Initial package diff --git a/rust2rpm/tests/test_generator.py b/rust2rpm/tests/test_generator.py index 9d6a7b0..9f5f189 100644 --- a/rust2rpm/tests/test_generator.py +++ b/rust2rpm/tests/test_generator.py @@ -78,7 +78,7 @@ def test_spec_file_render_crate(filename: str, target: str): assert rendered == expected -@pytest.mark.parametrize("filename", ["rust2rpm-helper-0.1.3.json"]) +@pytest.mark.parametrize("filename", ["rust2rpm-helper-0.1.3.json", "stgit-2.3.3.json"]) @pytest.mark.parametrize("target", ["plain", "fedora", "mageia", "opensuse"]) def test_spec_file_render_project(filename: str, target: str): crate_name_version = filename.removesuffix(".json") @@ -128,14 +128,12 @@ def test_spec_file_render_project(filename: str, target: str): def test_spec_file_render_workspace(filename: str, target: str): crate_name_version = filename.removesuffix(".json") crate = crate_name_version.rsplit("-", 1)[0] - version = crate_name_version.rsplit("-", 1)[1] real_path = resources.files("rust2rpm.tests.samples").joinpath(filename) metadata = Metadata.from_json(real_path.read_text()) rendered = spec_render_workspace( metadata=metadata, - upstream_version=version, main_package=guess_main_package(metadata), target=target, rpm_name=crate,