[gnome-builder] IdeBuildTarget: add get_language()



commit b2e1d33e070229375bbecfd099ceeaff89323d91
Author: Giovanni Campagna <gcampagn cs stanford edu>
Date:   Sun Nov 26 14:54:14 2017 -0800

    IdeBuildTarget: add get_language()
    
    Add a way to find the programming language of a build target.
    This will be used to weed out incompatible debuggers, profiling
    tools, etc.
    
    Cargo build targets are changed to return rust, NPM to return JS.
    Similarly, a future Cabal integration should say Haskell, Maven or ANT
    should say Java, etc.
    
    For now, automake, meson and cmake return "asm" (native code),
    because it's annoying to find if the build target is built from C,
    C++, Vala or Fortran, and it does not matter too much because gdb
    and valgrind can deal with it.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=790846

 src/libide/buildsystem/ide-build-target.c |   37 +++++++++++++++++++++++++++++
 src/libide/buildsystem/ide-build-target.h |    3 ++
 src/plugins/cargo/cargo_plugin.py         |    3 ++
 src/plugins/npm/npm_plugin.py             |    3 ++
 4 files changed, 46 insertions(+), 0 deletions(-)
---
diff --git a/src/libide/buildsystem/ide-build-target.c b/src/libide/buildsystem/ide-build-target.c
index be0dfaf..78dc767 100644
--- a/src/libide/buildsystem/ide-build-target.c
+++ b/src/libide/buildsystem/ide-build-target.c
@@ -28,10 +28,18 @@ ide_build_target_real_get_cwd (IdeBuildTarget *self)
   return NULL;
 }
 
+static gchar*
+ide_build_target_real_get_language (IdeBuildTarget *self)
+{
+  return g_strdup ("asm");
+}
+
+
 static void
 ide_build_target_default_init (IdeBuildTargetInterface *iface)
 {
   iface->get_cwd = ide_build_target_real_get_cwd;
+  iface->get_language = ide_build_target_real_get_language;
 }
 
 /**
@@ -152,3 +160,32 @@ ide_build_target_get_cwd (IdeBuildTarget *self)
 
   return IDE_BUILD_TARGET_GET_IFACE (self)->get_cwd (self);
 }
+
+/**
+ * ide_build_target_get_language:
+ * @self: a #IdeBuildTarget
+ *
+ * Return the main programming language that was used to
+ * write this build target.
+ *
+ * This method is primarily used to choose an appropriate
+ * debugger. Therefore, if a build target is composed of
+ * components in multiple language (eg. a GJS app with
+ * GObject Introspection libraries, or a Java app with JNI
+ * libraries), this should return the language that is
+ * most likely to be appropriate for debugging.
+ *
+ * The default implementation returns "asm", which indicates
+ * an unspecified language that compiles to native code.
+ *
+ * Returns: (transfer full): the programming language of this target
+ *
+ * Since: 3.28
+ */
+gchar *
+ide_build_target_get_language (IdeBuildTarget *self)
+{
+  g_return_val_if_fail (IDE_IS_BUILD_TARGET (self), NULL);
+
+  return IDE_BUILD_TARGET_GET_IFACE (self)->get_language (self);
+}
diff --git a/src/libide/buildsystem/ide-build-target.h b/src/libide/buildsystem/ide-build-target.h
index 9659190..64015ba 100644
--- a/src/libide/buildsystem/ide-build-target.h
+++ b/src/libide/buildsystem/ide-build-target.h
@@ -39,6 +39,7 @@ struct _IdeBuildTargetInterface
   gint    (*get_priority)          (IdeBuildTarget *self);
   gchar **(*get_argv)              (IdeBuildTarget *self);
   gchar  *(*get_cwd)               (IdeBuildTarget *self);
+  gchar  *(*get_language)          (IdeBuildTarget *self);
 };
 
 IDE_AVAILABLE_IN_ALL
@@ -52,6 +53,8 @@ gchar    **ide_build_target_get_argv              (IdeBuildTarget       *self);
 IDE_AVAILABLE_IN_3_28
 gchar     *ide_build_target_get_cwd               (IdeBuildTarget       *self);
 IDE_AVAILABLE_IN_3_28
+gchar     *ide_build_target_get_language          (IdeBuildTarget       *self);
+IDE_AVAILABLE_IN_3_28
 gboolean   ide_build_target_compare               (const IdeBuildTarget *left,
                                                    const IdeBuildTarget *right);
 
diff --git a/src/plugins/cargo/cargo_plugin.py b/src/plugins/cargo/cargo_plugin.py
index c49b563..adf462b 100644
--- a/src/plugins/cargo/cargo_plugin.py
+++ b/src/plugins/cargo/cargo_plugin.py
@@ -157,6 +157,9 @@ class CargoBuildTarget(Ide.Object, Ide.BuildTarget):
     def do_get_name(self):
         return 'cargo-run'
 
+    def do_get_language(self):
+        return 'rust'
+
     def do_get_argv(self):
         context = self.get_context()
         config_manager = context.get_configuration_manager()
diff --git a/src/plugins/npm/npm_plugin.py b/src/plugins/npm/npm_plugin.py
index dfe29a5..c5ced74 100644
--- a/src/plugins/npm/npm_plugin.py
+++ b/src/plugins/npm/npm_plugin.py
@@ -137,6 +137,9 @@ class NPMBuildTarget(Ide.Object, Ide.BuildTarget):
         project_file = context.get_project_file()
         return project_file.get_parent().get_path()
 
+    def do_get_language(self):
+        return 'js'
+
     def do_get_priority(self):
         if self._script == 'start':
             return -10


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