#178 Add %crate_instdir convenience macro, reuse installed license files, use %doc markup more
Merged 2 years ago by zbyszek. Opened 2 years ago by zbyszek.
fedora-rust/ zbyszek/rust2rpm add-create_instdir-macro  into  main

file modified
+2
@@ -10,6 +10,8 @@ 

  

  %cargo_registry %{_datadir}/cargo/registry

  

+ %crate_instdir %{cargo_registry}/%{crate}-%{version_no_tilde}

+ 

  %__cargo_is_lib() %__cargo_inspector --target-kinds Cargo.toml | grep -q -F -x "$(printf 'lib\\\nrlib\\\nproc-macro')"

  %__cargo_is_bin() %__cargo_inspector --target-kinds Cargo.toml | grep -q -F -x bin

  

file modified
+7
@@ -288,6 +288,9 @@ 

          cratef, crate, version = download(crate, version)

  

      with files_from_crate(cratef, crate, version) as (toml, doc_files, license_files):

+         if not license_files:

+             print(f"Warning: no license files detected in {crate}")

+ 

          diff = make_patch(toml, enabled=patch)

          metadata = Metadata.from_file(toml)

          if len(metadata) > 1:
@@ -360,6 +363,8 @@ 

                          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",
@@ -444,6 +449,8 @@ 

          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

file modified
+16 -3
@@ -43,7 +43,7 @@ 

  

  ExclusiveArch:  %{rust_arches}

  

- BuildRequires:  rust-packaging

+ BuildRequires:  rust-packaging >= 21

  {% if all_features %}

    {% set cargo_args = " -a" %}

  {% endif %}
@@ -101,6 +101,8 @@ 

  %files       -n %{crate}

    {% if license_files|length > 0 %}

  %license {{ license_files|join(' ') }}

+   {% else %}

+ # FIXME: no license files detected

    {% endif %}

    {% if doc_files|length > 0 %}

  %doc {{ doc_files|join(' ') }}
@@ -158,11 +160,22 @@ 

  %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 %}

- %{cargo_registry}/%{crate}-%{version_no_tilde}/

+       {% for file in doc_files %}

+ %doc %{crate_instdir}/{{ file }}

+       {% endfor %}

+ %{crate_instdir}/

      {% else %}

- %ghost %{cargo_registry}/%{crate}-%{version_no_tilde}/Cargo.toml

+ %ghost %{crate_instdir}/Cargo.toml

      {% endif %}

  

    {% endfor %}

Fixes #41.

The template is adjusted to use the new macro. This will only work
if the macro is defined, thus the required version of rust-packaging
is bumped.

Pull-Request has been merged by zbyszek

2 years ago