mirror of
https://github.com/flatpak/flatpak.git
synced 2026-07-20 13:03:59 -04:00
build-init: Add --extension support
This works just like in build-finish, but the main difference is that the extension point is added early, so that the build itself can use it. Closes: #1598 Approved by: alexlarsson
This commit is contained in:
committed by
Atomic Bot
parent
4246a20393
commit
b09059ca2c
@@ -32,12 +32,14 @@
|
||||
#include "flatpak-builtins.h"
|
||||
#include "flatpak-builtins-utils.h"
|
||||
#include "flatpak-utils.h"
|
||||
#include "flatpak-run.h"
|
||||
|
||||
static char *opt_arch;
|
||||
static char *opt_var;
|
||||
static char *opt_type;
|
||||
static char *opt_sdk_dir;
|
||||
static char **opt_sdk_extensions;
|
||||
static char **opt_extensions;
|
||||
static char **opt_tags;
|
||||
static char *opt_extension_tag;
|
||||
static char *opt_base;
|
||||
@@ -57,6 +59,7 @@ static GOptionEntry options[] = {
|
||||
{ "type", 0, 0, G_OPTION_ARG_STRING, &opt_type, N_("Specify the build type (app, runtime, extension)"), N_("TYPE") },
|
||||
{ "tag", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_tags, N_("Add a tag"), N_("TAG") },
|
||||
{ "sdk-extension", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_sdk_extensions, N_("Include this sdk extension in /usr"), N_("EXTENSION") },
|
||||
{ "extension", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_extensions, N_("Add extension point info"), N_("NAME=VARIABLE[=VALUE]") },
|
||||
{ "sdk-dir", 0, 0, G_OPTION_ARG_STRING, &opt_sdk_dir, N_("Where to store sdk (defaults to 'usr')"), N_("DIR") },
|
||||
{ "update", 0, 0, G_OPTION_ARG_NONE, &opt_update, N_("Re-initialize the sdk/var"), NULL },
|
||||
{ NULL }
|
||||
@@ -186,6 +189,9 @@ flatpak_builtin_build_init (int argc, char **argv, GCancellable *cancellable, GE
|
||||
gboolean is_app = FALSE;
|
||||
gboolean is_extension = FALSE;
|
||||
gboolean is_runtime = FALSE;
|
||||
g_autoptr(GKeyFile) keyfile = g_key_file_new ();
|
||||
g_autofree char *keyfile_data = NULL;
|
||||
gsize keyfile_data_len;
|
||||
|
||||
context = g_option_context_new (_("DIRECTORY APPNAME SDK RUNTIME [BRANCH] - Initialize a directory for building"));
|
||||
g_option_context_set_translation_domain (context, GETTEXT_PACKAGE);
|
||||
@@ -223,6 +229,7 @@ flatpak_builtin_build_init (int argc, char **argv, GCancellable *cancellable, GE
|
||||
if (!flatpak_is_valid_name (app_id, &my_error))
|
||||
return flatpak_fail (error, _("'%s' is not a valid application name: %s"), app_id, my_error->message);
|
||||
|
||||
|
||||
kinds = FLATPAK_KINDS_RUNTIME;
|
||||
sdk_dir = flatpak_find_installed_pref (sdk_pref, kinds, opt_arch, default_branch, TRUE, FALSE, FALSE, NULL,
|
||||
&sdk_ref, cancellable, error);
|
||||
@@ -390,8 +397,30 @@ flatpak_builtin_build_init (int argc, char **argv, GCancellable *cancellable, GE
|
||||
optional_extension_tag);
|
||||
}
|
||||
|
||||
/* Do the rest of the work as a keyfile, as we need things like full escaping, etc.
|
||||
* We should probably do everything this way actually... */
|
||||
if (!g_key_file_load_from_data (keyfile, metadata_contents->str, metadata_contents->len, 0, NULL))
|
||||
return flatpak_fail (error, "Internal error parsing generated keyfile");
|
||||
|
||||
for (i = 0; opt_extensions != NULL && opt_extensions[i] != NULL; i++)
|
||||
{
|
||||
g_auto(GStrv) elements = NULL;
|
||||
g_autofree char *groupname = NULL;
|
||||
|
||||
elements = g_strsplit (opt_extensions[i], "=", 3);
|
||||
if (g_strv_length (elements) < 2)
|
||||
return flatpak_fail (error, _("Too few elements in --extension argument %s, format should be NAME=VAR[=VALUE]"), opt_extensions[i]);
|
||||
|
||||
groupname = g_strconcat (FLATPAK_METADATA_GROUP_PREFIX_EXTENSION,
|
||||
elements[0], NULL);
|
||||
|
||||
g_key_file_set_string (keyfile, groupname, elements[1], elements[2] ? elements[2] : "true");
|
||||
}
|
||||
|
||||
keyfile_data = g_key_file_to_data (keyfile, &keyfile_data_len, NULL);
|
||||
|
||||
if (!g_file_replace_contents (metadata_file,
|
||||
metadata_contents->str, metadata_contents->len, NULL, FALSE,
|
||||
keyfile_data, keyfile_data_len, NULL, FALSE,
|
||||
G_FILE_CREATE_REPLACE_DESTINATION,
|
||||
NULL, cancellable, error))
|
||||
return FALSE;
|
||||
|
||||
@@ -126,6 +126,14 @@
|
||||
</para></listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>--extension=NAME=VARIABLE[=VALUE]</option></term>
|
||||
|
||||
<listitem><para>
|
||||
Add extension point info.
|
||||
</para></listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>--sdk-dir</option></term>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user