[gnome-builder/wip/tintou/toolchain] Make GbpCMakeToolchain and GbpMesonPlugin IdeSimpleToolchain subclasses



commit 35aa18a04f5f3ffdee34c8c601d9d5ac7f658699
Author: Corentin Noël <corentin noel collabora co uk>
Date:   Mon Apr 16 14:40:15 2018 +0100

    Make GbpCMakeToolchain and GbpMesonPlugin IdeSimpleToolchain subclasses

 src/libide/ide.h                                 |   1 +
 src/libide/toolchain/ide-simple-toolchain.c      |   1 +
 src/libide/toolchain/ide-toolchain-provider.c    |   1 -
 src/libide/toolchain/ide-toolchain.c             |   4 +-
 src/plugins/cmake/gbp-cmake-toolchain-provider.c |   4 +-
 src/plugins/cmake/gbp-cmake-toolchain.c          | 207 ++++++++++-------------
 src/plugins/cmake/gbp-cmake-toolchain.h          |   8 +-
 src/plugins/cmake/toolchain-info.ini.cmake       |   3 +-
 src/plugins/meson/gbp-meson-toolchain-provider.c |   2 +-
 src/plugins/meson/gbp-meson-toolchain.c          |  64 ++++---
 src/plugins/meson/gbp-meson-toolchain.h          |   2 +-
 11 files changed, 146 insertions(+), 151 deletions(-)
---
diff --git a/src/libide/ide.h b/src/libide/ide.h
index 3bce3743b..7ef885baa 100644
--- a/src/libide/ide.h
+++ b/src/libide/ide.h
@@ -178,6 +178,7 @@ G_BEGIN_DECLS
 #include "testing/ide-test-provider.h"
 #include "threading/ide-task.h"
 #include "threading/ide-thread-pool.h"
+#include "toolchain/ide-simple-toolchain.h"
 #include "toolchain/ide-toolchain.h"
 #include "toolchain/ide-toolchain-manager.h"
 #include "toolchain/ide-toolchain-provider.h"
diff --git a/src/libide/toolchain/ide-simple-toolchain.c b/src/libide/toolchain/ide-simple-toolchain.c
index 984310411..621e02a1a 100644
--- a/src/libide/toolchain/ide-simple-toolchain.c
+++ b/src/libide/toolchain/ide-simple-toolchain.c
@@ -159,6 +159,7 @@ ide_simple_toolchain_class_init (IdeSimpleToolchainClass *klass)
   object_class->finalize = ide_simple_toolchain_finalize;
 
   toolchain_class->get_tool_for_language = ide_simple_toolchain_get_tool_for_language;
+  toolchain_class->get_tools_for_id = ide_simple_toolchain_get_tools_for_id;
 }
 
 static void
