#4 Update to version 22; Fixes RHBZ#2110233
Merged 2 months ago by decathorpe. Opened 2 months ago by decathorpe.
Unknown source rawhide  into  rawhide

file modified
+1
@@ -16,3 +16,4 @@

  /rust2rpm-v19.tar.gz

  /rust2rpm-v20.tar.gz

  /rust2rpm-v21.tar.gz

+ /rust2rpm-v22.tar.gz

@@ -1,21 +0,0 @@

- From 0aa82d22b00b4191ddff1e9ba9cb53686481f8ac Mon Sep 17 00:00:00 2001

- From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>

- Date: Tue, 22 Feb 2022 11:28:52 +0100

- Subject: [PATCH 1/2] Add comment about unused macro

- 

- ---

-  data/macros.rust | 1 +

-  1 file changed, 1 insertion(+)

- 

- diff --git a/data/macros.rust b/data/macros.rust

- index 0940d06485..3a9281849f 100644

- --- a/data/macros.rust

- +++ b/data/macros.rust

- @@ -14,6 +14,7 @@

-  

-  %__global_rustflags %{build_rustflags}

-  

- +# Currently unused, retained for backwards compatibility.

-  %__global_rustflags_toml [%{lua:

-      for arg in string.gmatch(rpm.expand("%{build_rustflags}"), "%S+") do

-          print('"' .. arg .. '", ')

@@ -1,40 +0,0 @@

- From 1b14d44d5705e2c87bc52d56f9ea184994669da1 Mon Sep 17 00:00:00 2001

- From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>

- Date: Tue, 22 Feb 2022 11:41:46 +0100

- Subject: [PATCH 2/2] Allow easy overriding of the

-  opt-level/debuginfo/codegen-units flags

- 

- Some crates use debuginfo=0 or debuginfo=1 to reduce memory pressure during

- builds. This should make this easy.

- 

- Fixes https://pagure.io/fedora-rust/rust2rpm/issue/181

- ---

-  data/macros.rust | 10 +++++++---

-  1 file changed, 7 insertions(+), 3 deletions(-)

- 

- diff --git a/data/macros.rust b/data/macros.rust

- index 3a9281849f..efa46a3212 100644

- --- a/data/macros.rust

- +++ b/data/macros.rust

- @@ -1,14 +1,18 @@

-  %__rustc %{_bindir}/rustc

-  %__rustdoc %{_bindir}/rustdoc

-  

- +%rustflags_opt_level 3

- +%rustflags_debuginfo 2

- +%rustflags_codegen_units 1

- +

-  # Enable optimization, debuginfo, and link hardening.

-  %build_rustflags %{shrink:

- -  -Copt-level=3

- -  -Cdebuginfo=2

- +  -Copt-level=%rustflags_opt_level

- +  -Cdebuginfo=%rustflags_debuginfo

- +  -Ccodegen-units=%rustflags_codegen_units

-    -Clink-arg=-Wl,-z,relro

-    -Clink-arg=-Wl,-z,now

-    %{?_package_note_file:-Clink-arg=-Wl,-dT,%{_package_note_file}}

- -  -Ccodegen-units=1

-    --cap-lints=warn

-  }

-  

@@ -1,31 +0,0 @@

- From b9e95b4d61739f21c2f64ee3df497d93272a67af Mon Sep 17 00:00:00 2001

- From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>

- Date: Mon, 28 Feb 2022 14:01:20 +0100

- Subject: [PATCH 2/3] Fix autodetection of rpmautospec

- 

- When store_true or store_false are used, the default default changes

- from None to a boolean. I didn't know about this, and I wrote the code

- to assume args.rpmautospec would be None. rpmautospec detection was

- effectively always disabled.

- ---

-  rust2rpm/__main__.py | 2 ++

-  1 file changed, 2 insertions(+)

- 

- diff --git a/rust2rpm/__main__.py b/rust2rpm/__main__.py

- index 0f575ad12f..13dc26a313 100644

- --- a/rust2rpm/__main__.py

- +++ b/rust2rpm/__main__.py

- @@ -360,8 +360,10 @@ def main():

-      parser.add_argument("-s", "--store-crate", action="store_true",

-                          help="Store crate in current directory")

-      parser.add_argument("-a", "--rpmautospec", action="store_true",

- +                        default=None,

-                          help="Use autorelease and autochangelog features")

-      parser.add_argument("--no-rpmautospec", action="store_false",

- +                        default=None,

-                          help="Do not use rpmautospec")

-      parser.add_argument("--relative-license-paths", action="store_true",

-                          help="Put all license files in main license directory")

- -- 

- 2.35.1

- 

@@ -1,31 +0,0 @@

- From 7d8c9a802866ef0a35ab4d67d8869f30c650827a Mon Sep 17 00:00:00 2001

- From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>

- Date: Mon, 28 Feb 2022 10:32:10 +0100

- Subject: [PATCH 3/3] Print information about written files

- 

- We already output some messages, but not the most important part: what

- files were written.

- ---

-  rust2rpm/__main__.py | 3 ++-

-  1 file changed, 2 insertions(+), 1 deletion(-)

- 

- diff --git a/rust2rpm/__main__.py b/rust2rpm/__main__.py

- index 13dc26a313..a011217443 100644

- --- a/rust2rpm/__main__.py

- +++ b/rust2rpm/__main__.py

- @@ -515,10 +515,11 @@ def main():

-          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}')

-  

-  if __name__ == "__main__":

-      main()

- -- 

- 2.35.1

- 

@@ -1,27 +0,0 @@

- From 98638813aa1e085e05092ebfcbcad7ce7fd00a44 Mon Sep 17 00:00:00 2001

- From: Fabio Valentini <decathorpe@gmail.com>

- Date: Fri, 1 Jul 2022 19:29:56 +0200

- Subject: [PATCH] macros.cargo: vacuum up Cargo.toml.orig in addition to

-  Cargo.lock

- 

- This fixes builds with cargo from Rust 1.62+, which now complains

- and fails our builds if the Cargo.toml.orig file already exists.

- ---

-  data/macros.cargo | 1 +

-  1 file changed, 1 insertion(+)

- 

- diff --git a/data/macros.cargo b/data/macros.cargo

- index 344b44e..206df14 100644

- --- a/data/macros.cargo

- +++ b/data/macros.cargo

- @@ -44,6 +44,7 @@ registry = "https://crates.io"\

-  replace-with = "local-registry"\

-  EOF\

-  %{__rm} -f Cargo.lock \

- +%{__rm} -f Cargo.toml.orig \

-  )

