Skip to content
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
4 changes: 3 additions & 1 deletion doc/flatpak-builder.xml
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,9 @@
in the appstream xml to the specified URL. The resulting files
will be stored in the "screenshots" subdirectory in the app directory
for versions earlier than 1.3.4 and "files/share/app-info/media"
subdirectory for newer versions.
subdirectory for newer versions. Since version 1.4.5 this
will also create a screenshot ref in the exported OSTree
repo for each architecture containing the mirrored media.
</para></listitem>
</varlistentry>

Expand Down
85 changes: 85 additions & 0 deletions src/builder-main.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#include <glib/gi18n.h>
#include <gio/gio.h>
#include <ostree.h>
#include "libglnx.h"

#include "builder-flatpak-utils.h"
Expand Down Expand Up @@ -263,6 +264,80 @@ do_export (BuilderContext *build_context,
(const gchar * const *) args->pdata, NULL);
}

static gboolean
commit_screenshot_ref (const char *repo_path,
const char *app_dir_path,
const char *arch,
GError **error)
{
g_autofree char *media_dir_path = NULL;
g_autoptr(GFile) media_dir = NULL;
g_autoptr(GFile) repo_file = NULL;
g_autoptr(OstreeRepo) repo = NULL;
g_autoptr(OstreeMutableTree) tree = NULL;
g_autoptr(GFile) tree_root = NULL;
g_autofree char *commit_checksum = NULL;
g_autofree char *ref_name = NULL;
g_autoptr(OstreeRepoCommitModifier) modifier = NULL;
gboolean ret = FALSE;

media_dir_path = g_build_filename (app_dir_path, "files/share/app-info/media", NULL);
media_dir = g_file_new_for_path (media_dir_path);

if (!g_file_query_exists (media_dir, NULL))
{
g_print ("Media directory does not exist, skipping commit\n");
return TRUE;
}

ref_name = g_strdup_printf ("screenshots/%s", arch);

repo_file = g_file_new_for_path (repo_path);
repo = ostree_repo_new (repo_file);
if (!ostree_repo_open (repo, NULL, error))
return FALSE;

modifier = ostree_repo_commit_modifier_new (OSTREE_REPO_COMMIT_MODIFIER_FLAGS_CANONICAL_PERMISSIONS,
NULL, NULL, NULL);
if (!ostree_repo_prepare_transaction (repo, NULL, NULL, error))
return FALSE;

tree = ostree_mutable_tree_new ();

if (!ostree_repo_write_directory_to_mtree (repo, media_dir, tree, modifier, NULL, error))
goto out;

if (!ostree_repo_write_mtree (repo, tree, &tree_root, NULL, error))
goto out;

if (!ostree_repo_write_commit (repo,
NULL,
NULL,
NULL,
NULL,
OSTREE_REPO_FILE (tree_root),
&commit_checksum,
NULL, error))
goto out;

ostree_repo_transaction_set_ref (repo, NULL, ref_name, commit_checksum);

if (!ostree_repo_commit_transaction (repo, NULL, NULL, error))
goto out;

g_print ("Committed screenshot ref: %s (%s)\n", ref_name, commit_checksum);
ret = TRUE;

out:
if (!ret && repo)
{
if (!ostree_repo_abort_transaction (repo, NULL, NULL))
g_warning ("Failed to abort ostree transaction");
}

return ret;
}

