Commit d3f27e86 authored by Christian Hergert's avatar Christian Hergert
Browse files

config: add "run-opts" property

This can be used as a simple way to pass run options to the target
executable. The flatpak module still needs save support, but this adds
load support using x-run-args in the .json.
parent c7437352
......@@ -157,6 +157,7 @@ ide_buildconfig_configuration_provider_save_async (IdeConfigurationProvider *pro
PERSIST_STRING_KEY ("device", get_device_id);
PERSIST_STRING_KEY ("runtime", get_runtime_id);
PERSIST_STRING_KEY ("config-opts", get_config_opts);
PERSIST_STRING_KEY ("run-opts", get_run_opts);
PERSIST_STRING_KEY ("prefix", get_prefix);
PERSIST_STRING_KEY ("app-id", get_app_id);
#undef PERSIST_STRING_KEY
......@@ -370,6 +371,7 @@ ide_buildconfig_configuration_provider_load_group (IdeBuildconfigConfigurationPr
load_string (configuration, key_file, group, "config-opts", "config-opts");
load_string (configuration, key_file, group, "device", "device-id");
load_string (configuration, key_file, group, "name", "display-name");
load_string (configuration, key_file, group, "run-opts", "run-opts");
load_string (configuration, key_file, group, "runtime", "runtime-id");
load_string (configuration, key_file, group, "prefix", "prefix");
load_string (configuration, key_file, group, "app-id", "app-id");
......
......@@ -42,6 +42,7 @@ typedef struct
gchar *id;
gchar **post_install_commands;
gchar *prefix;
gchar *run_opts;
gchar *runtime_id;
IdeEnvironment *environment;
......@@ -81,6 +82,7 @@ enum {
PROP_POST_INSTALL_COMMANDS,
PROP_PREFIX,
PROP_READY,
PROP_RUN_OPTS,
PROP_RUNTIME,
PROP_RUNTIME_ID,
PROP_APP_ID,
......@@ -417,6 +419,10 @@ ide_configuration_get_property (GObject *object,
g_value_set_string (value, ide_configuration_get_runtime_id (self));
break;
case PROP_RUN_OPTS:
g_value_set_string (value, ide_configuration_get_run_opts (self));
break;
case PROP_APP_ID:
g_value_set_string (value, ide_configuration_get_app_id (self));
break;
......@@ -488,6 +494,10 @@ ide_configuration_set_property (GObject *object,
ide_configuration_set_runtime_id (self, g_value_get_string (value));
break;
case PROP_RUN_OPTS:
ide_configuration_set_run_opts (self, g_value_get_string (value));
break;
case PROP_APP_ID:
ide_configuration_set_app_id (self, g_value_get_string (value));
break;
......@@ -605,6 +615,13 @@ ide_configuration_class_init (IdeConfigurationClass *klass)
FALSE,
(G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
properties [PROP_RUN_OPTS] =
g_param_spec_string ("run-opts",
"Run Options",
"The options for running the target application",
NULL,
(G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
properties [PROP_RUNTIME] =
g_param_spec_object ("runtime",
"Runtime",
......@@ -1606,3 +1623,52 @@ ide_configuration_supports_runtime (IdeConfiguration *self,
IDE_RETURN (ret);
}
/**
* ide_configuration_get_run_opts:
* @self: a #IdeConfiguration
*
* Gets the command line options to use when running the target application.
* The result should be parsed with g_shell_parse_argv() to convert the run
* options to an array suitable for use in argv.
*
* Returns: (transfer none) (nullable): A string containing the run options
* or %NULL if none have been set.
*
* Since: 3.26
*/
const gchar *
ide_configuration_get_run_opts (IdeConfiguration *self)
{
IdeConfigurationPrivate *priv = ide_configuration_get_instance_private (self);
g_return_val_if_fail (IDE_IS_CONFIGURATION (self), NULL);
return priv->run_opts;
}
/**
* ide_configuration_set_run_opts:
* @self: a #IdeConfiguration
* @run_opts: (nullable): the run options for the target application
*
* Sets the run options to use when running the target application.
* See ide_configuration_get_run_opts() for more information.
*
* Since: 3.26
*/
void
ide_configuration_set_run_opts (IdeConfiguration *self,
const gchar *run_opts)
{
IdeConfigurationPrivate *priv = ide_configuration_get_instance_private (self);
g_return_if_fail (IDE_IS_CONFIGURATION (self));
if (g_strcmp0 (run_opts, priv->run_opts) != 0)
{
g_free (priv->run_opts);
priv->run_opts = g_strdup (run_opts);
g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_RUN_OPTS]);
}
}
......@@ -104,6 +104,9 @@ void ide_configuration_set_prefix (IdeConfigurat
const gchar *ide_configuration_get_config_opts (IdeConfiguration *self);
void ide_configuration_set_config_opts (IdeConfiguration *self,
const gchar *config_opts);
const gchar *ide_configuration_get_run_opts (IdeConfiguration *self);
void ide_configuration_set_run_opts (IdeConfiguration *self,
const gchar *run_opts);
const gchar * const *ide_configuration_get_build_commands (IdeConfiguration *self);
void ide_configuration_set_build_commands (IdeConfiguration *self,
const gchar *const *build_commands);
......
......@@ -181,6 +181,24 @@ get_strv_from_member (JsonObject *obj,
return (gchar **)g_ptr_array_free (finish_args, FALSE);
}
static gchar *
get_argv_from_member (JsonObject *obj,
const gchar *name)
{
g_auto(GStrv) argv = NULL;
if (NULL == (argv = get_strv_from_member (obj, name)))
return NULL;
for (guint i = 0; argv[i]; i++)
{
g_autofree gchar *freeme = argv[i];
argv[i] = g_shell_quote (argv[i]);
}
return g_strjoinv (" ", argv);
}
/**
* gbp_flatpak_configuration_load_from_file:
* @self: a #GbpFlatpakConfiguration
......@@ -342,6 +360,14 @@ gbp_flatpak_configuration_load_from_file (GbpFlatpakConfiguration *self,
gbp_flatpak_configuration_set_finish_args (self, (const gchar * const *)finish_args);
}
/* Our custom extension to store run options in the .json */
if (json_object_has_member (root_object, "x-run-args"))
{
g_autofree gchar *run_args = get_argv_from_member (root_object, "x-run-args");
ide_configuration_set_run_opts (IDE_CONFIGURATION (self), run_args);
}
if (app_id_node != NULL && JSON_NODE_HOLDS_VALUE (app_id_node))
ide_configuration_set_app_id (IDE_CONFIGURATION (self), json_node_get_string (app_id_node));
else
......@@ -353,32 +379,15 @@ gbp_flatpak_configuration_load_from_file (GbpFlatpakConfiguration *self,
{
const gchar *primary_module_name;
JsonObject *primary_module_object;
g_autofree gchar *config_opts = NULL;
primary_module_object = json_node_get_object (primary_module_node);
primary_module_name = json_object_get_string_member (primary_module_object, "name");
gbp_flatpak_configuration_set_primary_module (self, primary_module_name);
if (json_object_has_member (primary_module_object, "config-opts"))
{
JsonArray *config_opts_array;
config_opts_array = json_object_get_array_member (primary_module_object, "config-opts");
if (config_opts_array != NULL)
{
g_autoptr(GPtrArray) config_opts_strv = NULL;
config_opts_strv = g_ptr_array_new_with_free_func (g_free);
for (guint i = 0; i < json_array_get_length (config_opts_array); i++)
{
const gchar *next_option;
next_option = json_array_get_string_element (config_opts_array, i);
g_ptr_array_add (config_opts_strv, g_strdup (next_option));
}
g_ptr_array_add (config_opts_strv, NULL);
if (config_opts_strv->len > 1)
{
const gchar *config_opts;
config_opts = g_strjoinv (" ", (gchar **)config_opts_strv->pdata);
ide_configuration_set_config_opts (IDE_CONFIGURATION (self), config_opts);
}
}
}
config_opts = get_argv_from_member (primary_module_object, "config-opts");
ide_configuration_set_config_opts (IDE_CONFIGURATION (self), config_opts);
if (json_object_has_member (primary_module_object, "build-commands"))
{
JsonArray *build_commands_array;
......@@ -396,6 +405,7 @@ gbp_flatpak_configuration_load_from_file (GbpFlatpakConfiguration *self,
build_commands_strv = (gchar **)g_ptr_array_free (build_commands, FALSE);
ide_configuration_set_build_commands (IDE_CONFIGURATION (self), (const gchar * const *)build_commands_strv);
}
if (json_object_has_member (primary_module_object, "post-install"))
{
JsonArray *post_install_commands_array;
......
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