[gnome-builder] IdeBuildTarget: add get_cwd()



commit e891c0882620c91a7e65cc884f9a737943ab686a
Author: Giovanni Campagna <gcampagn cs stanford edu>
Date:   Sun Nov 26 12:44:46 2017 -0800

    IdeBuildTarget: add get_cwd()
    
    Some build systems (notably, npm), insist that their build targets
    be run in a specific working directory, or they'll misbehave.
    
    To allow BuildTargets and BuildTargetProviders specify that,
    introduce a vfunc get_cwd(). If this vfunc returns any non-NULL
    value, IdeRuntime uses it to set the cwd of the created IdeRunner.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=790846

 src/libide/buildsystem/ide-build-target.c |   30 +++++++++++++++++++++++++++++
 src/libide/buildsystem/ide-build-target.h |    3 ++
 src/libide/runtimes/ide-runtime.c         |    5 ++++
 3 files changed, 38 insertions(+), 0 deletions(-)
---
diff --git a/src/libide/buildsystem/ide-build-target.c b/src/libide/buildsystem/ide-build-target.c
index 890e547..be0dfaf 100644
--- a/src/libide/buildsystem/ide-build-target.c
+++ b/src/libide/buildsystem/ide-build-target.c
@@ -22,9 +22,16 @@
 
 G_DEFINE_INTERFACE (IdeBuildTarget, ide_build_target, IDE_TYPE_OBJECT)
 
+static gchar*
+ide_build_target_real_get_cwd (IdeBuildTarget *self)
+{
+  return NULL;
+}
+
 static void
 ide_build_target_default_init (IdeBuildTargetInterface *iface)
 {
+  iface->get_cwd = ide_build_target_real_get_cwd;
 }
 
 /**
@@ -122,3 +129,26 @@ ide_build_target_get_argv (IdeBuildTarget *self)
 
   return g_steal_pointer (&argv);
 }
+
+/**
+ * ide_build_target_get_cwd:
+ * @self: a #IdeBuildTarget
+ *
+ * For build systems and build target providers that insist to be run in
+ * a specific place, this method gets the correct working directory.
+ *
+ * If this method returns %NULL, the runtime will pick a default working
+ * directory for the spawned process (usually, the user home directory
+ * in the host system, or the flatpak sandbox home under flatpak).
+ *
+ * Returns: (nullable) (transfer full): the working directory to use for this target
+ *
+ * Since: 3.28
+ */
+gchar *
+ide_build_target_get_cwd (IdeBuildTarget *self)
+{
+  g_return_val_if_fail (IDE_IS_BUILD_TARGET (self), NULL);
+
+  return IDE_BUILD_TARGET_GET_IFACE (self)->get_cwd (self);
+}
diff --git a/src/libide/buildsystem/ide-build-target.h b/src/libide/buildsystem/ide-build-target.h
index 7af3904..9659190 100644
--- a/src/libide/buildsystem/ide-build-target.h
+++ b/src/libide/buildsystem/ide-build-target.h
@@ -38,6 +38,7 @@ struct _IdeBuildTargetInterface
   gchar  *(*get_name)              (IdeBuildTarget *self);
   gint    (*get_priority)          (IdeBuildTarget *self);
   gchar **(*get_argv)              (IdeBuildTarget *self);
+  gchar  *(*get_cwd)               (IdeBuildTarget *self);
 };
 
 IDE_AVAILABLE_IN_ALL
@@ -49,6 +50,8 @@ gint       ide_build_target_get_priority          (IdeBuildTarget       *self);
 IDE_AVAILABLE_IN_3_28
 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
 gboolean   ide_build_target_compare               (const IdeBuildTarget *left,
                                                    const IdeBuildTarget *right);
 
diff --git a/src/libide/runtimes/ide-runtime.c b/src/libide/runtimes/ide-runtime.c
index 7d538a4..ce182b7 100644
--- a/src/libide/runtimes/ide-runtime.c
+++ b/src/libide/runtimes/ide-runtime.c
@@ -169,6 +169,7 @@ ide_runtime_real_create_runner (IdeRuntime     *self,
   IdeRuntimePrivate *priv = ide_runtime_get_instance_private (self);
   g_autoptr(GFile) installdir = NULL;
   g_auto(GStrv) argv = NULL;
+  g_autofree gchar *cwd = NULL;
   IdeContext *context;
   IdeRunner *runner;
 
@@ -188,6 +189,7 @@ ide_runtime_real_create_runner (IdeRuntime     *self,
     {
       installdir = ide_build_target_get_install_directory (build_target);
       argv = ide_build_target_get_argv (build_target);
+      cwd = ide_build_target_get_cwd (build_target);
     }
 
   /* Possibly translate relative paths for the binary */
@@ -227,6 +229,9 @@ ide_runtime_real_create_runner (IdeRuntime     *self,
   if (argv != NULL)
     ide_runner_push_args (runner, (const gchar * const *)argv);
 
+  if (cwd != NULL)
+    ide_runner_set_cwd (runner, cwd);
+
   return runner;
 }
 


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