Greetings,
I recently implemented generators for Hare modules (provides and requires so far) and my current work in progress does what it says on the tin. However, trying to answer the question "what if the package installs garbage" I was not able to fail a package build with the dependency generators.
I made the scripts end with something written to stderr followed by an explicit "exit 1", and I can see the error message, but then it just succeeds. So my question is how to make RPM register that a dependency generator failed and in turn fail the build?
Bear with me, this is only work in progress and I already started to iron out a few kinks, and I have more to address, but I haven't touched my COPR repositories after reaching the first "it works" milestone, so don't look at the kinks.
You can grab the sources from here:
https://copr-dist-git.fedorainfracloud.org/cgit/dridi/harelang/hare.git/tree...
And on my system I use the following command to build packages with automatic dependencies:
rm -rf results_hare/ && fedpkg mockbuild --with bootstrap && mock --install results_hare/*/*/hare-rpm-macros-*.rpm && rm -rf results_hare/ && fedpkg mockbuild --no-clean
(I broke it down line by line for legibility. If there is a handy all-in-one command for a bootstrapped build followed by a regular build in fedpkg, I didn't find it and I'm interested.)
My default mock root points to rawhide. It takes a couple minutes to complete, at which point I can observe virtual provides for Hare modules:
$ rpm -qpP results_hare/*/*/hare-stdlib-*.rpm | tail hare(unix) = 0.24.2-1.fc42 hare(unix::hosts) = 0.24.2-1.fc42 hare(unix::passwd) = 0.24.2-1.fc42 hare(unix::poll) = 0.24.2-1.fc42 hare(unix::resolvconf) = 0.24.2-1.fc42 hare(unix::signal) = 0.24.2-1.fc42 hare(unix::tty) = 0.24.2-1.fc42 hare(uuid) = 0.24.2-1.fc42 hare(wordexp) = 0.24.2-1.fc42 hare-stdlib = 0.24.2-1.fc42
Like I said, if the hare.prov and hare.req script fail, the build happily completes. I thought of using a burp script but those look pretty arcane and I couldn't easily find a doc reference explaining how to work with them (they look essentially ad-hoc).
How do I get rpmdeps to propagate the exit status of the scripts?
Thanks, Dridi
I made the scripts end with something written to stderr followed by an explicit "exit 1", and I can see the error message, but then it just succeeds. So my question is how to make RPM register that a dependency generator failed and in turn fail the build?
I tried following the rpmdeps code but I gave up after one indirection too many. I'm unfortunately unfamiliar with the RPM code base. I also tried to use the %error macro using parametric macros for my generators. I was able to get an error message but it wouldn't fail the build either. Eventually, I accidentally found a nasty dirty trick to fail the build:
echo '!error: something went wrong!'
In the logs I get this:
RPM build errors: Dependency tokens must begin with alpha-numeric, '_' or '/': !error: something went wrong!
I can't say I'm proud of this hack but at least, the error message shows up to give a clue. I can finally add some error handling to my dependency generators.
Cheers, Dridi
On Sun, Sep 1, 2024 at 5:31 PM Dridi Boukelmoune dridi.boukelmoune@gmail.com wrote:
I made the scripts end with something written to stderr followed by an explicit "exit 1", and I can see the error message, but then it just succeeds. So my question is how to make RPM register that a dependency generator failed and in turn fail the build?
I tried following the rpmdeps code but I gave up after one indirection too many. I'm unfortunately unfamiliar with the RPM code base. I also tried to use the %error macro using parametric macros for my generators. I was able to get an error message but it wouldn't fail the build either. Eventually, I accidentally found a nasty dirty trick to fail the build:
echo '!error: something went wrong!'
In the logs I get this:
RPM build errors: Dependency tokens must begin with alpha-numeric, '_' or '/': !error: something went wrong!
I can't say I'm proud of this hack but at least, the error message shows up to give a clue. I can finally add some error handling to my dependency generators.
Yes, currently the exit code is ignored, and the only way to break the build is to generate a line that does not parse as a valid RPM dependency.
The Rust dependency generator does something similar, and the Python generator does too, AFAIK.
Fabio
I can't say I'm proud of this hack but at least, the error message shows up to give a clue. I can finally add some error handling to my dependency generators.
Yes, currently the exit code is ignored, and the only way to break the build is to generate a line that does not parse as a valid RPM dependency.
The Rust dependency generator does something similar, and the Python generator does too, AFAIK.
And with that, I'm no longer feeling guilty, thanks!
Dridi
On Sun, Sep 1, 2024 at 9:40 PM Dridi Boukelmoune dridi.boukelmoune@gmail.com wrote:
I can't say I'm proud of this hack but at least, the error message shows up to give a clue. I can finally add some error handling to my dependency generators.
Yes, currently the exit code is ignored, and the only way to break the build is to generate a line that does not parse as a valid RPM dependency.
The Rust dependency generator does something similar, and the Python generator does too, AFAIK.
And with that, I'm no longer feeling guilty, thanks!
And I found prior art to follow:
https://pagure.io/fedora-rust/cargo2rpm/blob/0dc93154e0cb9c27d9f255223c5b89c...
Thanks again!
On Sun, Sep 01, 2024 at 09:54:38PM +0000, Dridi Boukelmoune wrote:
On Sun, Sep 1, 2024 at 9:40 PM Dridi Boukelmoune dridi.boukelmoune@gmail.com wrote:
I can't say I'm proud of this hack but at least, the error message shows up to give a clue. I can finally add some error handling to my dependency generators.
Yes, currently the exit code is ignored, and the only way to break the build is to generate a line that does not parse as a valid RPM dependency.
The Rust dependency generator does something similar, and the Python generator does too, AFAIK.
And with that, I'm no longer feeling guilty, thanks!
And I found prior art to follow:
https://pagure.io/fedora-rust/cargo2rpm/blob/0dc93154e0cb9c27d9f255223c5b89c...
Here are a few more dependency generators that have been in use for years that you might take inspiration from:
https://src.fedoraproject.org/rpms/nbdkit/blob/rawhide/f/nbdkit-find-provide... https://src.fedoraproject.org/rpms/nbdkit/blob/rawhide/f/nbdkit.attr
https://src.fedoraproject.org/rpms/supermin/blob/rawhide/f/supermin-find-req... https://src.fedoraproject.org/rpms/supermin/blob/rawhide/f/supermin.attr
https://github.com/rpm-software-management/rpm/blob/master/scripts/ocamldeps... https://github.com/rpm-software-management/rpm/blob/master/fileattrs/ocaml.a...
I do see a few 'exit 1' in those :-(
Rich.
On Tue, Sep 3, 2024 at 1:50 PM Richard W.M. Jones rjones@redhat.com wrote:
On Sun, Sep 01, 2024 at 09:54:38PM +0000, Dridi Boukelmoune wrote:
On Sun, Sep 1, 2024 at 9:40 PM Dridi Boukelmoune dridi.boukelmoune@gmail.com wrote:
I can't say I'm proud of this hack but at least, the error message shows up to give a clue. I can finally add some error handling to my dependency generators.
Yes, currently the exit code is ignored, and the only way to break the build is to generate a line that does not parse as a valid RPM dependency.
The Rust dependency generator does something similar, and the Python generator does too, AFAIK.
And with that, I'm no longer feeling guilty, thanks!
And I found prior art to follow:
https://pagure.io/fedora-rust/cargo2rpm/blob/0dc93154e0cb9c27d9f255223c5b89c...
Here are a few more dependency generators that have been in use for years that you might take inspiration from:
https://src.fedoraproject.org/rpms/nbdkit/blob/rawhide/f/nbdkit-find-provide... https://src.fedoraproject.org/rpms/nbdkit/blob/rawhide/f/nbdkit.attr
https://src.fedoraproject.org/rpms/supermin/blob/rawhide/f/supermin-find-req... https://src.fedoraproject.org/rpms/supermin/blob/rawhide/f/supermin.attr
https://github.com/rpm-software-management/rpm/blob/master/scripts/ocamldeps... https://github.com/rpm-software-management/rpm/blob/master/fileattrs/ocaml.a...
Thanks!
I do see a few 'exit 1' in those :-(
I will have a look and open tickets if appropriate. Not sure when, I will soon run out of a big chunk of spare time.
Dridi