diff --git a/src/libide/toolchain/ide-toolchain-provider.c b/src/libide/toolchain/ide-toolchain-provider.c
index 198c64f82..72adb3cb1 100644
--- a/src/libide/toolchain/ide-toolchain-provider.c
+++ b/src/libide/toolchain/ide-toolchain-provider.c
@@ -143,7 +143,6 @@ ide_toolchain_provider_default_init (IdeToolchainProviderInterface *iface)
 /**
  * ide_toolchain_provider_load_async:
  * @self: a #IdeToolchainProvider
- * @manager: a #IdeToolchainManager
  * @cancellable: (nullable): a #GCancellable or %NULL
  * @callback: a callback to execute upon completion
  * @user_data: closure data for @callback
diff --git a/src/libide/toolchain/ide-toolchain.c b/src/libide/toolchain/ide-toolchain.c
index 9c75b68b9..b881943a1 100644
--- a/src/libide/toolchain/ide-toolchain.c
+++ b/src/libide/toolchain/ide-toolchain.c
@@ -76,7 +76,7 @@ ide_toolchain_set_id (IdeToolchain  *self,
 
   if (g_strcmp0 (id, priv->id) != 0)
     {
-      g_free (priv->id);
+      g_clear_pointer (&priv->id, g_free);
       priv->id = g_strdup (id);
       g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_ID]);
     }
@@ -282,7 +282,7 @@ ide_toolchain_class_init (IdeToolchainClass *klass)
                          "Id",
                          "The toolchain identifier",
                          NULL,
-                         (G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
+                         (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
 
   properties [PROP_HOST_TRIPLET] =
     g_param_spec_boxed ("host-triplet",
diff --git a/src/plugins/cmake/gbp-cmake-toolchain-provider.c 
b/src/plugins/cmake/gbp-cmake-toolchain-provider.c
index a3c2222c6..c4731abca 100644
--- a/src/plugins/cmake/gbp-cmake-toolchain-provider.c
+++ b/src/plugins/cmake/gbp-cmake-toolchain-provider.c
@@ -86,8 +86,8 @@ gbp_cmake_toolchain_provider_load_worker (IdeTask      *task,
           if (processor_name == NULL)
             continue;
 
-          toolchain = gbp_cmake_toolchain_new (context, file);
-          if (!gbp_cmake_toolchain_load (toolchain, file, &load_error))
+          toolchain = gbp_cmake_toolchain_new (context);
+          if (!gbp_cmake_toolchain_load (toolchain, file, cancellable, &load_error))
             {
               g_debug ("Error loading %s : %s", file_path, load_error->message);
               continue;
diff --git a/src/plugins/cmake/gbp-cmake-toolchain.c b/src/plugins/cmake/gbp-cmake-toolchain.c
index d253fa693..f00185996 100644
--- a/src/plugins/cmake/gbp-cmake-toolchain.c
+++ b/src/plugins/cmake/gbp-cmake-toolchain.c
@@ -25,16 +25,11 @@
 
 struct _GbpCMakeToolchain
 {
-  IdeToolchain            parent_instance;
+  IdeSimpleToolchain      parent_instance;
   gchar                  *file_path;
-  gchar                  *exe_wrapper;
-  gchar                  *archiver;
-  gchar                  *pkg_config;
-  GHashTable             *compilers;
-  GCancellable           *verify_cancellable;
 };
 
-G_DEFINE_TYPE (GbpCMakeToolchain, gbp_cmake_toolchain, IDE_TYPE_TOOLCHAIN)
+G_DEFINE_TYPE (GbpCMakeToolchain, gbp_cmake_toolchain, IDE_TYPE_SIMPLE_TOOLCHAIN)
 
 enum {
   PROP_0,
@@ -45,19 +40,14 @@ enum {
 static GParamSpec *properties [N_PROPS];
 
 GbpCMakeToolchain *
-gbp_cmake_toolchain_new (IdeContext   *context,
-                         GFile        *file)
+gbp_cmake_toolchain_new (IdeContext   *context)
 {
-  g_autofree gchar *path = g_file_get_path (file);
-  g_autofree gchar *id = g_strconcat ("cmake:", path, NULL);
   g_autoptr(IdeTriplet) triplet = NULL;
   g_autoptr(GbpCMakeToolchain) toolchain = NULL;
 
   triplet = ide_triplet_new_from_system ();
   toolchain = g_object_new (GBP_TYPE_CMAKE_TOOLCHAIN,
                             "context", context,
-                            "file-path", path,
-                            "id", id,
                             "host-triplet", triplet,
                             NULL);
 
@@ -65,12 +55,12 @@ gbp_cmake_toolchain_new (IdeContext   *context,
 }
 
 /**
- * ide_toolchain_get_id:
- * @self: an #IdeToolchain
+ * gbp_cmake_toolchain_get_file_path:
+ * @self: an #GbpCMakeToolchain
  *
- * Gets the internal identifier of the toolchain
+ * Gets the path to the CMake cross-compilation definitions
  *
- * Returns: (transfer none): the unique identifier.
+ * Returns: (transfer none): the path to the CMake cross-compilation definitions file.
  *
  * Since: 3.30
  */
@@ -82,60 +72,56 @@ gbp_cmake_toolchain_get_file_path (GbpCMakeToolchain  *self)
   return self->file_path;
 }
 