-  

-  %__cargo_parse_opts(naf:) %{shrink:\

- -- 

- 2.36.1

- 

file added
+152
@@ -0,0 +1,152 @@

+ From f0d04b09e8b60d0c9c5efe1c24fc63d06cc54e7b Mon Sep 17 00:00:00 2001

+ From: Fabio Valentini <decathorpe@gmail.com>

+ Date: Jul 25 2022 10:09:43 +0000

+ Subject: Ensure rust2rpm doesn't autogenerate architecture-dependent patches

+ 

+ 

+ The logic in the cfg-expression evaluator checked *too many cases*,

+ some of which would have resulted in generation of broken patches

+ and packages. We need to ensure that the evaluation is independent

+ of the host architecture (i.e. we need to keep *all* dependencies

+ that are valid on *any* of our build targets, even if they end up

+ being unused on *some* of them).

+ 

+ ---

+ 

+ diff --git a/rust2rpm/cfg.py b/rust2rpm/cfg.py

+ index b2e0944..51e5ff9 100644

+ --- a/rust2rpm/cfg.py

+ +++ b/rust2rpm/cfg.py

+ @@ -1,8 +1,5 @@

+  import ast

+ -import ctypes

+  import functools

+ -import platform

+ -import sys

+  

+  import pyparsing as pp

+  from pyparsing import ParseException

+ @@ -63,43 +60,69 @@ def cfg_grammar():

+  

+  

+  @functools.cache

+ -def evaluate_variable(name):

+ +def evaluate_predicate(name: str, value: str) -> bool:

+ +    # based on: https://doc.rust-lang.org/reference/conditional-compilation.html

+ +

+      match name:

+          case "target_arch":

+ -            return platform.machine()

+ +            # Needs to be ignored, as we cannot generate patches that are

+ +            # different depending on the host architecture - except if the

+ +            # target architecture is "wasm32", which we don't support.

+ +            return value != "wasm32"

+ +

+ +        case "target_feature":

+ +            # The "target_feature" predicate can be ignored as well, since the

+ +            # valid values for this predicate are architecture-dependent.

+ +            return True

+  

+          case "target_os":

+ -            return "linux"

+ +            return value == "linux"

+  

+          case "target_family":

+ -            return "unix"

+ -

+ -        case "unix":

+ -            return evaluate_variable("target_family") == "unix"

+ -

+ -        case "windows":

+ -            return evaluate_variable("target_family") == "windows"

+ +            return value == "unix"

+  

+          case "target_env":

+ -            # Key-value option set with further disambiguating information about the

+ -            # target platform with information about the ABI or libc used

+ -            return ...

+ +            # The "target_env" predicate is used to disambiguate target

+ +            # platforms based on its C library / C ABI (i.e. we can ignore

+ +            # "msvc" and "musl"), and if there's no need to disambiguate, the

+ +            # value can be the empty string.

+ +            return value in ["", "gnu"]

+  

+          case "target_endian":

+ -            return sys.byteorder

+ +            # Needs to be ignored, as we cannot generate patches that are

+ +            # different depending on the host architecture.

+ +            return True

+  

+          case "target_pointer_width":

+ -            return str(ctypes.sizeof(ctypes.c_void_p) * 8)

+ +            # Needs to be ignored, as we cannot generate patches that are

+ +            # different depending on the host architecture.

+ +            return True

+  

+          case "target_vendor":

+ -            return "unknown"

+ +            # On linux systems, "target_vendor" is always "unknown".

+ +            return value == "unknown"

+  

+          case _:

+ -            log.warn(f"Ignoring unknown variable {name!r} in cfg-expression.")

+ +            log.warn(f'Ignoring invalid predicate \'"{name}" = "{value}"\' in cfg-expression.')

+ +            return False

+ +

+ +

+ +@functools.cache

+ +def evaluate_atom(name: str) -> bool:

+ +    match name:

+ +        case "unix":

+ +            return True

+ +        case "windows":

+ +            return False

+ +        case _:

+ +            log.warn(

+ +                f"Ignoring invalid atom {name!r} in cfg-expression. "

+ +                + 'Only "unix" and "windows" are valid names for atoms.'

+ +            )

+              return False

+  

+  

+ -def evaluate(expr, nested=False):

+ +def evaluate(expr, nested=False) -> bool:

+      if hasattr(expr, "asList"):

+          expr = expr.asList()  # compat with pyparsing 2.7.x

+      match expr:

+ @@ -113,11 +136,9 @@ def evaluate(expr, nested=False):

+              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

+ +            return evaluate_predicate(variable, v)

+          case [variable] if nested:

+ -            x = evaluate_variable(variable)

+ -            return x

+ +            return evaluate_atom(variable)

+          case _:

+              raise ValueError

+  

+ diff --git a/rust2rpm/tests/test_cfg.py b/rust2rpm/tests/test_cfg.py

+ index c00008a..5a2b314 100644

+ --- a/rust2rpm/tests/test_cfg.py

+ +++ b/rust2rpm/tests/test_cfg.py

+ @@ -21,7 +21,7 @@ def test_pyparsing_run_tests():

+      [

+          ('cfg(target_os = "macos")', False),

+          ("cfg(any(foo, bar))", False),

+ -        ('cfg(all(unix, target_pointer_width = "16"))', False),

+ +        ('cfg(all(unix, target_pointer_width = "16"))', True),

+          ("cfg(not(foo))", True),

+          ("cfg(unix)", True),

+          ("cfg(not(unix))", False),

+ @@ -36,7 +36,6 @@ def test_pyparsing_run_tests():

+          ('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):

+ 

file modified
+46 -27
@@ -3,29 +3,34 @@

  %global debug_package %{nil}

  

  Name:           rust-packaging

- Version:        21

+ Version:        22

  Release:        %autorelease

  Summary:        RPM macros for building Rust packages

- 

  License:        MIT

+ 

  URL:            https://pagure.io/fedora-rust/rust2rpm

- Source:         https://pagure.io/fedora-rust/rust2rpm/archive/v%{version}/rust2rpm-v%{version}.tar.gz

+ Source:         %{url}/archive/v%{version}/rust2rpm-v%{version}.tar.gz

  

- Patch:          0001-Add-comment-about-unused-macro.patch

- Patch:          0002-Allow-easy-overriding-of-the-opt-level-debuginfo-cod.patch

- Patch:        	0003-Fix-autodetection-of-rpmautospec.patch

- Patch:        	0004-Print-information-about-written-files.patch

- Patch:          0005-macros.cargo-vacuum-up-Cargo.toml.orig-in-addition-t.patch

+ # upstream patch to avoid generation of architecture-specific patches

+ Patch:          https://pagure.io/fedora-rust/rust2rpm/c/f0d04b0.patch

  

  ExclusiveArch:  %{rust_arches}

  

- # gawk is needed for stripping dev-deps in macro

- Requires:       gawk

- Requires:       python3-rust2rpm = %{?epoch:%{epoch}:}%{version}-%{release}

+ BuildRequires:  python3-devel

+ 

+ %if %{with check}

+ BuildRequires:  cargo

+ %endif

+ 

+ Requires:       python3-rust2rpm-core = %{?epoch:%{epoch}:}%{version}-%{release}

  Requires:       rust-srpm-macros = %{version}

+ 

  Requires:       rust

  Requires:       cargo >= 1.41

  

+ # gawk is needed for stripping dev-deps in macro

+ Requires:       gawk

+ 

  %description

  The package provides RPM macros for building Rust projects.

  
@@ -34,48 +39,62 @@

  

  %package     -n python3-rust2rpm

  Summary:        Generate RPM spec files for Rust packages

- BuildRequires:  python3-devel

- BuildRequires:  python3-setuptools

- %if %{with check}

- BuildRequires:  python3-pytest

- BuildRequires:  cargo

- %endif

  Requires:       cargo

+ Requires:       python3-rust2rpm-core = %{?epoch:%{epoch}:}%{version}-%{release}

  Provides:       rust2rpm = %{version}-%{release}

- %{?python_provide:%python_provide python3-rust2rpm}

  

  %description -n python3-rust2rpm

- %{summary}.

+ rust2rpm is a tool that automates the generation of RPM spec files for

+ Rust crates.

+ 

+ %package     -n python3-rust2rpm-core

+ Summary:        Generate RPM spec files for Rust packages (core functionality)

+ Requires:       cargo

+ Provides:       cargo-inspector = %{version}-%{release}

+ 

+ %description -n python3-rust2rpm-core

+ rust2rpm is a tool that automates the generation of RPM spec files for

+ Rust crates.

+ 

+ This package contains the core functionality which doesn't depend on

+ any third-party python packages.

  

  %prep

  %autosetup -n rust2rpm-v%{version} -p1

  

+ %generate_buildrequires

+ %pyproject_buildrequires -t

+ 

  %build

- %py3_build

+ %pyproject_wheel

  

  %install

- %py3_install

+ %pyproject_install

+ 

  install -D -p -m 0644 -t %{buildroot}%{_rpmmacrodir} data/macros.rust data/macros.cargo

  install -D -p -m 0644 -t %{buildroot}%{_fileattrsdir} data/cargo.attr

  

  %if %{with check}

  %check

- py.test-%{python3_version} -vv test.py

+ %tox

  %endif

  

  %files

- %license LICENSE

  %{_rpmmacrodir}/macros.rust

  %{_rpmmacrodir}/macros.cargo

  %{_fileattrsdir}/cargo.attr

  

  %files -n python3-rust2rpm

- %license LICENSE

- %doc NEWS

  %{_bindir}/rust2rpm

- %{_bindir}/cargo-inspector

- %{python3_sitelib}/rust2rpm-*.egg-info/

+ %{python3_sitelib}/rust2rpm-*.dist-info/

  %{python3_sitelib}/rust2rpm/

+ %exclude %{python3_sitelib}/rust2rpm/core/

+ 

+ %files -n python3-rust2rpm-core

+ %license LICENSE

+ %doc README.md NEWS

+ %{_bindir}/cargo-inspector

+ %{python3_sitelib}/rust2rpm/core/

  

  %changelog

  %autochangelog

file modified
+1 -1
@@ -1,1 +1,1 @@

- SHA512 (rust2rpm-v21.tar.gz) = 50864eea0025d1c6d681e5e618f7e7dfe3aab576ec722134e07089459d73cb954e5886409578de7dd7d1a05dfbe7cc034af5f2b4d4e27db3310b0e0a2170869e

+ SHA512 (rust2rpm-v22.tar.gz) = f26e601dac7e2dba2303f1ca65e7a86465a3b4330196a9070e62ad6e1a1c8e3f8d761cb72ab05bca9db3a0a8049c66392632a38075c2f76aa2c2d1aa601a85f9

  • update to latest version
  • drop upstreamed patches
  • move to 202x-era Python packaging (%pyproject_{buildrequires,build,install} and %tox)
  • split dependency-less rust2rpm.core into separate package
  • move cargo-inspector to dependency-less python3-rust2rpm-core package
  • make rust-packaging macros package only depend on python3-rust2rpm-core

BuildRequires: python3-setuptools

This should not be needed. It's generated from the upstream metadata.

FWIW I consider the %{?epoch:%{epoch}:} bit quite safer in requirements for other subpacakges.

rebased onto 8f7a7ed

2 months ago

Thanks for taking a look, I have addressed both comments and force-pushed them.

(Not related to python but...)

I would not include the LICENSE file in both python3-rust2rpm* subpackages. You can remove the %doc and %license tags from %files -n python3-rust2rpm and add

%doc README.md NEWS # Note from Maxwell: The README wasn't installed before
%license LICENSE

to the core subpackage.

Obviously, don't include my comment in the actual file :).

Yeah, makes sense, given there's a hard and strict dependency from rust2rpm on rust2rpm-core.

rebased onto b250c28

2 months ago

EDIT: They are also duplicated in rust-packaging, which apparently also depends on python3-rust2rpm-core.

True, fixed as well. Now the doc/license files are only part of python3-rust2rpm-core, which is a hard / strict dependency of both rust-packaging and python3-rust2rpm.

rebased onto e6ac480

2 months ago

LGTM. Optionally, you can include the shared %description text in a macro, but I know you don't like too many macros so...

rebased onto e30950d

2 months ago

Pull-Request has been merged by decathorpe

2 months ago