#14 Make unversioned python macros not expand to empty
Closed 5 years ago by churchyard. Opened 5 years ago by churchyard.
rpms/ churchyard/rpm python_macros_not_empty  into  master

@@ -0,0 +1,37 @@ 

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

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

+ Date: Tue, 17 Jul 2018 13:01:44 +0200

+ Subject: [PATCH] macros: make unversioned python macros not expand to empty

+  when the executable is not installed

+ 

+ In Fedora the removal of /usr/bin/python in favour of explicit

+ /usr/bin/python2 and /usr/bin/python3 is happening now. Unless

+ python-unversioned-command.rpm is installed, /usr/bin/python does not

+ exists. This means that packages use

+ %python_{sitelib,sitearch,version}, they get a warning in the build

+ log, and the macro evaluates to an empty string.

+ It seems better to keep the unexpanded macro instead, as if it wasn't

+ defined at all.

+ 

+ See https://bugzilla.redhat.com/show_bug.cgi?id=1585626#c4.

+ ---

+  macros.in | 6 +++---

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

+ 

+ diff --git a/macros.in b/macros.in

+ index a69a8964d..32b35f2ac 100644

+ --- a/macros.in

+ +++ b/macros.in

+ @@ -1102,9 +1102,9 @@ package or when debugging this package.\

+  #------------------------------------------------------------------------------

+  # Useful python macros for determining python version and paths

+  #

+ -%python_sitelib %(%{__python} -Es %{_rpmconfigdir}/python-macro-helper sitelib)

+ -%python_sitearch %(%{__python} -Es %{_rpmconfigdir}/python-macro-helper sitearch)

+ -%python_version %(%{__python} -Es %{_rpmconfigdir}/python-macro-helper version)

+ +%python_sitelib %(%{__python} -Es %{_rpmconfigdir}/python-macro-helper sitelib || echo %%{python_sitelib})

+ +%python_sitearch %(%{__python} -Es %{_rpmconfigdir}/python-macro-helper sitearch || echo %%{python_sitearch})

+ +%python_version %(%{__python} -Es %{_rpmconfigdir}/python-macro-helper version || echo %%{python_version})

+  

+  #------------------------------------------------------------------------------

+  # arch macro for all Intel i?86 compatible processors

file modified
+7 -1
@@ -23,7 +23,7 @@ 

  

  %global rpmver 4.14.2

  %global snapver rc1

- %global rel 2

+ %global rel 3

  

  %global srcver %{version}%{?snapver:-%{snapver}}

  %global srcdir %{?snapver:testing}%{!?snapver:%{name}-%(echo %{version} | cut -d'.' -f1-2).x}
@@ -58,6 +58,8 @@ 

  Patch5: rpm-4.12.0-rpm2cpio-hack.patch

  # https://github.com/rpm-software-management/rpm/pull/473

  Patch6: 0001-find-debuginfo.sh-decompress-DWARF-compressed-ELF-se.patch

+ # https://github.com/rpm-software-management/rpm/pull/469

+ Patch7: rpm-4.14.2-make-unversioned-python-macros-not-expand-to-empty.patch

  

  # Patches already upstream:

  
@@ -594,6 +596,10 @@ 

  %doc doc/librpm/html/*

  

  %changelog

+ * Fri Aug 03 2018 Miro Hrončok <mhroncok@redhat.com> - 4.14.2-0.rc1.3

+ - Make unversioned python macros not expand to empty

+ - See https://bugzilla.redhat.com/show_bug.cgi?id=1585626#c9

+ 

  * Sat Jul 21 2018 Igor Gnatenko <ignatenkobrain@fedoraproject.org> - 4.14.2-0.rc1.2

  - Decompress DWARF compressed ELF sections

  

Anyone against me merging this?

Consider this a temporary fix. Feel free to provide a better one tough, I don't understand macro expansion as well as you do., but this is causing trouble and needs to be somehow sorted ASAP.

How about moving the macros to someplace in the python land? That way the macros would be undefined when python is not present so you don't need to fake it like this.

Let's just undefine those entirely?

I don't have any particular attachment to those macros, if somebody's willing to deal with the fallout, by all means.

What I do object to is adding more crud to make defined macros look like undefined ones.

Those macros are supposed to work if you redefine __python. Thay lack error handling if you define __python to nonexisitng command.

So how about turning the non-versioned use into an actual parse error, eg:

--- a/macros.in
+++ b/macros.in
@@ -50,7 +50,7 @@
 %__mv                  @__MV@
 %__patch               @__PATCH@
 %__perl                        @__PERL@
-%__python              @__PYTHON@
+%__python              %{error: attempt to use non-versioned python}
 %__restorecon          @__RESTORECON@
 %__rm                  @__RM@
 %__rsh                 @__RSH@

With that, trying to build a package that hasn't explicitly set %__python to one version or the other will get an error like this:

[pmatilai@sopuli SPECS]$ rpmbuild -bb deltarpm.spec 
error:  attempt to use non-versioned __python
error: line 129: %{python_sitearch}/*

[pmatilai@sopuli SPECS]$ 

There are packages that rely on __python being python (unfortunately). See for example this PR where I fixed it: https://src.fedoraproject.org/rpms/python-shortuuid/pull-request/2#request_diff

Sure there are, but in that case you just define %__python to "python" in the spec. It'd be an explicit error requiring explicit action.

That makes sene, but it is something that needs proper announcement, maybe change even.

Can we only set %{error: %{__python} command failed} if %python_sitelib definition actually fails?

Not quite, but you could define %__python to /usr/bin/python from python-unversioned-command package to that effect.

Still if users define python to /usr/bin/asdfghjkl, they is no error handling. A proper solution errors when python_sitelib etc. definition returns nonzero.

Well it is what it is. Turning shell expansion failure into an actual error in the macro engine would be trivial technically but people are relying on the no-error behavior for various situations.

Can we turn shell expansion failure into an actual error only when a special opt in mechanism is used and use that for python_sitelib etc.? as you propose in https://github.com/rpm-software-management/rpm/pull/469#issuecomment-410958585

The problem is that the only sane behavior is the other way around: error by default and opt-out with ? or something like that. And we can't just go and change the behavior in a stable rpm version, nor do we want to deviate from upstream behavior in such a way in Fedora.

Pull-Request has been closed by churchyard

5 years ago