static gboolean
do_install (BuilderContext *build_context,
const gchar *repodir,
Expand Down Expand Up @@ -974,6 +1049,16 @@ main (int argc,
return 1;
}

if (opt_mirror_screenshots_url &&
!commit_screenshot_ref (flatpak_file_get_path_cached (export_repo),
app_dir_path,
builder_context_get_arch (build_context),
&error))
{
g_printerr ("Failed to commit screenshot ref: %s\n", error->message);
return 1;
}

/* Export regular locale extensions */
dir_enum = g_file_enumerate_children (app_dir, "standard::name,standard::type",
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
Expand Down
3 changes: 3 additions & 0 deletions tests/Makefile.am.inc
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ dist_installed_test_data = \
tests/org.test.Deprecated.SHA1.file.yaml \
tests/hello.sh \
tests/hello.tar.xz \
tests/org.flatpak_builder.gui.desktop \
tests/org.flatpak_builder.gui.json \
tests/org.flatpak_builder.gui.metainfo.xml \
$(NULL)

installed_test_keyringdir = $(installed_testdir)/test-keyring
Expand Down
3 changes: 3 additions & 0 deletions tests/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ if get_option('installed_tests')
'test-runtime.json',
'test.json',
'test.yaml',
'tests/org.flatpak_builder.gui.desktop',
'tests/org.flatpak_builder.gui.json',
'tests/org.flatpak_builder.gui.metainfo.xml',

install_dir: installed_testdir,
install_mode: 'rw-r--r--',
Expand Down
9 changes: 9 additions & 0 deletions tests/org.flatpak_builder.gui.desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[Desktop Entry]
Name=Example
GenericName=Example
Comment=Example
Exec=hello %U
Icon=org.flatpak_builder.gui
Type=Application
Categories=Network;
Version=1.1
41 changes: 41 additions & 0 deletions tests/org.flatpak_builder.gui.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"id": "org.flatpak_builder.gui",
"runtime": "org.test.Platform",
"sdk": "org.test.Sdk",
"command": "hello",
"modules": [
{
"name": "hello_gui",
"buildsystem": "simple",
"build-commands": [
"mkdir -p ${FLATPAK_DEST}/bin ${FLATPAK_DEST}/share/metainfo ${FLATPAK_DEST}/share/applications",
"mkdir -p ${FLATPAK_DEST}/share/icons/hicolor/64x64/apps",
"cp -vf hello.sh ${FLATPAK_DEST}/bin/hello",
"cp -vf ${FLATPAK_ID}.metainfo.xml ${FLATPAK_DEST}/share/metainfo/${FLATPAK_ID}.metainfo.xml",
"cp -vf ${FLATPAK_ID}.desktop ${FLATPAK_DEST}/share/applications/${FLATPAK_ID}.desktop",
"cp -vf org.test.Hello.png ${FLATPAK_DEST}/share/icons/hicolor/64x64/apps/${FLATPAK_ID}.png"
],
"sources": [
{
"type": "script",
"dest-filename": "hello.sh",
"commands": [
"echo \"Hello world, from a sandbox\""
]
},
{
"type": "file",
"path": "org.flatpak_builder.gui.desktop"
},
{
"type": "file",
"path": "org.flatpak_builder.gui.metainfo.xml"
},
{
"type": "file",
"path": "org.test.Hello.png"
}
]
}
]
}
35 changes: 35 additions & 0 deletions tests/org.flatpak_builder.gui.metainfo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<component type="desktop-application">
<id>org.flatpak_builder.gui</id>
<launchable type="desktop-id">org.flatpak_builder.gui.desktop</launchable>
<metadata_license>CC0-1.0</metadata_license>
<project_license>GPL-2.0+</project_license>
<name>org.flatpak_builder.gui</name>
<developer_name>Flatpak</developer_name>
<summary>Foo foo foo foo</summary>
<url type="homepage">https://flatpak.org</url>
<description>
<p>An example desktop application</p>
</description>
<screenshots>
<!-- appstream silently continues without error if the file fails to
download. since the tag only accepts http(s) urls, we add
multiple sources so that in case one link fails, at least one
of the other ones work. Replace with any other screenshot
link if it fails
-->
<screenshot type="default">
<caption>An example screenshot</caption>
<image>https://raw.githubusercontent.com/flatpak/flatpak.github.io/0b56895e271bbcc7f86f9570933a96adff99e110/source/img/endless-apps.original.png</image>
</screenshot>
<screenshot>
<caption>An example screenshot</caption>
<image>https://docs.flathub.org/img/card.png</image>
</screenshot>
</screenshots>
<url type="bugtracker">https://flatpak.org</url>
<content_rating type="oars-1.1"/>
<releases>
<release version="0.0.1" date="2020-08-28"/>
</releases>
</component>
16 changes: 15 additions & 1 deletion tests/test-builder.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ set -euo pipefail

skip_without_fuse

echo "1..7"
echo "1..8"

setup_repo
install_repo
Expand All @@ -49,6 +49,10 @@ cp $(dirname $0)/Hello-desktop.appdata.xml .
cp $(dirname $0)/org.test.Hello.desktop .
cp $(dirname $0)/org.test.Hello.xml .
cp $(dirname $0)/org.test.Hello.appdata.xml .
cp $(dirname $0)/org.flatpak_builder.gui.desktop .
cp $(dirname $0)/org.flatpak_builder.gui.json .
cp $(dirname $0)/org.flatpak_builder.gui.metainfo.xml .
cp $(dirname $0)/org.test.Hello.png .
mkdir include1
cp $(dirname $0)/module1.json include1/
cp $(dirname $0)/module1.yaml include1/
Expand Down Expand Up @@ -127,3 +131,13 @@ ${FLATPAK_BUILDER} $FL_GPGARGS --repo=$REPO --force-clean runtimedir \
test-runtime.json >&2

echo "ok runtime build cleanup with build-args"

# test screenshot ref commit
${FLATPAK_BUILDER} --repo=$REPO/repo_sc --force-clean builddir_sc \
--mirror-screenshots-url=https://example.org/media \
org.flatpak_builder.gui.json >&2
ostree --repo=$REPO/repo_sc refs|grep -Eq "^screenshots/$(flatpak --default-arch)$"
ostree checkout --repo=$REPO/repo_sc -U screenshots/$(flatpak --default-arch) outdir_sc
find outdir_sc -path "*/screenshots/image-1_orig.png" -type f | grep -q .

echo "ok screenshot ref commit"