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

builddep: add support for remote arguments #1874

Merged
merged 1 commit into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions dnf5-plugins/builddep_plugin/builddep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.
#include "builddep.hpp"

#include "utils/string.hpp"
#include "utils/url.hpp"

#include "libdnf5/repo/file_downloader.hpp"

#include <dnf5/shared_options.hpp>
#include <libdnf5-cli/exception.hpp>
Expand Down Expand Up @@ -136,19 +139,35 @@ void BuildDepCommand::parse_builddep_specs(int specs_count, const char * const s
const std::string_view ext_srpm(".src.rpm");
const std::string_view ext_nosrpm(".nosrc.rpm");
std::set<std::string> unique_items;
libdnf5::repo::FileDownloader downloader(get_context().get_base());
for (int i = 0; i < specs_count; ++i) {
const std::string_view spec(specs[i]);
// Remote specs are downloaded to temp files which have random suffix.
// They cannot be used to compare extensions.
std::string spec_location(specs[i]);
if (auto [it, inserted] = unique_items.emplace(spec); inserted) {
// TODO(mblaha): download remote URLs to temporary location + remove them afterwards
if (libdnf5::utils::url::is_url(spec_location)) {
if (spec_location.starts_with("file://")) {
spec_location = spec_location.substr(7);
} else {
// Download remote argument
downloaded_remotes.push_back(std::make_unique<libdnf5::utils::fs::TempFile>(
std::filesystem::path(spec_location).filename()));
downloader.add(specs[i], downloaded_remotes.back()->get_path());
spec_location = downloaded_remotes.back()->get_path();
}
}

if (spec.ends_with(ext_spec)) {
spec_file_paths.emplace_back(spec);
spec_file_paths.emplace_back(std::move(spec_location));
} else if (spec.ends_with(ext_srpm) || spec.ends_with(ext_nosrpm)) {
srpm_file_paths.emplace_back(spec);
srpm_file_paths.emplace_back(std::move(spec_location));
} else {
pkg_specs.emplace_back(spec);
pkg_specs.emplace_back(std::move(spec_location));
}
}
}
downloader.download();
}

bool BuildDepCommand::add_from_spec_file(
Expand Down
5 changes: 5 additions & 0 deletions dnf5-plugins/builddep_plugin/builddep.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.
#define DNF5_COMMANDS_BUILD_DEP_BUILD_DEP_HPP


#include "libdnf5/utils/fs/temp.hpp"

#include <dnf5/context.hpp>
#include <dnf5/shared_options.hpp>
#include <libdnf5/conf/option_bool.hpp>
Expand Down Expand Up @@ -55,6 +57,9 @@ class BuildDepCommand : public Command {
std::vector<std::string> srpm_file_paths{};
std::vector<std::pair<std::string, std::string>> rpm_macros{};

// Args downloaded into temp files which are automatically cleaned up
std::vector<std::unique_ptr<libdnf5::utils::fs::TempFile>> downloaded_remotes{};

std::unique_ptr<AllowErasingOption> allow_erasing;
};

Expand Down
Loading