Skip to content

Commit

Permalink
Add --include-sdk/debug to install SDK/debuginfo along with a ref
Browse files Browse the repository at this point in the history
This makes it a lot easier to give guidance on using `flatpak run -d` or
`flatpak-coredumpctl`, because there's an easy way to install the
relevant refs.

Signed-off-by: Ryan Gonzalez <[email protected]>
  • Loading branch information
refi64 authored and mwleeds committed May 7, 2022
1 parent 3a2755d commit 12305b2
Show file tree
Hide file tree
Showing 4 changed files with 216 additions and 26 deletions.
13 changes: 13 additions & 0 deletions app/flatpak-builtins-install.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ static gboolean opt_no_deps;
static gboolean opt_no_static_deltas;
static gboolean opt_runtime;
static gboolean opt_app;
static gboolean opt_include_sdk;
static gboolean opt_include_debug;
static gboolean opt_bundle;
static gboolean opt_from;
static gboolean opt_yes;
Expand All @@ -69,6 +71,8 @@ static GOptionEntry options[] = {
{ "no-static-deltas", 0, 0, G_OPTION_ARG_NONE, &opt_no_static_deltas, N_("Don't use static deltas"), NULL },
{ "runtime", 0, 0, G_OPTION_ARG_NONE, &opt_runtime, N_("Look for runtime with the specified name"), NULL },
{ "app", 0, 0, G_OPTION_ARG_NONE, &opt_app, N_("Look for app with the specified name"), NULL },
{ "include-sdk", 0, 0, G_OPTION_ARG_NONE, &opt_include_sdk, N_("Additionally install the SDK used to build the given refs") },
{ "include-debug", 0, 0, G_OPTION_ARG_NONE, &opt_include_debug, N_("Additionally install the debug info for the given refs and their dependencies") },
{ "bundle", 0, 0, G_OPTION_ARG_NONE, &opt_bundle, N_("Assume LOCATION is a .flatpak single-file bundle"), NULL },
{ "from", 0, 0, G_OPTION_ARG_NONE, &opt_from, N_("Assume LOCATION is a .flatpakref application description"), NULL },
{ "gpg-file", 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &opt_gpg_file, N_("Check bundle signatures with GPG key from FILE (- for stdin)"), N_("FILE") },
Expand Down Expand Up @@ -171,6 +175,8 @@ install_bundle (FlatpakDir *dir,
flatpak_transaction_set_disable_related (transaction, opt_no_related);
flatpak_transaction_set_disable_auto_pin (transaction, opt_no_auto_pin);
flatpak_transaction_set_reinstall (transaction, opt_reinstall);
flatpak_transaction_set_auto_install_sdk (transaction, opt_include_sdk);
flatpak_transaction_set_auto_install_debug (transaction, opt_include_debug);

for (int i = 0; opt_sideload_repos != NULL && opt_sideload_repos[i] != NULL; i++)
flatpak_transaction_add_sideload_repo (transaction, opt_sideload_repos[i]);
Expand Down Expand Up @@ -249,6 +255,8 @@ install_from (FlatpakDir *dir,
flatpak_transaction_set_disable_auto_pin (transaction, opt_no_auto_pin);
flatpak_transaction_set_reinstall (transaction, opt_reinstall);
flatpak_transaction_set_default_arch (transaction, opt_arch);
flatpak_transaction_set_auto_install_sdk (transaction, opt_include_sdk);
flatpak_transaction_set_auto_install_debug (transaction, opt_include_debug);

for (int i = 0; opt_sideload_repos != NULL && opt_sideload_repos[i] != NULL; i++)
flatpak_transaction_add_sideload_repo (transaction, opt_sideload_repos[i]);
Expand Down Expand Up @@ -318,6 +326,9 @@ flatpak_builtin_install (int argc, char **argv, GCancellable *cancellable, GErro
if (opt_noninteractive)
opt_yes = TRUE; /* Implied */

if (opt_include_sdk || opt_include_debug)
opt_or_update = TRUE;

kinds = flatpak_kinds_from_bools (opt_app, opt_runtime);

if (!opt_noninteractive)
Expand Down Expand Up @@ -487,6 +498,8 @@ flatpak_builtin_install (int argc, char **argv, GCancellable *cancellable, GErro
flatpak_transaction_set_disable_related (transaction, opt_no_related);
flatpak_transaction_set_disable_auto_pin (transaction, opt_no_auto_pin);
flatpak_transaction_set_reinstall (transaction, opt_reinstall);
flatpak_transaction_set_auto_install_sdk (transaction, opt_include_sdk);
flatpak_transaction_set_auto_install_debug (transaction, opt_include_debug);

for (i = 0; opt_sideload_repos != NULL && opt_sideload_repos[i] != NULL; i++)
flatpak_transaction_add_sideload_repo (transaction, opt_sideload_repos[i]);
Expand Down
200 changes: 174 additions & 26 deletions common/flatpak-transaction.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ struct _FlatpakTransactionPrivate
gboolean force_uninstall;
gboolean can_run;
gboolean include_unused_uninstall_ops;
gboolean auto_install_sdk;
gboolean auto_install_debug;
char *default_arch;
guint max_op;

Expand Down Expand Up @@ -1889,6 +1891,84 @@ flatpak_transaction_get_include_unused_uninstall_ops (FlatpakTransaction *self)
return priv->include_unused_uninstall_ops;
}

/**
* flatpak_transaction_set_auto_install_sdk:
* @self: a #FlatpakTransaction
* @auto_install_sdk: whether to auto install SDKs for apps
*
* When this is set to %TRUE, Flatpak will automatically install the SDK for
* each app currently being installed or updated. Does nothing if an uninstall
* is taking place.
*
* Since: 1.13.3
*/
void
flatpak_transaction_set_auto_install_sdk (FlatpakTransaction *self,
gboolean auto_install_sdk)
{
FlatpakTransactionPrivate *priv = flatpak_transaction_get_instance_private (self);

priv->auto_install_sdk = auto_install_sdk;
}

/**
* flatpak_transaction_get_auto_install_sdk:
* @self: a #FlatpakTransaction
*
* Gets the value set by
* flatpak_transaction_set_auto_install_sdk().
*
* Returns: %TRUE if auto_install_sdk is set, %FALSE otherwise
*
* Since: 1.13.3
*/
gboolean
flatpak_transaction_get_auto_install_sdk (FlatpakTransaction *self)
{
FlatpakTransactionPrivate *priv = flatpak_transaction_get_instance_private (self);

return priv->auto_install_sdk;
}

/**
* flatpak_transaction_set_auto_install_debug:
* @self: a #FlatpakTransaction
* @auto_install_debug: whether to auto install debug info for apps
*
* When this is set to %TRUE, Flatpak will automatically install the debug info
* for each app currently being installed or updated, as well as its
* dependencies. Does nothing if an uninstall is taking place.
*
* Since: 1.13.3
*/
void
flatpak_transaction_set_auto_install_debug (FlatpakTransaction *self,
gboolean auto_install_debug)
{
FlatpakTransactionPrivate *priv = flatpak_transaction_get_instance_private (self);

priv->auto_install_debug = auto_install_debug;
}

/**
* flatpak_transaction_get_auto_install_debug:
* @self: a #FlatpakTransaction
*
* Gets the value set by
* flatpak_transaction_set_auto_install_debug().
*
* Returns: %TRUE if auto_install_debug is set, %FALSE otherwise
*
* Since: 1.13.3
*/
gboolean
flatpak_transaction_get_auto_install_debug (FlatpakTransaction *self)
{
FlatpakTransactionPrivate *priv = flatpak_transaction_get_instance_private (self);

return priv->auto_install_debug;
}

static FlatpakTransactionOperation *
flatpak_transaction_get_last_op_for_ref (FlatpakTransaction *self,
FlatpakDecomposed *ref)
Expand Down Expand Up @@ -2178,8 +2258,16 @@ add_related (FlatpakTransaction *self,
{
FlatpakRelated *rel = g_ptr_array_index (related, i);
FlatpakTransactionOperation *related_op;
gboolean download = rel->download;

if (!rel->download)
if (!download)
{
g_autofree char *id = flatpak_decomposed_dup_id (rel->ref);
if (priv->auto_install_debug && g_str_has_suffix (id, ".Debug"))
download = TRUE;
}

if (!download)
continue;

related_op = flatpak_transaction_add_op (self, rel->remote, rel->ref,
Expand Down Expand Up @@ -2382,14 +2470,74 @@ op_get_runtime_ref (FlatpakTransactionOperation *op)
return decomposed;
}

static FlatpakDecomposed *
op_get_sdk_ref (FlatpakTransactionOperation *op)
{
g_autofree char *sdk_pref = NULL;
FlatpakDecomposed *decomposed;

if (!op->resolved_metakey || !flatpak_decomposed_is_app (op->ref))
return NULL;

sdk_pref = g_key_file_get_string (op->resolved_metakey, "Application", "sdk", NULL);
if (sdk_pref == NULL)
return NULL;

decomposed = flatpak_decomposed_new_from_pref (FLATPAK_KINDS_RUNTIME, sdk_pref, NULL);
if (decomposed == NULL)
g_debug ("Invalid runtime ref %s in metadata", sdk_pref);

return decomposed;
}

static gboolean
add_new_dep_op (FlatpakTransaction *self,
FlatpakTransactionOperation *op,
FlatpakDecomposed *dep_ref,
FlatpakTransactionOperation **dep_op,
GError **error)
{
FlatpakTransactionPrivate *priv = flatpak_transaction_get_instance_private (self);
g_autofree char *dep_remote = NULL;

if (!ref_is_installed (self, dep_ref))
{
g_debug ("Installing dependency %s of %s", flatpak_decomposed_get_pref (dep_ref),
flatpak_decomposed_get_pref (op->ref));
dep_remote = find_runtime_remote (self, op->ref, op->remote, dep_ref, op->kind, NULL, error);
if (dep_remote == NULL)
return FALSE;

*dep_op = flatpak_transaction_add_op (self, dep_remote, dep_ref, NULL, NULL, NULL, NULL,
FLATPAK_TRANSACTION_OPERATION_INSTALL_OR_UPDATE, FALSE, error);
if (*dep_op == NULL)
return FALSE;
}
else
{
/* Update if in same dir */
if (dir_ref_is_installed (priv->dir, dep_ref, &dep_remote, NULL))
{
g_debug ("Updating dependency %s of %s", flatpak_decomposed_get_pref (dep_ref),
flatpak_decomposed_get_pref (op->ref));
*dep_op = flatpak_transaction_add_op (self, dep_remote, dep_ref, NULL, NULL, NULL, NULL,
FLATPAK_TRANSACTION_OPERATION_UPDATE, FALSE, error);
if (*dep_op == NULL)
return FALSE;
(*dep_op)->non_fatal = TRUE;
}
}

return TRUE;
}

static gboolean
add_deps (FlatpakTransaction *self,
FlatpakTransactionOperation *op,
GError **error)
{
FlatpakTransactionPrivate *priv = flatpak_transaction_get_instance_private (self);
g_autoptr(FlatpakDecomposed) runtime_ref = NULL;
g_autofree char *runtime_remote = NULL;
FlatpakTransactionOperation *runtime_op = NULL;

if (!op->resolved_metakey)
Expand All @@ -2416,30 +2564,8 @@ add_deps (FlatpakTransaction *self,

if (runtime_op == NULL)
{
if (!ref_is_installed (self, runtime_ref))
{
runtime_remote = find_runtime_remote (self, op->ref, op->remote, runtime_ref, op->kind, NULL, error);
if (runtime_remote == NULL)
return FALSE;

runtime_op = flatpak_transaction_add_op (self, runtime_remote, runtime_ref, NULL, NULL, NULL, NULL,
FLATPAK_TRANSACTION_OPERATION_INSTALL_OR_UPDATE, FALSE, error);
if (runtime_op == NULL)
return FALSE;
}
else
{
/* Update if in same dir */
if (dir_ref_is_installed (priv->dir, runtime_ref, &runtime_remote, NULL))
{
g_debug ("Updating dependent runtime %s", flatpak_decomposed_get_pref (runtime_ref));
runtime_op = flatpak_transaction_add_op (self, runtime_remote, runtime_ref, NULL, NULL, NULL, NULL,
FLATPAK_TRANSACTION_OPERATION_UPDATE, FALSE, error);
if (runtime_op == NULL)
return FALSE;
runtime_op->non_fatal = TRUE;
}
}
if (!add_new_dep_op (self, op, runtime_ref, &runtime_op, error))
return FALSE;
}

/* Install/Update the runtime before the app */
Expand All @@ -2455,6 +2581,28 @@ add_deps (FlatpakTransaction *self,
run_operation_before (runtime_op, op, 2);
}

if (priv->auto_install_sdk)
{
g_autoptr(FlatpakDecomposed) sdk_ref = NULL;

sdk_ref = op_get_sdk_ref (op);
if (sdk_ref != NULL)
{
FlatpakTransactionOperation *sdk_op = flatpak_transaction_get_last_op_for_ref (self, sdk_ref);
if (sdk_op == NULL)
{
if (!add_new_dep_op (self, op, sdk_ref, &sdk_op, error))
return FALSE;
}

if (sdk_op->kind != FLATPAK_TRANSACTION_OPERATION_UNINSTALL)
{
flatpak_transaction_operation_add_related_to_op (sdk_op, op);
run_operation_before (sdk_op, op, 2);
}
}
}

return TRUE;
}

Expand Down
10 changes: 10 additions & 0 deletions common/flatpak-transaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,16 @@ void flatpak_transaction_set_include_unused_uninstall_ops (Flatpa
FLATPAK_EXTERN
gboolean flatpak_transaction_get_include_unused_uninstall_ops (FlatpakTransaction *self);
FLATPAK_EXTERN
void flatpak_transaction_set_auto_install_sdk (FlatpakTransaction *self,
gboolean auto_install_sdk);
FLATPAK_EXTERN
gboolean flatpak_transaction_get_auto_install_sdk (FlatpakTransaction *self);
FLATPAK_EXTERN
void flatpak_transaction_set_auto_install_debug (FlatpakTransaction *self,
gboolean auto_install_debug);
FLATPAK_EXTERN
gboolean flatpak_transaction_get_auto_install_debug (FlatpakTransaction *self);
FLATPAK_EXTERN
void flatpak_transaction_add_dependency_source (FlatpakTransaction *self,
FlatpakInstallation *installation);
FLATPAK_EXTERN
Expand Down
19 changes: 19 additions & 0 deletions doc/flatpak-install.xml
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,25 @@
</para></listitem>
</varlistentry>

<varlistentry>
<term><option>--include-sdk</option></term>

<listitem><para>
For each app being installed, also installs the SDK that was used to build it.
Implies <option>--or-update</option>; incompatible with <option>--no-deps</option>.
</para></listitem>
</varlistentry>

<varlistentry>
<term><option>--include-debug</option></term>

<listitem><para>
For each ref being installed, as well as all dependencies, also installs its
debug info. Implies <option>--or-update</option>; incompatible with
<option>--no-deps</option>.
</para></listitem>
</varlistentry>

<varlistentry>
<term><option>-y</option></term>
<term><option>--assumeyes</option></term>
Expand Down

0 comments on commit 12305b2

Please sign in to comment.