[gnome-builder/wip/tintou/toolchain] Changed the IdeToolchain to be more generic, created IdeSimpleToolchain



commit 816ce169573cb50f6805e49bcd04f4e1bb560087
Author: Corentin Noël <corentin noel collabora co uk>
Date:   Thu Apr 12 16:49:51 2018 +0100

    Changed the IdeToolchain to be more generic, created IdeSimpleToolchain

 src/libide/toolchain/ide-simple-toolchain.c        | 116 +++++++
 src/libide/toolchain/ide-simple-toolchain.h        |  50 +++
 src/libide/toolchain/ide-toolchain-manager.c       |   7 +-
 src/libide/toolchain/ide-toolchain.c               | 345 +++------------------
 src/libide/toolchain/ide-toolchain.h               |  70 ++---
 src/libide/toolchain/meson.build                   |   2 +
 .../autotools/ide-autotools-pipeline-addin.c       |  30 +-
 src/plugins/cmake/gbp-cmake-toolchain.c            |  41 ++-
 src/plugins/meson/gbp-meson-pipeline-addin.c       |  21 +-
 src/plugins/meson/gbp-meson-toolchain.c            |  26 +-
 10 files changed, 330 insertions(+), 378 deletions(-)
---
diff --git a/src/libide/toolchain/ide-simple-toolchain.c b/src/libide/toolchain/ide-simple-toolchain.c
new file mode 100644
index 000000000..1da4ad981
--- /dev/null
+++ b/src/libide/toolchain/ide-simple-toolchain.c
@@ -0,0 +1,116 @@
+/* ide-simple-toolchain.c
+ *
+ * Copyright 2018 Corentin Noël <corentin noel collabora com>
+ * Copyright 2018 Collabora Ltd.
+ *
+ * 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-toolchain"
+
+#include "config.h"
+
+#include "ide-context.h"
+
+#include "toolchain/ide-simple-toolchain.h"
+
+typedef struct
+{
+  GHashTable *tools;
+} IdeSimpleToolchainPrivate;
+
+G_DEFINE_TYPE_WITH_PRIVATE (IdeSimpleToolchain, ide_simple_toolchain, IDE_TYPE_TOOLCHAIN)
+
+IdeSimpleToolchain *
+ide_simple_toolchain_new (IdeContext   *context,
+                          const gchar  *id)
+{
+  g_return_val_if_fail (IDE_IS_CONTEXT (context), NULL);
+  g_return_val_if_fail (id != NULL, NULL);
+
+  return g_object_new (IDE_TYPE_SIMPLE_TOOLCHAIN,
+                       "context", context,
+                       "id", id,
+                       NULL);
+}
+
+const gchar *
+ide_simple_toolchain_get_tool_for_language (IdeToolchain  *toolchain,
+                                            const gchar   *language,
+                                            const gchar   *tool_id)
+{
+  IdeSimpleToolchain *self = (IdeSimpleToolchain *)toolchain;
+  IdeSimpleToolchainPrivate *priv;
+
+  g_return_val_if_fail (IDE_IS_SIMPLE_TOOLCHAIN (self), NULL);
+  g_return_val_if_fail (tool_id != NULL, NULL);
+
+  priv = ide_simple_toolchain_get_instance_private (self);
+  return NULL;
+}
+
+/**
+ * ide_simple_toolchain_set_tool_for_language:
+ * @self: an #IdeSimpleToolchain
+ * @tool_id: the identifier of the tool like %IDE_TOOLCHAIN_TOOL_CC
+ * @language: the language of the tool like %IDE_TOOLCHAIN_LANGUAGE_C.
+ * @tool_path: The path of
+ *
+ * Gets the path of the compiler executable
+ *
+ * Since: 3.30
+ */
+void
+ide_simple_toolchain_set_tool_for_language  (IdeSimpleToolchain  *self,
+                                             const gchar         *language,
+                                             const gchar         *tool_id,
+                                             const gchar         *tool_path)
+{
+  IdeSimpleToolchainPrivate *priv;
+
+  g_return_if_fail (IDE_IS_SIMPLE_TOOLCHAIN (self));
+  g_return_if_fail (tool_id != NULL);
+
+  priv = ide_simple_toolchain_get_instance_private (self);
+  g_hash_table_insert (priv->tools, g_strconcat (tool_id, ":", language, NULL), g_strdup (tool_path));
+}
+
+static void
+ide_simple_toolchain_finalize (GObject *object)
+{
+  IdeSimpleToolchain *self = (IdeSimpleToolchain *)object;
+  IdeSimpleToolchainPrivate *priv = ide_simple_toolchain_get_instance_private (self);
+
+  g_clear_pointer (&priv->tools, g_hash_table_unref);
+
+  G_OBJECT_CLASS (ide_simple_toolchain_parent_class)->finalize (object);
+}
+
+static void
+ide_simple_toolchain_class_init (IdeSimpleToolchainClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  IdeToolchainClass *toolchain_class = IDE_TOOLCHAIN_CLASS (klass);
+
+  object_class->finalize = ide_simple_toolchain_finalize;
+
+  toolchain_class->get_tool_for_language = ide_simple_toolchain_get_tool_for_language;
+}
+
+static void
+ide_simple_toolchain_init (IdeSimpleToolchain *self)
+{
+  IdeSimpleToolchainPrivate *priv = ide_simple_toolchain_get_instance_private (self);
+  priv->tools = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
+}
diff --git a/src/libide/toolchain/ide-simple-toolchain.h b/src/libide/toolchain/ide-simple-toolchain.h
new file mode 100644
index 000000000..a1b7ff7f7
--- /dev/null
+++ b/src/libide/toolchain/ide-simple-toolchain.h
@@ -0,0 +1,50 @@
+/* ide-simple-toolchain.h
+ *
+ * Copyright 2018 Corentin Noël <corentin noel collabora com>
+ * Copyright 2018 Collabora Ltd.
+ *
+ * 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-version-macros.h"
+
+#include "toolchain/ide-toolchain.h"
+
+G_BEGIN_DECLS
+
+#define IDE_TYPE_SIMPLE_TOOLCHAIN (ide_simple_toolchain_get_type())
+
+IDE_AVAILABLE_IN_3_30
+G_DECLARE_DERIVABLE_TYPE (IdeSimpleToolchain, ide_simple_toolchain, IDE, SIMPLE_TOOLCHAIN, IdeToolchain)
+
+struct _IdeSimpleToolchainClass
+{
+  IdeToolchainClass parent;
+
+  /*< private >*/
+  gpointer _reserved[8];
+};
+
+IDE_AVAILABLE_IN_3_30
+IdeSimpleToolchain  *ide_simple_toolchain_new                    (IdeContext          *context,
+                                                                  const gchar         *id);
+IDE_AVAILABLE_IN_3_30
+void                 ide_simple_toolchain_set_tool_for_language  (IdeSimpleToolchain  *self,
+                                                                  const gchar         *language,
+                                                                  const gchar         *tool_id,
+                                                                  const gchar         *tool_path);
+
+G_END_DECLS
diff --git a/src/libide/toolchain/ide-toolchain-manager.c b/src/libide/toolchain/ide-toolchain-manager.c
index 10a80696b..cc013a1a5 100644
--- a/src/libide/toolchain/ide-toolchain-manager.c
+++ b/src/libide/toolchain/ide-toolchain-manager.c
@@ -30,6 +30,7 @@
 #include "buildsystem/ide-build-private.h"
 #include "config/ide-configuration.h"
 #include "devices/ide-device.h"
