Commit 501dbfca authored by Matthew Leeds's avatar Matthew Leeds
Browse files

flatpak: Add needed properties to GbpFlatpakConfiguration

It makes more sense to have these be GbpFlatpakConfiguration properties
rather than using the internal data structures of IdeConfiguration. This
commit adds the properties to GbpFlatpakConfiguration, initializes them
in GbpFlatpakConfigurationProvider, and uses them in
GbpFlatpakPipelineAddin.
parent 3059a8d4
......@@ -46,10 +46,15 @@ struct _GbpFlatpakConfigurationProvider
typedef struct
{
gchar *app_id;
gchar *branch;
gchar *command;
gchar *config_opts;
gchar **finish_args;
gchar *platform;
gchar *prefix;
gchar *primary_module;
gchar *runtime_id;
gchar *sdk;
GFile *file;
IdeEnvironment *environment;
} FlatpakManifest;
......@@ -595,10 +600,15 @@ flatpak_manifest_free (void *data)
FlatpakManifest *manifest = data;
g_free (manifest->app_id);
g_free (manifest->branch);
g_free (manifest->command);
g_free (manifest->config_opts);
g_free (manifest->platform);
g_free (manifest->prefix);
g_free (manifest->primary_module);
g_free (manifest->runtime_id);
g_free (manifest->sdk);
g_strfreev (manifest->finish_args);
g_clear_object (&manifest->environment);
g_clear_object (&manifest->file);
g_slice_free (FlatpakManifest, manifest);
......@@ -689,6 +699,8 @@ check_dir_for_manifests (GFile *directory,
JsonNode *sdk_node = NULL;
JsonNode *modules_node = NULL;
JsonNode *primary_module_node = NULL;
JsonNode *command_node = NULL;
JsonNode *finish_args_node = NULL;
JsonObject *root_object = NULL;
g_autoptr(GError) local_error = NULL;
g_autoptr(GFile) file = NULL;
......@@ -809,13 +821,41 @@ check_dir_for_manifests (GFile *directory,
}
platform = json_node_get_string (runtime_node);
manifest->platform = g_strdup (platform);
if (!JSON_NODE_HOLDS_VALUE (runtime_version_node) || ide_str_empty0 (json_node_get_string (runtime_version_node)))
branch = "master";
else
branch = json_node_get_string (runtime_version_node);
manifest->branch = g_strdup (branch);
arch = flatpak_get_default_arch ();
manifest->runtime_id = g_strdup_printf ("flatpak:%s/%s/%s", platform, branch, arch);
manifest->sdk = json_node_dup_string (sdk_node);
command_node = json_object_get_member (root_object, "command");
if (JSON_NODE_HOLDS_VALUE (command_node))
manifest->command = json_node_dup_string (command_node);
finish_args_node = json_object_get_member (root_object, "finish-args");
if (JSON_NODE_HOLDS_ARRAY (finish_args_node))
{
JsonArray *finish_args_array;
GPtrArray *finish_args;
finish_args = g_ptr_array_new ();
finish_args_array = json_node_get_array (finish_args_node);
for (guint i = 0; i < json_array_get_length (finish_args_array); i++)
{
gchar *arg;
arg = g_strdup (json_array_get_string_element (finish_args_array, i));
if (!ide_str_empty0 (arg))
g_ptr_array_add (finish_args, arg);
}
g_ptr_array_add (finish_args, NULL);
manifest->finish_args = (gchar **)g_ptr_array_free (finish_args, FALSE);
}
if (JSON_NODE_HOLDS_VALUE (app_id_node))
manifest->app_id = json_node_dup_string (app_id_node);
else
......@@ -957,16 +997,23 @@ gbp_flatpak_configuration_provider_load_manifests (GbpFlatpakConfigurationProvid
*/
configuration = g_object_new (GBP_TYPE_FLATPAK_CONFIGURATION,
"app-id", manifest->app_id,
"branch", manifest->branch,
"context", context,
"display-name", filename,
"device-id", "local",
"id", id,
"manifest", manifest->file,
"platform", manifest->platform,
"prefix", (manifest->prefix != NULL ? manifest->prefix : "/app"),
"runtime-id", manifest->runtime_id,
"sdk", manifest->sdk,
NULL);
if (manifest->primary_module != NULL)
gbp_flatpak_configuration_set_primary_module (configuration, manifest->primary_module);
if (manifest->command != NULL)
gbp_flatpak_configuration_set_command (configuration, manifest->command);
if (manifest->finish_args != NULL)
gbp_flatpak_configuration_set_finish_args (configuration, (const gchar * const *)manifest->finish_args);
if (manifest->environment != NULL)
ide_configuration_set_environment (IDE_CONFIGURATION (configuration), manifest->environment);
if (manifest->config_opts != NULL)
......
......@@ -27,21 +27,102 @@ struct _GbpFlatpakConfiguration
{
IdeConfiguration parent_instance;
GFile *manifest;
gchar *primary_module;
gchar *branch;
gchar *command;
gchar **finish_args;
GFile *manifest;
gchar *platform;
gchar *primary_module;
gchar *sdk;
};
G_DEFINE_TYPE (GbpFlatpakConfiguration, gbp_flatpak_configuration, IDE_TYPE_CONFIGURATION)
enum {
PROP_0,
PROP_BRANCH,
PROP_COMMAND,
PROP_FINISH_ARGS,
PROP_MANIFEST,
PROP_PLATFORM,
PROP_PRIMARY_MODULE,
PROP_SDK,
N_PROPS
};
static GParamSpec *properties [N_PROPS];
const gchar *
gbp_flatpak_configuration_get_branch (GbpFlatpakConfiguration *self)
{
g_return_val_if_fail (GBP_IS_FLATPAK_CONFIGURATION (self), NULL);
return self->branch;
}
void
gbp_flatpak_configuration_set_branch (GbpFlatpakConfiguration *self,
const gchar *branch)
{
g_return_if_fail (GBP_IS_FLATPAK_CONFIGURATION (self));
g_free (self->branch);
self->branch = g_strdup (branch);
g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_BRANCH]);
}
const gchar *
gbp_flatpak_configuration_get_command (GbpFlatpakConfiguration *self)
{
g_return_val_if_fail (GBP_IS_FLATPAK_CONFIGURATION (self), NULL);
return self->command;
}
void
gbp_flatpak_configuration_set_command (GbpFlatpakConfiguration *self,
const gchar *command)
{
g_return_if_fail (GBP_IS_FLATPAK_CONFIGURATION (self));
g_free (self->command);
self->command = g_strdup (command);
g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_COMMAND]);
}
const gchar * const *
gbp_flatpak_configuration_get_finish_args (GbpFlatpakConfiguration *self)
{
g_return_val_if_fail (GBP_IS_FLATPAK_CONFIGURATION (self), NULL);
return (const gchar * const *)self->finish_args;
}
void
gbp_flatpak_configuration_set_finish_args (GbpFlatpakConfiguration *self,
const gchar * const *finish_args)
{
g_return_if_fail (GBP_IS_FLATPAK_CONFIGURATION (self));
if (self->finish_args != (gchar **)finish_args)
{
g_strfreev (self->finish_args);
self->finish_args = g_strdupv ((gchar **)finish_args);
g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_FINISH_ARGS]);
}
}
gchar *
gbp_flatpak_configuration_get_manifest_path (GbpFlatpakConfiguration *self)
{
g_return_val_if_fail (GBP_IS_FLATPAK_CONFIGURATION (self), NULL);
if (self->manifest != NULL)
return g_file_get_path (self->manifest);
return NULL;
}
GFile *
gbp_flatpak_configuration_get_manifest (GbpFlatpakConfiguration *self)
{
......@@ -50,6 +131,25 @@ gbp_flatpak_configuration_get_manifest (GbpFlatpakConfiguration *self)
return self->manifest;
}
const gchar *
gbp_flatpak_configuration_get_platform (GbpFlatpakConfiguration *self)
{
g_return_val_if_fail (GBP_IS_FLATPAK_CONFIGURATION (self), NULL);
return self->platform;
}
void
gbp_flatpak_configuration_set_platform (GbpFlatpakConfiguration *self,
const gchar *platform)
{
g_return_if_fail (GBP_IS_FLATPAK_CONFIGURATION (self));
g_free (self->platform);
self->platform = g_strdup (platform);
g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_PLATFORM]);
}
const gchar *
gbp_flatpak_configuration_get_primary_module (GbpFlatpakConfiguration *self)
{
......@@ -60,12 +160,32 @@ gbp_flatpak_configuration_get_primary_module (GbpFlatpakConfiguration *self)
void
gbp_flatpak_configuration_set_primary_module (GbpFlatpakConfiguration *self,
const gchar *primary_module)
const gchar *primary_module)
{
g_return_if_fail (GBP_IS_FLATPAK_CONFIGURATION (self));
g_free (self->primary_module);
self->primary_module = g_strdup (primary_module);
g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_PRIMARY_MODULE]);
}
const gchar *
gbp_flatpak_configuration_get_sdk (GbpFlatpakConfiguration *self)
{
g_return_val_if_fail (GBP_IS_FLATPAK_CONFIGURATION (self), NULL);
return self->sdk;
}
void
gbp_flatpak_configuration_set_sdk (GbpFlatpakConfiguration *self,
const gchar *sdk)
{
g_return_if_fail (GBP_IS_FLATPAK_CONFIGURATION (self));
g_free (self->sdk);
self->sdk = g_strdup (sdk);
g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_SDK]);
}
static void
......@@ -78,14 +198,34 @@ gbp_flatpak_configuration_get_property (GObject *object,
switch (prop_id)
{
case PROP_BRANCH:
g_value_set_string (value, gbp_flatpak_configuration_get_branch (self));
break;
case PROP_COMMAND:
g_value_set_string (value, gbp_flatpak_configuration_get_command (self));
break;
case PROP_FINISH_ARGS:
g_value_set_boxed (value, gbp_flatpak_configuration_get_finish_args (self));
break;
case PROP_MANIFEST:
g_value_set_object (value, gbp_flatpak_configuration_get_manifest (self));
break;
case PROP_PLATFORM:
g_value_set_string (value, gbp_flatpak_configuration_get_platform (self));
break;
case PROP_PRIMARY_MODULE:
g_value_set_string (value, gbp_flatpak_configuration_get_primary_module (self));
break;
case PROP_SDK:
g_value_set_string (value, gbp_flatpak_configuration_get_sdk (self));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
}
......@@ -101,14 +241,34 @@ gbp_flatpak_configuration_set_property (GObject *object,
switch (prop_id)
{
case PROP_BRANCH:
gbp_flatpak_configuration_set_branch (self, g_value_get_string (value));
break;
case PROP_COMMAND:
gbp_flatpak_configuration_set_command (self, g_value_get_string (value));
break;
case PROP_FINISH_ARGS:
gbp_flatpak_configuration_set_finish_args (self, g_value_get_boxed (value));
break;
case PROP_MANIFEST:
self->manifest = g_value_dup_object (value);
break;
case PROP_PLATFORM:
gbp_flatpak_configuration_set_platform (self, g_value_get_string (value));
break;
case PROP_PRIMARY_MODULE:
gbp_flatpak_configuration_set_primary_module (self, g_value_get_string (value));
break;
case PROP_SDK:
gbp_flatpak_configuration_set_sdk (self, g_value_get_string (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
}
......@@ -119,8 +279,13 @@ gbp_flatpak_configuration_finalize (GObject *object)
{
GbpFlatpakConfiguration *self = (GbpFlatpakConfiguration *)object;
g_clear_pointer (&self->branch, g_free);
g_clear_pointer (&self->command, g_free);
g_clear_pointer (&self->finish_args, g_strfreev);
g_clear_object (&self->manifest);
g_clear_pointer (&self->platform, g_free);
g_clear_pointer (&self->primary_module, g_free);
g_clear_pointer (&self->sdk, g_free);
G_OBJECT_CLASS (gbp_flatpak_configuration_parent_class)->finalize (object);
}
......@@ -134,6 +299,33 @@ gbp_flatpak_configuration_class_init (GbpFlatpakConfigurationClass *klass)
object_class->get_property = gbp_flatpak_configuration_get_property;
object_class->set_property = gbp_flatpak_configuration_set_property;
properties [PROP_BRANCH] =
g_param_spec_string ("branch",
"Branch",
"Branch",
NULL,
(G_PARAM_READWRITE |
G_PARAM_CONSTRUCT |
G_PARAM_STATIC_STRINGS));
properties [PROP_COMMAND] =
g_param_spec_string ("command",
"Command",
"Command",
NULL,
(G_PARAM_READWRITE |
G_PARAM_CONSTRUCT |
G_PARAM_STATIC_STRINGS));
properties [PROP_FINISH_ARGS] =
g_param_spec_boxed ("finish-args",
"Finish args",
"Finish args",
G_TYPE_STRV,
(G_PARAM_READWRITE |
G_PARAM_CONSTRUCT |
G_PARAM_STATIC_STRINGS));
properties [PROP_MANIFEST] =
g_param_spec_object ("manifest",
"Manifest",
......@@ -143,6 +335,15 @@ gbp_flatpak_configuration_class_init (GbpFlatpakConfigurationClass *klass)
G_PARAM_CONSTRUCT |
G_PARAM_STATIC_STRINGS));
properties [PROP_PLATFORM] =
g_param_spec_string ("platform",
"Platform",
"Platform",
NULL,
(G_PARAM_READWRITE |
G_PARAM_CONSTRUCT |
G_PARAM_STATIC_STRINGS));
properties [PROP_PRIMARY_MODULE] =
g_param_spec_string ("primary-module",
"Primary module",
......@@ -152,6 +353,15 @@ gbp_flatpak_configuration_class_init (GbpFlatpakConfigurationClass *klass)
G_PARAM_CONSTRUCT |
G_PARAM_STATIC_STRINGS));
properties [PROP_SDK] =
g_param_spec_string ("sdk",
"Sdk",
"Sdk",
NULL,
(G_PARAM_READWRITE |
G_PARAM_CONSTRUCT |
G_PARAM_STATIC_STRINGS));
g_object_class_install_properties (object_class, N_PROPS, properties);
}
......
......@@ -27,10 +27,26 @@ G_BEGIN_DECLS
G_DECLARE_FINAL_TYPE (GbpFlatpakConfiguration, gbp_flatpak_configuration, GBP, FLATPAK_CONFIGURATION, IdeConfiguration)
GFile *gbp_flatpak_configuration_get_manifest (GbpFlatpakConfiguration *self);
const gchar *gbp_flatpak_configuration_get_primary_module (GbpFlatpakConfiguration *self);
void gbp_flatpak_configuration_set_primary_module (GbpFlatpakConfiguration *self,
const gchar *primary_module);
const gchar *gbp_flatpak_configuration_get_branch (GbpFlatpakConfiguration *self);
void gbp_flatpak_configuration_set_branch (GbpFlatpakConfiguration *self,
const gchar *branch);
const gchar *gbp_flatpak_configuration_get_command (GbpFlatpakConfiguration *self);
void gbp_flatpak_configuration_set_command (GbpFlatpakConfiguration *self,
const gchar *command);
const gchar * const *gbp_flatpak_configuration_get_finish_args (GbpFlatpakConfiguration *self);
void gbp_flatpak_configuration_set_finish_args (GbpFlatpakConfiguration *self,
const gchar * const *finish_args);
GFile *gbp_flatpak_configuration_get_manifest (GbpFlatpakConfiguration *self);
gchar *gbp_flatpak_configuration_get_manifest_path (GbpFlatpakConfiguration *self);
const gchar *gbp_flatpak_configuration_get_platform (GbpFlatpakConfiguration *self);
void gbp_flatpak_configuration_set_platform (GbpFlatpakConfiguration *self,
const gchar *platform);
const gchar *gbp_flatpak_configuration_get_primary_module (GbpFlatpakConfiguration *self);
void gbp_flatpak_configuration_set_primary_module (GbpFlatpakConfiguration *self,
const gchar *primary_module);
const gchar *gbp_flatpak_configuration_get_sdk (GbpFlatpakConfiguration *self);
void gbp_flatpak_configuration_set_sdk (GbpFlatpakConfiguration *self,
const gchar *sdk);
G_END_DECLS
......
......@@ -22,6 +22,7 @@
#include "gbp-flatpak-runtime.h"
#include "gbp-flatpak-transfer.h"
#include "gbp-flatpak-util.h"
#include "gbp-flatpak-configuration.h"
enum {
PREPARE_MKDIRS,
......@@ -97,9 +98,9 @@ register_remotes_stage (GbpFlatpakPipelineAddin *self,
config = ide_build_pipeline_get_configuration (pipeline);
platform = ide_configuration_get_internal_string (config, "flatpak-platform");
sdk = ide_configuration_get_internal_string (config, "flatpak-sdk");
branch = ide_configuration_get_internal_string (config, "flatpak-branch");
platform = gbp_flatpak_configuration_get_platform (GBP_FLATPAK_CONFIGURATION (config));
sdk = gbp_flatpak_configuration_get_sdk (GBP_FLATPAK_CONFIGURATION (config));
branch = gbp_flatpak_configuration_get_branch (GBP_FLATPAK_CONFIGURATION (config));
if (ide_str_equal0 (platform, "org.gnome.Platform") ||
ide_str_equal0 (platform, "org.gnome.Sdk") ||
......@@ -177,9 +178,9 @@ register_download_stage (GbpFlatpakPipelineAddin *self,
g_assert (IDE_IS_BUILD_PIPELINE (pipeline));
config = ide_build_pipeline_get_configuration (pipeline);
platform = ide_configuration_get_internal_string (config, "flatpak-platform");
sdk = ide_configuration_get_internal_string (config, "flatpak-sdk");
branch = ide_configuration_get_internal_string (config, "flatpak-branch");
platform = gbp_flatpak_configuration_get_platform (GBP_FLATPAK_CONFIGURATION (config));
sdk = gbp_flatpak_configuration_get_sdk (GBP_FLATPAK_CONFIGURATION (config));
branch = gbp_flatpak_configuration_get_branch (GBP_FLATPAK_CONFIGURATION (config));
items[0] = platform;
items[1] = sdk;
......@@ -261,10 +262,11 @@ register_build_init_stage (GbpFlatpakPipelineAddin *self,
config = ide_build_pipeline_get_configuration (pipeline);
staging_dir = gbp_flatpak_get_staging_dir (config);
platform = ide_configuration_get_internal_string (config, "flatpak-platform");
app_id = ide_configuration_get_app_id (config);
sdk = ide_configuration_get_internal_string (config, "flatpak-sdk");
branch = ide_configuration_get_internal_string (config, "flatpak-branch");
platform = gbp_flatpak_configuration_get_platform (GBP_FLATPAK_CONFIGURATION (config));
sdk = gbp_flatpak_configuration_get_sdk (GBP_FLATPAK_CONFIGURATION (config));
branch = gbp_flatpak_configuration_get_branch (GBP_FLATPAK_CONFIGURATION (config));
if (platform == NULL && sdk == NULL)
{
......@@ -328,7 +330,7 @@ register_dependencies_stage (GbpFlatpakPipelineAddin *self,
g_autofree gchar *staging_dir = NULL;
g_autofree gchar *stop_at_option = NULL;
IdeConfiguration *config;
const gchar *manifest_path;
g_autofree gchar *manifest_path = NULL;
const gchar *primary_module;
guint stage_id;
......@@ -338,8 +340,8 @@ register_dependencies_stage (GbpFlatpakPipelineAddin *self,
config = ide_build_pipeline_get_configuration (pipeline);
primary_module = ide_configuration_get_internal_string (config, "flatpak-module");
manifest_path = ide_configuration_get_internal_string (config, "flatpak-manifest");
primary_module = gbp_flatpak_configuration_get_primary_module (GBP_FLATPAK_CONFIGURATION (config));
manifest_path = gbp_flatpak_configuration_get_manifest_path (GBP_FLATPAK_CONFIGURATION (config));
/* If there is no manifest, then there are no dependencies
* to build for this configuration.
......@@ -382,7 +384,7 @@ register_build_finish_stage (GbpFlatpakPipelineAddin *self,
g_autofree gchar *staging_dir = NULL;
g_autofree gchar *export_path = NULL;
IdeConfiguration *config;
const gchar *manifest_path;
g_autofree gchar *manifest_path = NULL;
const gchar *command;
guint stage_id;
......@@ -392,9 +394,9 @@ register_build_finish_stage (GbpFlatpakPipelineAddin *self,
config = ide_build_pipeline_get_configuration (pipeline);
manifest_path = ide_configuration_get_internal_string (config, "flatpak-manifest");
command = ide_configuration_get_internal_string (config, "flatpak-command");
finish_args = ide_configuration_get_internal_strv (config, "flatpak-finish-args");
manifest_path = gbp_flatpak_configuration_get_manifest_path (GBP_FLATPAK_CONFIGURATION (config));
command = gbp_flatpak_configuration_get_command (GBP_FLATPAK_CONFIGURATION (config));
finish_args = gbp_flatpak_configuration_get_finish_args (GBP_FLATPAK_CONFIGURATION (config));
/* If there is no manifest, then there are no dependencies
* to build for this configuration.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment