Expose more from treefile via cxx-rs; adapt _install_langs to use it

We only honor `_install_langs` in the compose path, so move the
code to look at the treefile and move the string concatention to
Rust.
This commit is contained in:
Colin Walters 2021-04-16 16:47:22 -04:00
parent f2bc1d86ef
commit a015fb345f
3 changed files with 35 additions and 16 deletions

View File

@ -255,6 +255,11 @@ pub mod ffi {
fn get_ostree_override_layers(&self) -> Vec<String>;
fn get_all_ostree_layers(&self) -> Vec<String>;
fn get_repos(&self) -> Vec<String>;
fn get_packages(&self) -> Vec<String>;
fn get_exclude_packages(&self) -> Vec<String>;
fn get_install_langs(&self) -> Vec<String>;
fn format_install_langs_macro(&self) -> String;
fn get_lockfile_repos(&self) -> Vec<String>;
fn get_ref(&self) -> &str;
fn get_rojig_spec_path(&self) -> String;
fn get_rojig_name(&self) -> String;

View File

@ -537,10 +537,36 @@ impl Treefile {
.collect()
}
pub(crate) fn get_packages(&self) -> Vec<String> {
self.parsed.packages.clone().unwrap_or_default()
}
pub(crate) fn get_exclude_packages(&self) -> Vec<String> {
self.parsed.exclude_packages.clone().unwrap_or_default()
}
pub(crate) fn get_install_langs(&self) -> Vec<String> {
self.parsed.install_langs.clone().unwrap_or_default()
}
/// If install_langs is set, generate a value suitable for the RPM macro `_install_langs`;
/// otherwise return the empty string.
pub(crate) fn format_install_langs_macro(&self) -> String {
if let Some(langs) = self.parsed.install_langs.as_ref() {
langs.join(":")
} else {
"".to_string()
}
}
pub(crate) fn get_repos(&self) -> Vec<String> {
self.parsed.repos.clone().unwrap_or_default()
}
pub(crate) fn get_lockfile_repos(&self) -> Vec<String> {
self.parsed.lockfile_repos.clone().unwrap_or_default()
}
pub(crate) fn get_ref(&self) -> &str {
self.parsed.treeref.as_deref().unwrap_or_default()
}

View File

@ -693,7 +693,6 @@ rpmostree_context_setup (RpmOstreeContext *self,
GError **error)
{
std::string releasever;
g_autofree char **instlangs = NULL;
/* This exists (as a canonically empty dir) at least on RHEL7+ */
static const char emptydir_path[] = "/usr/share/empty";
@ -726,22 +725,11 @@ rpmostree_context_setup (RpmOstreeContext *self,
/* Set the RPM _install_langs macro, which gets processed by librpm; this is
* currently only referenced in the traditional or non-"unified core" code.
*/
if (g_variant_dict_lookup (self->spec->dict, "instlangs", "^a&s", &instlangs))
if (!self->is_system && self->treefile_rs)
{
g_autoptr(GString) opt = g_string_new ("");
gboolean first = TRUE;
for (char **iter = instlangs; iter && *iter; iter++)
{
const char *v = *iter;
if (!first)
g_string_append_c (opt, ':');
else
first = FALSE;
g_string_append (opt, v);
}
dnf_context_set_rpm_macro (self->dnfctx, "_install_langs", opt->str);
auto instlangs = self->treefile_rs->format_install_langs_macro();
if (instlangs.length() > 0)
dnf_context_set_rpm_macro (self->dnfctx, "_install_langs", instlangs.c_str());
}
/* This is what we use as default. Note we should be able to drop this in the