+#include "toolchain/ide-simple-toolchain.h"
 #include "toolchain/ide-toolchain.h"
 #include "toolchain/ide-toolchain-manager.h"
 #include "toolchain/ide-toolchain-provider.h"
@@ -102,7 +103,7 @@ ide_toolchain_manager_initable_init (GInitable     *initable,
 {
   IdeToolchainManager *self = (IdeToolchainManager *)initable;
   IdeContext *context;
-  g_autoptr(IdeToolchain) default_toolchain = NULL;
+  g_autoptr(IdeSimpleToolchain) default_toolchain = NULL;
 
   g_assert (IDE_IS_TOOLCHAIN_MANAGER (self));
   context = ide_object_get_context (IDE_OBJECT (self));
@@ -126,8 +127,8 @@ ide_toolchain_manager_initable_init (GInitable     *initable,
                               ide_toolchain_manager_extension_added,
                               self);
 
-  default_toolchain = ide_toolchain_new (context, "default");
-  ide_toolchain_manager_add (self, default_toolchain);
+  default_toolchain = ide_simple_toolchain_new (context, "default");
+  ide_toolchain_manager_add (self, IDE_TOOLCHAIN (default_toolchain));
 
   return TRUE;
 }
diff --git a/src/libide/toolchain/ide-toolchain.c b/src/libide/toolchain/ide-toolchain.c
index 99ee177f2..9c75b68b9 100644
--- a/src/libide/toolchain/ide-toolchain.c
+++ b/src/libide/toolchain/ide-toolchain.c
@@ -32,42 +32,19 @@ typedef struct
 {
   gchar *id;
   IdeTriplet *host_triplet;
-  GHashTable *compilers;
-  gchar *archiver;
-  gchar *strip;
-  gchar *pkg_config;
-  gchar *exe_wrapper;
 } IdeToolchainPrivate;
 
-G_DEFINE_TYPE_WITH_PRIVATE (IdeToolchain, ide_toolchain, IDE_TYPE_OBJECT)
+G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (IdeToolchain, ide_toolchain, IDE_TYPE_OBJECT)
 
 enum {
   PROP_0,
   PROP_ID,
   PROP_HOST_TRIPLET,
-  PROP_COMPILERS,
-  PROP_ARCHIVER,
-  PROP_STRIP,
-  PROP_PKG_CONFIG,
-  PROP_EXE_WRAPPER,
   N_PROPS
 };
 
 static GParamSpec *properties [N_PROPS];
 
-IdeToolchain *
-ide_toolchain_new (IdeContext   *context,
-                   const gchar  *id)
-{
-  g_return_val_if_fail (IDE_IS_CONTEXT (context), NULL);
-  g_return_val_if_fail (id != NULL, NULL);
-
-  return g_object_new (IDE_TYPE_TOOLCHAIN,
-                       "context", context,
-                       "id", id,
-                       NULL);
-}
-
 /**
  * ide_toolchain_get_id:
  * @self: an #IdeToolchain
@@ -154,259 +131,84 @@ ide_toolchain_get_host_triplet (IdeToolchain *self)
   return ide_triplet_ref (priv->host_triplet);
 }
 
-/**
- * ide_toolchain_get_compilers:
- * @self: an #IdeToolchain
- *
- * Gets the path of the compiler executable
- *
- * Returns: (transfer none) (element-type utf8 utf8): A #GHashTable containing a the entries of
- * language and compiler paths.
- *
- * Since: 3.30
- */
-GHashTable *
-ide_toolchain_get_compilers (IdeToolchain  *self)
-{
-  IdeToolchainPrivate *priv = ide_toolchain_get_instance_private (self);
-
-  g_return_val_if_fail (IDE_IS_TOOLCHAIN (self), NULL);
-
-  return priv->compilers;
-}
-
-/**
- * ide_toolchain_get_compiler:
- * @self: an #IdeToolchain
- * @language: the name of the language supported by this compiler
- *
- * Gets the path of the compiler executable
- *
- * Returns: (nullable) (transfer none): A path or %NULL.
- *
- * Since: 3.30
- */
 const gchar *
-ide_toolchain_get_compiler (IdeToolchain  *self,
-                            const gchar   *language)
+ide_toolchain_real_get_tool_for_language (IdeToolchain  *self,
+                                          const gchar   *language,
+                                          const gchar   *tool_id)
 {
-  IdeToolchainPrivate *priv = ide_toolchain_get_instance_private (self);
-
   g_return_val_if_fail (IDE_IS_TOOLCHAIN (self), NULL);
 
-  return g_hash_table_lookup (priv->compilers, language);
-}
-
-/**
- * ide_toolchain_set_compiler:
- * @self: an #IdeToolchain
- * @language: the name of the language supported by this compiler
- * @path: (nullable): the path to the archiver executable
- *
- * Sets the path of the compiler executable
- * If the @path is %NULL then the language row will simply be removed from the #GHashTable
- *
- * Since: 3.30
- */
-void
-ide_toolchain_set_compiler (IdeToolchain  *self,
-                            const gchar   *language,
-                            const gchar   *path)
-{
-  IdeToolchainPrivate *priv = ide_toolchain_get_instance_private (self);
-  const gchar *current_path = ide_toolchain_get_compiler (self, language);
+  g_critical ("%s has not implemented get_tool_for_language()", G_OBJECT_TYPE_NAME (self));
 
-  g_return_if_fail (IDE_IS_TOOLCHAIN (self));
-
-  if (g_strcmp0 (path, current_path) != 0)
-    {
-      if (path == NULL)
-        g_hash_table_remove (priv->compilers, language);
-      else
-        g_hash_table_insert (priv->compilers, g_strdup (language), g_strdup (path));
-
-      g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_COMPILERS]);
-    }
+  return NULL;
 }
 
