From c86e6c1fc578514d5c138ec9d256634b713cc45c Mon Sep 17 00:00:00 2001 From: bbhtt Date: Wed, 6 Aug 2025 08:16:30 +0530 Subject: [PATCH 1/2] builder-utils: Add a function to check appstream version requirements This could've been done with the libappstream API but since flatpak-builder has until now avoided linking to it, we continue the theme. It also matches the pattern in flatpak_version_check() The CLI output format has been stable for 8+ years, see [1] [2]. We prefer the library version incase of a mismatch as ultimately compose will run with the features offered by the library [1]: https://github.com/ximion/appstream/commit/d83174a4695e13ef41730c7a055b7e9b9077c211 [2]: https://github.com/ximion/appstream/blob/56ecd0067495213a64f3a490cbbc030fcfd5b8f1/tools/appstreamcli.c#L1594-L1604 --- src/builder-utils.c | 47 +++++++++++++++++++++++++++++++++++++++++++++ src/builder-utils.h | 4 ++++ 2 files changed, 51 insertions(+) diff --git a/src/builder-utils.c b/src/builder-utils.c index 7c838170..d1283128 100644 --- a/src/builder-utils.c +++ b/src/builder-utils.c @@ -1836,3 +1836,50 @@ flatpak_version_check (int major, return FALSE; } + +gboolean +appstream_version_check (int major, + int minor, + int micro) +{ + static int as_major = 0; + static int as_minor = 0; + static int as_micro = 0; + + if (as_major == 0 && + as_minor == 0 && + as_micro == 0) + { + const char * argv[] = { "appstreamcli", "--version", NULL }; + g_autoptr(GSubprocess) subp = NULL; + g_autofree char *out = NULL; + + subp = g_subprocess_newv (argv, G_SUBPROCESS_FLAGS_STDOUT_PIPE, NULL); + g_subprocess_communicate_utf8 (subp, NULL, NULL, &out, NULL, NULL); + + gchar **lines = g_strsplit (out, "\n", -1); + for (int i = 0; lines[i] != NULL; i++) + { + /* Only prefer library version over cli version in case of mismatch */ + if (g_str_has_prefix (lines[i], "AppStream library version:")) + { + if (sscanf (lines[i], "AppStream library version: %d.%d.%d", &as_major, &as_minor, &as_micro) == 3) + break; + } + else if (g_str_has_prefix (lines[i], "AppStream version:")) + { + if (sscanf (lines[i], "AppStream version: %d.%d.%d", &as_major, &as_minor, &as_micro) == 3) + break; + } + } + g_strfreev (lines); + + if (as_major == 0 && as_minor == 0 && as_micro == 0) + g_warning ("Failed to find appstream version"); + g_debug ("Found AppStream version %d.%d.%d", as_major, as_minor, as_micro); + } + + return (as_major > major) || + (as_major == major && as_minor > minor) || + (as_major == major && as_minor == minor && as_micro >= micro); +} diff --git a/src/builder-utils.h b/src/builder-utils.h index 05dfd839..6e2ebe52 100644 --- a/src/builder-utils.h +++ b/src/builder-utils.h @@ -216,6 +216,10 @@ gboolean flatpak_version_check (int major, int minor, int micro); +gboolean appstream_version_check (int major, + int minor, + int micro); + G_DEFINE_AUTOPTR_CLEANUP_FUNC (FlatpakXml, flatpak_xml_free); G_END_DECLS From fba37bf694c6d03af255a9e1f6e5ddbd5efc2bda Mon Sep 17 00:00:00 2001 From: bbhtt Date: Wed, 6 Aug 2025 08:18:12 +0530 Subject: [PATCH 2/2] builder-manifest: Run appstream-compose with no-partial-urls argument When 0.16.3 is available This is an alternative to https://github.com/flatpak/flatpak-builder/pull/576 We check at runtime instead of build-time and downgrade instead of erroring. Checking at build time is insufficient as there is no guarantee flatpak-builder is run with the same appstream version it was compiled with. Ideally we want to compose with `--no-partial-urls` so a warning is printed if it is not found. `--no-partial-urls` makes the mirrored URLs in appstream catalogue data the full URL. So if `--mirror-screenshot-url=https://example.org/media` and the metainfo has `https://github.com/foobar.png` After composing with `--no-partial-urls`, it will become https://example.org/media/foobar.png` instead of `/media/foobar.png`. This is needed by Flathub and generally should be a standard requirement for any software store (to have a full working URL instead of a partial whatever-that-is). --- src/builder-manifest.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/builder-manifest.c b/src/builder-manifest.c index 74d1074f..85e4a270 100644 --- a/src/builder-manifest.c +++ b/src/builder-manifest.c @@ -3056,9 +3056,16 @@ builder_manifest_cleanup (BuilderManifest *self, g_autofree char *arg_media_dir = g_strdup_printf ("--media-dir=%s", flatpak_file_get_path_cached (media_dir)); + gboolean has_no_partial_urls = appstream_version_check (0, 16, 3); + if (!has_no_partial_urls) + { + g_warning ("Found AppStream version < 0.16.3. Failed to add '--no-partial-urls' to compose"); + } + g_print ("Running appstreamcli compose\n"); g_print ("Saving screenshots in %s\n", flatpak_file_get_path_cached (media_dir)); if (!appstreamcli_compose (error, + has_no_partial_urls ? "--no-partial-urls" : NULL, "--prefix=/", origin, arg_base_url,