[gnome-builder] buildsystem: add IdeSimpleBuildTarget



commit 65a15a55373be020c81642dc05c72366d2f1caf8
Author: Christian Hergert <chergert redhat com>
Date:   Thu Mar 15 04:54:20 2018 -0700

    buildsystem: add IdeSimpleBuildTarget
    
    This is a helper that can be used to make a build target without having
    to re-implement generic interface plumbing.

 src/libide/buildsystem/ide-simple-build-target.c | 217 +++++++++++++++++++++++
 src/libide/buildsystem/ide-simple-build-target.h |  51 ++++++
 src/libide/buildsystem/meson.build               |   2 +
 src/libide/ide.h                                 |   1 +
 4 files changed, 271 insertions(+)
---
diff --git a/src/libide/buildsystem/ide-simple-build-target.c 
b/src/libide/buildsystem/ide-simple-build-target.c
new file mode 100644
index 000000000..1ce113aea
--- /dev/null
+++ b/src/libide/buildsystem/ide-simple-build-target.c
@@ -0,0 +1,217 @@
+/* ide-simple-build-target.c
+ *
+ * Copyright 2018 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#define G_LOG_DOMAIN "ide-simple-build-target"
+
+#include "buildsystem/ide-build-target.h"
+#include "buildsystem/ide-simple-build-target.h"
+
+typedef struct
+{
+  GFile *install_directory;
+  gchar *name;
+  gchar **argv;
+  gchar *cwd;
+  gchar *language;
+  gint priority;
+} IdeSimpleBuildTargetPrivate;
+
+static void build_target_iface_init (IdeBuildTargetInterface *iface);
+
+G_DEFINE_TYPE_WITH_CODE (IdeSimpleBuildTarget, ide_simple_build_target, IDE_TYPE_OBJECT,
+                         G_ADD_PRIVATE (IdeSimpleBuildTarget)
+                         G_IMPLEMENT_INTERFACE (IDE_TYPE_BUILD_TARGET,
+                                                build_target_iface_init))
+
+static void
+ide_simple_build_target_finalize (GObject *object)
+{
+  IdeSimpleBuildTarget *self = (IdeSimpleBuildTarget *)object;
+  IdeSimpleBuildTargetPrivate *priv = ide_simple_build_target_get_instance_private (self);
+
+  g_clear_object (&priv->install_directory);
+  g_clear_pointer (&priv->name, g_free);
+  g_clear_pointer (&priv->argv, g_strfreev);
+  g_clear_pointer (&priv->cwd, g_free);
+  g_clear_pointer (&priv->language, g_free);
+
+  G_OBJECT_CLASS (ide_simple_build_target_parent_class)->finalize (object);
+}
+
+static void
+ide_simple_build_target_class_init (IdeSimpleBuildTargetClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  object_class->finalize = ide_simple_build_target_finalize;
+}
+
+static void
+ide_simple_build_target_init (IdeSimpleBuildTarget *self)
+{
+}
+
+IdeSimpleBuildTarget *
+ide_simple_build_target_new (IdeContext *context)
+{
+  return g_object_new (IDE_TYPE_SIMPLE_BUILD_TARGET,
+                       "context", context,
+                       NULL);
+}
+
+void
+ide_simple_build_target_set_install_directory (IdeSimpleBuildTarget *self,
+                                               GFile                *install_directory)
+{
+  IdeSimpleBuildTargetPrivate *priv = ide_simple_build_target_get_instance_private (self);
+
+  g_return_if_fail (IDE_IS_SIMPLE_BUILD_TARGET (self));
+  g_return_if_fail (!install_directory || G_IS_FILE (install_directory));
+
+  g_set_object (&priv->install_directory, install_directory);
+}
+
+void
+ide_simple_build_target_set_name (IdeSimpleBuildTarget *self,
+                                  const gchar          *name)
+{
+  IdeSimpleBuildTargetPrivate *priv = ide_simple_build_target_get_instance_private (self);
+
+  g_return_if_fail (IDE_IS_SIMPLE_BUILD_TARGET (self));
+
+  if (g_strcmp0 (priv->name, name) != 0)
+    {
+      g_free (priv->name);
+      priv->name = g_strdup (name);
+    }
+}
+
+void
+ide_simple_build_target_set_priority (IdeSimpleBuildTarget *self,
+                                      gint                  priority)
+{
+  IdeSimpleBuildTargetPrivate *priv = ide_simple_build_target_get_instance_private (self);
+
+  g_return_if_fail (IDE_IS_SIMPLE_BUILD_TARGET (self));
+
+  priv->priority = priority;
+}
+
+void
+ide_simple_build_target_set_argv (IdeSimpleBuildTarget *self,
+                                  const gchar * const  *argv)
+{
+  IdeSimpleBuildTargetPrivate *priv = ide_simple_build_target_get_instance_private (self);
+
+  g_return_if_fail (IDE_IS_SIMPLE_BUILD_TARGET (self));
+
+  if (priv->argv != (gchar **)argv)
+    {
+      g_strfreev (priv->argv);
+      priv->argv = g_strdupv ((gchar **)argv);
+    }
+}
+
+void
+ide_simple_build_target_set_cwd (IdeSimpleBuildTarget *self,
+                                 const gchar          *cwd)
+{
+  IdeSimpleBuildTargetPrivate *priv = ide_simple_build_target_get_instance_private (self);
+
+  g_return_if_fail (IDE_IS_SIMPLE_BUILD_TARGET (self));
+
+  if (g_strcmp0 (priv->cwd, cwd) != 0)
+    {
+      g_free (priv->cwd);
+      priv->cwd = g_strdup (cwd);
+    }
+}
+
+void
+ide_simple_build_target_set_language (IdeSimpleBuildTarget *self,
+                                      const gchar          *language)
+{
+  IdeSimpleBuildTargetPrivate *priv = ide_simple_build_target_get_instance_private (self);
+
+  g_return_if_fail (IDE_IS_SIMPLE_BUILD_TARGET (self));
+
+  if (g_strcmp0 (priv->language, language) != 0)
+    {
+      g_free (priv->language);
+      priv->language = g_strdup (language);
+    }
+}
+
+static GFile *
+get_install_directory (IdeBuildTarget *target)
+{
+  IdeSimpleBuildTarget *self = IDE_SIMPLE_BUILD_TARGET (target);
+  IdeSimpleBuildTargetPrivate *priv = ide_simple_build_target_get_instance_private (self);
+  return priv->install_directory ? g_object_ref (priv->install_directory) : NULL;
+}
+
+static gchar *
+get_name (IdeBuildTarget *target)
+{
+  IdeSimpleBuildTarget *self = IDE_SIMPLE_BUILD_TARGET (target);
+  IdeSimpleBuildTargetPrivate *priv = ide_simple_build_target_get_instance_private (self);
+  return g_strdup (priv->name);
+}
+
+static gchar **
+get_argv (IdeBuildTarget *target)
+{
+  IdeSimpleBuildTarget *self = IDE_SIMPLE_BUILD_TARGET (target);
+  IdeSimpleBuildTargetPrivate *priv = ide_simple_build_target_get_instance_private (self);
+  return g_strdupv (priv->argv);
+}
+
+static gchar *
+get_cwd (IdeBuildTarget *target)
+{
+  IdeSimpleBuildTarget *self = IDE_SIMPLE_BUILD_TARGET (target);
+  IdeSimpleBuildTargetPrivate *priv = ide_simple_build_target_get_instance_private (self);
+  return g_strdup (priv->cwd);
+}
+
+static gchar *
+get_language (IdeBuildTarget *target)
+{
+  IdeSimpleBuildTarget *self = IDE_SIMPLE_BUILD_TARGET (target);
+  IdeSimpleBuildTargetPrivate *priv = ide_simple_build_target_get_instance_private (self);
+  return g_strdup (priv->language);
+}
+
+static gint
+get_priority (IdeBuildTarget *target)
+{
+  IdeSimpleBuildTarget *self = IDE_SIMPLE_BUILD_TARGET (target);
+  IdeSimpleBuildTargetPrivate *priv = ide_simple_build_target_get_instance_private (self);
+  return priv->priority;
+}
+
+static void
+build_target_iface_init (IdeBuildTargetInterface *iface)
+{
+  iface->get_install_directory = get_install_directory;
+  iface->get_name = get_name;
+  iface->get_priority = get_priority;
+  iface->get_argv = get_argv;
+  iface->get_cwd = get_cwd;
+  iface->get_language = get_language;
+}
diff --git a/src/libide/buildsystem/ide-simple-build-target.h 
b/src/libide/buildsystem/ide-simple-build-target.h
new file mode 100644
index 000000000..0356f83ee
--- /dev/null
+++ b/src/libide/buildsystem/ide-simple-build-target.h
@@ -0,0 +1,51 @@
+/* ide-simple-build-target.h
+ *
+ * Copyright 2018 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#include <ide.h>
+
+G_BEGIN_DECLS
+
+#define IDE_TYPE_SIMPLE_BUILD_TARGET (ide_simple_build_target_get_type())
+
+G_DECLARE_DERIVABLE_TYPE (IdeSimpleBuildTarget, ide_simple_build_target, IDE, SIMPLE_BUILD_TARGET, IdeObject)
+
+struct _IdeSimpleBuildTargetClass
+{
+  IdeObjectClass parent_class;
+
+  /*< private >*/
+  gpointer _reserved[8];
+};
+
+IdeSimpleBuildTarget *ide_simple_build_target_new                   (IdeContext           *context);
+void                  ide_simple_build_target_set_install_directory (IdeSimpleBuildTarget *self,
+                                                                     GFile                
*install_directory);
+void                  ide_simple_build_target_set_name              (IdeSimpleBuildTarget *self,
+                                                                     const gchar          *name);
+void                  ide_simple_build_target_set_priority          (IdeSimpleBuildTarget *self,
+                                                                     gint                  priority);
+void                  ide_simple_build_target_set_argv              (IdeSimpleBuildTarget *self,
+                                                                     const gchar * const  *argv);
+void                  ide_simple_build_target_set_cwd               (IdeSimpleBuildTarget *self,
+                                                                     const gchar          *cwd);
+void                  ide_simple_build_target_set_language          (IdeSimpleBuildTarget *self,
+                                                                     const gchar          *language);
+
+G_END_DECLS
diff --git a/src/libide/buildsystem/meson.build b/src/libide/buildsystem/meson.build
index 29a6c8eb7..e141fa024 100644
--- a/src/libide/buildsystem/meson.build
+++ b/src/libide/buildsystem/meson.build
@@ -16,6 +16,7 @@ buildsystem_headers = [
   'ide-dependency-updater.h',
   'ide-environment-variable.h',
   'ide-environment.h',
+  'ide-simple-build-target.h',
 ]
 
 buildsystem_sources = [
@@ -35,6 +36,7 @@ buildsystem_sources = [
   'ide-dependency-updater.c',
   'ide-environment-variable.c',
   'ide-environment.c',
+  'ide-simple-build-target.c',
 ]
 
 buildsystem_private_sources = [
diff --git a/src/libide/ide.h b/src/libide/ide.h
index 6f60b9ebf..5d224edd7 100644
--- a/src/libide/ide.h
+++ b/src/libide/ide.h
@@ -62,6 +62,7 @@ G_BEGIN_DECLS
 #include "buildsystem/ide-dependency-updater.h"
 #include "buildsystem/ide-environment-variable.h"
 #include "buildsystem/ide-environment.h"
+#include "buildsystem/ide-simple-build-target.h"
 #include "config/ide-configuration.h"
 #include "config/ide-configuration-manager.h"
 #include "config/ide-configuration-provider.h"


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