-/**
- * ide_toolchain_get_archiver:
- * @self: an #IdeToolchain
- *
- * Gets the path of the archiver executable
- *
- * Returns: (nullable) (transfer none): A path or %NULL.
- *
- * Since: 3.30
- */
-const gchar *
-ide_toolchain_get_archiver (IdeToolchain  *self)
+GHashTable *
+ide_toolchain_real_get_tools_for_id (IdeToolchain  *self,
+                                     const gchar   *tool_id)
 {
-  IdeToolchainPrivate *priv = ide_toolchain_get_instance_private (self);
-
   g_return_val_if_fail (IDE_IS_TOOLCHAIN (self), NULL);
 
-  return priv->archiver;
-}
+  g_critical ("%s has not implemented get_tools_for_id()", G_OBJECT_TYPE_NAME (self));
 
-/**
- * ide_toolchain_set_archiver:
- * @self: an #IdeToolchain
- * @path: (nullable): the path to the archiver executable
- *
- * Sets the path of the archiver executable
- *
- * Since: 3.30
- */
-void
-ide_toolchain_set_archiver (IdeToolchain  *self,
-                            const gchar   *path)
-{
-  IdeToolchainPrivate *priv = ide_toolchain_get_instance_private (self);
-
-  g_return_if_fail (IDE_IS_TOOLCHAIN (self));
-
-  if (g_strcmp0 (path, priv->archiver) != 0)
-    {
-      g_free (priv->archiver);
-      priv->archiver = g_strdup (path);
-      g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_ARCHIVER]);
-    }
+  return NULL;
 }
 
 /**
- * ide_toolchain_get_strip:
+ * ide_toolchain_get_tool_for_language:
  * @self: an #IdeToolchain
+ * @language: the language of the tool like %IDE_TOOLCHAIN_LANGUAGE_C.
+ * @tool_id: the identifier of the tool like %IDE_TOOLCHAIN_TOOL_CC
  *
- * Gets the path of the strip executable
+ * Gets the path of the specified tool for the requested language.
+ * If %IDE_TOOLCHAIN_LANGUAGE_ANY is used in the @language field, the first tool matching @tool_id
+ * will be returned.
  *
- * Returns: (nullable) (transfer none): A path or %NULL.
+ * Returns: (transfer full): A string containing the path of the tool for the given language, or
+ * %NULL is no tool has been found. The returned string should be freed when no longer needed.
  *
  * Since: 3.30
  */
 const gchar *
-ide_toolchain_get_strip (IdeToolchain  *self)
+ide_toolchain_get_tool_for_language (IdeToolchain *self,
+                                     const gchar  *language,
+                                     const gchar  *tool_id)
 {
-  IdeToolchainPrivate *priv = ide_toolchain_get_instance_private (self);
+  const gchar *ret;
 
-  g_return_val_if_fail (IDE_IS_TOOLCHAIN (self), NULL);
-
-  return priv->strip;
-}
-
-/**
- * ide_toolchain_set_strip:
- * @self: an #IdeToolchain
- * @path: (nullable): the path to the strip executable
- *
- * Sets the path of the strip executable
- *
- * Since: 3.30
- */
-void
-ide_toolchain_set_strip (IdeToolchain  *self,
-                         const gchar   *path)
-{
-  IdeToolchainPrivate *priv = ide_toolchain_get_instance_private (self);
-
-  g_return_if_fail (IDE_IS_TOOLCHAIN (self));
-
-  if (g_strcmp0 (path, priv->strip) != 0)
-    {
-      g_free (priv->strip);
-      priv->strip = g_strdup (path);
-      g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_STRIP]);
-    }
-}
-
-/**
- * ide_toolchain_get_pkg_config:
- * @self: an #IdeToolchain
- *
- * Gets the path of the pkg-config executable
- *
- * Returns: (nullable) (transfer none): A path or %NULL.
- *
- * Since: 3.30
- */
-const gchar *
-ide_toolchain_get_pkg_config (IdeToolchain  *self)
-{
-  IdeToolchainPrivate *priv = ide_toolchain_get_instance_private (self);
+  IDE_ENTRY;
 
   g_return_val_if_fail (IDE_IS_TOOLCHAIN (self), NULL);
 
-  return priv->pkg_config;
-}
+  ret = IDE_TOOLCHAIN_GET_CLASS (self)->get_tool_for_language (self, language, tool_id);
 
