【问题标题】:How to build a debuginfo RPM without source code?如何在没有源代码的情况下构建 debuginfo RPM?
【发布时间】:2015-03-15 11:20:52
【问题描述】:

我正在使用专有代码库,所有者希望用户获得有用的堆栈跟踪但无法查看源代码。生成带有调试符号但没有源代码的 Debian dbg 软件包很简单,但 Redhat debuginfo RPM 是使用源代码自动创建的。

有没有办法配置 rpmbuild 来构建一个没有源代码的 debuginfo RPM?

如果不是,从 debuginfo 包中删除源代码的最佳方法是什么?有人有脚本吗?

【问题讨论】:

  • 即使在spec文件中设置nosource标签也会出现这种情况吗?
  • 是的,即使使用 nosource 标签也会发生这种情况。似乎 nosource 仅适用于源 RPM,而不适用于调试信息。我研究了 /usr/lib/rpm/find-debuginfo.sh 脚本,它似乎确定了直接从生成的 .so 文件中包含哪些源。但是感谢您的建议 - 我没想过尝试。

标签: packages rpm debug-symbols rpmbuild


【解决方案1】:

-debuginfo 包只是一个子包,可以在没有源代码的情况下手动创建。自动生成将必要的语法添加到规范文件中,但您也可以手动执行此操作,在规范文件中添加调试信息包。

禁用*-debuginfo.rpm 的自动生成,在%install 末尾运行find-debuginfo.sh,然后删除源文件。

另一种(更简单/更干净)的方法是删除源文件会覆盖此宏

%__debug_install_post   \
   %{_rpmconfigdir}/find-debuginfo.sh %{?_missing_build_ids_terminate_build:--strict-build-id} %{?_find_debuginfo_opts} "%{_builddir}/%{?buildsubdir}"\
%{nil}

在规范文件中,将%{_rpmconfigdir}/find-debuginfo.sh 替换为修改/自定义的find-debuginfo.sh 脚本。

在规范文件中包含修改后的脚本

SourceN: my-find-debuginfo.sh

然后使用宏

%{SOURCEn}

(其中N == n,一些适当的小整数)而不是默认生成调试符号而无需源代码。

【讨论】:

    【解决方案2】:

    刚刚完成了一轮测试,最后我们将以下内容插入到 .spec 文件中的 %description 标签上方:

    # Override the macro that invokes find-debuginfo.sh to remove
    # the source files before the debuginfo pkg is assembled.
    # It would be nice to remove the entire /usr/src tree but
    # rpmbuild is running a check-files utility that fails the
    # build if /usr/src/debug/%{name} isn't there.  Tried to
    # just delete the contents but it's tricky getting an
    # asterisk to expand properly so we remove the entire
    # directory and then restore an empty one.  Sigh!
    %define __debug_install_post   \
       %{_rpmconfigdir}/find-debuginfo.sh %{?_missing_build_ids_terminate_build:--strict-build-id} %{?_find_debuginfo_opts} "%{_builddir}/%{?buildsubdir}";\
       rm -rf "${RPM_BUILD_ROOT}/usr/src/debug/%{name}"; \
       mkdir "${RPM_BUILD_ROOT}/usr/src/debug/%{name}"; \
    %{nil}
    

    这适用于 RHEl 6 和 7,但会导致 RHEl 5 中的 bash 错误,因此我们通过不安装 redhat-rpm-config 包来避免为后者构建 debuginfo 包。

    我们决定避免按照建议创建修改后的 find-debuginfo.sh 脚本,因为不同平台之间已经存在差异,我们更喜欢一个适用于所有目标的单一补丁,包括未来的新目标。这并不完美,但与我们想出的一样接近。

    【讨论】:

      【解决方案3】:

      CentOS 7 需要对 Guy 的解决方案稍作修改。这是我成功使用的:

      # Remove source code from debuginfo package.
      %define __debug_install_post \
        %{_rpmconfigdir}/find-debuginfo.sh %{?_missing_build_ids_terminate_build:--strict-build-id} %{?_find_debuginfo_opts} "%{_builddir}/%{?buildsubdir}"; \
        rm -rf "${RPM_BUILD_ROOT}/usr/src/debug"; \
        mkdir -p "${RPM_BUILD_ROOT}/usr/src/debug/%{name}-%{version}"; \
      %{nil}
      

      以下可用于验证源代码不再包含在 RPM 中:

      rpm -qpl xxx-debuginfo-1.0.0-1.el7.x86_64.rpm
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-01-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多