如何安全地从已编译库中删除路径字符串而不损坏库?

如何安全地从已编译库中删除路径字符串而不损坏库?

我的 RPM 构建过程抱怨 buildroot 路径字符串出现在多个.so文件中。我尝试使用sedperl对该字符串进行正则表达式替换'',但这样做虽然可以消除check-buildroot,但却会损坏 .so 文件并导致使用它的任何东西都出现段错误。

此字符串显然不是 rpath 的一部分,因为chrpath --delete它不会消除来自 的错误消息check-buildroot。我不知道为什么 buildroot 路径会出现在这些.so文件中。

那么,防止 buildroot 路径出现在.so文件中的“正确”方法是什么?

编辑:这是我的 spec 文件:

%{!?tgrelease: %define tgrelease() %2}
%if 0%{?amzn}

# Prevent /usr/lib/rpm/check-buildroot from running, because the only remedy we've found to silence its error messages
# also corrupts the .so files it complains about.
%define __arch_install_post /usr/lib/rpm/check-rpaths

%define __python python
%define __python_ver python2.6
%define __python_prefix python
%else
%define __python python2.6
%define __python_ver python2.6
%define __python_prefix python26
%endif
%define python_sitelib %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib()")

%define __package directory
%define __package_safe %(echo %{__package} | sed 's/[-. ]/_/g')
%define __pip_package %(echo %{__package} | sed 's/_/-/g' | tr '[A-Z]' '[a-z]')

%define __configdir etc/prod
%define __django_root REDACTED
%define __requirements REDACTED

Name:           %{__package}
Version:        %{__version}
Release:        %tgrelease 0 1
Summary:        REDACTED
Group:          Development/Languages
License:        Restricted
Source0:        %{rname}/%{name}-%{version}.tar.gz
BuildRoot:      %{_tmppath}/%{name}-%(%{__id_u} -n)

BuildRequires:  %{__python_prefix}
BuildRequires:  %{__python_prefix}-setuptools
BuildRequires:  %{__python_prefix}-virtualenv
# Uncomment this when we get git as an RPM on RH6
BuildRequires:  git
BuildRequires:  openldap-devel
BuildRequires:  libxml2-devel
BuildRequires:  libxslt-devel
BuildRequires:  chrpath

Requires:  %{__python_prefix}
Requires:  %{__python_prefix}-virtualenv
Requires:  openldap
Requires:  mysql

%description
REDACTED

%prep
%setup -q -n %{name}-%{version}

%install
rm -rf $RPM_BUILD_ROOT

%{__install} -d %{buildroot}%{__django_root}/conf.d
%{__install} -d %{buildroot}%{__django_root}/cron/daily
%{__install} -d %{buildroot}%{__django_root}/cron/hourly
%{__install} -d %{buildroot}%{__django_root}/%{name}/ve
%{__install} -d %{buildroot}%{__django_root}/%{name}/current_settings
%{__install} -d %{buildroot}%{__django_root}/html/static

#virtualenv
virtualenv-2.6 --no-site-packages %{buildroot}%{__django_root}/%{name}/ve
source  %{buildroot}%{__django_root}/%{name}/ve/bin/activate
pip install -r %{__requirements}
virtualenv-2.6 --relocatable %{buildroot}%{__django_root}/%{name}/ve
deactivate


# Put the settings file into current_settings and add the symlink we will want when installed.
%{__install} -m 664 %{buildroot}%{__django_root}/%{name}/ve/src/%{__pip_package}/%{__configdir}/settings/settings.py %{buildroot}%{__django_root}/%{name}/current_settings/settings.py
rm -f %{__django_root}/%{name}/current_settings/settings.py
ln -sf %{__django_root}/%{name}/current_settings/settings.py %{buildroot}%{__django_root}/%{name}/ve/src/%{__pip_package}/directory/settings/settings.py

#fix the wrong paths in easy_install.pth
perl -p -i -e "s#$RPM_BUILD_ROOT##g" %{buildroot}%{__django_root}/%{name}/ve/lib/%{__python_ver}/site-packages/easy-install.pth
#fix the wrong paths in activate
perl -p -i -e "s#$RPM_BUILD_ROOT##g" %{buildroot}%{__django_root}/%{name}/ve/bin/activate*

# The Linux build hosts we use have recently become persnickety about references to the build root in deployed files.
# egg-links and *.so files in our site-packages folder have this problem:
# THIS IS COMMENTED OUT BECAUSE IT CORRUPTS THE *.so FILES.
#find %{buildroot} -name "*.egg-link" -o -name "*.so" -o -name "*.txt" | xargs perl -p -i -e "s{\Q$RPM_BUILD_ROOT\E}{}g"

# The Linux build slaves we use are persnickety about rpaths in libraries pointing to directories that don't exist.
# So we use chrpath to purge them.
chrpath --delete %{buildroot}REDACTED/ve/lib/python2.6/site-packages/_ldap.so

# Un prelink everything
# http://www.alexhudson.com/2013/05/24/packaging-a-virtualenv-really-not-relocatable/
find %{buildroot}%{__django_root}/%{name}/ve -type f -perm /u+x,g+x -exec /usr/sbin/prelink -u {} \;
# re-point the lib64 symlink - not needed on newer virtualenv
if test -d %{buildroot}%{__django_root}/%{name}/ve/lib64; then
  rm %{buildroot}%{__django_root}/%{name}/ve/lib64
  ln -sf %{__django_root}/%{name}/ve/lib %{buildroot}%{__django_root}/%{name}/ve/lib64
fi


%clean
rm -rf $RPM_BUILD_ROOT

%preun
if [ $1 -eq 0 ]; then
    rm -rf %{__django_root}/%{name}/html
    rm -rf %{__django_root}/whoosh
fi

%files
%defattr(-,root,root,-)
# Prevent RPM from deleting our manually edited settings files during upgrade.
%config(noreplace) %attr(660,apache,apache) %{__django_root}/conf.d/%{name}_apache.conf
%config(noreplace) %attr(660,apache,apache) %{__django_root}/%{name}/current_settings/settings.py
%attr(775,apache,apache) %{__django_root}/%{name}/html/static
%{__django_root}/%{name}/ve
%{__django_root}/%{name}/current_settings

答案1

虽然我无法给出关于如何解决你的问题的权威答案,因为我对这个包装问题也很陌生,但我确实想为未来的读者提供一条帮助我解决此类问题的线索。

在构建配置阶段,我认为最好使用该工具的 PREFIX 将安装目录设置为 /path/to/buildroot/

这导致了 check-buildroot 在构建文件内查找路径时出现同样的问题。

对我有帮助的是使用 PREFIX=/ 进行设置,以便文件通过检查,然后使用DESTDIR=/path/to/buildroot make install,将文件放到适当的位置。

这可能就是您想要研究的内容。构建项目/库,就像您要正常安装它一样,并且仅在稍后阶段使用您各自的构建/安装系统提供的任何方法执行到 rpm buildroot 的重定位。

相关内容