-/**
- * ide_toolchain_set_pkg_config:
- * @self: an #IdeToolchain
- * @path: (nullable): the path to the pkg-config executable
- *
- * Sets the path of the pkg-config executable
- *
- * Since: 3.30
- */
-void
-ide_toolchain_set_pkg_config (IdeToolchain  *self,
-                              const gchar   *path)
-{
-  IdeToolchainPrivate *priv = ide_toolchain_get_instance_private (self);
-
-  g_return_if_fail (IDE_IS_TOOLCHAIN (self));
-
-  if (g_strcmp0 (path, priv->pkg_config) != 0)
-    {
-      g_free (priv->pkg_config);
-      priv->pkg_config = g_strdup (path);
-      g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_PKG_CONFIG]);
-    }
+  IDE_RETURN (ret);
 }
 
 /**
- * ide_toolchain_get_exe_wrapper:
+ * ide_toolchain_get_tools_for_id:
  * @self: an #IdeToolchain
+ * @tool_id: the identifier of the tool like %IDE_TOOLCHAIN_TOOL_CC
  *
- * Gets the path of the wrapper to use when running the compiled executables
+ * Gets the list of all the paths to the specified tool id.
  *
- * Returns: (nullable) (transfer none): A path or %NULL.
+ * Returns: (transfer full) (element-type utf8 utf8): A table of language names and paths.
  *
  * Since: 3.30
  */
-const gchar *
-ide_toolchain_get_exe_wrapper (IdeToolchain  *self)
+GHashTable *
+ide_toolchain_get_tools_for_id (IdeToolchain  *self,
+                                const gchar   *tool_id)
 {
-  IdeToolchainPrivate *priv = ide_toolchain_get_instance_private (self);
+  GHashTable *ret;
 
-  g_return_val_if_fail (IDE_IS_TOOLCHAIN (self), NULL);
+  IDE_ENTRY;
 
-  return priv->exe_wrapper;
-}
-
-/**
- * ide_toolchain_set_exe_wrapper:
- * @self: an #IdeToolchain
- * @path: (nullable): the path of the executable wrapper
- *
- * Sets the path of the wrapper to use when running the compiled executables
- *
- * Since: 3.30
- */
-void
-ide_toolchain_set_exe_wrapper (IdeToolchain  *self,
-                               const gchar   *path)
-{
-  IdeToolchainPrivate *priv = ide_toolchain_get_instance_private (self);
+  g_return_val_if_fail (IDE_IS_TOOLCHAIN (self), NULL);
 
-  g_return_if_fail (IDE_IS_TOOLCHAIN (self));
+  ret = IDE_TOOLCHAIN_GET_CLASS (self)->get_tools_for_id (self, tool_id);
 
-  if (g_strcmp0 (path, priv->exe_wrapper) != 0)
-    {
-      g_free (priv->exe_wrapper);
-      priv->exe_wrapper = g_strdup (path);
-      g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_EXE_WRAPPER]);
-    }
+  IDE_RETURN (ret);
 }
 
 static void
@@ -417,11 +219,6 @@ ide_toolchain_finalize (GObject *object)
 
   g_clear_pointer (&priv->id, g_free);
   g_clear_pointer (&priv->host_triplet, ide_triplet_unref);
-  g_clear_pointer (&priv->compilers, g_hash_table_unref);
-  g_clear_pointer (&priv->archiver, g_free);
-  g_clear_pointer (&priv->strip, g_free);
-  g_clear_pointer (&priv->pkg_config, g_free);
-  g_clear_pointer (&priv->exe_wrapper, g_free);
 
   G_OBJECT_CLASS (ide_toolchain_parent_class)->finalize (object);
 }
@@ -442,21 +239,6 @@ ide_toolchain_get_property (GObject    *object,
     case PROP_HOST_TRIPLET:
       g_value_set_boxed (value, ide_toolchain_get_host_triplet (self));
       break;
-    case PROP_COMPILERS:
-      g_value_set_boxed (value, ide_toolchain_get_compilers (self));
-      break;
-    case PROP_ARCHIVER:
-      g_value_set_string (value, ide_toolchain_get_archiver (self));
-      break;
-    case PROP_STRIP:
-      g_value_set_string (value, ide_toolchain_get_strip (self));
-      break;
-    case PROP_PKG_CONFIG:
-      g_value_set_string (value, ide_toolchain_get_pkg_config (self));
-      break;
-    case PROP_EXE_WRAPPER:
-      g_value_set_string (value, ide_toolchain_get_exe_wrapper (self));
-      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
     }
@@ -478,18 +260,6 @@ ide_toolchain_set_property (GObject      *object,
     case PROP_HOST_TRIPLET:
       ide_toolchain_set_host_triplet (self, g_value_get_boxed (value));
       break;
-    case PROP_ARCHIVER:
-      ide_toolchain_set_archiver (self, g_value_get_string (value));
-      break;
-    case PROP_STRIP:
-      ide_toolchain_set_strip (self, g_value_get_string (value));
-      break;
-    case PROP_PKG_CONFIG:
-      ide_toolchain_set_pkg_config (self, g_value_get_string (value));
-      break;
-    case PROP_EXE_WRAPPER:
-      ide_toolchain_set_exe_wrapper (self, g_value_get_string (value));
-      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
     }
