Wednesday, April 13, 2022

[SOLVED] Shipping *.so and binaries while building RPM package

Issue

I have created a python application in which I would like to ship .so and some binary files in the final RPM package. After long reading I found a way to add binaries/ image and other data files in setup.py. Now, when I build an RPM with python setup.py bdist_rpm command, it complains about architecture dependency:

    Arch dependent binaries in noarch package
error: command 'rpmbuild' failed with exit status 1

After googling I found that we can add:

#%define _binaries_in_noarch_packages_terminate_build 0

or removing the line BuildArch: noarch in the packagename.spec file to overcome the rpmbuild failure. However, every time I add or remove line from build/bdist.linux-i686/rpm/SPECS/packagename.spec the command python setup.py bdist_rpm always overwrites the .spe file.

Is there a way to avoid Arch dependent binaries and ship *.so and other binary files in rpm?


Solution

The behavior of bdist_rpm is defined by a bunch of settings in:

  • /usr/lib/rpm/macros
  • /etc/rpm/macros
  • $HOME/.rpmmacros

I'm willing to bet that only /usr/lib/rpm/macros exists on your system. This is normal.

So, in order to prevent the "Arch dependent binaries in noarch package" error you would create /etc/rpm/macros or ~/.rpmmacros and add the following:

%_unpackaged_files_terminate_build      0
%_binaries_in_noarch_packages_terminate_build   0

Do not modify /usr/lib/rpm/macros because that file will be overwritten by the system whenever the rpm-build package is upgraded, downgraded, or re-installed.

If you want to override the behavior for everyone on the system put the settings in /etc/rpm/macros. If you want override the behavior for a particular user then add the settings to $HOME/.rpmmacros.

.rpmmacros trumps /etc/rpm/macros which trumps /usr/lib/rpm/macros.

Note: it's useful to examine /usr/lib/rpm/macros to see what settings are available and for syntax examples.

As a side note, %_unpackaged_files_terminate_build 0 setting prevents the error: Installed (but unpackaged) file(s) found: error.



Answered By - shrewmouse
Answer Checked By - Timothy Miller (WPSolving Admin)