-void
-gbp_cmake_toolchain_set_file_path (GbpCMakeToolchain  *self,
-                                   const gchar        *file_path)
-{
-  g_return_if_fail (GBP_IS_CMAKE_TOOLCHAIN (self));
-  g_return_if_fail (file_path != NULL);
-
-  if (g_strcmp0 (file_path, self->file_path) != 0)
-    {
-      g_clear_pointer (&self->file_path, g_free);
-      self->file_path = g_strdup (file_path);
-      g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_FILE_PATH]);
-    }
-}
-
 static gchar *
-_gbp_cmake_toolchain_deploy_temporary_cmake (GCancellable  *cancellable)
+_gbp_cmake_toolchain_deploy_temporary_cmake (GbpCMakeToolchain  *self,
+                                             GCancellable  *cancellable)
 {
-  g_autoptr(GError) error = NULL;
-  g_autoptr(GFile) cmake_lists_res = NULL;
-  g_autoptr(GFile) cmake_ini_res = NULL;
-  g_autoptr(GFile) cmake_lists = NULL;
-  g_autoptr(GFile) cmake_ini = NULL;
-  g_autoptr(GFile) tmp_file = NULL;
-  g_autofree gchar *tmp_dir = NULL;
-
-  tmp_dir = g_dir_make_tmp (".builder-cmake-XXXXXX", &error);
-  if (error != NULL)
-    {
-      //TODO
-      return NULL;
-    }
+  IdeContext *context;
+  g_autofree gchar *defined_path = NULL;
 
-  tmp_file = g_file_new_for_path (tmp_dir);
-  cmake_lists_res = g_file_new_for_uri ("resource:///org/gnome/builder/plugins/cmake/CMakeLists.txt");
-  cmake_ini_res = g_file_new_for_uri 
("resource:///org/gnome/builder/plugins/cmake/toolchain-info.ini.cmake");
-  cmake_lists = g_file_get_child (tmp_file, "CMakeLists.txt");
-  cmake_ini = g_file_get_child (tmp_file, "toolchain-info.ini.cmake");
+  g_assert (GBP_IS_CMAKE_TOOLCHAIN(self));
 
-  g_file_copy (cmake_lists_res, cmake_lists, G_FILE_COPY_NONE, cancellable, NULL, NULL, &error);
-  if (error != NULL)
+  context = ide_object_get_context (IDE_OBJECT(self));
+  defined_path = ide_context_cache_filename (context, "cmake", "toolchain-detection", NULL);
+  if (!g_file_test (defined_path, G_FILE_TEST_EXISTS))
     {
-      //TODO
-      return NULL;
-    }
-
-  g_file_copy (cmake_ini_res, cmake_ini, G_FILE_COPY_NONE, cancellable, NULL, NULL, &error);
-  if (error != NULL)
+      g_autoptr(GError) error = NULL;
+      g_autoptr(GFile) tmp_file = g_file_new_for_path (defined_path);
+      g_autoptr(GFile) cmake_lists_res = g_file_new_for_uri 
("resource:///org/gnome/builder/plugins/cmake/CMakeLists.txt");
+      g_autoptr(GFile) cmake_ini_res = g_file_new_for_uri 
("resource:///org/gnome/builder/plugins/cmake/toolchain-info.ini.cmake");
+      g_autoptr(GFile) cmake_lists = g_file_get_child (tmp_file, "CMakeLists.txt");
+      g_autoptr(GFile) cmake_ini = g_file_get_child (tmp_file, "toolchain-info.ini.cmake");
+
+      if (g_mkdir_with_parents (defined_path, 0750) != 0)
+        {
+          g_critical ("Error creating temporary CMake folder at %s", defined_path);
+          return NULL;
+        }
+
+      g_file_copy (cmake_lists_res, cmake_lists, G_FILE_COPY_NONE, cancellable, NULL, NULL, &error);
+      if (error != NULL)
+        {
+          g_critical ("Error creating temporary CMake folder: %s", error->message);
+          return NULL;
+        }
+
+      g_file_copy (cmake_ini_res, cmake_ini, G_FILE_COPY_NONE, cancellable, NULL, NULL, &error);
+      if (error != NULL)
+        {
+          g_critical ("Error creating temporary CMake folder: %s", error->message);
+          return NULL;
+        }
+  }
+
+  for (guint i = 0; i < G_MAXUINT; i++)
     {
-      //TODO
-      return NULL;
+      g_autofree gchar *build_folder = g_strdup_printf ("build%u", i);
+      g_autofree gchar *builddir = g_build_filename (defined_path, build_folder, NULL);
+      if (!g_file_test (builddir, G_FILE_TEST_EXISTS) && g_mkdir (builddir, 0750) == 0)
+        return g_steal_pointer (&builddir);
     }
 
-  return g_steal_pointer (&tmp_dir);
+  return NULL;
 }
 
 static gboolean
@@ -151,6 +137,8 @@ _gbp_cmake_toolchain_parse_keyfile (GbpCMakeToolchain  *self,
   g_autofree gchar *system_lowercase = NULL;
   g_autofree gchar *cpu = NULL;
   g_autofree gchar *pkg_config = NULL;
+  g_autofree gchar *ar_path = NULL;
+  g_autofree gchar *exec_path = NULL;
 
   if (!g_key_file_load_from_file (keyfile, filename, G_KEY_FILE_NONE, NULL))
     return FALSE;
@@ -164,69 +152,78 @@ _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);
 
-  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);
+  exec_path = g_key_file_get_string (keyfile, "binaries", "exe_wrapper", NULL);
+  ide_simple_toolchain_set_tool_for_language (IDE_SIMPLE_TOOLCHAIN(self),
+                                              IDE_TOOLCHAIN_LANGUAGE_ANY,
+                                              IDE_TOOLCHAIN_TOOL_EXEC,
+                                              exec_path);
+
+  ar_path = g_key_file_get_string (keyfile, "binaries", "ar", NULL);
+  ide_simple_toolchain_set_tool_for_language (IDE_SIMPLE_TOOLCHAIN(self),
+                                              IDE_TOOLCHAIN_LANGUAGE_ANY,
+                                              IDE_TOOLCHAIN_TOOL_AR,
+                                              exec_path);
+
+  pkg_config = g_key_file_get_string (keyfile, "binaries", "pkg_config", NULL);
+  ide_simple_toolchain_set_tool_for_language (IDE_SIMPLE_TOOLCHAIN(self),
+                                              IDE_TOOLCHAIN_LANGUAGE_ANY,
+                                              IDE_TOOLCHAIN_TOOL_PKG_CONFIG,
+                                              pkg_config);
 
   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);
-      g_hash_table_insert (self->compilers, g_strdup (compilers[i]), g_steal_pointer (&compiler_path));
+      ide_simple_toolchain_set_tool_for_language (IDE_SIMPLE_TOOLCHAIN(self),
+                                                  compilers[i],
+                                                  IDE_TOOLCHAIN_TOOL_CC,
+                                                  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;
-}
-
 /* It is far easier and more reliable to get the variables from cmake itself,
  * Here is a small projects that exports the content of the cross-file */
 gboolean
 gbp_cmake_toolchain_load (GbpCMakeToolchain *self,
                           GFile             *file,
+                          GCancellable      *cancellable,
                           GError           **error)
 {
-  g_autofree gchar *tmp_dir = NULL;
+  g_autofree gchar *build_dir = NULL;
   g_autofree gchar *toolchain_arg = NULL;
   g_autoptr(IdeSubprocessLauncher) cmake_launcher = NULL;
   g_autoptr(IdeSubprocess) cmake_subprocess = NULL;
+  g_autofree gchar *id = NULL;
 
   g_assert (GBP_IS_CMAKE_TOOLCHAIN (self));
 
-  g_clear_object (&self->verify_cancellable);
-  self->verify_cancellable = g_cancellable_new ();
-
   g_clear_pointer (&self->file_path, g_free);
   self->file_path = g_file_get_path (file);
 
-  tmp_dir = _gbp_cmake_toolchain_deploy_temporary_cmake (self->verify_cancellable);
+  id = g_strconcat ("cmake:", self->file_path, NULL);
+  ide_toolchain_set_id (IDE_TOOLCHAIN(self), id);
+
+  build_dir = _gbp_cmake_toolchain_deploy_temporary_cmake (self, cancellable);
+  if (build_dir == NULL)
+    return FALSE;
+
   toolchain_arg = g_strdup_printf ("-DCMAKE_TOOLCHAIN_FILE=%s", self->file_path);
 
   cmake_launcher = ide_subprocess_launcher_new 
(G_SUBPROCESS_FLAGS_STDOUT_SILENCE|G_SUBPROCESS_FLAGS_STDERR_SILENCE);
   ide_subprocess_launcher_push_argv (cmake_launcher, "cmake");
-  ide_subprocess_launcher_push_argv (cmake_launcher, ".");
+  ide_subprocess_launcher_push_argv (cmake_launcher, "..");
   ide_subprocess_launcher_push_argv (cmake_launcher, toolchain_arg);
-  ide_subprocess_launcher_set_cwd (cmake_launcher, tmp_dir);
-  cmake_subprocess = ide_subprocess_launcher_spawn (cmake_launcher, self->verify_cancellable, error);
+  ide_subprocess_launcher_set_cwd (cmake_launcher, build_dir);
+  cmake_subprocess = ide_subprocess_launcher_spawn (cmake_launcher, cancellable, error);
   if (cmake_subprocess == NULL)
     return FALSE;
 
-  if (!ide_subprocess_wait_check (cmake_subprocess, self->verify_cancellable, error))
+  if (!ide_subprocess_wait_check (cmake_subprocess, cancellable, error))
     return FALSE;
 
-  if (!_gbp_cmake_toolchain_parse_keyfile (self, tmp_dir))
+  if (!_gbp_cmake_toolchain_parse_keyfile (self, build_dir))
     return FALSE;
 
   return TRUE;
@@ -238,10 +235,6 @@ 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);
 }
@@ -264,42 +257,20 @@ gbp_cmake_toolchain_get_property (GObject    *object,
     }
 }
 
-static void
-gbp_cmake_toolchain_set_property (GObject      *object,
-                                  guint         prop_id,
-                                  const GValue *value,
-                                  GParamSpec   *pspec)
-{
-  GbpCMakeToolchain *self = GBP_CMAKE_TOOLCHAIN (object);
-
-  switch (prop_id)
-    {
-    case PROP_FILE_PATH:
-      gbp_cmake_toolchain_set_file_path (self, g_value_get_string (value));
-      break;
-    default:
-      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
-    }
-}
-
 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",
                          "The path of the cross-file",
                          NULL,
