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

Support for building rpms on the fly #193

Closed
Lunarequest opened this issue Nov 9, 2023 · 6 comments
Closed

Support for building rpms on the fly #193

Lunarequest opened this issue Nov 9, 2023 · 6 comments

Comments

@Lunarequest
Copy link
Contributor

Currently I'm working on a tool that generates rpms from yaml part of the issue is that I will never know the files in the final rpm until the build is completed. Currently with PackageBuilder does not implement Copy which means it's impossible to generate a rpm on the fly using a loop. the old package rpm-rs while having a clunkier interface supported this. the two solutions i can see are

a) add the copy trait to PackageBuilder, this may cause issues we can not foresee.
b) implement a .with_files which takes a vec of tuples with (source, options)

@dralley
Copy link
Collaborator

dralley commented Nov 12, 2023

the old package rpm-rs while having a clunkier interface supported this

Where was that the case? The interface is mostly unchanged

@Lunarequest
Copy link
Contributor Author

the old package rpm-rs while having a clunkier interface supported this

Where was that the case? The interface is mostly unchanged

here is some code using the old RPMBuilder api, https://github.com/Lunarequest/sddm2rpm/blob/mistress/src/rpm_build.rs#L43-L55 it was possible to iterate over and add files to the rpm. which the new Packagebuild this isn't possible

@dralley
Copy link
Collaborator

dralley commented Nov 13, 2023

It's possible in exactly the same way though? This code (copied from your example & slightly simplified / corrected for new idioms) compiles and executes fine

use rpm;
use std::env;
use std::path::Path;
use std::process::exit;
use walkdir;

fn main() {
    let mut pkg = rpm::PackageBuilder::new(
        "test",
        "0.0.1",
        "GPLv2",
        "noarch",
        "autogenrated sddm theme rpm",
    )
    .compression(rpm::CompressionType::Zstd)
    .requires(rpm::Dependency::any("sddm"));

    let info = "suse";
    if info.contains("suse") {
        pkg = pkg.requires(rpm::Dependency::any("kf5-plasma"))
            .requires(rpm::Dependency::any("libqt5-qtquickcontrols"))
            .requires(rpm::Dependency::any("libqt5-qtvirtualkeyboard"));
    } else if info.contains("Fedora Linux") {
        pkg = pkg.requires(rpm::Dependency::any("libKF5Plasma5"))
            .requires(rpm::Dependency::any("qt5-qtquickcontrols"))
            .requires(rpm::Dependency::any("desktop-backgrounds-compat"));
    } else {
        eprintln!("unsupported distro falling back to common package names\nNote: this may not be all dependencies");
    }

    for entry in walkdir::WalkDir::new("./src/")
        .into_iter()
        .filter_map(|e| e.ok())
    {
        let file = entry.path();
        if Path::new(&file.as_os_str()).is_file() {
            let dest = file
                .to_string_lossy()
                .replace("./", "/usr/share/sddm/themes/");
            let options = rpm::FileOptions::new(dest);
            pkg = pkg.with_file(file, options).expect("Error");
        }
    }
    let package = pkg.build().unwrap();
    let name = "test";
    let mut f = std::fs::File::create(format!("{}.rpm", name)).unwrap();
    match package.write(&mut f) {
        Ok(()) => println!("created {name}.rpm"),
        Err(e) => {
            eprintln!("Failed to synathsize rpm {e}");
            exit(1);
        }
    };
}

Don't close your PR because it may still be a worthwhile addition, but I'm not sure any aspect of this is currently impossible?

@Lunarequest
Copy link
Contributor Author

Thats strange rust was refusing to allow this in another project saying PackageBuilder does not implement copy

@dralley
Copy link
Collaborator

dralley commented Nov 13, 2023

Maybe the issue is that pkg wasn't marked mutable and/or maybe it was attempting to be assigned to a new not-pkg variable.

@dralley
Copy link
Collaborator

dralley commented Nov 13, 2023

Closing the issue. The PR is still valid though, as mentioned before.

@dralley dralley closed this as completed Nov 13, 2023
@dralley dralley closed this as not planned Won't fix, can't repro, duplicate, stale Nov 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants