-
Notifications
You must be signed in to change notification settings - Fork 14
contrib/packaging: New spec file #109
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces a new RPM spec file for bcvk and significantly refactors the xtask packaging logic to support generating source tarballs and SRPMs. The changes are well-structured and mirror practices from the bootc project. My review focuses on the new Rust code in xtask. I've found a critical issue in the SRPM generation logic that would prevent it from working correctly, along with a few medium-severity issues related to robustness and efficiency. The suggestions aim to fix the bug and improve the code quality.
crates/xtask/src/xtask.rs
Outdated
| let config = config.as_table_mut().unwrap(); | ||
| let source_table = config.get_mut("source").unwrap(); | ||
| let source_table = source_table.as_table_mut().unwrap(); | ||
| let vendored_sources = source_table.get_mut("vendored-sources").unwrap(); | ||
| let vendored_sources = vendored_sources.as_table_mut().unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This chain of unwrap() calls is brittle and will cause a panic if the structure of the cargo-vendor-filterer output TOML changes. While this is an internal build script, it's better to handle this gracefully with proper error handling. Consider using and_then or ? with ok_or_else to provide more informative error messages.
| let config = config.as_table_mut().unwrap(); | |
| let source_table = config.get_mut("source").unwrap(); | |
| let source_table = source_table.as_table_mut().unwrap(); | |
| let vendored_sources = source_table.get_mut("vendored-sources").unwrap(); | |
| let vendored_sources = vendored_sources.as_table_mut().unwrap(); | |
| let vendored_sources = config | |
| .as_table_mut() | |
| .and_then(|c| c.get_mut("source")) | |
| .and_then(|s| s.as_table_mut()) | |
| .and_then(|s| s.get_mut("vendored-sources")) | |
| .and_then(|vs| vs.as_table_mut()) | |
| .ok_or_else(|| eyre!("malformed vendor config: missing [source.vendored-sources] table"))?; |
| // Add vendor config to source archive | ||
| cmd!(sh, "tar --owner=0 --group=0 --numeric-owner --sort=name --mtime=@{source_date_epoch} -rf {temp_tar} --transform='s|.*/.cargo-vendor-config.toml|bcvk-{version}/.cargo/vendor-config.toml|' {vendor_config_path}").run()?; | ||
| let p = Utf8Path::new("target"); | ||
| let pkg = impl_package(sh)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The impl_package() function, which can be time-consuming as it creates tarballs, is called inside both update_spec() (here) and impl_srpm() (line 259). This means that running separate xtasks like spec and package-srpm will cause the packaging process to run multiple times unnecessarily. Consider refactoring to call impl_package() once per high-level task and pass the resulting Package struct to the helper functions. This would improve efficiency and make the data flow clearer.
crates/xtask/src/xtask.rs
Outdated
| let pkg = impl_package(sh)?; | ||
| let td = tempfile::tempdir_in("target").context("Allocating tmpdir")?; | ||
| let td = td.keep(); | ||
| let td: &Utf8Path = td.as_path().try_into().unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The use of unwrap() here can cause a panic if the temporary directory path created by tempfile is not valid UTF-8. While unlikely on most systems, it's safer to handle this potential error explicitly by using ? and providing an error context.
| let td: &Utf8Path = td.as_path().try_into().unwrap(); | |
| let td: &Utf8Path = td.as_path().try_into().context("temporary directory path is not valid UTF-8")?; |
contrib/packaging/bcvk.spec
Outdated
|
|
||
| # Apache-2.0 OR MIT | ||
| License: Apache-2.0 OR MIT | ||
| URL: https://github.com/bootc-dev/bcvk.rpm |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
URL: https://github.com/bootc-dev/bcvk
The .rpm suffix is not needed
b5f70c6 to
ed68458
Compare
This mirrors exactly what we're doing in bootc, motivated by prep for shipping this in Fedora (including EPEL). Signed-off-by: Colin Walters <walters@verbum.org>
ed68458 to
6c2efa4
Compare
| fn package(sh: &Shell) -> Result<()> { | ||
| use std::env; | ||
| const NAME: &str = "bcvk"; | ||
| const TAR_REPRODUCIBLE_OPTS: &[&str] = &[ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We will probably want to figure out how to keep this code in sync with other repos going forward.
This mirrors exactly what we're doing in bootc, motivated by prep for shipping this in Fedora (including EPEL).