From 970160a316dcf4fb8d4c4f2af5b6eccf6620a75d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Mon, 14 Feb 2022 13:15:09 +0100 Subject: [PATCH] Use license files installed by crate Before, we'd use the same pattern for the main package (if present), and the -devel files: %license LICENSE1 LICENSE2 Since the create usually also installs the license files to %create_instdir, we end up with duplicated files in -devel. It seems reasonable to reuse the file that is already present in %create_instdir. Fedora packaging guidelines only say that "%license must be used for license files", and doesn't say anything about the location. And in fact, you can't assume any fixed location, because packages will often use a common license directory, so the only reliable way to list license files is to look at the %license mark. And in our particular case, -devel files are not installed on user systems, so we can assume that users will not manually search for license files by browsing /usr/share/licenses/. We can't remove the license file from %{create_instdir}, because the crate might be need it, for example to display the license text internally. Thus, I think reasonable and not against the guidelines to "reuse" the license file present under %{create_instdir}. For the main package though, it seems better to keep the existing location. Those packages *are* installed on end-user systems, and also it'd be strange to suddently have one file under /usr/share/cargo/registry/. So this patch uses absolute paths under %create_instdir for -devel, and the relative path (effectively under /usr/share/licenses) for the main package. It is possible to opt-out of the new behaviour with --relative-license-paths. Fixes #176. --- rust2rpm/__main__.py | 4 ++++ rust2rpm/templates/main.spec | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/rust2rpm/__main__.py b/rust2rpm/__main__.py index b5fd6f3..49023bd 100644 --- a/rust2rpm/__main__.py +++ b/rust2rpm/__main__.py @@ -363,6 +363,8 @@ def main(): help="Use autorelease and autochangelog features") parser.add_argument("--no-rpmautospec", action="store_false", help="Do not use rpmautospec") + parser.add_argument("--relative-license-paths", action="store_true", + help="Put all license files in main license directory") parser.add_argument("--all-features", action="store_true", help="Activate all available features") parser.add_argument("--dynamic-buildrequires", action="store_true", @@ -447,6 +449,8 @@ def main(): rpmautospec = detect_rpmautospec(default_target, spec_file) kwargs["rpmautospec"] = rpmautospec + kwargs["relative_license_paths"] = args.relative_license_paths + if args.target in {"fedora", "mageia", "opensuse"}: kwargs["include_build_requires"] = True kwargs["include_provides"] = False diff --git a/rust2rpm/templates/main.spec b/rust2rpm/templates/main.spec index 30fce2a..0799363 100644 --- a/rust2rpm/templates/main.spec +++ b/rust2rpm/templates/main.spec @@ -160,7 +160,13 @@ use {% if feature is not none %}the "{{ feature }}" feature of {% endif %}the "% %files {{ pkg }} {% if feature is none %} {% if license_files|length > 0 %} + {% if relative_license_paths %} %license {{ license_files|join(' ') }} + {% else %} + {% for file in license_files %} +%license %{crate_instdir}/{{ file }} + {% endfor %} + {% endif %} {% else %} # FIXME: no license files detected {% endif %}