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

Add RequireRef to pull in target app of extension #5768

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
53 changes: 39 additions & 14 deletions common/flatpak-transaction.c
Original file line number Diff line number Diff line change
Expand Up @@ -2449,27 +2449,52 @@ find_runtime_remote (FlatpakTransaction *self,
static FlatpakDecomposed *
op_get_runtime_ref (FlatpakTransactionOperation *op)
{
g_autofree char *runtime_pref = NULL;
FlatpakDecomposed *decomposed;
FlatpakDecomposed *decomposed = NULL;
g_autoptr (GError) my_error = NULL;

if (!op->resolved_metakey)
return NULL;

/* Generally only app needs runtimes dependencies, not dependencies because you don't run extensions directly.
However if the extension has extra data (and doesn't define NoRuntime) its also needed so we can run the
apply-extra script. */
/* Apps always need runtime dependencies */
if (flatpak_decomposed_is_app (op->ref))
runtime_pref = g_key_file_get_string (op->resolved_metakey, "Application", "runtime", NULL);
else if (g_key_file_has_group (op->resolved_metakey, "Extra Data") &&
!g_key_file_get_boolean (op->resolved_metakey, "Extra Data", "NoRuntime", NULL))
runtime_pref = g_key_file_get_string (op->resolved_metakey, "ExtensionOf", "runtime", NULL);
{
g_autofree char *runtime_pref = g_key_file_get_string (
op->resolved_metakey, "Application", "runtime", NULL);
if (runtime_pref)
{
decomposed = flatpak_decomposed_new_from_pref (
FLATPAK_KINDS_RUNTIME, runtime_pref, &my_error);
}
}

if (runtime_pref == NULL)
return NULL;
if (g_key_file_has_group (op->resolved_metakey, "ExtensionOf"))
{
if (g_key_file_get_boolean (op->resolved_metakey, "ExtensionOf",
"RequireRef", NULL))
{
/* The extension requires its target to be installed */
g_autofree char *app_ref = g_key_file_get_string (
op->resolved_metakey, "ExtensionOf", "ref", NULL);
decomposed = flatpak_decomposed_new_from_ref (app_ref, &my_error);
}
else if (g_key_file_has_group (op->resolved_metakey, "Extra Data") &&
!g_key_file_get_boolean (op->resolved_metakey, "Extra Data",
"NoRuntime", NULL))
{
/* If the extension has extra data (and doesn't define NoRuntime) it
* needs a runtime so it can run the apply-extra script. */
g_autofree char *runtime_pref = g_key_file_get_string (
op->resolved_metakey, "ExtensionOf", "runtime", NULL);
if (runtime_pref)
{
decomposed = flatpak_decomposed_new_from_pref (
FLATPAK_KINDS_RUNTIME, runtime_pref, &my_error);
}
}
}

decomposed = flatpak_decomposed_new_from_pref (FLATPAK_KINDS_RUNTIME, runtime_pref, NULL);
if (decomposed == NULL)
g_info ("Invalid runtime ref %s in metadata", runtime_pref);
if (my_error != NULL)
g_info ("Cannot get decomposed dependency: %s", my_error->message);

return decomposed;
}
Expand Down
25 changes: 25 additions & 0 deletions tests/make-test-app.sh
Original file line number Diff line number Diff line change
Expand Up @@ -239,3 +239,28 @@ else
fi

rm -rf ${DIR}


# build a plugin extension that pulls in app as dependency

DIR=`mktemp -d`

# Init dir
cat > ${DIR}/metadata <<EOF
[Runtime]
name=${APP_ID}.Plugin.joy

[ExtensionOf]
ref=app/$APP_ID/$ARCH/$BRANCH
RequireRef=true
EOF

mkdir -p ${DIR}/files/plug-ins/joy

flatpak build-finish ${DIR} >&2
mkdir -p repos

flatpak build-export --no-update-summary --runtime ${collection_args} ${GPGARGS-} ${EXPORT_ARGS-} ${REPO} ${DIR} ${BRANCH} >&2


rm -rf ${DIR}
49 changes: 49 additions & 0 deletions tests/test-install-extension.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/bash
#
# Copyright (C) 2024 Eitan Isaacson <[email protected]>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.

set -euo pipefail

. "$(dirname $0)/libtest.sh"

skip_without_bwrap
skip_revokefs_without_fuse

echo "1..3"

setup_repo "" "" master

$FLATPAK list --app ${U} > app_list
assert_not_file_has_content app_list "Hello world"

ok "App is not installed"

${FLATPAK} ${U} install -y test-repo org.test.Hello.Plugin.fun v1 >&2

$FLATPAK list ${U} | grep org.test.Hello.Plugin.fun > /dev/null
$FLATPAK list --app ${U} > app_list
assert_not_file_has_content app_list "Hello world"

ok "fun extension does not pull in app"

${FLATPAK} ${U} install -y test-repo org.test.Hello.Plugin.joy >&2

$FLATPAK list --app ${U} > app_list
assert_file_has_content app_list "Hello world"

ok "Pulled in extension's app"
1 change: 1 addition & 0 deletions tests/test-matrix/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,4 @@ wrapped_tests += {'name' : 'test-unused.sh', 'script' : 'test-unused.sh'}
wrapped_tests += {'name' : 'test-prune.sh', 'script' : 'test-prune.sh'}
wrapped_tests += {'name' : 'test-seccomp.sh', 'script' : 'test-seccomp.sh'}
wrapped_tests += {'name' : 'test-repair.sh', 'script' : 'test-repair.sh'}
wrapped_tests += {'name' : 'test-install-extension.sh', 'script' : 'test-install-extension.sh'}
5 changes: 3 additions & 2 deletions tests/testlibrary.c
Original file line number Diff line number Diff line change
Expand Up @@ -1109,7 +1109,8 @@ test_list_remote_refs (void)
g_assert_cmpint (flatpak_ref_get_kind (ref), ==, FLATPAK_REF_KIND_APP);
}
else if (strcmp ("org.test.Hello.Locale", flatpak_ref_get_name (ref)) == 0 ||
strcmp ("org.test.Hello.Plugin.fun", flatpak_ref_get_name (ref)) == 0)
strcmp ("org.test.Hello.Plugin.fun", flatpak_ref_get_name (ref)) == 0 ||
strcmp ("org.test.Hello.Plugin.joy", flatpak_ref_get_name (ref)) == 0)
{
g_assert_cmpint (flatpak_ref_get_kind (ref), ==, FLATPAK_REF_KIND_RUNTIME);
}
Expand Down Expand Up @@ -1179,7 +1180,7 @@ test_list_remote_refs_noenumerate (void)
refs = flatpak_installation_list_remote_refs_sync (inst, repo_name, NULL, &error);
g_assert_no_error (error);
g_assert_nonnull (refs);
g_assert_cmpint (refs->len, ==, 4);
g_assert_cmpint (refs->len, ==, 5);

/* Install a runtime */
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
Expand Down
1 change: 1 addition & 0 deletions tests/update-test-matrix
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ TEST_MATRIX_SOURCE=(
'tests/test-prune.sh' \
'tests/test-seccomp.sh' \
'tests/test-repair.sh' \
'tests/test-install-extension.sh' \
)

"${tests_srcdir}/expand-test-matrix.sh" --meson "${TEST_MATRIX_SOURCE[*]}" > "${tests_srcdir}/test-matrix/meson.build"