From pmatilai at redhat.com Mon Jan 2 09:13:36 2023 From: pmatilai at redhat.com (Panu Matilainen) Date: Mon, 2 Jan 2023 11:13:36 +0200 Subject: Memoizing macro values In-Reply-To: <87y1r12h8v.fsf@oldenburg.str.redhat.com> References: <87y1r12h8v.fsf@oldenburg.str.redhat.com> Message-ID: <1cfc6e05-d8c8-e30c-6fec-acdebc9412b0@redhat.com> On 12/21/22 12:17, Florian Weimer wrote: > In Fedora, we have this: > > /usr/lib/rpm/macros.d/macros.python:%python_sitelib %(RPM_BUILD_ROOT= %{__python} -Esc "import sysconfig; print(sysconfig.get_path('purelib', vars={'platbase': '%{_prefix}', 'base': '%{_prefix}'}))") > /usr/lib/rpm/macros.d/macros.python3:%python3_sitelib %(RPM_BUILD_ROOT= %{__python3} -Ic "import sysconfig; print(sysconfig.get_path('purelib', vars={'platbase': '%{_prefix}', 'base': '%{_prefix}'}))") > > This is a %define-style macro, so the macro gets re-evaluated for every > expansion. It can make spec file operations really, really slow. > > It's possible to work around this in spec files like this: > > %{?python3_sitearch: %global python3_sitearch %{python3_sitearch}} > > But this is quite ugly, and I wonder if there is a nice way to do it > directly in the macros file instead. I think I know how do it with Lua, > but maybe there is a better way? %python3_sitearch %{global python3_sitearch %(RPM_BUILD_ROOT= %{__python3} -Esc "import sysconfig; print(sysconfig.get_path('platlib', vars={'platbase': '%{_prefix}', 'base': '%{_prefix}'}))")}%{python3_sitearch} Ie just push the evaluated macro on top of the original one as a global on first use, re-evaluation can be forced with %undefine and no helper macros needed. There's also an upstream RFE on this use-case, it's quite common indeed: https://github.com/rpm-software-management/rpm/issues/1155 - Panu - From mhroncok at redhat.com Mon Jan 2 10:05:37 2023 From: mhroncok at redhat.com (=?UTF-8?Q?Miro_Hron=c4=8dok?=) Date: Mon, 2 Jan 2023 11:05:37 +0100 Subject: Memoizing macro values In-Reply-To: <1cfc6e05-d8c8-e30c-6fec-acdebc9412b0@redhat.com> References: <87y1r12h8v.fsf@oldenburg.str.redhat.com> <1cfc6e05-d8c8-e30c-6fec-acdebc9412b0@redhat.com> Message-ID: <69c0420e-7f74-b779-4ad4-236e4fadf5c1@redhat.com> On 02. 01. 23 10:13, Panu Matilainen wrote: > On 12/21/22 12:17, Florian Weimer wrote: >> In Fedora, we have this: >> >> /usr/lib/rpm/macros.d/macros.python:%python_sitelib %(RPM_BUILD_ROOT= >> %{__python} -Esc "import sysconfig; print(sysconfig.get_path('purelib', >> vars={'platbase': '%{_prefix}', 'base': '%{_prefix}'}))") >> /usr/lib/rpm/macros.d/macros.python3:%python3_sitelib %(RPM_BUILD_ROOT= >> %{__python3} -Ic "import sysconfig; print(sysconfig.get_path('purelib', >> vars={'platbase': '%{_prefix}', 'base': '%{_prefix}'}))") >> >> This is a %define-style macro, so the macro gets re-evaluated for every >> expansion.? It can make spec file operations really, really slow. >> >> It's possible to work around this in spec files like this: >> >> %{?python3_sitearch: %global python3_sitearch %{python3_sitearch}} >> >> But this is quite ugly, and I wonder if there is a nice way to do it >> directly in the macros file instead.? I think I know how do it with Lua, >> but maybe there is a better way? > > %python3_sitearch %{global python3_sitearch %(RPM_BUILD_ROOT= %{__python3} -Esc > "import sysconfig; print(sysconfig.get_path('platlib', vars={'platbase': > '%{_prefix}', 'base': '%{_prefix}'}))")}%{python3_sitearch} > > Ie just push the evaluated macro on top of the original one as a global on > first use, re-evaluation can be forced with %undefine and no helper macros needed. How does this work when Python is installed mid-build somehow? Do we need to care about that or can we absolutely assume that when packages are installed, the RPM build process is restarted? > There's also an upstream RFE on this use-case, it's quite common indeed: > https://github.com/rpm-software-management/rpm/issues/1155 Thanks for the link. -- Miro Hron?ok -- Phone: +420777974800 IRC: mhroncok From pmatilai at redhat.com Mon Jan 2 11:23:26 2023 From: pmatilai at redhat.com (Panu Matilainen) Date: Mon, 2 Jan 2023 13:23:26 +0200 Subject: Memoizing macro values In-Reply-To: <69c0420e-7f74-b779-4ad4-236e4fadf5c1@redhat.com> References: <87y1r12h8v.fsf@oldenburg.str.redhat.com> <1cfc6e05-d8c8-e30c-6fec-acdebc9412b0@redhat.com> <69c0420e-7f74-b779-4ad4-236e4fadf5c1@redhat.com> Message-ID: <68db5658-3158-bc8f-9a2b-5f37290125d0@redhat.com> On 1/2/23 12:05, Miro Hron?ok wrote: > On 02. 01. 23 10:13, Panu Matilainen wrote: >> On 12/21/22 12:17, Florian Weimer wrote: >>> In Fedora, we have this: >>> >>> /usr/lib/rpm/macros.d/macros.python:%python_sitelib %(RPM_BUILD_ROOT= >>> %{__python} -Esc "import sysconfig; >>> print(sysconfig.get_path('purelib', vars={'platbase': '%{_prefix}', >>> 'base': '%{_prefix}'}))") >>> /usr/lib/rpm/macros.d/macros.python3:%python3_sitelib >>> %(RPM_BUILD_ROOT= %{__python3} -Ic "import sysconfig; >>> print(sysconfig.get_path('purelib', vars={'platbase': '%{_prefix}', >>> 'base': '%{_prefix}'}))") >>> >>> This is a %define-style macro, so the macro gets re-evaluated for every >>> expansion.? It can make spec file operations really, really slow. >>> >>> It's possible to work around this in spec files like this: >>> >>> %{?python3_sitearch: %global python3_sitearch %{python3_sitearch}} >>> >>> But this is quite ugly, and I wonder if there is a nice way to do it >>> directly in the macros file instead.? I think I know how do it with Lua, >>> but maybe there is a better way? >> >> %python3_sitearch %{global python3_sitearch %(RPM_BUILD_ROOT= >> %{__python3} -Esc "import sysconfig; >> print(sysconfig.get_path('platlib', vars={'platbase': '%{_prefix}', >> 'base': '%{_prefix}'}))")}%{python3_sitearch} >> >> Ie just push the evaluated macro on top of the original one as a >> global on first use, re-evaluation can be forced with %undefine and no >> helper macros needed. > > How does this work when Python is installed mid-build somehow? Do we > need to care about that or can we absolutely assume that when packages > are installed, the RPM build process is restarted? I hope nobody is expecting to install anything during rpmbuild execution. rpmbuild doesn't take such a thing into account at all and the results (not just wrt macros) would be totally random: some things would inevitably affect the output, others would not. If you mean by something like mock which consists of multiple independent rpmbuild runs where build-deps are installed in between, I don't see how that would be a problem because the macros are not persistent. - Panu - - Panu - From scott.andrews at columbus.rr.com Mon Jan 2 20:21:18 2023 From: scott.andrews at columbus.rr.com (scott.andrews at columbus.rr.com) Date: Mon, 2 Jan 2023 15:21:18 -0500 Subject: Setting armv8hnl Message-ID: <39f00f0b-b078-f3ad-0ecb-7b091a70ba00@columbus.rr.com> I am looking to set the rpmbuild environment from armv7hnl to armv8hnl so rpm -showrc has all of the defaults changed from armv7hnl to armv8hnl can this be done in the local .rpmmacros file? From mhroncok at redhat.com Wed Jan 25 14:44:16 2023 From: mhroncok at redhat.com (=?UTF-8?Q?Miro_Hron=c4=8dok?=) Date: Wed, 25 Jan 2023 15:44:16 +0100 Subject: Memoizing macro values In-Reply-To: <87tu1p2es6.fsf@oldenburg.str.redhat.com> References: <87y1r12h8v.fsf@oldenburg.str.redhat.com> <87tu1p2es6.fsf@oldenburg.str.redhat.com> Message-ID: On 21. 12. 22 12:10, Florian Weimer wrote: > Could you bring this to Fedora (rawhide in 37 preferably)? I think it > will really help package maintainers. This has landed in Fedora Rawhide. https://src.fedoraproject.org/rpms/python-rpm-macros/pull-request/157 https://bodhi.fedoraproject.org/updates/FEDORA-2023-4e0643d578 Please test and report problems via Fedora channels (e.g. Bugzilla). I don't think it is that important to backport it to Fedora 37. We have lived with this problem for 2 decades. Some day we need to put it in https://github.com/rpm-software-management/python-rpm-packaging but the macros aren't even there yet :( -- Miro Hron?ok -- Phone: +420777974800 IRC: mhroncok