Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The debuginfo machinery breaks if %install follows directly after %prep or preamble #1870

Closed
eclipseo opened this issue Dec 20, 2021 · 17 comments
Assignees

Comments

@eclipseo
Copy link

Hi,

When building noarch subpackages, adding a section %generate_buildrequires will trigger the search for the debuginfo data. It should not.

Mail ref:

Yes I know, but not in this case as go libraries are noarch.
The problem that when we add the %generate_buildrequires section, it triggers the detection of the debug info. Without it, the detection of debug info is skipped so the package builds normally. I don't know what is the expected behavior.

Okay, this wasn't quite so clear in the initial context. %generate_buildrequires should not trigger the debuginfo machinery, that's a bug of some sort. Please file a ticket at https://github.com/rpm-software-management/rpm

- Panu -
@ffesti ffesti self-assigned this Dec 23, 2021
@pmatilai pmatilai added this to RPM Jun 21, 2022
@pmatilai pmatilai moved this to Backlog in RPM Jun 21, 2022
@eclipseo
Copy link
Author

Slight tiny bump.
Any info on the source of this issue?

@pmatilai pmatilai moved this from Backlog to Todo in RPM Jun 29, 2022
@ffesti
Copy link
Contributor

ffesti commented Jul 11, 2022

Do you have a link to an example?

@gotmax23
Copy link
Contributor

@ffesti, you can look at https://src.fedoraproject.org/rpms/golang-x-net/blob/rawhide/f/golang-x-net.spec. It only has one noarch subpackage. (%gopkg generates the subpackage definitions). When using static BuildRequires it builds fine, but when using %generate_buildrequires it fails with error: Empty %files file debugfiles.list and requires %global debug_package %{nil}. You can use go2rpm -f https://github.com/golang/net --commit 0bcc04d9c69b4e379010f97e15bb7751dc57156b -R golang.org/x/net to generate the same specfile as linked above but with static BuildRequires.

@pmatilai pmatilai added the bug label Aug 22, 2022
@pmatilai
Copy link
Member

Oh, this one's rather special.

Debuginfo processing triggers when two conditions are met: the package is not a noarch package, and there is no %build section. For whatever reason, the main package here is arch specific instead of noarch, and so the first condition is met (noarch sub-packages are a wacko special case in rpm and do not count for this purpose at all). That package has no %build section at all, and that is how it avoids the debuginfo machinery in the first place, but apparently %generate_buildrequires counts as a "build script" for the purposes of that check. Maybe there's a fallthrough switch-case someplace, dunno. But that does indeed seem like a clear-cut bug.

@ffesti ffesti moved this from Todo to In Progress in RPM Aug 23, 2022
@pmatilai
Copy link
Member

pmatilai commented Sep 26, 2022

Ehm, scratch the above, the debuginfo stuff is hooked on %install, not %build. Sorry for the misleading comment.

This seems one of those "spec specials", really. It's probably some interplay between how the spec parser works and expands macros and sections - if you move the %generate_buildrequires section before %prep in the golang-x-net.spec case, the phenomenon disappears.

@pmatilai
Copy link
Member

pmatilai commented Sep 26, 2022

Yup. The reason I remembered debuginfo depending on %build section is easily demonstrated with the golang example too (after removing the line to disable debuginfo):

  1. move %generate_buildrequires before %prep, debuginfo disappears
  2. add (an empty) %build section between %prep and %install, and debuginfo reappears
  3. remove the empty %build section, debuginfo disappears
  4. move the %check section before %install, debuginfo reappears

