[gnome-builder/wip/mwleeds/ide-config-provider: 15/15] This doesn't work
- From: Matthew Leeds <mwleeds src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/mwleeds/ide-config-provider: 15/15] This doesn't work
- Date: Tue, 24 Jan 2017 06:39:06 +0000 (UTC)
commit 47a312eb63a4ab553686b15991c5de77c0757788
Author: Matthew Leeds <mwl458 gmail com>
Date: Mon Jan 23 23:51:25 2017 -0600
This doesn't work
libide/buildsystem/ide-configuration.c | 5 +-
libide/buildsystem/ide-environment.c | 46 ++++++++
.../flatpak/gbp-flatpak-configuration-provider.c | 119 +++++++++++++++++++-
3 files changed, 163 insertions(+), 7 deletions(-)
---
diff --git a/libide/buildsystem/ide-configuration.c b/libide/buildsystem/ide-configuration.c
index 4179516..42b39c8 100644
--- a/libide/buildsystem/ide-configuration.c
+++ b/libide/buildsystem/ide-configuration.c
@@ -188,9 +188,6 @@ ide_configuration_runtime_manager_items_changed (IdeConfiguration *self,
static void
ide_configuration_environment_changed (IdeConfiguration *self,
- guint position,
- guint added,
- guint removed,
IdeEnvironment *environment)
{
IDE_ENTRY;
@@ -510,7 +507,7 @@ ide_configuration_init (IdeConfiguration *self)
priv->internal = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, _value_free);
g_signal_connect_object (priv->environment,
- "items-changed",
+ "changed",
G_CALLBACK (ide_configuration_environment_changed),
self,
G_CONNECT_SWAPPED);
diff --git a/libide/buildsystem/ide-environment.c b/libide/buildsystem/ide-environment.c
index 3bdbdae..31eb9d0 100644
--- a/libide/buildsystem/ide-environment.c
+++ b/libide/buildsystem/ide-environment.c
@@ -30,6 +30,13 @@ static void list_model_iface_init (GListModelInterface *iface);
G_DEFINE_TYPE_EXTENDED (IdeEnvironment, ide_environment, G_TYPE_OBJECT, 0,
G_IMPLEMENT_INTERFACE (G_TYPE_LIST_MODEL, list_model_iface_init))
+enum {
+ CHANGED,
+ LAST_SIGNAL
+};
+
+static guint signals [LAST_SIGNAL];
+
static void
ide_environment_finalize (GObject *object)
{
@@ -46,12 +53,31 @@ ide_environment_class_init (IdeEnvironmentClass *klass)
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->finalize = ide_environment_finalize;
+
+ signals [CHANGED] =
+ g_signal_new ("changed",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST,
+ 0, NULL, NULL, NULL, G_TYPE_NONE, 0);
+}
+
+static void
+ide_environment_items_changed (IdeEnvironment *self)
+{
+ g_assert (IDE_IS_ENVIRONMENT (self));
+
+ g_signal_emit (self, signals [CHANGED], 0);
}
static void
ide_environment_init (IdeEnvironment *self)
{
self->variables = g_ptr_array_new_with_free_func (g_object_unref);
+
+ g_signal_connect (self,
+ "items-changed",
+ G_CALLBACK (ide_environment_items_changed),
+ NULL);
}
static GType
@@ -90,6 +116,16 @@ list_model_iface_init (GListModelInterface *iface)
iface->get_item_type = ide_environment_get_item_type;
}
+static void
+ide_environment_variable_notify (IdeEnvironment *self,
+ GParamSpec *pspec,
+ IdeEnvironmentVariable *variable)
+{
+ g_assert (IDE_IS_ENVIRONMENT (self));
+
+ g_signal_emit (self, signals [CHANGED], 0);
+}
+
void
ide_environment_setenv (IdeEnvironment *self,
const gchar *key,
@@ -128,6 +164,11 @@ ide_environment_setenv (IdeEnvironment *self,
"key", key,
"value", value,
NULL);
+ g_signal_connect_object (var,
+ "notify",
+ G_CALLBACK (ide_environment_variable_notify),
+ self,
+ G_CONNECT_SWAPPED);
g_ptr_array_add (self->variables, var);
g_list_model_items_changed (G_LIST_MODEL (self), position, 0, 1);
}
@@ -230,6 +271,11 @@ ide_environment_append (IdeEnvironment *self,
position = self->variables->len;
+ g_signal_connect_object (variable,
+ "notify",
+ G_CALLBACK (ide_environment_variable_notify),
+ self,
+ G_CONNECT_SWAPPED);
g_ptr_array_add (self->variables, g_object_ref (variable));
g_list_model_items_changed (G_LIST_MODEL (self), position, 0, 1);
}
diff --git a/plugins/flatpak/gbp-flatpak-configuration-provider.c
b/plugins/flatpak/gbp-flatpak-configuration-provider.c
index 22a0690..912d349 100644
--- a/plugins/flatpak/gbp-flatpak-configuration-provider.c
+++ b/plugins/flatpak/gbp-flatpak-configuration-provider.c
@@ -112,28 +112,33 @@ gbp_flatpak_configuration_provider_save_async (GbpFlatpakConfigurationProvider *
g_autoptr(GFileInputStream) file_stream = NULL;
g_autoptr(GDataInputStream) data_stream = NULL;
g_autoptr(GRegex) runtime_regex = NULL;
+ g_autoptr(GRegex) build_options_regex = NULL;
g_autoptr(GRegex) config_opts_regex = NULL;
g_autoptr(GRegex) primary_module_regex = NULL;
g_autoptr(GPtrArray) new_lines = NULL;
g_autoptr(GBytes) bytes = NULL;
g_auto(GStrv) new_config_opts = NULL;
g_auto(GStrv) new_runtime_parts = NULL;
+ g_auto(GStrv) new_environ = NULL;
g_autofree gchar *primary_module_regex_str = NULL;
g_autofree gchar *primary_module_right_curly_brace = NULL;
g_autofree gchar *right_curly_brace_line = NULL;
g_autofree gchar *primary_module_indent = NULL;
+ g_autofree gchar *build_options_indent = NULL;
g_autofree gchar *config_opt_indent = NULL;
g_autofree gchar *array_prefix = NULL;
g_autofree gchar *new_config_opts_string = NULL;
- gchar *json_string = NULL;
+ gchar *json_string;
const gchar *primary_module;
const gchar *new_runtime_id;
gchar *new_runtime_name;
- guint opts_per_line;
GFile *manifest;
gboolean in_config_opts_array;
gboolean in_primary_module;
+ gboolean in_build_options;
gboolean config_opts_replaced;
+ guint opts_per_line;
+ guint nested_curly_braces;
GbpFlatpakConfiguration *configuration = (GbpFlatpakConfiguration *)g_ptr_array_index
(self->configurations, i);
@@ -158,6 +163,7 @@ gbp_flatpak_configuration_provider_save_async (GbpFlatpakConfigurationProvider *
data_stream = g_data_input_stream_new (G_INPUT_STREAM (file_stream));
runtime_regex = g_regex_new ("^\\s*\"runtime\"\\s*:\\s*\"(?<id>.+)\",$", 0, 0, NULL);
+ build_options_regex = g_regex_new ("^\\s*\"build-options\"\\s*:\\s*{$", 0, 0, NULL);
config_opts_regex = g_regex_new ("^(\\s*\"config-opts\"\\s*:\\s*\\[).+$", 0, 0, NULL);
primary_module_regex_str = g_strdup_printf ("^(\\s*)\"name\"\\s*:\\s*\"%s\",$", primary_module);
primary_module_regex = g_regex_new (primary_module_regex_str, 0, 0, NULL);
@@ -176,10 +182,14 @@ gbp_flatpak_configuration_provider_save_async (GbpFlatpakConfigurationProvider *
new_config_opts = g_strsplit (g_strstrip (new_config_opts_string), " ", 0);
}
+ new_environ = ide_configuration_get_environ (IDE_CONFIGURATION (configuration));
+
new_lines = g_ptr_array_new_with_free_func (g_free);
in_config_opts_array = FALSE;
in_primary_module = FALSE;
- config_opts_replaced = 0;
+ in_build_options = FALSE;
+ config_opts_replaced = FALSE;
+ nested_curly_braces = 0;
for (;;)
{
gchar *line;
@@ -226,6 +236,109 @@ gbp_flatpak_configuration_provider_save_async (GbpFlatpakConfigurationProvider *
}
}
+ /* Update the environment variables */
+ //TODO add support for single-line build-options?
+ //TODO account for module-specific build-options?
+ if (!in_build_options)
+ {
+ g_autoptr(GMatchInfo) match_info = NULL;
+ g_regex_match (build_options_regex, line, 0, &match_info);
+ if (g_match_info_matches (match_info))
+ {
+ in_build_options = TRUE;
+ }
+ }
+ else
+ {
+ if (g_strstr_len (line, -1, "{") != NULL)
+ nested_curly_braces++;
+ if (g_strstr_len (line, -1, "}") == NULL)
+ {
+ if (build_options_indent == NULL)
+ {
+ g_autoptr(GRegex) build_options_internal_regex = NULL;
+ g_autoptr(GMatchInfo) match_info = NULL;
+ build_options_internal_regex = g_regex_new ("^(\\s*)\".+\"\\s*:.*$", 0, 0, NULL);
+ g_regex_match (build_options_internal_regex, line, 0, &match_info);
+ if (g_match_info_matches (match_info))
+ {
+ build_options_indent = g_match_info_fetch (match_info, 1);
+ }
+ }
+ continue;
+ }
+ else
+ {
+ if (nested_curly_braces > 0)
+ nested_curly_braces--;
+ else
+ {
+ guint num_env;
+ num_env = g_strv_length (new_environ);
+ if (num_env > 0)
+ {
+ g_autofree gchar *cflags_line = NULL;
+ g_autofree gchar *cxxflags_line = NULL;
+ g_autoptr(GPtrArray) env_lines = NULL;
+ if (build_options_indent == NULL)
+ build_options_indent = g_strdup (" ");
+ for (guint j = 0; new_environ[j]; j++)
+ {
+ g_auto(GStrv) line_parts = NULL;
+ line_parts = g_strsplit (new_environ[j], "=", 2);
+ //TODO account for prefix
+ if (g_strcmp0 (line_parts[0], "CFLAGS") == 0)
+ cflags_line = g_strdup_printf ("%s\"cflags\": \"%s\"",
+ build_options_indent,
+ line_parts[1]);
+ else if (g_strcmp0 (line_parts[0], "CXXFLAGS") == 0)
+ cxxflags_line = g_strdup_printf ("%s\"cxxflags\": \"%s\"",
+ build_options_indent,
+ line_parts[1]);
+ else
+ {
+ if (env_lines == NULL)
+ {
+ env_lines = g_ptr_array_new_with_free_func (g_free);
+ g_ptr_array_add (env_lines, g_strdup_printf ("%s\"env\": {",
build_options_indent));
+ }
+ g_ptr_array_add (env_lines, g_strdup_printf ("%s \"%s\": \"%s\"",
+ build_options_indent,
+ line_parts[0],
+ line_parts[1]));
+ }
+ }
+ if (cflags_line != NULL)
+ {
+ gchar *line_ending;
+ line_ending = (cxxflags_line != NULL || env_lines != NULL) ? "," : "";
+ g_ptr_array_add (new_lines, g_strdup_printf ("%s%s", cflags_line,
line_ending));
+ }
+ if (cxxflags_line != NULL)
+ {
+ gchar *line_ending;
+ line_ending = (env_lines != NULL) ? "," : "";
+ g_ptr_array_add (new_lines, g_strdup_printf ("%s%s", cxxflags_line,
line_ending));
+ }
+ if (env_lines != NULL)
+ {
+ g_ptr_array_add (env_lines, g_strdup_printf ("%s}", build_options_indent));
+ g_ptr_array_add (env_lines, NULL);
+ for (guint j = 0; j < env_lines->len; j++)
+ {
+ gchar *env_line;
+ gchar *line_ending;
+ line_ending = (j > 0 && j < env_lines->len - 2) ? "," : "";
+ env_line = (gchar *)g_ptr_array_index (env_lines, j);
+ g_ptr_array_add (new_lines, g_strdup_printf ("%s%s", env_line,
line_ending));
+ }
+ }
+ }
+ in_build_options = FALSE;
+ }
+ }
+ }
+
if (in_primary_module)
{
g_autoptr(GMatchInfo) match_info = NULL;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]