From 9563cfaeb7cb6ced0bbd44be8eb1bd44662eba8a Mon Sep 17 00:00:00 2001 From: Ludovico de Nittis <ludovico.denittis@collabora.com> Date: Thu, 8 Oct 2020 15:44:14 +0200 Subject: [PATCH] Add support for Arch Linux /etc/locale.gen Fixes #5 Signed-off-by: Ludovico de Nittis <ludovico.denittis@collabora.com> --- pressure-vessel/pressure-vessel-locale-gen | 6 +++- tests/locale.c | 40 ++++++++++++++++++++-- 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/pressure-vessel/pressure-vessel-locale-gen b/pressure-vessel/pressure-vessel-locale-gen index 55c18f98e..70822228d 100755 --- a/pressure-vessel/pressure-vessel-locale-gen +++ b/pressure-vessel/pressure-vessel-locale-gen @@ -46,11 +46,15 @@ fi # We currently only look for I18NDIR data in /usr/share/i18n, the # glibc default path. # +# Instead of just /usr/share/i18n/SUPPORTED, we also try to parse +# /etc/locale.gen because in some distributions, e.g. Arch Linux, +# /usr/share/i18n/SUPPORTED might not be present. +# # If we discover that some distros use a different default, then we # should enhance this script to iterate through a search path. # # Please keep this in sync with srt_system_info_get_locale_issues(). -SUPPORTED="/usr/share/i18n/SUPPORTED" +SUPPORTED="/etc/locale.gen /usr/share/i18n/SUPPORTED" log () { printf '%s\n' "$me: $*" >&2 diff --git a/tests/locale.c b/tests/locale.c index 27bdc2602..f1901356e 100644 --- a/tests/locale.c +++ b/tests/locale.c @@ -128,6 +128,22 @@ test_object (Fixture *f, g_object_unref (locale); } +static gboolean +is_host_os_like (SrtSystemInfo *info, + const gchar *host) +{ + g_auto(GStrv) os_like = NULL; + gsize i; + + os_like = srt_system_info_dup_os_id_like (info, TRUE); + for (i = 0; os_like != NULL && os_like[i] != NULL; i++) + { + if (g_strcmp0 (os_like[i], host) == 0) + return TRUE; + } + return FALSE; +} + static void test_complete (Fixture *f, gconstpointer context) @@ -135,13 +151,20 @@ test_complete (Fixture *f, SrtLocale *locale = NULL; SrtSystemInfo *info = srt_system_info_new (NULL); SrtLocaleIssues issues; + SrtLocaleIssues additional_issues = SRT_LOCALE_ISSUES_NONE; GError *error = NULL; + /* With Arch Linux it is expected to not have the SUPPORTED locale file */ + if (is_host_os_like (info, "arch")) + additional_issues = SRT_LOCALE_ISSUES_I18N_SUPPORTED_MISSING; + srt_system_info_set_primary_multiarch_tuple (info, "mock"); srt_system_info_set_helpers_path (info, f->builddir); issues = srt_system_info_get_locale_issues (info); - g_assert_cmpint (issues, ==, SRT_LOCALE_ISSUES_NONE); + g_assert_cmpint (issues, ==, + (SRT_LOCALE_ISSUES_NONE + | additional_issues)); locale = srt_system_info_check_locale (info, "C", &error); g_assert_no_error (error); @@ -222,15 +245,20 @@ test_legacy (Fixture *f, SrtLocale *locale = NULL; SrtSystemInfo *info = srt_system_info_new (NULL); SrtLocaleIssues issues; + SrtLocaleIssues additional_issues = SRT_LOCALE_ISSUES_NONE; GError *error = NULL; + if (is_host_os_like (info, "arch")) + additional_issues = SRT_LOCALE_ISSUES_I18N_SUPPORTED_MISSING; + srt_system_info_set_primary_multiarch_tuple (info, "mock-legacy"); srt_system_info_set_helpers_path (info, f->builddir); issues = srt_system_info_get_locale_issues (info); g_assert_cmpint (issues, ==, (SRT_LOCALE_ISSUES_DEFAULT_NOT_UTF8 - | SRT_LOCALE_ISSUES_C_UTF8_MISSING)); + | SRT_LOCALE_ISSUES_C_UTF8_MISSING + | additional_issues)); locale = srt_system_info_check_locale (info, "C", &error); g_assert_no_error (error); @@ -306,13 +334,19 @@ test_unamerican (Fixture *f, SrtLocale *locale = NULL; SrtSystemInfo *info = srt_system_info_new (NULL); SrtLocaleIssues issues; + SrtLocaleIssues additional_issues = SRT_LOCALE_ISSUES_NONE; GError *error = NULL; + if (is_host_os_like (info, "arch")) + additional_issues = SRT_LOCALE_ISSUES_I18N_SUPPORTED_MISSING; + srt_system_info_set_primary_multiarch_tuple (info, "mock-unamerican"); srt_system_info_set_helpers_path (info, f->builddir); issues = srt_system_info_get_locale_issues (info); - g_assert_cmpint (issues, ==, SRT_LOCALE_ISSUES_EN_US_UTF8_MISSING); + g_assert_cmpint (issues, ==, + (SRT_LOCALE_ISSUES_EN_US_UTF8_MISSING + | additional_issues)); locale = srt_system_info_check_locale (info, "C", &error); g_assert_no_error (error); -- GitLab