So the ugly hack of debuginfo enabling (see #2204) relies on some rather subtle spec parser quirks, and does not work after %prep because that's processed differently from other sections, ditto for preamble.

And as noted, this is an arch-specific package so debuginfo should be generated for it, unless disabled. But I guess debug extraction still doesn't work for golang (?) so disabling it for this is the right thing to do, regardless of all the weird stuff that the spec parser is throwing at you.

This is one weird ticket 😆

@ffesti
Copy link
Contributor

ffesti commented Sep 26, 2022

OK, I think I have an idea what's wrong here:

If %install is encountered after/as part of %prep debuginfo does not work. The reason is that %prep is first parsed and %setup - which is setting %buildsubdir - is only executed after the whole %prep section is processed and all macros are expanded.
As a result %buildsubdir is not yet set when %install is encountered and expanded into the debuginfo magic. But the debuginfo foo checks for %buildsubdir as it probably needs that.

So, %generate_buildrequires is an innocent bystander here and the golang-x-net package relied on the broken behavior to "switch off" debuginfo creation.

Two things are to fix here:

@gotmax23
Copy link
Contributor

Golang library packages often don't ship any go binaries and thus no arched (sub)packages, but they're built on all arches to ensure that the tests pass everywhere and that the noarch -devel subpackage does not contain different contents when built on different architectures. Rust libraries work similarly and also have to disable debuginfo like this. For Go application packages (e.g. hugo or containerd) that build binaries and thus ship arched RPMs, debuginfo extraction works just fine. There's just nothing to extract if no bianries are built.

@ffesti ffesti changed the title %generate_buildrequires should not trigger the debuginfo machinery The debuginfo machinery breaks if %install follows directly after %prep Sep 26, 2022
@ffesti
Copy link
Contributor

ffesti commented Sep 26, 2022

I wonder if adding %end to the %install macro fixes the issue. The %end would be useful for once...

@gotmax23
Copy link
Contributor

What does %end do?

@ffesti
Copy link
Contributor

ffesti commented Sep 26, 2022

It closes a section. So it would end the %prep section. Idea is that the debuginfo magic wold then be evaluated after the prep section. Basically the same as if there was another section inbetween.

@pmatilai pmatilai changed the title The debuginfo machinery breaks if %install follows directly after %prep The debuginfo machinery breaks if %install follows directly after %prep or preamble Sep 27, 2022
@pmatilai
Copy link
Member

Adding %end works for terminating %prep, but it doesn't help %install following the preamble.
The proper fix for this is to eliminate the %install override macro hack.

@ffesti
Copy link
Contributor

ffesti commented Sep 27, 2022

Well, %install following the preamble is technically a different issue. %prep is setting %buildsubdir via %setup and everything that makes use of that needs to be after %prep. This is not limited to the debuginfo magic - although it is especially non-obvious there.

@pmatilai
Copy link
Member

Oh, I forgot that %buildsubdir dependency, which what explains not working before %prep. Tricksy 😄

And @gotmax23 - that Golang (and others) do not have debuginfo is yet another, separate matter. Like said, for now the right thing to do is to explicitly disable the debuginfo package in the spec for such cases.

@gotmax23
Copy link
Contributor

gotmax23 commented Sep 27, 2022

And @gotmax23 - that Golang (and others) do not have debuginfo is yet another, separate matter. Like said, for now the right thing to do is to explicitly disable the debuginfo package in the spec for such cases

Go binaries do have debuginfo. Go libraries are just source code, i.e. text files.

@pmatilai
Copy link
Member

Well, those that do have no problem. Those that don't, should be "BuildArch: noarch" in the main package and no debuginfo will be attempted on them. Sub-package level noarch is a special case to allow shared noarch content in an otherwise arch dependent package. The golang package abuses that for it's own reasons (I'm sure there are some) at the cost of requiring packages to disable debuginfo manually.

@pmatilai pmatilai moved this from In Progress to Todo in RPM May 5, 2023
@ffesti ffesti removed their assignment Oct 25, 2023
@pmatilai pmatilai self-assigned this Oct 25, 2023
@pmatilai
Copy link
Member

Fixed by #2730

And no, don't ask for backports (see the part about sacrifices in the PR). This will only be in rpm >= 4.20.

@github-project-automation github-project-automation bot moved this from Todo to Done in RPM Oct 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

No branches or pull requests

4 participants