[gnome-builder] buffer: add convenience API to get build flags



commit 5454a29cb7953d8c5a361b8d50b6330274532ed1
Author: Christian Hergert <chergert redhat com>
Date:   Mon Jun 18 15:01:45 2018 -0700

    buffer: add convenience API to get build flags
    
    This is convenient for cases where we need build flags in things like
    diagnostics/completion providers. We can probably do some caching as
    well, but in practice, the build systems are doing that too.

 src/libide/buffers/ide-buffer.c | 71 +++++++++++++++++++++++++++++++++++++++++
 src/libide/buffers/ide-buffer.h |  9 ++++++
 2 files changed, 80 insertions(+)
---
diff --git a/src/libide/buffers/ide-buffer.c b/src/libide/buffers/ide-buffer.c
index af395b3ed..b05c82c95 100644
--- a/src/libide/buffers/ide-buffer.c
+++ b/src/libide/buffers/ide-buffer.c
@@ -27,6 +27,7 @@
 #include "ide-debug.h"
 
 #include "application/ide-application.h"
+#include "buildsystem/ide-build-system.h"
 #include "buffers/ide-buffer-addin.h"
 #include "buffers/ide-buffer-change-monitor.h"
 #include "buffers/ide-buffer-manager.h"
@@ -3418,3 +3419,73 @@ _ide_buffer_set_auto_save (IdeBuffer *self,
 
   ide_buffer_queue_auto_save (self);
 }
+
+static void
+ide_buffer_get_build_flags_cb (GObject      *object,
+                               GAsyncResult *result,
+                               gpointer      user_data)
+{
+  IdeBuildSystem *build_system = (IdeBuildSystem *)object;
+  g_autoptr(IdeTask) task = user_data;
+  g_autoptr(GError) error = NULL;
+  g_auto(GStrv) build_flags = NULL;
+
+  g_assert (IDE_IS_BUILD_SYSTEM (build_system));
+  g_assert (G_IS_ASYNC_RESULT (result));
+  g_assert (IDE_IS_TASK (task));
+
+  build_flags = ide_build_system_get_build_flags_finish (build_system, result, &error);
+
+  if (error != NULL)
+    ide_task_return_error (task, g_steal_pointer (&error));
+  else
+    ide_task_return_pointer (task, g_steal_pointer (&build_flags), (GDestroyNotify)g_strfreev);
+}
+
+void
+ide_buffer_get_build_flags_async (IdeBuffer           *self,
+                                  GCancellable        *cancellable,
+                                  GAsyncReadyCallback  callback,
+                                  gpointer             user_data)
+{
+  IdeBufferPrivate *priv = ide_buffer_get_instance_private (self);
+  g_autoptr(IdeTask) task = NULL;
+  IdeBuildSystem *build_system;
+
+  g_return_if_fail (IDE_IS_BUFFER (self));
+  g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
+
+  task = ide_task_new (self, cancellable, callback, user_data);
+  ide_task_set_source_tag (task, ide_buffer_get_build_flags_async);
+
+  build_system = ide_context_get_build_system (priv->context);
+
+  ide_build_system_get_build_flags_async (build_system,
+                                          priv->file,
+                                          cancellable,
+                                          ide_buffer_get_build_flags_cb,
+                                          g_steal_pointer (&task));
+}
+
+/**
+ * ide_buffer_get_build_flags_finish:
+ * @self: a #IdeBuffer
+ * @result: the result provided to callback
+ * @error: location for a #GError, or %NULL
+ *
+ * Completes a request to get the build flags for the buffer.
+ *
+ * Returns: (transfer full) (array zero-terminated=1): an array of build flags
+ *
+ * Since: 3.30
+ */
+gchar **
+ide_buffer_get_build_flags_finish (IdeBuffer     *self,
+                                   GAsyncResult  *result,
+                                   GError       **error)
+{
+  g_return_val_if_fail (IDE_IS_BUFFER (self), NULL);
+  g_return_val_if_fail (IDE_IS_TASK (result), NULL);
+
+  return ide_task_propagate_pointer (IDE_TASK (result), error);
+}
diff --git a/src/libide/buffers/ide-buffer.h b/src/libide/buffers/ide-buffer.h
index d8b54329e..ac439d595 100644
--- a/src/libide/buffers/ide-buffer.h
+++ b/src/libide/buffers/ide-buffer.h
@@ -161,5 +161,14 @@ IDE_AVAILABLE_IN_3_28
 const GError             *ide_buffer_get_failure                   (IdeBuffer            *self);
 IDE_AVAILABLE_IN_ALL
 gboolean                  ide_buffer_get_has_diagnostics           (IdeBuffer            *self);
+IDE_AVAILABLE_IN_3_30
+void                      ide_buffer_get_build_flags_async         (IdeBuffer            *self,
+                                                                    GCancellable         *cancellable,
+                                                                    GAsyncReadyCallback   callback,
+                                                                    gpointer              user_data);
+IDE_AVAILABLE_IN_3_30
+gchar                   **ide_buffer_get_build_flags_finish        (IdeBuffer            *self,
+                                                                    GAsyncResult         *result,
+                                                                    GError              **error);
 
 G_END_DECLS


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]