@@ -504,6 +274,9 @@ ide_toolchain_class_init (IdeToolchainClass *klass)
   object_class->get_property = ide_toolchain_get_property;
   object_class->set_property = ide_toolchain_set_property;
 
+  klass->get_tool_for_language = ide_toolchain_real_get_tool_for_language;
+  klass->get_tools_for_id = ide_toolchain_real_get_tools_for_id;
+
   properties [PROP_ID] =
     g_param_spec_string ("id",
                          "Id",
@@ -518,41 +291,6 @@ ide_toolchain_class_init (IdeToolchainClass *klass)
                          IDE_TYPE_TRIPLET,
                          (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
 
-  properties [PROP_COMPILERS] =
-    g_param_spec_boxed ("compilers",
-                         "Compilers",
-                         "The table of languages and compiler executables",
-                         G_TYPE_HASH_TABLE,
-                         (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
-
-  properties [PROP_ARCHIVER] =
-    g_param_spec_string ("archiver",
-                         "Archiver",
-                         "The path to the archiver executable",
-                         NULL,
-                         (G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
-
-  properties [PROP_STRIP] =
-    g_param_spec_string ("strip",
-                         "Strip",
-                         "The path to the strip executable",
-                         NULL,
-                         (G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
-
-  properties [PROP_PKG_CONFIG] =
-    g_param_spec_string ("pkg-config",
-                         "PkgConfig",
-                         "The path to the pkg-config executable",
-                         NULL,
-                         (G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
-
-  properties [PROP_EXE_WRAPPER] =
-    g_param_spec_string ("exe-wrapper",
-                         "Exe Wrapper",
-                         "The path of the wrapper to use when running the compiled executables",
-                         NULL,
-                         (G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
-
   g_object_class_install_properties (object_class, N_PROPS, properties);
 }
 
@@ -560,6 +298,5 @@ static void
 ide_toolchain_init (IdeToolchain *self)
 {
   IdeToolchainPrivate *priv = ide_toolchain_get_instance_private (self);
-  priv->compilers = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
   priv->host_triplet = ide_triplet_new_from_system ();
 }
diff --git a/src/libide/toolchain/ide-toolchain.h b/src/libide/toolchain/ide-toolchain.h
index de5fc9684..014ca7471 100644
--- a/src/libide/toolchain/ide-toolchain.h
+++ b/src/libide/toolchain/ide-toolchain.h
@@ -34,50 +34,48 @@ struct _IdeToolchainClass
 {
   IdeObjectClass parent;
 
+  const gchar *(*get_tool_for_language) (IdeToolchain  *self,
+                                         const gchar   *language,
+                                         const gchar   *tool_id);
+
+  GHashTable  *(*get_tools_for_id)      (IdeToolchain  *self,
+                                         const gchar   *tool_id);
+
   gpointer _reserved[12];
 };
 
+#define IDE_TOOLCHAIN_TOOL_CC          "cc"
+#define IDE_TOOLCHAIN_TOOL_CPP         "cpp"
+#define IDE_TOOLCHAIN_TOOL_AR          "ar"
+#define IDE_TOOLCHAIN_TOOL_LD          "ld"
+#define IDE_TOOLCHAIN_TOOL_STRIP       "strip"
+#define IDE_TOOLCHAIN_TOOL_EXEC        "exec"
+#define IDE_TOOLCHAIN_TOOL_PKG_CONFIG  "pkg-config"
+
+#define IDE_TOOLCHAIN_LANGUAGE_ANY       "*"
+#define IDE_TOOLCHAIN_LANGUAGE_C         "c"
+#define IDE_TOOLCHAIN_LANGUAGE_CPLUSPLUS "c++"
+#define IDE_TOOLCHAIN_LANGUAGE_PYTHON    "python"
+#define IDE_TOOLCHAIN_LANGUAGE_VALA      "vala"
+#define IDE_TOOLCHAIN_LANGUAGE_FORTRAN   "fortran"
+#define IDE_TOOLCHAIN_LANGUAGE_D         "d"
+
 IDE_AVAILABLE_IN_3_30
-IdeToolchain  *ide_toolchain_new              (IdeContext    *context,
-                                               const gchar   *id);
-IDE_AVAILABLE_IN_3_30
-const gchar   *ide_toolchain_get_id           (IdeToolchain  *self);
-IDE_AVAILABLE_IN_3_30
-void           ide_toolchain_set_id           (IdeToolchain  *self,
-                                               const gchar   *id);
-IDE_AVAILABLE_IN_3_30
-IdeTriplet    *ide_toolchain_get_host_triplet (IdeToolchain  *self);
-IDE_AVAILABLE_IN_3_30
-void           ide_toolchain_set_host_triplet (IdeToolchain  *self,
-                                               IdeTriplet    *host_triplet);
-IDE_AVAILABLE_IN_3_30
-const gchar   *ide_toolchain_get_compiler     (IdeToolchain  *self,
-                                               const gchar   *language);
-IDE_AVAILABLE_IN_3_30
-void           ide_toolchain_set_compiler     (IdeToolchain  *self,
-                                               const gchar   *language,
-                                               const gchar   *path);
-IDE_AVAILABLE_IN_3_30
-GHashTable    *ide_toolchain_get_compilers    (IdeToolchain  *self);
-IDE_AVAILABLE_IN_3_30
-const gchar   *ide_toolchain_get_archiver     (IdeToolchain  *self);
-IDE_AVAILABLE_IN_3_30
-void           ide_toolchain_set_archiver     (IdeToolchain  *self,
-                                               const gchar   *path);
-IDE_AVAILABLE_IN_3_30
-const gchar   *ide_toolchain_get_strip        (IdeToolchain  *self);
+const gchar   *ide_toolchain_get_id                (IdeToolchain  *self);
 IDE_AVAILABLE_IN_3_30
-void           ide_toolchain_set_strip        (IdeToolchain  *self,
-                                               const gchar   *path);
+void           ide_toolchain_set_id                (IdeToolchain  *self,
+                                                    const gchar   *id);
 IDE_AVAILABLE_IN_3_30
-const gchar   *ide_toolchain_get_pkg_config   (IdeToolchain  *self);
+IdeTriplet    *ide_toolchain_get_host_triplet      (IdeToolchain  *self);
 IDE_AVAILABLE_IN_3_30
-void           ide_toolchain_set_pkg_config   (IdeToolchain  *self,
-                                               const gchar   *path);
+void           ide_toolchain_set_host_triplet      (IdeToolchain  *self,
+                                                    IdeTriplet    *host_triplet);
 IDE_AVAILABLE_IN_3_30
-const gchar   *ide_toolchain_get_exe_wrapper  (IdeToolchain  *self);
+const gchar   *ide_toolchain_get_tool_for_language (IdeToolchain  *self,
+                                                    const gchar   *language,
+                                                    const gchar   *tool_id);
 IDE_AVAILABLE_IN_3_30
-void           ide_toolchain_set_exe_wrapper  (IdeToolchain  *self,
-                                               const gchar   *path);
+GHashTable    *ide_toolchain_get_tools_for_id      (IdeToolchain  *self,
+                                                    const gchar   *tool_id);
 
 G_END_DECLS
diff --git a/src/libide/toolchain/meson.build b/src/libide/toolchain/meson.build
index d3305b013..901d4f952 100644
--- a/src/libide/toolchain/meson.build
+++ b/src/libide/toolchain/meson.build
@@ -1,10 +1,12 @@
 toolchain_headers = [
+  'ide-simple-toolchain.h',
   'ide-toolchain.h',
   'ide-toolchain-provider.h',
   'ide-toolchain-manager.h'
 ]
 
 toolchain_sources = [
+  'ide-simple-toolchain.c',
   'ide-toolchain.c',
   'ide-toolchain-provider.c',
   'ide-toolchain-manager.c'
diff --git a/src/plugins/autotools/ide-autotools-pipeline-addin.c 
b/src/plugins/autotools/ide-autotools-pipeline-addin.c
index 60ac07dbd..481579140 100644
--- a/src/plugins/autotools/ide-autotools-pipeline-addin.c
+++ b/src/plugins/autotools/ide-autotools-pipeline-addin.c
@@ -26,6 +26,8 @@
 #include "ide-autotools-makecache-stage.h"
 #include "ide-autotools-pipeline-addin.h"
 
+#include "toolchain/ide-simple-toolchain.h"
+
 static gboolean
 register_autoreconf_stage (IdeAutotoolsPipelineAddin  *self,
                            IdeBuildPipeline           *pipeline,
@@ -161,19 +163,22 @@ check_configure_status (IdeAutotoolsPipelineAddin *self,
 static const gchar *
 compiler_environment_from_language (gchar *language)
 {
-  if (g_strcmp0 (language, "c") == 0)
+  if (g_strcmp0 (language, IDE_TOOLCHAIN_LANGUAGE_C) == 0)
     return "CC";
 
-  if (g_strcmp0 (language, "c++") == 0 || g_strcmp0 (language, "cpp") == 0)
+  if (g_strcmp0 (language, IDE_TOOLCHAIN_LANGUAGE_CPLUSPLUS) == 0)
     return "CXX";
 
-  if (g_strcmp0 (language, "fortran") == 0)
+  if (g_strcmp0 (language, IDE_TOOLCHAIN_LANGUAGE_PYTHON) == 0)
+    return "PYTHON";
+
+  if (g_strcmp0 (language, IDE_TOOLCHAIN_LANGUAGE_FORTRAN) == 0)
     return "FC";
 
-  if (g_strcmp0 (language, "d") == 0)
+  if (g_strcmp0 (language, IDE_TOOLCHAIN_LANGUAGE_D) == 0)
     return "DC";
 
-  if (g_strcmp0 (language, "vala") == 0)
+  if (g_strcmp0 (language, IDE_TOOLCHAIN_LANGUAGE_VALA) == 0)
     return "VALAC";
 
   return NULL;
@@ -231,20 +236,27 @@ register_configure_stage (IdeAutotoolsPipelineAddin  *self,
 
   if (g_strcmp0 (ide_toolchain_get_id (toolchain), "default") != 0)
     {
-      GHashTable *compilers = ide_toolchain_get_compilers (toolchain);
+      GHashTable *compilers = ide_toolchain_get_tools_for_id (toolchain,
+                                                              IDE_TOOLCHAIN_TOOL_CC);
       const gchar *tool_path;
 
       g_hash_table_foreach (compilers, add_compiler_env_variables, launcher);
 
-      tool_path = ide_toolchain_get_archiver (toolchain);
+      tool_path = ide_toolchain_get_tool_for_language (toolchain,
+                                                       IDE_TOOLCHAIN_LANGUAGE_ANY,
+                                                       IDE_TOOLCHAIN_TOOL_AR);
       if (tool_path != NULL)
         ide_subprocess_launcher_setenv (launcher, "AR", tool_path, TRUE);
 
-      tool_path = ide_toolchain_get_strip (toolchain);
+      tool_path = ide_toolchain_get_tool_for_language (toolchain,
+                                                       IDE_TOOLCHAIN_LANGUAGE_ANY,
+                                                       IDE_TOOLCHAIN_TOOL_STRIP);
       if (tool_path != NULL)
         ide_subprocess_launcher_setenv (launcher, "STRIP", tool_path, TRUE);
 
-      tool_path = ide_toolchain_get_pkg_config (toolchain);
+      tool_path = ide_toolchain_get_tool_for_language (toolchain,
+                                                       IDE_TOOLCHAIN_LANGUAGE_ANY,
+                                                       IDE_TOOLCHAIN_TOOL_PKG_CONFIG);
       if (tool_path != NULL)
         ide_subprocess_launcher_setenv (launcher, "PKG_CONFIG", tool_path, TRUE);
     }
diff --git a/src/plugins/cmake/gbp-cmake-toolchain.c b/src/plugins/cmake/gbp-cmake-toolchain.c
index f3d3e7de4..339ddfe04 100644
--- a/src/plugins/cmake/gbp-cmake-toolchain.c
+++ b/src/plugins/cmake/gbp-cmake-toolchain.c
@@ -27,6 +27,10 @@ struct _GbpCMakeToolchain
 {
   IdeToolchain            parent_instance;
   gchar                  *file_path;
+  gchar                  *exe_wrapper;
+  gchar                  *archiver;
+  gchar                  *pkg_config;
+  GHashTable             *compilers;
 };
 
 G_DEFINE_TYPE (GbpCMakeToolchain, gbp_cmake_toolchain, IDE_TYPE_TOOLCHAIN)
@@ -145,8 +149,6 @@ _gbp_cmake_toolchain_parse_keyfile (GbpCMakeToolchain  *self,
   g_autofree gchar *system = NULL;
   g_autofree gchar *system_lowercase = NULL;
   g_autofree gchar *cpu = NULL;
-  g_autofree gchar *exe_wrapper = NULL;
-  g_autofree gchar *ar = NULL;
   g_autofree gchar *pkg_config = NULL;
 
   if (!g_key_file_load_from_file (keyfile, filename, G_KEY_FILE_NONE, NULL))
@@ -161,25 +163,33 @@ _gbp_cmake_toolchain_parse_keyfile (GbpCMakeToolchain  *self,
   host_triplet = ide_triplet_new_with_triplet (cpu, system_lowercase, NULL);
   ide_toolchain_set_host_triplet (IDE_TOOLCHAIN(self), host_triplet);
 
-  exe_wrapper = g_key_file_get_string (keyfile, "binaries", "exe_wrapper", NULL);
-  ide_toolchain_set_exe_wrapper (IDE_TOOLCHAIN(self), exe_wrapper);
-
-  ar = g_key_file_get_string (keyfile, "binaries", "ar", NULL);
-  ide_toolchain_set_archiver (IDE_TOOLCHAIN(self), ar);
-
-  pkg_config = g_key_file_get_string (keyfile, "binaries", "pkg_config", NULL);
-  ide_toolchain_set_pkg_config (IDE_TOOLCHAIN(self), pkg_config);
+  self->exe_wrapper = g_key_file_get_string (keyfile, "binaries", "exe_wrapper", NULL);
+  self->archiver = g_key_file_get_string (keyfile, "binaries", "ar", NULL);
+  self->pkg_config = g_key_file_get_string (keyfile, "binaries", "pkg_config", NULL);
 
   compilers = g_key_file_get_keys (keyfile, "compilers", &compilers_length, NULL);
   for (gint i = 0; i < compilers_length; i++)
     {
       g_autofree gchar *compiler_path = g_key_file_get_string (keyfile, "compilers", compilers[i], NULL);
-      ide_toolchain_set_compiler (IDE_TOOLCHAIN(self), compilers[i], compiler_path);
+      g_hash_table_insert (self->compilers, g_strdup (compilers[i]), g_steal_pointer (&compiler_path));
     }
 
   return TRUE;
 }
 
+const gchar *
+gbp_cmake_toolchain_get_tool_for_language (IdeToolchain  *toolchain,
+                                           const gchar   *language,
+                                           const gchar   *tool_id)
+{
+  GbpCMakeToolchain *self = (GbpCMakeToolchain *)toolchain;
+
+  g_return_val_if_fail (GBP_IS_CMAKE_TOOLCHAIN (self), NULL);
+  g_return_val_if_fail (tool_id != NULL, NULL);
+
+  return NULL;
+}
+
 static void
 gbp_cmake_toolchain_verify_worker (IdeTask      *task,
                                    gpointer      source_object,
@@ -271,6 +281,10 @@ gbp_cmake_toolchain_finalize (GObject *object)
   GbpCMakeToolchain *self = (GbpCMakeToolchain *)object;
 
   g_clear_pointer (&self->file_path, g_free);
+  g_clear_pointer (&self->exe_wrapper, g_free);
+  g_clear_pointer (&self->archiver, g_free);
+  g_clear_pointer (&self->pkg_config, g_free);
+  g_clear_pointer (&self->compilers, g_hash_table_unref);
 
   G_OBJECT_CLASS (gbp_cmake_toolchain_parent_class)->finalize (object);
 }
@@ -315,11 +329,14 @@ static void
 gbp_cmake_toolchain_class_init (GbpCMakeToolchainClass *klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  IdeToolchainClass *toolchain_class = IDE_TOOLCHAIN_CLASS (klass);
 
   object_class->finalize = gbp_cmake_toolchain_finalize;
   object_class->get_property = gbp_cmake_toolchain_get_property;
   object_class->set_property = gbp_cmake_toolchain_set_property;
 
+  toolchain_class->get_tool_for_language = gbp_cmake_toolchain_get_tool_for_language;
+
   properties [PROP_FILE_PATH] =
     g_param_spec_string ("file-path",
                          "File path",
@@ -333,5 +350,5 @@ gbp_cmake_toolchain_class_init (GbpCMakeToolchainClass *klass)
 static void
 gbp_cmake_toolchain_init (GbpCMakeToolchain *self)
 {
-  
+  self->compilers = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
 }
diff --git a/src/plugins/meson/gbp-meson-pipeline-addin.c b/src/plugins/meson/gbp-meson-pipeline-addin.c
index df2b0aa2d..afd37dabb 100644
--- a/src/plugins/meson/gbp-meson-pipeline-addin.c
+++ b/src/plugins/meson/gbp-meson-pipeline-addin.c
@@ -155,6 +155,7 @@ gbp_meson_pipeline_addin_load (IdeBuildPipelineAddin *addin,
       g_autoptr(IdeTriplet) triplet = NULL;
       g_autofree gchar *crossfile_name = NULL;
       const gchar *binary_path;
+      GHashTable *compilers;
 
       crossfile_name = g_strdup_printf ("gnome-builder-%s.crossfile", ide_toolchain_get_id (toolchain));
       crossbuild_file = ide_build_pipeline_build_builddir_path (pipeline, crossfile_name, NULL);
@@ -162,18 +163,28 @@ gbp_meson_pipeline_addin_load (IdeBuildPipelineAddin *addin,
       crossbuild_keyfile = g_key_file_new ();
       triplet = ide_toolchain_get_host_triplet (toolchain);
 
-      g_hash_table_foreach (ide_toolchain_get_compilers (toolchain), (GHFunc)add_lang_executable, 
crossbuild_keyfile);
+      compilers  = ide_toolchain_get_tools_for_id (toolchain,
+                                                   IDE_TOOLCHAIN_TOOL_CC);
+      g_hash_table_foreach (compilers, (GHFunc)add_lang_executable, crossbuild_keyfile);
 
-      binary_path = ide_toolchain_get_archiver (toolchain);
+      binary_path = ide_toolchain_get_tool_for_language (toolchain,
+                                                         IDE_TOOLCHAIN_LANGUAGE_ANY,
+                                                         IDE_TOOLCHAIN_TOOL_AR);
       _g_key_file_set_string_quoted (crossbuild_keyfile, "binaries", "ar", binary_path);
 
-      binary_path = ide_toolchain_get_strip (toolchain);
+      binary_path = ide_toolchain_get_tool_for_language (toolchain,
+                                                         IDE_TOOLCHAIN_LANGUAGE_ANY,
+                                                         IDE_TOOLCHAIN_TOOL_STRIP);
       _g_key_file_set_string_quoted (crossbuild_keyfile, "binaries", "strip", binary_path);
 
-      binary_path = ide_toolchain_get_pkg_config (toolchain);
+      binary_path = ide_toolchain_get_tool_for_language (toolchain,
+                                                         IDE_TOOLCHAIN_LANGUAGE_ANY,
+                                                         IDE_TOOLCHAIN_TOOL_PKG_CONFIG);
       _g_key_file_set_string_quoted (crossbuild_keyfile, "binaries", "pkgconfig", binary_path);
 
-      binary_path = ide_toolchain_get_exe_wrapper (toolchain);
+      binary_path = ide_toolchain_get_tool_for_language (toolchain,
+                                                         IDE_TOOLCHAIN_LANGUAGE_ANY,
+                                                         IDE_TOOLCHAIN_TOOL_EXEC);
       _g_key_file_set_string_quoted (crossbuild_keyfile, "binaries", "exe_wrapper", binary_path);
 
       binary_path = ide_triplet_get_kernel (triplet);
diff --git a/src/plugins/meson/gbp-meson-toolchain.c b/src/plugins/meson/gbp-meson-toolchain.c
index 0540c38d2..27bb213e9 100644
--- a/src/plugins/meson/gbp-meson-toolchain.c
+++ b/src/plugins/meson/gbp-meson-toolchain.c
@@ -25,6 +25,11 @@ struct _GbpMesonToolchain
 {
   IdeToolchain            parent_instance;
   gchar                  *file_path;
+  gchar                  *exe_wrapper;
+  gchar                  *archiver;
+  gchar                  *pkg_config;
+  gchar                  *strip;
+  GHashTable             *compilers;
 };
 
 G_DEFINE_TYPE (GbpMesonToolchain, gbp_meson_toolchain, IDE_TYPE_TOOLCHAIN)
@@ -107,15 +112,18 @@ gbp_meson_toolchain_new (IdeContext   *context,
       g_autofree gchar *exec_path = NULL;
       g_autoptr(GError) key_error = NULL;
 
-      // Well-known binaries that are not compilers, everything else is considered as a compiler
-      if (g_strcmp0 (lang, "ar") == 0 ||
-          g_strcmp0 (lang, "strip") == 0 ||
-          g_strcmp0 (lang, "pkg_config") == 0 ||
-          g_strcmp0 (lang, "exe_wrapper") == 0)
-        continue;
-
-      exec_path = _g_key_file_get_string_quoted (keyfile, "binaries", lang, &key_error);
-      ide_toolchain_set_compiler (IDE_TOOLCHAIN (toolchain), lang, exec_path);
+      if (g_strcmp0 (lang, "ar") == 0)
+        toolchain->archiver = _g_key_file_get_string_quoted (keyfile, "binaries", lang, &key_error);
+      else if (g_strcmp0 (lang, "strip") == 0)
+        toolchain->strip = _g_key_file_get_string_quoted (keyfile, "binaries", lang, &key_error);
+      else if (g_strcmp0 (lang, "pkg_config") == 0)
+        toolchain->pkg_config = _g_key_file_get_string_quoted (keyfile, "binaries", lang, &key_error);
+      else if (g_strcmp0 (lang, "exe_wrapper") == 0)
+        toolchain->exe_wrapper = _g_key_file_get_string_quoted (keyfile, "binaries", lang, &key_error);
+      else
+        g_hash_table_insert (toolchain->compilers,
+                             g_strdup (lang),
+                             _g_key_file_get_string_quoted (keyfile, "binaries", lang, &key_error));
     }
 
   return g_steal_pointer (&toolchain);



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