-                         (G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
+                         (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
 
   g_object_class_install_properties (object_class, N_PROPS, properties);
 }
@@ -307,5 +278,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/cmake/gbp-cmake-toolchain.h b/src/plugins/cmake/gbp-cmake-toolchain.h
index 4ebfb1eca..8322d2fd9 100644
--- a/src/plugins/cmake/gbp-cmake-toolchain.h
+++ b/src/plugins/cmake/gbp-cmake-toolchain.h
@@ -25,14 +25,12 @@ G_BEGIN_DECLS
 
 #define GBP_TYPE_CMAKE_TOOLCHAIN (gbp_cmake_toolchain_get_type())
 
-G_DECLARE_FINAL_TYPE (GbpCMakeToolchain, gbp_cmake_toolchain, GBP, CMAKE_TOOLCHAIN, IdeToolchain)
+G_DECLARE_FINAL_TYPE (GbpCMakeToolchain, gbp_cmake_toolchain, GBP, CMAKE_TOOLCHAIN, IdeSimpleToolchain)
 
-GbpCMakeToolchain  *gbp_cmake_toolchain_new           (IdeContext           *context,
-                                                       GFile                *file);
+GbpCMakeToolchain  *gbp_cmake_toolchain_new           (IdeContext           *context);
 const gchar        *gbp_cmake_toolchain_get_file_path (GbpCMakeToolchain    *self);
-void                gbp_cmake_toolchain_set_file_path (GbpCMakeToolchain    *self,
-                                                       const gchar          *file_path);
 gboolean            gbp_cmake_toolchain_load          (GbpCMakeToolchain    *self,
                                                        GFile                *file,
+                                                       GCancellable         *cancellable,
                                                        GError              **error);
 G_END_DECLS
diff --git a/src/plugins/cmake/toolchain-info.ini.cmake b/src/plugins/cmake/toolchain-info.ini.cmake
index 4374214d5..eb65602dc 100644
--- a/src/plugins/cmake/toolchain-info.ini.cmake
+++ b/src/plugins/cmake/toolchain-info.ini.cmake
@@ -8,6 +8,7 @@ ar=@CMAKE_AR@
 pkg_config=@PKG_CONFIG_EXECUTABLE@
 
 [compilers]
+# The name of the compiler should be the language name as defined with IDE_TOOLCHAIN_LANGUAGE_ keys
 c=@CMAKE_C_COMPILER@
-cpp=@CMAKE_CXX_COMPILER@
+c++=@CMAKE_CXX_COMPILER@
 vala=@CMAKE_VALA_COMPILER@
diff --git a/src/plugins/meson/gbp-meson-toolchain-provider.c 
b/src/plugins/meson/gbp-meson-toolchain-provider.c
index f1b56cd2e..118815606 100644
--- a/src/plugins/meson/gbp-meson-toolchain-provider.c
+++ b/src/plugins/meson/gbp-meson-toolchain-provider.c
@@ -71,7 +71,7 @@ gbp_meson_toolchain_provider_load_worker (IdeTask      *task,
                                      cancellable,
                                      &file_error);
       content_type = g_file_info_get_content_type (file_info);
-      if (!g_content_type_is_mime_type (content_type, "text/plain"))
+      if (g_content_type_is_mime_type (content_type, "text/plain"))
         {
           g_autoptr(GKeyFile) keyfile = g_key_file_new ();
           g_autofree gchar *path = g_file_get_path (file);
diff --git a/src/plugins/meson/gbp-meson-toolchain.c b/src/plugins/meson/gbp-meson-toolchain.c
index beccc4ca5..bc1349418 100644
--- a/src/plugins/meson/gbp-meson-toolchain.c
+++ b/src/plugins/meson/gbp-meson-toolchain.c
@@ -23,16 +23,11 @@
 
 struct _GbpMesonToolchain
 {
-  IdeToolchain            parent_instance;
+  IdeSimpleToolchain      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)
+G_DEFINE_TYPE (GbpMesonToolchain, gbp_meson_toolchain, IDE_TYPE_SIMPLE_TOOLCHAIN)
 
 enum {
   PROP_0,
@@ -58,7 +53,7 @@ _g_key_file_get_string_quoted (GKeyFile     *key_file,
 }
 
 GbpMesonToolchain *
-gbp_meson_toolchain_new (IdeContext   *context)
+gbp_meson_toolchain_new (IdeContext *context)
 {
   g_autoptr(GbpMesonToolchain) toolchain = NULL;
 
@@ -72,6 +67,22 @@ gbp_meson_toolchain_new (IdeContext   *context)
   return g_steal_pointer (&toolchain);
 }
 
+static const gchar *
+meson_toolchain_get_language (const gchar *meson_tool_name)
+{
+  g_return_val_if_fail (meson_tool_name != NULL, NULL);
+
+  if (g_strcmp0 (meson_tool_name, "c") == 0)
+    return IDE_TOOLCHAIN_LANGUAGE_C;
+
+  if (g_strcmp0 (meson_tool_name, "cpp") == 0)
+    return IDE_TOOLCHAIN_LANGUAGE_CPLUSPLUS;
+
+  if (g_strcmp0 (meson_tool_name, "valac") == 0)
+    return IDE_TOOLCHAIN_LANGUAGE_VALA;
+
+  return meson_tool_name;
+}
 
 gboolean
 gbp_meson_toolchain_load (GbpMesonToolchain  *self,
@@ -110,33 +121,46 @@ gbp_meson_toolchain_load (GbpMesonToolchain  *self,
   for (int i = 0; binaries[i] != NULL; i++)
     {
       const gchar *lang = binaries[i];
-      g_autofree gchar *exec_path = NULL;
       g_autoptr(GError) key_error = NULL;
+      g_autofree gchar *exec_path = _g_key_file_get_string_quoted (keyfile, "binaries", lang, &key_error);
 
       if (g_strcmp0 (lang, "ar") == 0)
-        self->archiver = _g_key_file_get_string_quoted (keyfile, "binaries", lang, &key_error);
+        ide_simple_toolchain_set_tool_for_language (IDE_SIMPLE_TOOLCHAIN(self),
+                                                    IDE_TOOLCHAIN_LANGUAGE_ANY,
+                                                    IDE_TOOLCHAIN_TOOL_AR,
+                                                    exec_path);
       else if (g_strcmp0 (lang, "strip") == 0)
-        self->strip = _g_key_file_get_string_quoted (keyfile, "binaries", lang, &key_error);
+        ide_simple_toolchain_set_tool_for_language (IDE_SIMPLE_TOOLCHAIN(self),
+                                                    IDE_TOOLCHAIN_LANGUAGE_ANY,
+                                                    IDE_TOOLCHAIN_TOOL_STRIP,
+                                                    exec_path);
       else if (g_strcmp0 (lang, "pkg_config") == 0)
-        self->pkg_config = _g_key_file_get_string_quoted (keyfile, "binaries", lang, &key_error);
+        ide_simple_toolchain_set_tool_for_language (IDE_SIMPLE_TOOLCHAIN(self),
+                                                    IDE_TOOLCHAIN_LANGUAGE_ANY,
+                                                    IDE_TOOLCHAIN_TOOL_PKG_CONFIG,
+                                                    exec_path);
       else if (g_strcmp0 (lang, "exe_wrapper") == 0)
-        self->exe_wrapper = _g_key_file_get_string_quoted (keyfile, "binaries", lang, &key_error);
+        ide_simple_toolchain_set_tool_for_language (IDE_SIMPLE_TOOLCHAIN(self),
+                                                    IDE_TOOLCHAIN_LANGUAGE_ANY,
+                                                    IDE_TOOLCHAIN_TOOL_EXEC,
+                                                    exec_path);
       else
-        g_hash_table_insert (self->compilers,
-                             g_strdup (lang),
-                             _g_key_file_get_string_quoted (keyfile, "binaries", lang, &key_error));
+        ide_simple_toolchain_set_tool_for_language (IDE_SIMPLE_TOOLCHAIN(self),
+                                                    meson_toolchain_get_language (lang),
+                                                    IDE_TOOLCHAIN_TOOL_CC,
+                                                    exec_path);
     }
 
   return TRUE;
 }
 
 /**
- * ide_toolchain_get_id:
- * @self: an #IdeToolchain
+ * gbp_meson_toolchain_get_file_path:
+ * @self: an #GbpMesonToolchain
  *
- * Gets the internal identifier of the toolchain
+ * Gets the path to the Meson cross-file
  *
- * Returns: (transfer none): the unique identifier.
+ * Returns: (transfer none): the path to the Meson cross-file.
  *
  * Since: 3.30
  */
diff --git a/src/plugins/meson/gbp-meson-toolchain.h b/src/plugins/meson/gbp-meson-toolchain.h
index afd3e1de1..a150d409d 100644
--- a/src/plugins/meson/gbp-meson-toolchain.h
+++ b/src/plugins/meson/gbp-meson-toolchain.h
@@ -25,7 +25,7 @@ G_BEGIN_DECLS
 
 #define GBP_TYPE_MESON_TOOLCHAIN (gbp_meson_toolchain_get_type())
 
-G_DECLARE_FINAL_TYPE (GbpMesonToolchain, gbp_meson_toolchain, GBP, MESON_TOOLCHAIN, IdeToolchain)
+G_DECLARE_FINAL_TYPE (GbpMesonToolchain, gbp_meson_toolchain, GBP, MESON_TOOLCHAIN, IdeSimpleToolchain)
 
 GbpMesonToolchain  *gbp_meson_toolchain_new              (IdeContext             *context);
 gboolean            gbp_meson_toolchain_load             (GbpMesonToolchain      *self,


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